Sunday, August 12, 2012

World Constructor

This time, I fixed an annoying heap corruption error in my world loading code. The code gets a pointer to a loaded string from the string input method, then uses it according to an algorithm to load a virtual 2D integer array of tile ID's. It turns out that I had one symbol wrong: I used '+' instead of '-' in my algorithm (actually a big deal). This caused weird memory problems that showed their ugly faces when I tried to delete the string, leading me to believe that the problem was in my loading method memory management (side note: the loading method was changed because according to Stack Overflow you aren't supposed to return a pointer to a std::string). Lesson learned: everything can be the problem, so don't leave anything out. After that, the loading method seemed to work just fine, but I couldn't test it because console output isn't working with SDL (it outputs to a file but there is no output).

Next, I will hook up the world data to a tilemap and graphics. I will have to pull the tiles from a sprite sheet, but I've done that before. I'm thinking I might use a map<int,SDL_Surface*> data structure, maybe in the world class or in an art class.

No comments:

Post a Comment