src/supertux/tile_manager.cpp

Go to the documentation of this file.
00001 //  SuperTux
00002 //  Copyright (C) 2004 Tobias Glaesser <tobi.web@gmx.de>
00003 //  Copyright (C) 2006 Matthias Braun <matze@braunis.de>
00004 //
00005 //  This program is free software: you can redistribute it and/or modify
00006 //  it under the terms of the GNU General Public License as published by
00007 //  the Free Software Foundation, either version 3 of the License, or
00008 //  (at your option) any later version.
00009 //
00010 //  This program is distributed in the hope that it will be useful,
00011 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
00012 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013 //  GNU General Public License for more details.
00014 //
00015 //  You should have received a copy of the GNU General Public License
00016 //  along with this program.  If not, see <http://www.gnu.org/licenses/>.
00017 
00018 #include "supertux/tile_manager.hpp"
00019 
00020 #include <limits>
00021 
00022 #include "lisp/list_iterator.hpp"
00023 #include "supertux/tile_set.hpp"
00024 
00025 TileManager::TileManager() :
00026   tilesets()
00027 {
00028 }
00029 
00030 TileManager::~TileManager()
00031 {
00032 }
00033 
00034 TileSet* TileManager::get_tileset(const std::string &filename)
00035 {
00036   TileSets::const_iterator i = tilesets.find(filename);
00037   if(i != tilesets.end())
00038     return i->second;
00039 
00040   std::auto_ptr<TileSet> tileset (new TileSet(filename));
00041   tilesets.insert(std::make_pair(filename, tileset.get()));
00042 
00043   return tileset.release();
00044 }
00045 
00046 TileSet* TileManager::parse_tileset_definition(const Reader& reader)
00047 {
00048   std::auto_ptr<TileSet> result(new TileSet());
00049 
00050   lisp::ListIterator iter(&reader);
00051   while(iter.next()) {
00052     const std::string& token = iter.item();
00053     if(token != "tileset") {
00054       log_warning << "Skipping unrecognized token \"" << token << "\" in tileset definition" << std::endl;
00055       continue;
00056     }
00057     const lisp::Lisp* tileset_reader = iter.lisp();
00058 
00059     std::string file; 
00060     if (!tileset_reader->get("file", file)) {
00061       log_warning << "Skipping tileset import without file name" << std::endl;
00062       continue;
00063     }
00064 
00065     const TileSet *tileset = get_tileset(file);
00066 
00067     uint32_t start  = 0;
00068     uint32_t end    = std::numeric_limits<uint32_t>::max();
00069     uint32_t offset = 0;
00070     tileset_reader->get("start",  start);
00071     tileset_reader->get("end",    end);
00072     tileset_reader->get("offset", offset);
00073 
00074     result->merge(tileset, start, end, offset);
00075   }
00076 
00077   return result.release();
00078 }
00079 
00080 /* EOF */

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