patterncsharpMinor
RoomModel class
Viewed 0 times
roommodelclassstackoverflow
Problem
I have coded a quick room model system, let me run you should how it exactly works
Example, a simple room model structure would be like below:
I am just looking for any way to improove it as I am self taught and would like to learn more about how C# can be optimized for better performance.
Here is my code:
```
using System;
namespace Sahara.Base.Game.Rooms
{
internal class RoomModel
{
private readonly bool _clubOnly;
private readonly int _doorX;
private readonly int _doorY;
private readonly double _doorZ;
private readonly int _doorDirection;
private readonly string _modelHeightmap;
private readonly int _modelSizeX;
private readonly int _modelSizeY;
private readonly int _wallHeight;
private readonly short[,] _squareFloorHeight;
private readonly byte[,] _squareSeatRotation;
private readonly SquareState[,] _squareState;
private readonly string _modelFurniMap;
private readonly bool _publicPool;
private readonly byte[,] _roomModelEffects;
public RoomModel(bool clubOnly, int doorPositionX, int doorPositionY, int wallHeight, double doorPositionZ, int doorDirection, string modelHeightMap, string modelFurniMap, string poolMap)
{
_doorX = doorPositionX;
_doorY = doorPositionY;
_doorZ = doorPositionZ;
_doorDirection = doorDirection;
_wallHeight = wallHeight;
_modelHeightmap = modelHeightMap.ToLower();
_modelFurniMap = modelFurniMap;
if (poolMap != string.Empty)
{
_publicPool = true;
_roomModelEffects = new byte[_modelSizeX, _mo
X = 1 square
0 = block square
1 = 1 level higher
2 = 2 levels higher
and so on...Example, a simple room model structure would be like below:
XXXXXXXXXX0XX
XXXXXXXXXX0XX
XXXXXXXXXX0XX
XXXXXXXXXX0XX
XXXXXXXXXX0XX
XXXXXXXXXX0XX
XXXXXXXXXX0XX
XXXXXXXXXX0XX
XXXXXXXXXX0XX
XXXXXXXXXX0XX
XXXXXXXXXX0XX
XXXXXXXXXX0XXI am just looking for any way to improove it as I am self taught and would like to learn more about how C# can be optimized for better performance.
Here is my code:
```
using System;
namespace Sahara.Base.Game.Rooms
{
internal class RoomModel
{
private readonly bool _clubOnly;
private readonly int _doorX;
private readonly int _doorY;
private readonly double _doorZ;
private readonly int _doorDirection;
private readonly string _modelHeightmap;
private readonly int _modelSizeX;
private readonly int _modelSizeY;
private readonly int _wallHeight;
private readonly short[,] _squareFloorHeight;
private readonly byte[,] _squareSeatRotation;
private readonly SquareState[,] _squareState;
private readonly string _modelFurniMap;
private readonly bool _publicPool;
private readonly byte[,] _roomModelEffects;
public RoomModel(bool clubOnly, int doorPositionX, int doorPositionY, int wallHeight, double doorPositionZ, int doorDirection, string modelHeightMap, string modelFurniMap, string poolMap)
{
_doorX = doorPositionX;
_doorY = doorPositionY;
_doorZ = doorPositionZ;
_doorDirection = doorDirection;
_wallHeight = wallHeight;
_modelHeightmap = modelHeightMap.ToLower();
_modelFurniMap = modelFurniMap;
if (poolMap != string.Empty)
{
_publicPool = true;
_roomModelEffects = new byte[_modelSizeX, _mo
Solution
One suggestion I'd make:
Instead of having so many fields in your class, it becomes much easier to write your code, if you break out related fields into sub classes e.g:
Instead of having so many fields in your class, it becomes much easier to write your code, if you break out related fields into sub classes e.g:
private class Door
{
public int X;
public int Y;
public double Z;
public int Direction;
}Code Snippets
private class Door
{
public int X;
public int Y;
public double Z;
public int Direction;
}Context
StackExchange Code Review Q#154175, answer score: 9
Revisions (0)
No revisions yet.