X-Git-Url: https://git.verplant.org/?a=blobdiff_plain;f=src%2Ftile_manager.h;h=961e07751cf91db5f3fb2449952074d01a717510;hb=2b18d7e2549f4be99533fed58c0f07887a19db37;hp=e05f6b38fc5dce5836ed175991a2396d7b5970f8;hpb=71e724e90583aae6541cf060792fc6c3deff8bdb;p=supertux.git diff --git a/src/tile_manager.h b/src/tile_manager.h index e05f6b38f..961e07751 100644 --- a/src/tile_manager.h +++ b/src/tile_manager.h @@ -25,8 +25,9 @@ #include #include #include - -class Tile; +#include +#include +#include "tile.h" struct TileGroup { @@ -41,36 +42,55 @@ struct TileGroup class TileManager { - private: - TileManager(); - ~TileManager(); - - typedef std::map 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(); + + 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]; + } - unsigned int total_ids() - { return tiles.size(); } + 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; + } + + int get_default_height() const + { + return 32; + } }; #endif - -/* EOF */