FIFE  6e1afdbeda11afe9ac53e6023a4be96ef88f1dc6
layer.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  * Copyright (C) 2005-2017 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 // Standard C++ library includes
23 
24 // 3rd party library includes
25 
26 // FIFE includes
27 // These includes are split up in two parts, separated by one empty line
28 // First block: files included from the FIFE root src directory
29 // Second block: files included from the same folder
30 #include "util/log/logger.h"
31 #include "util/structures/purge.h"
33 
34 #include "layer.h"
35 #include "instance.h"
36 #include "map.h"
37 #include "instancetree.h"
38 #include "cell.h"
39 #include "cellcache.h"
40 #include "trigger.h"
41 
42 namespace FIFE {
46  static Logger _log(LM_STRUCTURES);
47 
48  Layer::Layer(const std::string& identifier, Map* map, CellGrid* grid)
49  : m_id(identifier),
50  m_map(map),
51  m_instancesVisibility(true),
52  m_transparency(0),
53  m_instanceTree(new InstanceTree()),
54  m_grid(grid),
55  m_pathingStrategy(CELL_EDGES_ONLY),
56  m_sortingStrategy(SORTING_CAMERA),
57  m_walkable(false),
58  m_interact(false),
59  m_walkableId(""),
60  m_cellCache(NULL),
61  m_changeListeners(),
62  m_changedInstances(),
63  m_changed(false),
64  m_static(false) {
65  }
66 
68  // if this is a walkable layer
70  // if this is a interact layer
71  if (m_interact) {
72  Layer* temp = m_map->getLayer(m_walkableId);
73  if (temp) {
74  temp->removeInteractLayer(this);
75  }
76  }
78  delete m_instanceTree;
79  }
80 
81  const std::string& Layer::getId() const {
82  return m_id;
83  }
84 
85  void Layer::setId(const std::string& id) {
86  m_id = id;
87  }
88 
89  Map* Layer::getMap() const {
90  return m_map;
91  }
92 
94  return m_grid;
95  }
96 
98  m_grid = grid;
99  }
100 
102  return m_instanceTree;
103  }
104 
105  bool Layer::hasInstances() const {
106  return !m_instances.empty();
107  }
108 
109  Instance* Layer::createInstance(Object* object, const ModelCoordinate& p, const std::string& id) {
110  ExactModelCoordinate emc(static_cast<double>(p.x), static_cast<double>(p.y), static_cast<double>(p.z));
111  return createInstance(object, emc, id);
112  }
113 
114  Instance* Layer::createInstance(Object* object, const ExactModelCoordinate& p, const std::string& id) {
115  Location location(this);
116  location.setExactLayerCoordinates(p);
117 
118  Instance* instance = new Instance(object, location, id);
119  if(instance->isActive()) {
120  setInstanceActivityStatus(instance, instance->isActive());
121  }
122  m_instances.push_back(instance);
123  m_instanceTree->addInstance(instance);
124 
125  std::vector<LayerChangeListener*>::iterator i = m_changeListeners.begin();
126  while (i != m_changeListeners.end()) {
127  (*i)->onInstanceCreate(this, instance);
128  ++i;
129  }
130  m_changed = true;
131  return instance;
132  }
133 
135  if( !instance ){
136  FL_ERR(_log, "Tried to add an instance to layer, but given instance is invalid");
137  return false;
138  }
139 
140  Location& location = instance->getLocationRef();
141  location.setLayer(this);
142  location.setExactLayerCoordinates(p);
143 
144  m_instances.push_back(instance);
145  m_instanceTree->addInstance(instance);
146  if(instance->isActive()) {
147  setInstanceActivityStatus(instance, instance->isActive());
148  }
149 
150  std::vector<LayerChangeListener*>::iterator i = m_changeListeners.begin();
151  while (i != m_changeListeners.end()) {
152  (*i)->onInstanceCreate(this, instance);
153  ++i;
154  }
155  m_changed = true;
156  return true;
157  }
158 
159  void Layer::removeInstance(Instance* instance) {
160  // If the instance is changed and removed on the same pump,
161  // it can happen that the instance can not cleanly be removed,
162  // to avoid this we have to update the instance first and send
163  // the result to the LayerChangeListeners.
164  if (instance->isActive()) {
165  if (instance->update() != ICHANGE_NO_CHANGES) {
166  std::vector<Instance*> updateInstances;
167  updateInstances.push_back(instance);
168  std::vector<LayerChangeListener*>::iterator i = m_changeListeners.begin();
169  while (i != m_changeListeners.end()) {
170  (*i)->onLayerChanged(this, updateInstances);
171  ++i;
172  }
173  }
174  }
175 
176  std::vector<LayerChangeListener*>::iterator i = m_changeListeners.begin();
177  while (i != m_changeListeners.end()) {
178  (*i)->onInstanceDelete(this, instance);
179  ++i;
180  }
181  setInstanceActivityStatus(instance, false);
182  std::vector<Instance*>::iterator it = m_instances.begin();
183  for(; it != m_instances.end(); ++it) {
184  if(*it == instance) {
186  m_instances.erase(it);
187  break;
188  }
189  }
190  m_changed = true;
191  }
192 
193  void Layer::deleteInstance(Instance* instance) {
194  // If the instance is changed and deleted on the same pump,
195  // it can happen that the instance can not cleanly be removed,
196  // to avoid this we have to update the instance first and send
197  // the result to the LayerChangeListeners.
198  if (instance->isActive()) {
199  if (instance->update() != ICHANGE_NO_CHANGES) {
200  std::vector<Instance*> updateInstances;
201  updateInstances.push_back(instance);
202  std::vector<LayerChangeListener*>::iterator i = m_changeListeners.begin();
203  while (i != m_changeListeners.end()) {
204  (*i)->onLayerChanged(this, updateInstances);
205  ++i;
206  }
207  }
208  }
209 
210  std::vector<LayerChangeListener*>::iterator i = m_changeListeners.begin();
211  while (i != m_changeListeners.end()) {
212  (*i)->onInstanceDelete(this, instance);
213  ++i;
214  }
215  setInstanceActivityStatus(instance, false);
216  std::vector<Instance*>::iterator it = m_instances.begin();
217  for(; it != m_instances.end(); ++it) {
218  if(*it == instance) {
220  delete *it;
221  m_instances.erase(it);
222  break;
223  }
224  }
225 
226  m_changed = true;
227  }
228 
229  const std::vector<Instance*>& Layer::getInstances() const {
230  return m_instances;
231  }
232 
233  void Layer::setInstanceActivityStatus(Instance* instance, bool active) {
234  if(active) {
235  m_activeInstances.insert(instance);
236  } else {
237  m_activeInstances.erase(instance);
238  }
239  }
240 
241  Instance* Layer::getInstance(const std::string& id) {
242  std::vector<Instance*>::iterator it = m_instances.begin();
243  for(; it != m_instances.end(); ++it) {
244  if((*it)->getId() == id)
245  return *it;
246  }
247 
248  return 0;
249  }
250 
251  std::vector<Instance*> Layer::getInstances(const std::string& id) {
252  std::vector<Instance*> matching_instances;
253  std::vector<Instance*>::iterator it = m_instances.begin();
254  for(; it != m_instances.end(); ++it) {
255  if((*it)->getId() == id)
256  matching_instances.push_back(*it);
257  }
258  return matching_instances;
259  }
260 
261  std::vector<Instance*> Layer::getInstancesAt(Location& loc, bool use_exactcoordinates) {
262  std::vector<Instance*> matching_instances;
263  std::vector<Instance*>::iterator it = m_instances.begin();
264 
265  for(; it != m_instances.end(); ++it) {
266  if (use_exactcoordinates) {
267  if ((*it)->getLocationRef().getExactLayerCoordinatesRef() == loc.getExactLayerCoordinatesRef()) {
268  matching_instances.push_back(*it);
269  }
270  } else {
271  if ((*it)->getLocationRef().getLayerCoordinates() == loc.getLayerCoordinates()) {
272  matching_instances.push_back(*it);
273  }
274  }
275  }
276 
277  return matching_instances;
278  }
279 
280  std::list<Instance*> Layer::getInstancesIn(Rect& rec) {
281  std::list<Instance*> matching_instances;
282  ModelCoordinate mc(rec.x, rec.y);
283  m_instanceTree->findInstances(mc, rec.w, rec.h, matching_instances);
284 
285  return matching_instances;
286  }
287 
288  std::vector<Instance*> Layer::getInstancesInLine(const ModelCoordinate& pt1, const ModelCoordinate& pt2) {
289  std::vector<Instance*> instances;
290  std::list<Instance*> matchingInstances;
291  std::vector<ModelCoordinate> coords = m_grid->getCoordinatesInLine(pt1, pt2);
292  for (std::vector<ModelCoordinate>::iterator it = coords.begin(); it != coords.end(); ++it) {
293  m_instanceTree->findInstances(*it, 0, 0, matchingInstances);
294  if (!matchingInstances.empty()) {
295  instances.insert(instances.end(), matchingInstances.begin(), matchingInstances.end());
296  }
297  }
298  return instances;
299  }
300 
301  std::vector<Instance*> Layer::getInstancesInCircle(const ModelCoordinate& center, uint16_t radius) {
302  std::vector<Instance*> instances;
303  std::list<Instance*> matchingInstances;
304  //radius power 2
305  uint16_t radiusp2 = (radius+1) * radius;
306 
307  ModelCoordinate current(center.x-radius, center.y-radius);
308  ModelCoordinate target(center.x+radius, center.y+radius);
309  for (; current.y < center.y; current.y++) {
310  current.x = center.x-radius;
311  for (; current.x < center.x; current.x++) {
312  uint16_t dx = center.x - current.x;
313  uint16_t dy = center.y - current.y;
314  uint16_t distance = dx*dx + dy*dy;
315  if (distance <= radiusp2) {
316  m_instanceTree->findInstances(current, 0, 0, matchingInstances);
317  if (!matchingInstances.empty()) {
318  instances.insert(instances.end(), matchingInstances.begin(), matchingInstances.end());
319  }
320 
321  current.x = center.x + dx;
322  m_instanceTree->findInstances(current, 0, 0, matchingInstances);
323  if (!matchingInstances.empty()) {
324  instances.insert(instances.end(), matchingInstances.begin(), matchingInstances.end());
325  }
326 
327  current.y = center.y + dy;
328  m_instanceTree->findInstances(current, 0, 0, matchingInstances);
329  if (!matchingInstances.empty()) {
330  instances.insert(instances.end(), matchingInstances.begin(), matchingInstances.end());
331  }
332 
333  current.x = center.x-dx;
334  m_instanceTree->findInstances(current, 0, 0, matchingInstances);
335  if (!matchingInstances.empty()) {
336  instances.insert(instances.end(), matchingInstances.begin(), matchingInstances.end());
337  }
338 
339  current.y = center.y-dy;
340  }
341  }
342  }
343  current.x = center.x;
344  current.y = center.y-radius;
345  for (; current.y <= target.y; current.y++) {
346  m_instanceTree->findInstances(current, 0, 0, matchingInstances);
347  if (!matchingInstances.empty()) {
348  instances.insert(instances.end(), matchingInstances.begin(), matchingInstances.end());
349  }
350  }
351 
352  current.y = center.y;
353  current.x = center.x-radius;
354  for (; current.x <= target.x; current.x++) {
355  m_instanceTree->findInstances(current, 0, 0, matchingInstances);
356  if (!matchingInstances.empty()) {
357  instances.insert(instances.end(), matchingInstances.begin(), matchingInstances.end());
358  }
359  }
360  return instances;
361  }
362 
363  std::vector<Instance*> Layer::getInstancesInCircleSegment(const ModelCoordinate& center, uint16_t radius, int32_t sangle, int32_t eangle) {
364  std::vector<Instance*> instances;
365  ExactModelCoordinate exactCenter(center.x, center.y);
366  std::vector<Instance*> tmpInstances = getInstancesInCircle(center, radius);
367  int32_t s = (sangle + 360) % 360;
368  int32_t e = (eangle + 360) % 360;
369  bool greater = (s > e) ? true : false;
370  for (std::vector<Instance*>::iterator it = tmpInstances.begin(); it != tmpInstances.end(); ++it) {
371  int32_t angle = getAngleBetween(exactCenter, intPt2doublePt((*it)->getLocationRef().getLayerCoordinates()));
372  if (greater) {
373  if (angle >= s || angle <= e) {
374  instances.push_back(*it);
375  }
376  } else {
377  if (angle >= s && angle <= e) {
378  instances.push_back(*it);
379  }
380  }
381  }
382  return instances;
383  }
384 
385  void Layer::getMinMaxCoordinates(ModelCoordinate& min, ModelCoordinate& max, const Layer* layer) const {
386  if (!layer) {
387  layer = this;
388  }
389 
390  if (m_instances.empty()) {
391  min = ModelCoordinate();
392  max = min;
393  } else {
394  min = m_instances.front()->getLocationRef().getLayerCoordinates(layer);
395  max = min;
396 
397  for (std::vector<Instance*>::const_iterator i = m_instances.begin(); i != m_instances.end(); ++i) {
398  ModelCoordinate coord = (*i)->getLocationRef().getLayerCoordinates(layer);
399  min.x = std::min(min.x, coord.x);
400  max.x = std::max(max.x, coord.x);
401  min.y = std::min(min.y, coord.y);
402  max.y = std::max(max.y, coord.y);
403  }
404  }
405 
406  }
407 
408  float Layer::getZOffset() const {
409  static const float globalmax = 100.0;
410  static const float globalrange = 200.0;
411  int32_t numlayers = m_map->getLayerCount();
412  int32_t thislayer = 1; // we don't need 0 indexed
413 
414  const std::list<Layer*>& layers = m_map->getLayers();
415  std::list<Layer*>::const_iterator iter = layers.begin();
416  for (; iter != layers.end(); ++iter, ++thislayer) {
417  if (*iter == this) {
418  break;
419  }
420  }
421 
422  float offset = globalmax - (numlayers - (thislayer - 1)) * (globalrange/numlayers);
423  return offset;
424  }
425 
427  return m_map->getLayerCount();
428  }
429 
430  void Layer::setInstancesVisible(bool vis) {
431  if (m_instancesVisibility != vis) {
432  m_instancesVisibility = vis;
433  std::vector<Instance*>::iterator it = m_instances.begin();
434  for (; it != m_instances.end(); ++it) {
435  (*it)->callOnVisibleChange();
436  }
437  }
438  }
439 
441  if (m_transparency != transparency) {
442  m_transparency = transparency;
443  std::vector<Instance*>::iterator it = m_instances.begin();
444  for (; it != m_instances.end(); ++it) {
445  (*it)->callOnTransparencyChange();
446  }
447  }
448  }
449 
451  return m_transparency;
452  }
453 
456  }
457 
459  return m_instancesVisibility;
460  }
461 
463  bool blockingInstance = false;
464  if (m_cellCache) {
465  Cell* cell = m_cellCache->getCell(cellCoordinate);
466  if (cell) {
467  return cell->getCellType() != CTYPE_NO_BLOCKER;
468  }
469  } else {
470  std::list<Instance*> adjacentInstances;
471  m_instanceTree->findInstances(cellCoordinate, 0, 0, adjacentInstances);
472  for(std::list<Instance*>::const_iterator j = adjacentInstances.begin(); j != adjacentInstances.end(); ++j) {
473  if((*j)->isBlocking() && (*j)->getLocationRef().getLayerCoordinates() == cellCoordinate) {
474  blockingInstance = true;
475  break;
476  }
477  }
478  }
479  return blockingInstance;
480  }
481 
482  std::vector<Instance*> Layer::getBlockingInstances(const ModelCoordinate& cellCoordinate) {
483  std::vector<Instance*> blockingInstances;
484  if (m_cellCache) {
485  Cell* cell = m_cellCache->getCell(cellCoordinate);
486  if (cell) {
487  const std::set<Instance*>& blocker = cell->getInstances();
488  for (std::set<Instance*>::const_iterator it = blocker.begin(); it != blocker.end(); ++it) {
489  if ((*it)->isBlocking()) {
490  blockingInstances.push_back(*it);
491  }
492  }
493  }
494  } else {
495  std::list<Instance*> adjacentInstances;
496  m_instanceTree->findInstances(cellCoordinate, 0, 0, adjacentInstances);
497  for(std::list<Instance*>::const_iterator j = adjacentInstances.begin(); j != adjacentInstances.end(); ++j) {
498  if((*j)->isBlocking() && (*j)->getLocationRef().getLayerCoordinates() == cellCoordinate) {
499  blockingInstances.push_back(*j);
500  }
501  }
502  }
503  return blockingInstances;
504  }
505 
507  m_pathingStrategy = strategy;
509  }
510 
512  return m_pathingStrategy;
513  }
514 
516  m_sortingStrategy = strategy;
517  }
518 
520  return m_sortingStrategy;
521  }
522 
523  void Layer::setWalkable(bool walkable) {
524  m_walkable = walkable;
525  }
526 
528  return m_walkable;
529  }
530 
531  void Layer::setInteract(bool interact, const std::string& id) {
532  m_interact = interact;
533  m_walkableId = id;
534  }
535 
537  return m_interact;
538  }
539 
540  const std::string& Layer::getWalkableId() {
541  return m_walkableId;
542  }
543 
545  if (m_walkable) {
546  m_interacts.push_back(layer);
547  }
548  }
549 
550  const std::vector<Layer*>& Layer::getInteractLayers() {
551  return m_interacts;
552  }
553 
555  if (m_walkable) {
556  std::vector<Layer*>::iterator it = m_interacts.begin();
557  for (; it != m_interacts.end(); ++it) {
558  if (*it == layer) {
559  (*it)->removeChangeListener(m_cellCache->getCellCacheChangeListener());
560  m_interacts.erase(it);
561  break;
562  }
563  }
564  }
565  }
566 
568  if (!m_cellCache && m_walkable) {
569  m_cellCache = new CellCache(this);
570  }
571  }
572 
574  return m_cellCache;
575  }
576 
578  if (m_walkable) {
580  if (!m_interacts.empty()) {
581  std::vector<Layer*>::iterator it = m_interacts.begin();
582  for (; it != m_interacts.end(); ++it) {
583  (*it)->removeChangeListener(m_cellCache->getCellCacheChangeListener());
584  (*it)->setInteract(false, "");
585  }
586  m_interacts.clear();
587  }
588  delete m_cellCache;
589  m_cellCache = NULL;
590  m_walkable = false;
591  }
592  }
593 
594  bool Layer::update() {
595  m_changedInstances.clear();
596  std::vector<Instance*> inactiveInstances;
597  std::set<Instance*>::iterator it = m_activeInstances.begin();
598  for(; it != m_activeInstances.end(); ++it) {
599  if ((*it)->update() != ICHANGE_NO_CHANGES) {
600  m_changedInstances.push_back(*it);
601  m_changed = true;
602  } else if (!(*it)->isActive()) {
603  inactiveInstances.push_back(*it);
604  }
605  }
606  if (!m_changedInstances.empty()) {
607  std::vector<LayerChangeListener*>::iterator i = m_changeListeners.begin();
608  while (i != m_changeListeners.end()) {
609  (*i)->onLayerChanged(this, m_changedInstances);
610  ++i;
611  }
612  //std::cout << "Layer named " << Id() << " changed = 1\n";
613  }
614  // remove inactive instances from m_activeInstances
615  if (!inactiveInstances.empty()) {
616  std::vector<Instance*>::iterator i = inactiveInstances.begin();
617  while (i != inactiveInstances.end()) {
618  m_activeInstances.erase(*i);
619  ++i;
620  }
621  }
622  //std::cout << "Layer named " << Id() << " changed = 0\n";
623  bool retval = m_changed;
624  m_changed = false;
625  return retval;
626  }
627 
629  m_changeListeners.push_back(listener);
630  }
631 
633  std::vector<LayerChangeListener*>::iterator i = m_changeListeners.begin();
634  while (i != m_changeListeners.end()) {
635  if ((*i) == listener) {
636  m_changeListeners.erase(i);
637  return;
638  }
639  ++i;
640  }
641  }
642 
644  return m_changed;
645  }
646 
647  std::vector<Instance*>& Layer::getChangedInstances() {
648  return m_changedInstances;
649  }
650 
651  void Layer::setStatic(bool stati) {
652  m_static = stati;
653  }
654 
656  return m_static;
657  }
658 
659 } // FIFE
void setInstancesVisible(bool vis)
Set object visibility.
Definition: layer.cpp:430
SortingStrategy m_sortingStrategy
sorting strategy for rendering
Definition: layer.h:400
std::vector< LayerChangeListener * > m_changeListeners
listeners for layer changes
Definition: layer.h:412
Map * getMap() const
Get the map this layer is contained in.
Definition: layer.cpp:89
bool isChanged()
Returns true, if layer information was changed during previous update round.
Definition: layer.cpp:643
int32_t getAngleBetween(const Location &loc1, const Location &loc2)
Gets angle of vector defined by given locations.
Definition: angles.cpp:98
bool m_walkable
is walkable true/false
Definition: layer.h:402
bool m_static
true if layer is static
Definition: layer.h:418
void setExactLayerCoordinates(const ExactModelCoordinate &coordinates)
Sets precise layer coordinates to this location.
Definition: location.cpp:87
Layer * getLayer(const std::string &identifier)
Get the layer with the given id.
Definition: map.cpp:73
std::vector< Instance * > getInstancesAt(Location &loc, bool use_exactcoordinates=false)
Returns instances that match given location.
Definition: layer.cpp:261
T h
Height of the rectangle.
Definition: rect.h:93
std::vector< Instance * > getInstancesInLine(const ModelCoordinate &pt1, const ModelCoordinate &pt2)
Returns instances that match given line between pt1 and pt2.
Definition: layer.cpp:288
std::vector< Instance * > getInstancesInCircleSegment(const ModelCoordinate &center, uint16_t radius, int32_t sangle, int32_t eangle)
Returns all instances in the circle segment.
Definition: layer.cpp:363
InstanceTree * m_instanceTree
The instance tree.
Definition: layer.h:394
Object class.
Definition: object.h:51
bool isActive() const
If this returns true, the instance needs to be updated.
Definition: instance.cpp:291
void setLayer(Layer *layer)
Sets layer where this location is pointing to.
Definition: location.cpp:79
~Layer()
Destructs a Layer instance.
Definition: layer.cpp:67
std::vector< Instance * > & getChangedInstances()
Returns instances that were changed during previous update round.
Definition: layer.cpp:647
T x
The X Coordinate.
Definition: rect.h:84
void setId(const std::string &id)
Sets the identifier for this layer.
Definition: layer.cpp:85
uint32_t getLayerCount() const
Get the overall number of layers.
Definition: layer.cpp:426
A CellCache is an abstract depiction of one or a few layers and contains additional information...
Definition: cellcache.h:111
void toggleInstancesVisible()
Toggle object visibility.
Definition: layer.cpp:454
void setSortingStrategy(SortingStrategy strategy)
Sets sorting strategy for the layer.
Definition: layer.cpp:515
bool hasInstances() const
Check existance of objects on this layer.
Definition: layer.cpp:105
void destroyCellCache()
Destroys the CellCache of this layer.
Definition: layer.cpp:577
std::list< Instance * > getInstancesIn(Rect &rec)
Returns instances that match given rect.
Definition: layer.cpp:280
CellCache * getCellCache()
Returns the CellCache of this layer.
Definition: layer.cpp:573
void createCellCache()
Called from Map to create a CellCache.
Definition: layer.cpp:567
Instance * createInstance(Object *object, const ModelCoordinate &p, const std::string &id="")
Add an instance of an object at a specific position.
Definition: layer.cpp:109
static Logger _log(LM_AUDIO)
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
Layer(const std::string &identifier, Map *map, CellGrid *grid)
Constructor Layers are created by calling addLayer from map, thus this method should really be called...
Definition: layer.cpp:48
bool areInstancesVisible() const
Check object visibility.
Definition: layer.cpp:458
InstanceTree * getInstanceTree(void) const
Get the instance tree.
Definition: layer.cpp:101
CellCache * m_cellCache
pointer to cellcache
Definition: layer.h:410
Location & getLocationRef()
Gets reference of current location of instance.
Definition: instance.cpp:318
ModelCoordinate getLayerCoordinates() const
Gets cell precision layer coordinates set to this location.
Definition: location.cpp:113
void setCellGrid(CellGrid *grid)
Set the Cellgrid.
Definition: layer.cpp:97
std::set< Instance * > m_activeInstances
all the active instances on this layer
Definition: layer.h:392
bool update()
Called periodically to update events on layer.
Definition: layer.cpp:594
void addInteractLayer(Layer *layer)
Adds a interact layer to the walkable layer.
Definition: layer.cpp:544
uint32_t getLayerCount() const
Get the overall number of layers.
Definition: map.cpp:82
std::vector< Instance * > getBlockingInstances(const ModelCoordinate &cellCoordinate)
Returns instances that blocks on given cell.
Definition: layer.cpp:482
uint8_t m_transparency
transparency, value 0 means total visible, 128 semi-transparent and 255 invisibility ...
Definition: layer.h:388
void removeInstance(Instance *instance)
Remove an instance from the layer.
Definition: layer.cpp:159
#define FL_ERR(logger, msg)
Definition: logger.h:73
void setPathingStrategy(PathingStrategy strategy)
Sets pathing strategy for the layer.
Definition: layer.cpp:506
void getMinMaxCoordinates(ModelCoordinate &min, ModelCoordinate &max, const Layer *layer=0) const
Retrieves the minimum/maximum coordinates of instances on the layer.
Definition: layer.cpp:385
void purge(Seq &c)
Definition: purge.h:28
void findInstances(const ModelCoordinate &point, int32_t w, int32_t h, InstanceList &list)
Find all instances in a given area.
unsigned char uint8_t
Definition: core.h:38
void setStatic(bool stati)
Marks this layer as visual static.
Definition: layer.cpp:651
void removeChangeListener(LayerChangeListener *listener)
Removes associated change listener.
Definition: layer.cpp:632
bool addInstance(Instance *instance, const ExactModelCoordinate &p)
Add a valid instance at a specific position.
Definition: layer.cpp:134
const std::string & getWalkableId()
Returns the id of the walkable layer if this is a interact layer otherwise the string is empty...
Definition: layer.cpp:540
Cell * getCell(const ModelCoordinate &mc)
Returns cell on this coordinate.
Definition: cellcache.cpp:706
Point3D ModelCoordinate
Definition: modelcoords.h:38
const std::set< Instance * > & getInstances()
Returns all instances on this cell.
Definition: cell.cpp:503
CellTypeInfo getCellType()
Returns blocker type.
Definition: cell.cpp:495
bool m_changed
true if layer (or it&#39;s instance) information was changed during previous update round ...
Definition: layer.h:416
Instance * getInstance(const std::string &identifier)
Get the first instance on this layer with the given identifier.
Definition: layer.cpp:241
A basic layer on a map.
Definition: layer.h:99
bool isWalkable()
Returns if a layer is walkable.
Definition: layer.cpp:527
Listener interface for changes happening on a layer.
Definition: layer.h:71
void removeInstance(Instance *instance)
Removes an instance from the quad tree.
SortingStrategy
Definition: layer.h:63
void addChangeListener(LayerChangeListener *listener)
Adds new change listener.
Definition: layer.cpp:628
bool isStatic()
Returns true, if layer is static.
Definition: layer.cpp:655
void setLayerTransparency(uint8_t transparency)
Sets the transparency of all instances on the layer.
Definition: layer.cpp:440
ExactModelCoordinate & getExactLayerCoordinatesRef()
Gets reference to exact layer coordinates.
Definition: location.cpp:105
A basic cell on a CellCache.
Definition: cell.h:136
unsigned short uint16_t
Definition: core.h:39
void setAllowDiagonals(const bool allow_diagonals)
Set whether diagonal cell access is allowed.
Definition: cellgrid.h:233
T y
The Y Coordinate.
Definition: rect.h:87
std::iterator_traits< octet_iterator >::difference_type distance(octet_iterator first, octet_iterator last)
Definition: checked.h:198
CellGrid * getCellGrid() const
Get the Cellgrid.
Definition: layer.cpp:93
void addInstance(Instance *instance)
Adds an instance to the quad tree.
PathingStrategy getPathingStrategy() const
Gets pathing strategy for the layer.
Definition: layer.cpp:511
void setInteract(bool interact, const std::string &id)
Sets interact for the layer.
Definition: layer.cpp:531
const std::vector< Layer * > & getInteractLayers()
Returns all assigned interact layer.
Definition: layer.cpp:550
void setWalkable(bool walkable)
Sets walkable for the layer.
Definition: layer.cpp:523
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
const std::string & getId() const
Get the id of this layer.
Definition: layer.cpp:81
SortingStrategy getSortingStrategy() const
Gets sorting strategy for the layer.
Definition: layer.cpp:519
std::vector< Instance * > m_instances
all the instances on this layer
Definition: layer.h:390
DoublePoint intPt2doublePt(Point pt)
Convert from 2D int32_t point to 2D double point.
Definition: point.h:349
LayerChangeListener * getCellCacheChangeListener()
Returns change listener.
Definition: cellcache.cpp:798
const std::list< Layer * > & getLayers() const
Get the layers on this map.
Definition: map.h:120
float getZOffset() const
Calculates z offset for the layer.
Definition: layer.cpp:408
InstanceChangeInfo update()
Updates the instance related to the current action.
Definition: instance.cpp:757
const std::vector< Instance * > & getInstances() const
Get the list of instances on this layer.
Definition: layer.cpp:229
bool cellContainsBlockingInstance(const ModelCoordinate &cellCoordinate)
Determines if a given cell on the layer contains a blocking instance.
Definition: layer.cpp:462
virtual std::vector< ModelCoordinate > getCoordinatesInLine(const ModelCoordinate &start, const ModelCoordinate &end)=0
Returns point vector with coordinates for a line from start to end.
void removeInteractLayer(Layer *layer)
Removes a interact layer from the walkable layer.
Definition: layer.cpp:554
std::vector< Layer * > m_interacts
all assigned interact layers
Definition: layer.h:408
void setInstanceActivityStatus(Instance *instance, bool active)
Sets the activity status for given instance on this layer.
Definition: layer.cpp:233
A container of Layer(s).
Definition: map.h:88
unsigned int uint32_t
Definition: core.h:40
void deleteInstance(Instance *instance)
Remove an instance from the layer and delete it.
Definition: layer.cpp:193
PathingStrategy m_pathingStrategy
pathing strategy for the layer
Definition: layer.h:398
bool isInteract()
Returns if a layer is interact.
Definition: layer.cpp:536
uint8_t getLayerTransparency()
Returns the layer&#39;s transparency value.
Definition: layer.cpp:450
Map * m_map
pointer to map
Definition: layer.h:384
std::vector< Instance * > getInstancesInCircle(const ModelCoordinate &center, uint16_t radius)
Returns instances that match given center and radius of the circle.
Definition: layer.cpp:301
T w
Width of the rectangle.
Definition: rect.h:90
An Instance is an "instantiation" of an Object at a Location.
Definition: instance.h:101
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