More effective method of freeing tilesets
authorTobias Markus <tobbi@mozilla-uk.org>
Sat, 28 Sep 2013 21:13:49 +0000 (23:13 +0200)
committerTobias Markus <tobbi@mozilla-uk.org>
Sat, 28 Sep 2013 21:13:49 +0000 (23:13 +0200)
src/supertux/resources.cpp
src/supertux/resources.hpp
src/supertux/tile_manager.hpp

index 589dcc6..17ef56b 100644 (file)
@@ -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;
index 8dc5b11..7466010 100644 (file)
@@ -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();
index 8d081ee..5d1317e 100644 (file)
@@ -26,6 +26,7 @@ class TileSet;
 
 class TileManager
 {
+  friend class Resources;
 private:
   typedef std::map<std::string, TileSet*> TileSets;
   TileSets tilesets;