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_LAYER_H 00023 #define FIFE_LAYER_H 00024 00025 // Standard C++ library includes 00026 #include <algorithm> 00027 #include <string> 00028 #include <vector> 00029 #include <set> 00030 00031 // 3rd party library includes 00032 00033 // FIFE includes 00034 // These includes are split up in two parts, separated by one empty line 00035 // First block: files included from the FIFE root src directory 00036 // Second block: files included from the same folder 00037 #include "util/base/resourceclass.h" 00038 #include "model/metamodel/modelcoords.h" 00039 #include "model/metamodel/object.h" 00040 00041 #include "instance.h" 00042 00043 namespace FIFE { 00044 00045 class Map; 00046 class Selection; 00047 class CellGrid; 00048 class Object; 00049 class InstanceTree; 00050 00057 enum PathingStrategy { 00058 CELL_EDGES_ONLY, 00059 CELL_EDGES_AND_DIAGONALS, 00060 FREEFORM 00061 }; 00062 00065 class LayerChangeListener { 00066 public: 00067 virtual ~LayerChangeListener() {}; 00068 00074 virtual void onLayerChanged(Layer* layer, std::vector<Instance*>& changedInstances) = 0; 00075 00080 virtual void onInstanceCreate(Layer* layer, Instance* instance) = 0; 00081 00087 virtual void onInstanceDelete(Layer* layer, Instance* instance) = 0; 00088 }; 00089 00090 00093 class Layer : public ResourceClass { 00094 public: 00099 Layer(const std::string& identifier, Map* map, CellGrid* grid); 00100 00103 ~Layer(); 00104 00107 const std::string& getId() const { return m_id; } 00108 00111 void setId(const std::string& id) { m_id = id; } 00112 00115 Map* getMap() const { return m_map; } 00116 00120 CellGrid* getCellGrid() const { return m_grid; } 00121 00124 void setCellGrid(CellGrid* grid) { m_grid = grid; } 00125 00129 InstanceTree* getInstanceTree(void) const { return m_instanceTree; } 00130 00134 bool hasInstances() const; 00135 00138 Instance* createInstance(Object* object, const ModelCoordinate& p, const std::string& id=""); 00139 00142 Instance* createInstance(Object* object, const ExactModelCoordinate& p, const std::string& id=""); 00143 00147 bool addInstance(Instance* instance, const ExactModelCoordinate& p); 00148 00151 void deleteInstance(Instance* object); 00152 00155 const std::vector<Instance*>& getInstances() const { return m_instances; } 00156 00159 std::vector<Instance*> getInstances(const std::string& id); 00160 00165 std::vector<Instance*> getInstancesAt(Location& loc, bool use_exactcoordinates=false); 00166 00169 Instance* getInstance(const std::string& identifier); 00170 00173 void setInstancesVisible(bool vis); 00174 00178 void setLayerTransparency(uint8_t transparency); 00179 00182 uint8_t getLayerTransparency(); 00183 00189 void getMinMaxCoordinates(ModelCoordinate& min, ModelCoordinate& max, const Layer* layer = 0) const; 00190 00196 bool cellContainsBlockingInstance(const ModelCoordinate& cellCoordinate); 00197 00201 void toggleInstancesVisible(); 00202 00206 bool areInstancesVisible() const { return m_instances_visibility; } 00207 00211 bool update(); 00212 00216 void setPathingStrategy(PathingStrategy strategy) { m_pathingstrategy = strategy; } 00217 00221 PathingStrategy getPathingStrategy() const { return m_pathingstrategy; } 00222 00226 void addChangeListener(LayerChangeListener* listener); 00227 00231 void removeChangeListener(LayerChangeListener* listener); 00232 00235 bool isChanged() { return m_changed; } 00236 00240 std::vector<Instance*>& getChangedInstances() { return m_changedinstances; } 00241 00242 void setInstanceActivityStatus(Instance* instance, bool active); 00243 00244 protected: 00245 std::string m_id; 00246 00247 Map* m_map; 00248 00249 bool m_instances_visibility; 00250 00251 uint8_t m_transparency; 00252 00253 // all the instances on this layer 00254 std::vector<Instance*> m_instances; 00255 00256 // all the active instances on this layer 00257 std::set<Instance*> m_active_instances; 00258 00259 //The instance tree 00260 InstanceTree* m_instanceTree; 00261 00262 // layer's cellgrid 00263 CellGrid* m_grid; 00264 00265 // pathing strategy for the layer 00266 PathingStrategy m_pathingstrategy; 00267 00268 // listeners for layer changes 00269 std::vector<LayerChangeListener*> m_changelisteners; 00270 00271 // holds changed instances after each update 00272 std::vector<Instance*> m_changedinstances; 00273 00274 // true if layer (or it's instance) information was changed during previous update round 00275 bool m_changed; 00276 }; 00277 00278 } // FIFE 00279 00280 #endif