FIFE  2008.0
 All Classes Namespaces Functions Variables Enumerations Enumerator Pages
layer.h
1 /***************************************************************************
2  * Copyright (C) 2005-2008 by the FIFE team *
3  * http://www.fifengine.de *
4  * This file is part of FIFE. *
5  * *
6  * FIFE is free software; you can redistribute it and/or *
7  * modify it under the terms of the GNU Lesser General Public *
8  * License as published by the Free Software Foundation; either *
9  * version 2.1 of the License, or (at your option) any later version. *
10  * *
11  * This library is distributed in the hope that it will be useful, *
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
14  * Lesser General Public License for more details. *
15  * *
16  * You should have received a copy of the GNU Lesser General Public *
17  * License along with this library; if not, write to the *
18  * Free Software Foundation, Inc., *
19  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA *
20  ***************************************************************************/
21 
22 #ifndef FIFE_LAYER_H
23 #define FIFE_LAYER_H
24 
25 // Standard C++ library includes
26 #include <algorithm>
27 #include <string>
28 #include <vector>
29 #include <set>
30 
31 // 3rd party library includes
32 
33 // FIFE includes
34 // These includes are split up in two parts, separated by one empty line
35 // First block: files included from the FIFE root src directory
36 // Second block: files included from the same folder
37 #include "util/base/resourceclass.h"
38 #include "model/metamodel/modelcoords.h"
39 #include "model/metamodel/object.h"
40 
41 #include "instance.h"
42 
43 namespace FIFE {
44 
45  class Map;
46  class Selection;
47  class CellGrid;
48  class Object;
49  class InstanceTree;
50 
58  CELL_EDGES_ONLY,
59  CELL_EDGES_AND_DIAGONALS,
60  FREEFORM
61  };
62 
66  public:
67  virtual ~LayerChangeListener() {};
68 
74  virtual void onLayerChanged(Layer* layer, std::vector<Instance*>& changedInstances) = 0;
75 
80  virtual void onInstanceCreate(Layer* layer, Instance* instance) = 0;
81 
87  virtual void onInstanceDelete(Layer* layer, Instance* instance) = 0;
88  };
89 
90 
93  class Layer : public ResourceClass {
94  public:
99  Layer(const std::string& identifier, Map* map, CellGrid* grid);
100 
103  ~Layer();
104 
107  const std::string& getId() const { return m_id; }
108 
111  void setId(const std::string& id) { m_id = id; }
112 
115  Map* getMap() const { return m_map; }
116 
120  CellGrid* getCellGrid() const { return m_grid; }
121 
124  void setCellGrid(CellGrid* grid) { m_grid = grid; }
125 
129  InstanceTree* getInstanceTree(void) const { return m_instanceTree; }
130 
134  bool hasInstances() const;
135 
138  Instance* createInstance(Object* object, const ModelCoordinate& p, const std::string& id="");
139 
142  Instance* createInstance(Object* object, const ExactModelCoordinate& p, const std::string& id="");
143 
147  bool addInstance(Instance* instance, const ExactModelCoordinate& p);
148 
151  void deleteInstance(Instance* object);
152 
155  const std::vector<Instance*>& getInstances() const { return m_instances; }
156 
159  std::vector<Instance*> getInstances(const std::string& id);
160 
165  std::vector<Instance*> getInstancesAt(Location& loc, bool use_exactcoordinates=false);
166 
169  Instance* getInstance(const std::string& identifier);
170 
173  void setInstancesVisible(bool vis);
174 
178  void setLayerTransparency(uint8_t transparency);
179 
182  uint8_t getLayerTransparency();
183 
189  void getMinMaxCoordinates(ModelCoordinate& min, ModelCoordinate& max, const Layer* layer = 0) const;
190 
196  bool cellContainsBlockingInstance(const ModelCoordinate& cellCoordinate);
197 
201  void toggleInstancesVisible();
202 
206  bool areInstancesVisible() const { return m_instances_visibility; }
207 
211  bool update();
212 
216  void setPathingStrategy(PathingStrategy strategy) { m_pathingstrategy = strategy; }
217 
221  PathingStrategy getPathingStrategy() const { return m_pathingstrategy; }
222 
226  void addChangeListener(LayerChangeListener* listener);
227 
232 
235  bool isChanged() { return m_changed; }
236 
240  std::vector<Instance*>& getChangedInstances() { return m_changedinstances; }
241 
242  void setInstanceActivityStatus(Instance* instance, bool active);
243 
244  protected:
245  std::string m_id;
246 
247  Map* m_map;
248 
249  bool m_instances_visibility;
250 
251  uint8_t m_transparency;
252 
253  // all the instances on this layer
254  std::vector<Instance*> m_instances;
255 
256  // all the active instances on this layer
257  std::set<Instance*> m_active_instances;
258 
259  //The instance tree
260  InstanceTree* m_instanceTree;
261 
262  // layer's cellgrid
263  CellGrid* m_grid;
264 
265  // pathing strategy for the layer
266  PathingStrategy m_pathingstrategy;
267 
268  // listeners for layer changes
269  std::vector<LayerChangeListener*> m_changelisteners;
270 
271  // holds changed instances after each update
272  std::vector<Instance*> m_changedinstances;
273 
274  // true if layer (or it's instance) information was changed during previous update round
275  bool m_changed;
276  };
277 
278 } // FIFE
279 
280 #endif