FIFE
2008.0
|
00001 /*************************************************************************** 00002 * Copyright (C) 2005-2008 by the FIFE team * 00003 * http://www.fifengine.de * 00004 * This file is part of FIFE. * 00005 * * 00006 * FIFE is free software; you can redistribute it and/or * 00007 * modify it under the terms of the GNU Lesser General Public * 00008 * License as published by the Free Software Foundation; either * 00009 * version 2.1 of the License, or (at your option) any later version. * 00010 * * 00011 * This library is distributed in the hope that it will be useful, * 00012 * but WITHOUT ANY WARRANTY; without even the implied warranty of * 00013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * 00014 * Lesser General Public License for more details. * 00015 * * 00016 * You should have received a copy of the GNU Lesser General Public * 00017 * License along with this library; if not, write to the * 00018 * Free Software Foundation, Inc., * 00019 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * 00020 ***************************************************************************/ 00021 00022 #ifndef FIFE_MAP_MAP_H 00023 #define FIFE_MAP_MAP_H 00024 00025 // Standard C++ library includes 00026 #include <list> 00027 #include <string> 00028 #include <vector> 00029 00030 // 3rd party library includes 00031 00032 // FIFE includes 00033 // These includes are split up in two parts, separated by one empty line 00034 // First block: files included from the FIFE root src directory 00035 // Second block: files included from the same folder 00036 #include "util/base/resourceclass.h" 00037 #include "util/resource/resource.h" 00038 #include "model/metamodel/timeprovider.h" 00039 #include "util/structures/rect.h" 00040 00041 #include "location.h" 00042 00043 namespace FIFE { 00044 00045 class RendererBase; 00046 class RenderBackend; 00047 class ImagePool; 00048 class AnimationPool; 00049 class Layer; 00050 class CellGrid; 00051 class Map; 00052 class Camera; 00053 00056 class MapChangeListener { 00057 public: 00058 virtual ~MapChangeListener() {}; 00059 00067 virtual void onMapChanged(Map* map, std::vector<Layer*>& changedLayers) = 0; 00068 00073 virtual void onLayerCreate(Map* map, Layer* layer) = 0; 00074 00080 virtual void onLayerDelete(Map* map, Layer* layer) = 0; 00081 }; 00082 00088 class Map : public ResourceClass { 00089 public: 00090 00095 Map(const std::string& identifier, RenderBackend* renderbackend, 00096 const std::vector<RendererBase*>& renderers, ImagePool* imagepool, 00097 AnimationPool* animpool, TimeProvider* tp_master=NULL); 00098 00101 ~Map(); 00102 00105 const std::string& getId() const { return m_id; } 00106 00109 void setId(const std::string& id) { m_id = id; } 00110 00113 Layer* createLayer(const std::string& identifier, CellGrid* grid); 00114 00117 void deleteLayer(Layer*); 00118 00121 const std::list<Layer*>& getLayers() const { return m_layers; } 00122 00125 Layer* getLayer(const std::string& identifier); 00126 00129 uint32_t getNumLayers() const; 00130 00133 void deleteLayers(); 00134 00137 void getMatchingCoordinates(const ModelCoordinate& coord_to_map, const Layer* from_layer, 00138 const Layer* to_layer, std::vector<ModelCoordinate>& matching_coords) const; 00139 00143 bool update(); 00144 00147 void setTimeMultiplier(float multip) { m_timeprovider.setMultiplier(multip); } 00148 00151 float getTimeMultiplier() const { return m_timeprovider.getMultiplier(); } 00152 00155 TimeProvider* getTimeProvider() { return &m_timeprovider; } 00156 00160 void addChangeListener(MapChangeListener* listener); 00161 00165 void removeChangeListener(MapChangeListener* listener); 00166 00169 bool isChanged() { return !m_changedlayers.empty(); } 00170 00173 std::vector<Layer*>& getChangedLayers() { return m_changedlayers; } 00174 00178 Camera* addCamera(const std::string& id, Layer *layer, const Rect& viewport); 00179 00182 void removeCamera(const std::string& id); 00183 00186 Camera* getCamera(const std::string& id); 00187 00190 std::vector<Camera*>& getCameras(); 00191 00192 private: 00193 std::string m_id; 00194 00195 std::list<Layer*> m_layers; 00196 TimeProvider m_timeprovider; 00197 00198 Map(const Map& map); 00199 Map& operator=(const Map& map); 00200 00201 // listeners for map changes 00202 std::vector<MapChangeListener*> m_changelisteners; 00203 00204 // holds changed layers after each update 00205 std::vector<Layer*> m_changedlayers; 00206 00207 // holds the cameras attached to this map 00208 std::vector<Camera*> m_cameras; 00209 00210 RenderBackend* m_renderbackend; 00211 ImagePool* m_imagepool; 00212 AnimationPool* m_animpool; 00213 00214 // holds handles to all created renderers 00215 std::vector<RendererBase*> m_renderers; 00216 00217 // true, if something was changed on map during previous update (layer change, creation, deletion) 00218 bool m_changed; 00219 }; 00220 00221 } //FIFE 00222 00223 #endif 00224 /* vim: set noexpandtab: set shiftwidth=2: set tabstop=2: */