X-Git-Url: https://git.verplant.org/?a=blobdiff_plain;f=src%2Ftile_manager.h;h=961e07751cf91db5f3fb2449952074d01a717510;hb=609794e5b7fb466ca1a53d7a2406e2a8ed547de8;hp=a72777b13e065974a629df4249f25b688cfa8d99;hpb=4768775a296265eea1afae5cf971b1706fc049fd;p=supertux.git diff --git a/src/tile_manager.h b/src/tile_manager.h index a72777b13..961e07751 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,47 +42,55 @@ 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; } +public: + TileManager(const std::string& filename); + ~TileManager(); - unsigned int total_ids() - { return tiles.size(); } + 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(tile->images.size() == 0 && tile->imagespecs.size() != 0) + tile->load_images(tiles_path); + + return tile; + } - Tile& get(unsigned int id) { + uint32_t get_max_tileid() const + { + return tiles.size(); + } + + int get_default_width() const + { + return 32; + } - 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]; - } + int get_default_height() const + { + return 32; } }; #endif - -/* EOF */