Closed btstevens89 closed 10 years ago
Hey pretty sweet! As a side note I learned a bit back that SDL2 also has render to texture support so that would probably be quicker than doing the blitting to build the map since it'll be done on the GPU, but that could be changed later since it may require a bunch of reworking of other parts of the code. Eventually I'd like to rewrite most of the project anyway since it's kind of ended up being a bit of mess design-wise but since I'm focusing more on some other projects that may not be for a long time.
The cool thing about the way it's working now is that it'll only have to be blitted once. After that we keep the texture in memory and only recreate it from scratch when there's a new tile placed. That could be optimized to just blit the new tile over the existing map, but i'll save that for another day. It's only a problem when working with huge maps.
Oh yea, the idea/technique would be the same but just instead of blitting the tiles onto the map we'd use the map as a render target and draw the tiles on the map like that instead. Although I doubt there would be much difference except for pretty big maps.
I've reworked the way we Save, Load, and Draw Maps.
Save - Maps are in their own folder in /res/maps. They consist of 'rows', 'columns' and 'tiles' attributes. -tiles are name/index pairs where each name has a list of indicies for where the tile should be drawn based on the # of rows and columns.
Load Maps are loaded through the game state's 'Map' attribute. This should link to a map in the /res/maps directory.
Draw Maps now are only created once. On the first click we create the map texture and save it into memory. All subsequent draws use the prerendered image. Calling Map->RebuildMap() will force a redraw.