So far I've come up with 3 different ways that I could go about storing the maps in memory:
- A 3-Dimensional vector
A 1-Dimensional vector with an algorithm that finds the appropriate index for any particular tile
A 1-Dimensional vector storing a Layer class object for each layer, each of which contains a 1D (with index algorithm) vector storing tile data.
Code: Select all
//declaration
vector<vector<vector<Tile*>>> mapData;
//accessing contents
mapData[layer][x][y]->getTileType();
Code: Select all
//declaration
vector<Tile*> mapData;
//accessing contents
int tempTileNumber = GetTileNumber(layer, x, y);
mapData[tempTileNumber]->getTileType();
//Index finding function
int GetTileNumber(int layer, int x, int y)
{
int tempa = x / tileWidth;
int tempb = y / tileHeight;
//Note: first layer is 0
int tilenum = layer * tilesPerLayer + tempa + tempb * tilesPerRow;
return tilenum;
}
Level.cpp
Code: Select all
//declaration
vector<Layer*> layerData;
//accessing contents
mapData[layer]->layerGetTileType(x, y);
Code: Select all
//declaration
vector<Tile*> tileData;
//Index finding function
int GetTileNumber(int layer, int x, int y)
{
int tempa = x / tileWidth;
int tempb = y / tileHeight;
//Note: first layer is 0
int tilenum = layer * tilesPerLayer + tempa + tempb * tilesPerRow;
return tilenum;
}
//returns tile type
int layerGetTileType(int x, int y)
{
int tempTileNumber = GetTileNumber( x, y);
return tileData[tempTileNumber]->getTileType();
}
Any opinions regarding ease of use later in the project, performance hits, etc. are much appreciated.