I have coded a quick room model system, let me run you should how it exactly works
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
XXXXXXXXXX0XX
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, _modelSizeY];
}
var temporaryHeightmap = _modelHeightmap.Split(Convert.ToChar(13));
_modelSizeX = temporaryHeightmap[0].Length;
_modelSizeY = temporaryHeightmap.Length;
_clubOnly = clubOnly;
_squareState = new SquareState[_modelSizeX, _modelSizeY];
_squareFloorHeight = new short[_modelSizeX, _modelSizeY];
_squareSeatRotation = new byte[_modelSizeX, _modelSizeY];
for (var y = 0; y < _modelSizeY; y++)
{
var line = temporaryHeightmap[y];
line = line.Replace("\r", "");
line = line.Replace("\n", "");
var x = 0;
foreach (var modelSquare in line)
{
if (modelSquare == 'x')
{
_squareState[x, y] = SquareState.Blocked;
}
else
{
_squareState[x, y] = SquareState.Open;
_squareFloorHeight[x, y] = ParseModelSquare(modelSquare);
}
x++;
}
}
}
public static short ParseModelSquare(char input)
{
switch (input)
{
case '0':
return 0;
case '1':
return 1;
case '2':
return 2;
case '3':
return 3;
case '4':
return 4;
case '5':
return 5;
case '6':
return 6;
case '7':
return 7;
case '8':
return 8;
case '9':
return 9;
case 'a':
return 10;
case 'b':
return 11;
case 'c':
return 12;
case 'd':
return 13;
case 'e':
return 14;
case 'f':
return 15;
case 'g':
return 16;
case 'h':
return 17;
case 'i':
return 18;
case 'j':
return 19;
case 'k':
return 20;
case 'l':
return 21;
case 'm':
return 22;
case 'n':
return 23;
case 'o':
return 24;
case 'p':
return 25;
case 'q':
return 26;
case 'r':
return 27;
case 's':
return 28;
case 't':
return 29;
case 'u':
return 30;
case 'v':
return 31;
case 'w':
return 32;
default:
throw new FormatException("The input was not in a correct format: input must be between (0-k)");
}
}
}
}