#include <tile_set.hpp>
Public Member Functions | |
TileSet () | |
~TileSet () | |
void | merge (const TileSet *tileset, uint32_t start, uint32_t end, uint32_t offset) |
const Tile * | get (const uint32_t id) const |
uint32_t | get_max_tileid () const |
Private Types | |
typedef std::vector< Tile * > | Tiles |
Private Member Functions | |
TileSet (const std::string &filename) | |
Private Attributes | |
Tiles | tiles |
bool | tiles_loaded |
Friends | |
class | TileManager |
class | Tile |
class | TileSetParser |
Definition at line 27 of file tile_set.hpp.
typedef std::vector<Tile*> TileSet::Tiles [private] |
Definition at line 30 of file tile_set.hpp.
TileSet::TileSet | ( | const std::string & | filename | ) | [private] |
Definition at line 29 of file tile_set.cpp.
References log_debug, log_info, TileSetParser::parse(), and tiles.
00029 : 00030 tiles(), 00031 tiles_loaded(true) 00032 { 00033 TileSetParser parser(*this, filename); 00034 parser.parse(); 00035 00036 if (0) 00037 { // enable this if you want to see a list of free tiles 00038 log_info << "Last Tile ID is " << tiles.size()-1 << std::endl; 00039 int last = -1; 00040 for(int i = 0; i < int(tiles.size()); ++i) 00041 { 00042 if (tiles[i] == 0 && last == -1) 00043 { 00044 last = i; 00045 } 00046 else if (tiles[i] && last != -1) 00047 { 00048 log_info << "Free Tile IDs (" << i - last << "): " << last << " - " << i-1 << std::endl; 00049 last = -1; 00050 } 00051 } 00052 } 00053 00054 if (0) 00055 { // enable this to dump the (large) list of tiles to log_debug 00056 // Two dumps are identical iff the tilesets specify identical tiles 00057 log_debug << "Tileset in " << filename << std::endl; 00058 for(int i = 0; i < int(tiles.size()); ++i) 00059 { 00060 if(tiles[i] != 0) 00061 { 00062 tiles[i]->print_debug(i); 00063 } 00064 } 00065 } 00066 }
TileSet::TileSet | ( | ) |
Definition at line 21 of file tile_set.cpp.
00021 : 00022 tiles(), 00023 tiles_loaded(false) 00024 { 00025 tiles.resize(1, 0); 00026 tiles[0] = new Tile(); 00027 }
TileSet::~TileSet | ( | ) |
Definition at line 68 of file tile_set.cpp.
References tiles, and tiles_loaded.
00069 { 00070 if(tiles_loaded) { 00071 for(Tiles::iterator i = tiles.begin(); i != tiles.end(); ++i) 00072 delete *i; 00073 } 00074 }
void TileSet::merge | ( | const TileSet * | tileset, | |
uint32_t | start, | |||
uint32_t | end, | |||
uint32_t | offset | |||
) |
Definition at line 76 of file tile_set.cpp.
References log_warning, and tiles.
00078 { 00079 for(uint32_t id = start; id <= end && id < tileset->tiles.size(); ++id) { 00080 uint32_t dest_id = id - start + offset; 00081 00082 if(dest_id >= tiles.size()) 00083 tiles.resize(dest_id + 1, 0); 00084 00085 if(dest_id == 0) 00086 continue; 00087 00088 Tile *tile = tileset->tiles[id]; 00089 if(tile == NULL) 00090 continue; 00091 00092 if(tiles[dest_id] != NULL) { 00093 log_warning << "tileset merge resulted in multiple definitions for id " 00094 << dest_id << "(originally " << id << ")" << std::endl; 00095 } 00096 tiles[dest_id] = tile; 00097 } 00098 }
const Tile* TileSet::get | ( | const uint32_t | id | ) | const [inline] |
Definition at line 48 of file tile_set.hpp.
References log_warning, and tiles.
Referenced by TileMap::draw(), TileMap::get_tile(), TileMap::get_tile_at(), TileMap::set(), and TileMap::TileMap().
00049 { 00050 assert(id < tiles.size()); 00051 Tile* tile = tiles[id]; 00052 if(!tile) { 00053 log_warning << "Invalid tile: " << id << std::endl; 00054 return tiles[0]; 00055 } 00056 00057 tile->load_images(); 00058 00059 return tile; 00060 }
uint32_t TileSet::get_max_tileid | ( | ) | const [inline] |
Definition at line 62 of file tile_set.hpp.
References tiles.
00063 { 00064 return tiles.size(); 00065 }
friend class TileManager [friend] |
Definition at line 35 of file tile_set.hpp.
friend class Tile [friend] |
friend class TileSetParser [friend] |
Definition at line 37 of file tile_set.hpp.
Tiles TileSet::tiles [private] |
Definition at line 31 of file tile_set.hpp.
Referenced by get(), get_max_tileid(), merge(), TileSetParser::parse(), TileSetParser::parse_tile(), TileSetParser::parse_tiles(), TileSet(), and ~TileSet().
bool TileSet::tiles_loaded [private] |