2 // Copyright (C) 2008 Matthias Braun <matze@braunis.de>
4 // This program is free software: you can redistribute it and/or modify
5 // it under the terms of the GNU General Public License as published by
6 // the Free Software Foundation, either version 3 of the License, or
7 // (at your option) any later version.
9 // This program is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
14 // You should have received a copy of the GNU General Public License
15 // along with this program. If not, see <http://www.gnu.org/licenses/>.
17 #include "supertux/tile_set.hpp"
19 #include "supertux/tile_set_parser.hpp"
27 tiles[0] = new Tile(*this);
30 TileSet::TileSet(const std::string& filename) :
35 TileSetParser parser(*this, filename);
39 { // enable this if you want to see a list of free tiles
40 log_info << "Last Tile ID is " << tiles.size()-1 << std::endl;
42 for(int i = 0; i < int(tiles.size()); ++i)
44 if (tiles[i] == 0 && last == -1)
48 else if (tiles[i] && last != -1)
50 log_info << "Free Tile IDs (" << i - last << "): " << last << " - " << i-1 << std::endl;
57 { // enable this to dump the (large) list of tiles to log_debug
58 // Two dumps are identical iff the tilesets specify identical tiles
59 log_debug << "Tileset in " << filename << std::endl;
60 for(int i = 0; i < int(tiles.size()); ++i)
64 tiles[i]->print_debug(i);
73 for(Tiles::iterator i = tiles.begin(); i != tiles.end(); ++i)
78 void TileSet::merge(const TileSet *tileset, uint32_t start, uint32_t end,
81 for(uint32_t id = start; id <= end && id < tileset->tiles.size(); ++id) {
82 uint32_t dest_id = id - start + offset;
84 if(dest_id >= tiles.size())
85 tiles.resize(dest_id + 1, 0);
90 Tile *tile = tileset->tiles[id];
94 if(tiles[dest_id] != NULL) {
95 log_warning << "tileset merge resulted in multiple definitions for id "
96 << dest_id << "(originally " << id << ")" << std::endl;
98 tiles[dest_id] = tile;