updated squirrel version
[supertux.git] / src / tile_manager.h
index a55fcb8..6eb0506 100644 (file)
 #include <set>
 #include <vector>
 #include <string>
-
-class Tile;
+#include <map>
+#include <stdint.h>
+#include <assert.h>
+#include "tile.h"
 
 struct TileGroup
 {
@@ -40,43 +42,56 @@ struct TileGroup
 
 class TileManager
 {
- private:
-  TileManager();
-  ~TileManager();
-  
-  std::vector<Tile*> tiles;
+private:
+  typedef std::vector<Tile*> Tiles;
+  Tiles tiles;
+
   static TileManager* instance_ ;
-  static std::set<TileGroup>* tilegroups_;
-  void load_tileset(std::string filename);
+  std::set<TileGroup> tilegroups;
 
-  std::string current_tileset;
+  std::string tiles_path;
   
- public:
-  static TileManager* instance()
-  { return instance_ ? instance_ : instance_ = new TileManager(); }
-  static void destroy_instance()
-  { delete instance_; instance_ = 0; }
+  void load_tileset(std::string filename);
 
-  void draw_tile(DrawingContext& context, unsigned int id,
-      const Vector& pos, int layer);
-  
-  static std::set<TileGroup>* tilegroups() { if(!instance_) { instance_ = new TileManager(); } return tilegroups_ ? tilegroups_ : tilegroups_ = new std::set<TileGroup>; }
-  Tile& get(unsigned int id) {
+public:
+  TileManager(const std::string& filename);
+  ~TileManager();
+
+  const std::set<TileGroup>& get_tilegroups() const
+  {
+    return tilegroups;
+  }
+
+  const Tile* get(uint32_t id) const
+  {
+    //FIXME: Commenting out tiles in sprites.strf makes tiles.size() fail - it's being set to the first tile commented out.
+    assert(id < tiles.size());
+    Tile* tile = tiles[id];
+    if(!tile) {
+      std::cout << "TileManager: Invalid tile: " << id << std::endl;
+      return tiles[0];
+    }
 
-    if(id < tiles.size())
-      {
-        return *tiles[id]; 
-      }
-    else
-      {
-        // Never return 0, but return the 0th tile instead so that
-        // user code doesn't have to check for NULL pointers all over
-        // the place
-        return *tiles[0]; 
-      } 
+    if(tile->images.size() == 0 && tile->imagespecs.size() != 0)
+      tile->load_images(tiles_path);
+    
+    return tile;
+  }
+
+  uint32_t get_max_tileid() const
+  {
+    return tiles.size();
+  }
+
+  int get_default_width() const
+  {
+    return 32;
+  }
+
+  int get_default_height() const
+  {
+    return 32;
   }
 };
 
 #endif
-
-/* EOF */