From 0dbb74fca20b0525d6d111ade609447683f647f7 Mon Sep 17 00:00:00 2001 From: Tobias Markus Date: Sat, 28 Sep 2013 23:13:49 +0200 Subject: [PATCH] More effective method of freeing tilesets --- src/supertux/resources.cpp | 21 ++++++--------------- src/supertux/resources.hpp | 5 ----- src/supertux/tile_manager.hpp | 1 + 3 files changed, 7 insertions(+), 20 deletions(-) diff --git a/src/supertux/resources.cpp b/src/supertux/resources.cpp index 589dcc6e2..17ef56b3c 100644 --- a/src/supertux/resources.cpp +++ b/src/supertux/resources.cpp @@ -36,10 +36,6 @@ SurfacePtr Resources::back; SurfacePtr Resources::arrow_left; SurfacePtr Resources::arrow_right; -TileSet* Resources::general_tiles; -TileSet* Resources::worldmap_tiles; -TileSet* Resources::iceworld_tiles; - /* Load graphics/sounds shared between all levels: */ void Resources::load_shared() @@ -63,11 +59,6 @@ Resources::load_shared() tile_manager = new TileManager(); sprite_manager = new SpriteManager(); - - /* Create a reference to tilesets */ - general_tiles = tile_manager->get_tileset("images/tiles.strf"); - worldmap_tiles = tile_manager->get_tileset("images/worldmap.strf"); - iceworld_tiles = tile_manager->get_tileset("images/ice_world.strf"); } /* Free shared data: */ @@ -88,12 +79,12 @@ Resources::unload_shared() big_font.reset(); /* Free tilesets */ - delete worldmap_tiles; - worldmap_tiles = NULL; - delete general_tiles; - general_tiles = NULL; - delete iceworld_tiles; - iceworld_tiles = NULL; + for(TileManager::TileSets::iterator it = tile_manager->tilesets.begin(); + it != tile_manager->tilesets.end(); ++it) + { + delete it->second; + it->second = NULL; + } delete sprite_manager; sprite_manager = NULL; diff --git a/src/supertux/resources.hpp b/src/supertux/resources.hpp index 8dc5b119a..746601028 100644 --- a/src/supertux/resources.hpp +++ b/src/supertux/resources.hpp @@ -39,11 +39,6 @@ public: static SurfacePtr back; static SurfacePtr arrow_left; static SurfacePtr arrow_right; - -private: - static TileSet* general_tiles; - static TileSet* worldmap_tiles; - static TileSet* iceworld_tiles; public: static void load_shared(); diff --git a/src/supertux/tile_manager.hpp b/src/supertux/tile_manager.hpp index 8d081ee36..5d1317ea2 100644 --- a/src/supertux/tile_manager.hpp +++ b/src/supertux/tile_manager.hpp @@ -26,6 +26,7 @@ class TileSet; class TileManager { + friend class Resources; private: typedef std::map TileSets; TileSets tilesets; -- 2.11.0