0

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
    }
}
DarkGuardsman
  • 126
  • 4
  • 15
  • Variables do take up memory, but not enough to worry about (check out [this](http://stackoverflow.com/questions/26965896/java-performance-is-storing-a-hashmap-value-in-a-variable-redundant/26966017#26966017) post). If it makes your code easier to manage, use the extra variable. As for the tile ID, I'm not sure what purpose it's supposed to serve. Is ID suppose to represent where the tile is located? Why not use an x and y coord system? – Vince Nov 20 '14 at 18:53
  • I updated the post to explain the code. The tile is only created once so it does not store location data. It only controls what it does and looks like at each location. Placement of each tile is stored in the map. I didn't design it to work this way as i'm building on existing code. Also ty for the link that answers that question :) – DarkGuardsman Nov 20 '14 at 19:21

0 Answers0