51 m_instancesVisibility(true),
127 (*i)->onInstanceCreate(
this, instance);
136 FL_ERR(
_log,
"Tried to add an instance to layer, but given instance is invalid");
152 (*i)->onInstanceCreate(
this, instance);
166 std::vector<Instance*> updateInstances;
167 updateInstances.push_back(instance);
170 (*i)->onLayerChanged(
this, updateInstances);
178 (*i)->onInstanceDelete(
this, instance);
182 std::vector<Instance*>::iterator it =
m_instances.begin();
184 if(*it == instance) {
200 std::vector<Instance*> updateInstances;
201 updateInstances.push_back(instance);
204 (*i)->onLayerChanged(
this, updateInstances);
212 (*i)->onInstanceDelete(
this, instance);
216 std::vector<Instance*>::iterator it =
m_instances.begin();
218 if(*it == instance) {
242 std::vector<Instance*>::iterator it =
m_instances.begin();
244 if((*it)->getId() == id)
252 std::vector<Instance*> matching_instances;
253 std::vector<Instance*>::iterator it =
m_instances.begin();
255 if((*it)->getId() == id)
256 matching_instances.push_back(*it);
258 return matching_instances;
262 std::vector<Instance*> matching_instances;
263 std::vector<Instance*>::iterator it =
m_instances.begin();
266 if (use_exactcoordinates) {
268 matching_instances.push_back(*it);
272 matching_instances.push_back(*it);
277 return matching_instances;
281 std::list<Instance*> matching_instances;
285 return matching_instances;
289 std::vector<Instance*> instances;
290 std::list<Instance*> matchingInstances;
292 for (std::vector<ModelCoordinate>::iterator it = coords.begin(); it != coords.end(); ++it) {
294 if (!matchingInstances.empty()) {
295 instances.insert(instances.end(), matchingInstances.begin(), matchingInstances.end());
302 std::vector<Instance*> instances;
303 std::list<Instance*> matchingInstances;
305 uint16_t radiusp2 = (radius+1) * radius;
309 for (; current.
y < center.
y; current.
y++) {
310 current.
x = center.
x-radius;
311 for (; current.
x < center.
x; current.
x++) {
315 if (distance <= radiusp2) {
317 if (!matchingInstances.empty()) {
318 instances.insert(instances.end(), matchingInstances.begin(), matchingInstances.end());
321 current.
x = center.
x + dx;
323 if (!matchingInstances.empty()) {
324 instances.insert(instances.end(), matchingInstances.begin(), matchingInstances.end());
327 current.
y = center.
y + dy;
329 if (!matchingInstances.empty()) {
330 instances.insert(instances.end(), matchingInstances.begin(), matchingInstances.end());
333 current.
x = center.
x-dx;
335 if (!matchingInstances.empty()) {
336 instances.insert(instances.end(), matchingInstances.begin(), matchingInstances.end());
339 current.
y = center.
y-dy;
343 current.
x = center.
x;
344 current.
y = center.
y-radius;
345 for (; current.
y <= target.
y; current.
y++) {
347 if (!matchingInstances.empty()) {
348 instances.insert(instances.end(), matchingInstances.begin(), matchingInstances.end());
352 current.
y = center.
y;
353 current.
x = center.
x-radius;
354 for (; current.
x <= target.
x; current.
x++) {
356 if (!matchingInstances.empty()) {
357 instances.insert(instances.end(), matchingInstances.begin(), matchingInstances.end());
364 std::vector<Instance*> instances;
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) {
373 if (angle >= s || angle <= e) {
374 instances.push_back(*it);
377 if (angle >= s && angle <= e) {
378 instances.push_back(*it);
394 min =
m_instances.front()->getLocationRef().getLayerCoordinates(layer);
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);
409 static const float globalmax = 100.0;
410 static const float globalrange = 200.0;
412 int32_t thislayer = 1;
415 std::list<Layer*>::const_iterator iter = layers.begin();
416 for (; iter != layers.end(); ++iter, ++thislayer) {
422 float offset = globalmax - (numlayers - (thislayer - 1)) * (globalrange/numlayers);
433 std::vector<Instance*>::iterator it =
m_instances.begin();
435 (*it)->callOnVisibleChange();
443 std::vector<Instance*>::iterator it =
m_instances.begin();
445 (*it)->callOnTransparencyChange();
463 bool blockingInstance =
false;
470 std::list<Instance*> 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;
479 return blockingInstance;
483 std::vector<Instance*> blockingInstances;
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);
495 std::list<Instance*> 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);
503 return blockingInstances;
556 std::vector<Layer*>::iterator it =
m_interacts.begin();
581 std::vector<Layer*>::iterator it =
m_interacts.begin();
584 (*it)->setInteract(
false,
"");
596 std::vector<Instance*> inactiveInstances;
602 }
else if (!(*it)->isActive()) {
603 inactiveInstances.push_back(*it);
615 if (!inactiveInstances.empty()) {
616 std::vector<Instance*>::iterator i = inactiveInstances.begin();
617 while (i != inactiveInstances.end()) {
635 if ((*i) == listener) {
void setInstancesVisible(bool vis)
Set object visibility.
SortingStrategy m_sortingStrategy
sorting strategy for rendering
std::vector< LayerChangeListener * > m_changeListeners
listeners for layer changes
bool isChanged()
Returns true, if layer information was changed during previous update round.
SortingStrategy getSortingStrategy() const
Gets sorting strategy for the layer.
int32_t getAngleBetween(const Location &loc1, const Location &loc2)
Gets angle of vector defined by given locations.
bool m_walkable
is walkable true/false
bool m_static
true if layer is static
void setExactLayerCoordinates(const ExactModelCoordinate &coordinates)
Sets precise layer coordinates to this location.
Layer * getLayer(const std::string &identifier)
Get the layer with the given id.
std::vector< Instance * > getInstancesAt(Location &loc, bool use_exactcoordinates=false)
Returns instances that match given location.
T h
Height of the rectangle.
std::vector< Instance * > getInstancesInLine(const ModelCoordinate &pt1, const ModelCoordinate &pt2)
Returns instances that match given line between pt1 and pt2.
std::vector< Instance * > getInstancesInCircleSegment(const ModelCoordinate ¢er, uint16_t radius, int32_t sangle, int32_t eangle)
Returns all instances in the circle segment.
InstanceTree * m_instanceTree
The instance tree.
void setLayer(Layer *layer)
Sets layer where this location is pointing to.
~Layer()
Destructs a Layer instance.
std::vector< Instance * > & getChangedInstances()
Returns instances that were changed during previous update round.
void setId(const std::string &id)
Sets the identifier for this layer.
bool hasInstances() const
Check existance of objects on this layer.
A CellCache is an abstract depiction of one or a few layers and contains additional information...
void toggleInstancesVisible()
Toggle object visibility.
void setSortingStrategy(SortingStrategy strategy)
Sets sorting strategy for the layer.
const std::string & getId() const
Get the id of this layer.
void destroyCellCache()
Destroys the CellCache of this layer.
std::list< Instance * > getInstancesIn(Rect &rec)
Returns instances that match given rect.
CellCache * getCellCache()
Returns the CellCache of this layer.
const std::list< Layer * > & getLayers() const
Get the layers on this map.
void createCellCache()
Called from Map to create a CellCache.
Instance * createInstance(Object *object, const ModelCoordinate &p, const std::string &id="")
Add an instance of an object at a specific position.
bool isActive() const
If this returns true, the instance needs to be updated.
static Logger _log(LM_AUDIO)
CellGrid * m_grid
layer's cellgrid
bool m_instancesVisibility
if true the instances are visibility otherwise they are skipped during rendering
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...
CellCache * m_cellCache
pointer to cellcache
Location & getLocationRef()
Gets reference of current location of instance.
void setCellGrid(CellGrid *grid)
Set the Cellgrid.
std::set< Instance * > m_activeInstances
all the active instances on this layer
bool update()
Called periodically to update events on layer.
void addInteractLayer(Layer *layer)
Adds a interact layer to the walkable layer.
std::vector< Instance * > getBlockingInstances(const ModelCoordinate &cellCoordinate)
Returns instances that blocks on given cell.
uint8_t m_transparency
transparency, value 0 means total visible, 128 semi-transparent and 255 invisibility ...
void removeInstance(Instance *instance)
Remove an instance from the layer.
#define FL_ERR(logger, msg)
void setPathingStrategy(PathingStrategy strategy)
Sets pathing strategy for the layer.
void findInstances(const ModelCoordinate &point, int32_t w, int32_t h, InstanceList &list)
Find all instances in a given area.
void setStatic(bool stati)
Marks this layer as visual static.
void removeChangeListener(LayerChangeListener *listener)
Removes associated change listener.
bool addInstance(Instance *instance, const ExactModelCoordinate &p)
Add a valid instance at a specific position.
const std::string & getWalkableId()
Returns the id of the walkable layer if this is a interact layer otherwise the string is empty...
Cell * getCell(const ModelCoordinate &mc)
Returns cell on this coordinate.
const std::set< Instance * > & getInstances()
Returns all instances on this cell.
CellTypeInfo getCellType()
Returns blocker type.
bool m_changed
true if layer (or it's instance) information was changed during previous update round ...
Instance * getInstance(const std::string &identifier)
Get the first instance on this layer with the given identifier.
bool isWalkable()
Returns if a layer is walkable.
Listener interface for changes happening on a layer.
void removeInstance(Instance *instance)
Removes an instance from the quad tree.
void addChangeListener(LayerChangeListener *listener)
Adds new change listener.
bool isStatic()
Returns true, if layer is static.
PathingStrategy getPathingStrategy() const
Gets pathing strategy for the layer.
bool areInstancesVisible() const
Check object visibility.
void setLayerTransparency(uint8_t transparency)
Sets the transparency of all instances on the layer.
ExactModelCoordinate & getExactLayerCoordinatesRef()
Gets reference to exact layer coordinates.
A basic cell on a CellCache.
void setAllowDiagonals(const bool allow_diagonals)
Set whether diagonal cell access is allowed.
std::iterator_traits< octet_iterator >::difference_type distance(octet_iterator first, octet_iterator last)
void addInstance(Instance *instance)
Adds an instance to the quad tree.
void setInteract(bool interact, const std::string &id)
Sets interact for the layer.
const std::vector< Layer * > & getInteractLayers()
Returns all assigned interact layer.
void setWalkable(bool walkable)
Sets walkable for the layer.
std::string m_id
string identifier
void getMinMaxCoordinates(ModelCoordinate &min, ModelCoordinate &max, const Layer *layer=0) const
Retrieves the minimum/maximum coordinates of instances on the layer.
InstanceTree * getInstanceTree(void) const
Get the instance tree.
bool m_interact
is interact true/false
CellGrid * getCellGrid() const
Get the Cellgrid.
const std::vector< Instance * > & getInstances() const
Get the list of instances on this layer.
PathingStrategy
Defines how pathing can be performed on this layer.
std::vector< Instance * > m_instances
all the instances on this layer
DoublePoint intPt2doublePt(Point pt)
Convert from 2D int32_t point to 2D double point.
LayerChangeListener * getCellCacheChangeListener()
Returns change listener.
InstanceChangeInfo update()
Updates the instance related to the current action.
uint32_t getLayerCount() const
Get the overall number of layers.
bool cellContainsBlockingInstance(const ModelCoordinate &cellCoordinate)
Determines if a given cell on the layer contains a blocking instance.
ModelCoordinate getLayerCoordinates() const
Gets cell precision layer coordinates set to this location.
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.
std::vector< Layer * > m_interacts
all assigned interact layers
Map * getMap() const
Get the map this layer is contained in.
void setInstanceActivityStatus(Instance *instance, bool active)
Sets the activity status for given instance on this layer.
void deleteInstance(Instance *instance)
Remove an instance from the layer and delete it.
PathingStrategy m_pathingStrategy
pathing strategy for the layer
bool isInteract()
Returns if a layer is interact.
uint8_t getLayerTransparency()
Returns the layer's transparency value.
Map * m_map
pointer to map
uint32_t getLayerCount() const
Get the overall number of layers.
float getZOffset() const
Calculates z offset for the layer.
std::vector< Instance * > getInstancesInCircle(const ModelCoordinate ¢er, uint16_t radius)
Returns instances that match given center and radius of the circle.
T w
Width of the rectangle.
An Instance is an "instantiation" of an Object at a Location.
std::string m_walkableId
walkable id
std::vector< Instance * > m_changedInstances
holds changed instances after each update