src/supertux/tile_set.cpp

Go to the documentation of this file.
00001 //  SuperTux
00002 //  Copyright (C) 2008 Matthias Braun <matze@braunis.de>
00003 //
00004 //  This program is free software: you can redistribute it and/or modify
00005 //  it under the terms of the GNU General Public License as published by
00006 //  the Free Software Foundation, either version 3 of the License, or
00007 //  (at your option) any later version.
00008 //
00009 //  This program is distributed in the hope that it will be useful,
00010 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
00011 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012 //  GNU General Public License for more details.
00013 //
00014 //  You should have received a copy of the GNU General Public License
00015 //  along with this program.  If not, see <http://www.gnu.org/licenses/>.
00016 
00017 #include "supertux/tile_set.hpp"
00018 
00019 #include "supertux/tile_set_parser.hpp"
00020 
00021 TileSet::TileSet() :
00022   tiles(),
00023   tiles_loaded(false)
00024 {
00025   tiles.resize(1, 0);
00026   tiles[0] = new Tile();
00027 }
00028 
00029 TileSet::TileSet(const std::string& filename) :
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 }
00067 
00068 TileSet::~TileSet()
00069 {
00070   if(tiles_loaded) {
00071     for(Tiles::iterator i = tiles.begin(); i != tiles.end(); ++i)
00072       delete *i;
00073   }
00074 }
00075 
00076 void TileSet::merge(const TileSet *tileset, uint32_t start, uint32_t end,
00077                     uint32_t offset)
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 }
00099 
00100 /* EOF */

Generated on Mon Jun 9 03:38:23 2014 for SuperTux by  doxygen 1.5.1