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"
26 tiles[0] = new Tile();
29 TileSet::TileSet(const std::string& filename) :
33 TileSetParser parser(*this, filename);
37 { // enable this if you want to see a list of free tiles
38 log_info << "Last Tile ID is " << tiles.size()-1 << std::endl;
40 for(int i = 0; i < int(tiles.size()); ++i)
42 if (tiles[i] == 0 && last == -1)
46 else if (tiles[i] && last != -1)
48 log_info << "Free Tile IDs (" << i - last << "): " << last << " - " << i-1 << std::endl;
55 { // enable this to dump the (large) list of tiles to log_debug
56 // Two dumps are identical iff the tilesets specify identical tiles
57 log_debug << "Tileset in " << filename << std::endl;
58 for(int i = 0; i < int(tiles.size()); ++i)
62 tiles[i]->print_debug(i);
71 for(Tiles::iterator i = tiles.begin(); i != tiles.end(); ++i)
76 void TileSet::merge(const TileSet *tileset, uint32_t start, uint32_t end,
79 for(uint32_t id = start; id <= end && id < tileset->tiles.size(); ++id) {
80 uint32_t dest_id = id - start + offset;
82 if(dest_id >= tiles.size())
83 tiles.resize(dest_id + 1, 0);
88 Tile *tile = tileset->tiles[id];
92 if(tiles[dest_id] != NULL) {
93 log_warning << "tileset merge resulted in multiple definitions for id "
94 << dest_id << "(originally " << id << ")" << std::endl;
96 tiles[dest_id] = tile;