HiveBrain v1.2.0
Get Started
← Back to all entries
patterncsharpMinor

RoomModel class

Submitted by: @import:stackexchange-codereview··
0
Viewed 0 times
roommodelclassstackoverflow

Problem

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, _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:

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.