I have implemented a map loading logic in this 2d sidescroller i'm making and it work. But recently, i've questionned if what i did was the right way to do it and if it won't screw me in the future.
One of the first thing i've coded in my game engin is the map loading logic.
The way i did is read a large text file from disk and store it's content into a string.
For reference the text file is formatted in this way:
Header~Tile1Param1;Tile1Param2;Tile1ParamN;~Tile2Param1;Tile2ParamN;~TileNParamN;~
as you can see, each cell is seperated by '~' and the cell parameters by ';'. To sort everything i tokenize the whole string into tile then for each tile i retokenize to extract the parameters and finaly feed this tile to the game engine.
But the problem is i do several thousands tokenize to get to that end. I've done some test and load time "seems" okay with a map size of half a million tiles (750 tile by 750 tile. Each tile is 16 pixel wide). If i could improve this, i wouldn't have to limit myself to that size.
Beside this performance issue, i'm wondering if this is the right approche for the future? What will happens when i will use something else than a txt file? Right now, i'm loading a map when the actor pass throught the door trigger. Should i preload all adjacent map before this time?
By the way, just for the curious, this is my tokenize function that i call.
//////////////////////////////////////////////////////////////////////////
//
void CMapManager::Tokenize(vector<string> &tokens, const string &str, char delim)
{
stringstream ss(str); //convert string to stream
string item;
while(getline(ss, item, delim)) {
tokens.push_back(item); //add token to vector
}
}
I am very sorry if my english sound terrible and thank you for your time.