X-Git-Url: https://git.verplant.org/?a=blobdiff_plain;f=src%2Ftile_manager.h;h=db8a70ccb88bbf6cb3bfb91df5fdac243f54700d;hb=74dd78e6fe41f686057eeca65a88dc23547f9803;hp=a55fcb84d8f228fe04af0fce23835ab9bc9665a1;hpb=c79b901309bf5e0544fef1e92d264f51402f4370;p=supertux.git diff --git a/src/tile_manager.h b/src/tile_manager.h index a55fcb84d..db8a70ccb 100644 --- a/src/tile_manager.h +++ b/src/tile_manager.h @@ -24,8 +24,10 @@ #include #include #include - -class Tile; +#include +#include +#include +#include "tile.h" struct TileGroup { @@ -40,43 +42,45 @@ struct TileGroup class TileManager { - private: - TileManager(); - ~TileManager(); - - std::vector tiles; +private: + typedef std::vector Tiles; + Tiles tiles; + static TileManager* instance_ ; - static std::set* tilegroups_; - void load_tileset(std::string filename); + std::set 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* tilegroups() { if(!instance_) { instance_ = new TileManager(); } return tilegroups_ ? tilegroups_ : tilegroups_ = new std::set; } - Tile& get(unsigned int id) { +public: + TileManager(const std::string& filename); + ~TileManager(); + + const std::set& get_tilegroups() const + { + return tilegroups; + } + + const Tile* get(uint32_t id) const + { + 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(); } }; #endif - -/* EOF */