FIFE  be64c707dea6b3250bd4355bf5c825d25920087d
layer.h
Go to the documentation of this file.
1 /***************************************************************************
2  * Copyright (C) 2005-2019 by the FIFE team *
3  * http://www.fifengine.net *
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/fifeclass.h"
38 #include "util/structures/rect.h"
40 #include "model/metamodel/object.h"
41 
42 #include "instance.h"
43 
44 namespace FIFE {
45 
46  class Map;
47  class CellGrid;
48  class Object;
49  class InstanceTree;
50  class CellCache;
51  class Trigger;
52 
61  };
62 
67  };
68 
72  public:
73  virtual ~LayerChangeListener() {};
74 
80  virtual void onLayerChanged(Layer* layer, std::vector<Instance*>& changedInstances) = 0;
81 
86  virtual void onInstanceCreate(Layer* layer, Instance* instance) = 0;
87 
93  virtual void onInstanceDelete(Layer* layer, Instance* instance) = 0;
94  };
95 
96 
99  class Layer : public FifeClass {
100  public:
105  Layer(const std::string& identifier, Map* map, CellGrid* grid);
106 
109  ~Layer();
110 
113  const std::string& getId() const;
114 
117  void setId(const std::string& id);
118 
121  Map* getMap() const;
122 
126  CellGrid* getCellGrid() const;
127 
130  void setCellGrid(CellGrid* grid);
131 
135  InstanceTree* getInstanceTree(void) const;
136 
140  bool hasInstances() const;
141 
144  Instance* createInstance(Object* object, const ModelCoordinate& p, const std::string& id="");
145 
148  Instance* createInstance(Object* object, const ExactModelCoordinate& p, const std::string& id="");
149 
153  bool addInstance(Instance* instance, const ExactModelCoordinate& p);
154 
157  void removeInstance(Instance* instance);
158 
161  void deleteInstance(Instance* instance);
162 
165  const std::vector<Instance*>& getInstances() const;
166 
169  std::vector<Instance*> getInstances(const std::string& id);
170 
175  std::vector<Instance*> getInstancesAt(Location& loc, bool use_exactcoordinates=false);
176 
180  std::list<Instance*> getInstancesIn(Rect& rec);
181 
187  std::vector<Instance*> getInstancesInLine(const ModelCoordinate& pt1, const ModelCoordinate& pt2);
188 
194  std::vector<Instance*> getInstancesInCircle(const ModelCoordinate& center, uint16_t radius);
195 
203  std::vector<Instance*> getInstancesInCircleSegment(const ModelCoordinate& center, uint16_t radius, int32_t sangle, int32_t eangle);
204 
207  Instance* getInstance(const std::string& identifier);
208 
211  void setInstancesVisible(bool vis);
212 
216  void setLayerTransparency(uint8_t transparency);
217 
220  uint8_t getLayerTransparency();
221 
227  void getMinMaxCoordinates(ModelCoordinate& min, ModelCoordinate& max, const Layer* layer = 0) const;
228 
232  float getZOffset() const;
233 
236  uint32_t getLayerCount() const;
237 
243  bool cellContainsBlockingInstance(const ModelCoordinate& cellCoordinate);
244 
250  std::vector<Instance*> getBlockingInstances(const ModelCoordinate& cellCoordinate);
251 
255  void toggleInstancesVisible();
256 
260  bool areInstancesVisible() const;
261 
265  bool update();
266 
270  void setPathingStrategy(PathingStrategy strategy);
271 
275  PathingStrategy getPathingStrategy() const;
276 
280  void setSortingStrategy(SortingStrategy strategy);
281 
285  SortingStrategy getSortingStrategy() const;
286 
291  void setWalkable(bool walkable);
292 
296  bool isWalkable();
297 
303  void setInteract(bool interact, const std::string& id);
304 
308  bool isInteract();
309 
313  const std::string& getWalkableId();
314 
318  void addInteractLayer(Layer* layer);
319 
323  const std::vector<Layer*>& getInteractLayers();
324 
328  void removeInteractLayer(Layer* layer);
329 
332  void createCellCache();
333 
337  CellCache* getCellCache();
338 
341  void destroyCellCache();
342 
346  void addChangeListener(LayerChangeListener* listener);
347 
351  void removeChangeListener(LayerChangeListener* listener);
352 
355  bool isChanged();
356 
360  std::vector<Instance*>& getChangedInstances();
361 
366  void setInstanceActivityStatus(Instance* instance, bool active);
367 
373  void setStatic(bool stati);
374 
378  bool isStatic();
379 
380  protected:
382  std::string m_id;
390  std::vector<Instance*> m_instances;
392  std::set<Instance*> m_activeInstances;
406  std::string m_walkableId;
408  std::vector<Layer*> m_interacts;
412  std::vector<LayerChangeListener*> m_changeListeners;
414  std::vector<Instance*> m_changedInstances;
416  bool m_changed;
418  bool m_static;
419  };
420 
421 } // FIFE
422 
423 #endif
SortingStrategy m_sortingStrategy
sorting strategy for rendering
Definition: layer.h:400
std::vector< LayerChangeListener * > m_changeListeners
listeners for layer changes
Definition: layer.h:412
bool m_walkable
is walkable true/false
Definition: layer.h:402
bool m_static
true if layer is static
Definition: layer.h:418
InstanceTree * m_instanceTree
The instance tree.
Definition: layer.h:394
Object class.
Definition: object.h:51
A CellCache is an abstract depiction of one or a few layers and contains additional information...
Definition: cellcache.h:111
Base class for all fife classes Used e.g.
Definition: fifeclass.h:42
CellGrid * m_grid
layer&#39;s cellgrid
Definition: layer.h:396
bool m_instancesVisibility
if true the instances are visibility otherwise they are skipped during rendering
Definition: layer.h:386
CellCache * m_cellCache
pointer to cellcache
Definition: layer.h:410
virtual void onInstanceDelete(Layer *layer, Instance *instance)=0
Called when some instance gets deleted on layer.
std::set< Instance * > m_activeInstances
all the active instances on this layer
Definition: layer.h:392
uint8_t m_transparency
transparency, value 0 means total visible, 128 semi-transparent and 255 invisibility ...
Definition: layer.h:388
unsigned char uint8_t
Definition: core.h:38
bool m_changed
true if layer (or it&#39;s instance) information was changed during previous update round ...
Definition: layer.h:416
A basic layer on a map.
Definition: layer.h:99
Listener interface for changes happening on a layer.
Definition: layer.h:71
SortingStrategy
Definition: layer.h:63
unsigned short uint16_t
Definition: core.h:39
virtual void onLayerChanged(Layer *layer, std::vector< Instance *> &changedInstances)=0
Called when some instance is changed on layer.
std::string m_id
string identifier
Definition: layer.h:382
bool m_interact
is interact true/false
Definition: layer.h:404
A 3D Point.
Definition: point.h:205
PathingStrategy
Defines how pathing can be performed on this layer.
Definition: layer.h:58
std::vector< Instance * > m_instances
all the instances on this layer
Definition: layer.h:390
std::vector< Layer * > m_interacts
all assigned interact layers
Definition: layer.h:408
virtual ~LayerChangeListener()
Definition: layer.h:73
A container of Layer(s).
Definition: map.h:88
virtual void onInstanceCreate(Layer *layer, Instance *instance)=0
Called when some instance gets created on layer.
unsigned int uint32_t
Definition: core.h:40
PathingStrategy m_pathingStrategy
pathing strategy for the layer
Definition: layer.h:398
Map * m_map
pointer to map
Definition: layer.h:384
An Instance is an "instantiation" of an Object at a Location.
Definition: instance.h:94
std::string m_walkableId
walkable id
Definition: layer.h:406
std::vector< Instance * > m_changedInstances
holds changed instances after each update
Definition: layer.h:414