Which is better for a Tile map storing a reference to the tile or tile id

97 views Asked by At

I'm working on some JUnit code and this though came to mind. When it comes to creating tile(2D or 3D) based maps what is the idea way to store the tile at a location. Currently the game i'm working on stores it by using an ID. For my JUnits for the game i've been using the reference since the tests are only 16x256x16 sized maps. Without knowing some good memory tools i have no way to test which is more effect. As well i'm unsure which is easier on the processor.

Addition question to this does a reference to a variable use memory?

Bellow is the code. Tile once creates is used for basic information on what the tile looks like etc. It has an id which is used to reference what it is when saved/loaded. MapA and MapB are two different examples of how i want to store a basic test map. Coord system is the map matrix of [x][y][z].

public class Tile
{
   public int id = 0; //Assign when the tile is registered can be 0 - 4096
   //... rest of tile code which is not important
}

public class MapA
{
    int[][][] map = new int[16][256][16]
}

public class MapB
{
    Data[][][] map = new Data[16][256][16]

    public static class Data
    {
       Tile tile;
       int tileRotation;
       // Data that goes with the tile
    }
}
0

There are 0 answers