50 m_instancesVisibility(true),
126 (*i)->onInstanceCreate(
this, instance);
135 FL_ERR(
_log,
"Tried to add an instance to layer, but given instance is invalid");
151 (*i)->onInstanceCreate(
this, instance);
165 std::vector<Instance*> updateInstances;
166 updateInstances.push_back(instance);
169 (*i)->onLayerChanged(
this, updateInstances);
177 (*i)->onInstanceDelete(
this, instance);
181 std::vector<Instance*>::iterator it =
m_instances.begin();
183 if(*it == instance) {
199 std::vector<Instance*> updateInstances;
200 updateInstances.push_back(instance);
203 (*i)->onLayerChanged(
this, updateInstances);
211 (*i)->onInstanceDelete(
this, instance);
215 std::vector<Instance*>::iterator it =
m_instances.begin();
217 if(*it == instance) {
241 std::vector<Instance*>::iterator it =
m_instances.begin();
243 if((*it)->getId() == id)
251 std::vector<Instance*> matching_instances;
252 std::vector<Instance*>::iterator it =
m_instances.begin();
254 if((*it)->getId() == id)
255 matching_instances.push_back(*it);
257 return matching_instances;
261 std::vector<Instance*> matching_instances;
262 std::vector<Instance*>::iterator it =
m_instances.begin();
265 if (use_exactcoordinates) {
267 matching_instances.push_back(*it);
271 matching_instances.push_back(*it);
276 return matching_instances;
280 std::list<Instance*> matching_instances;
284 return matching_instances;
296 min =
m_instances.front()->getLocationRef().getLayerCoordinates(layer);
300 ModelCoordinate coord = (*i)->getLocationRef().getLayerCoordinates(layer);
301 min.
x = std::min(min.
x, coord.
x);
302 max.
x = std::max(max.
x, coord.
x);
303 min.
y = std::min(min.
y, coord.
y);
304 max.
y = std::max(max.
y, coord.
y);
313 std::vector<Instance*>::iterator it =
m_instances.begin();
315 (*it)->callOnVisibleChange();
323 std::vector<Instance*>::iterator it =
m_instances.begin();
325 (*it)->callOnTransparencyChange();
343 bool blockingInstance =
false;
350 std::list<Instance*> adjacentInstances;
352 for(std::list<Instance*>::const_iterator j = adjacentInstances.begin(); j != adjacentInstances.end(); ++j) {
353 if((*j)->isBlocking() && (*j)->getLocationRef().getLayerCoordinates() == cellCoordinate) {
354 blockingInstance =
true;
359 return blockingInstance;
363 std::vector<Instance*> blockingInstances;
367 const std::set<Instance*>& blocker = cell->
getInstances();
368 for (std::set<Instance*>::const_iterator it = blocker.begin(); it != blocker.end(); ++it) {
369 if ((*it)->isBlocking()) {
370 blockingInstances.push_back(*it);
375 std::list<Instance*> adjacentInstances;
377 for(std::list<Instance*>::const_iterator j = adjacentInstances.begin(); j != adjacentInstances.end(); ++j) {
378 if((*j)->isBlocking() && (*j)->getLocationRef().getLayerCoordinates() == cellCoordinate) {
379 blockingInstances.push_back(*j);
383 return blockingInstances;
436 std::vector<Layer*>::iterator it =
m_interacts.begin();
461 std::vector<Layer*>::iterator it =
m_interacts.begin();
464 (*it)->setInteract(
false,
"");
476 std::vector<Instance*> inactiveInstances;
482 }
else if (!(*it)->isActive()) {
483 inactiveInstances.push_back(*it);
495 if (!inactiveInstances.empty()) {
496 std::vector<Instance*>::iterator i = inactiveInstances.begin();
497 while (i != inactiveInstances.end()) {
515 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
Map * getMap() const
Get the map this layer is contained in.
bool isChanged()
Returns true, if layer information was changed during previous update round.
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.
InstanceTree * m_instanceTree
The instance tree.
bool isActive() const
If this returns true, the instance needs to be updated.
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.
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.
bool hasInstances() const
Check existance of objects on 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.
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.
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...
bool areInstancesVisible() const
Check object visibility.
InstanceTree * getInstanceTree(void) const
Get the instance tree.
CellCache * m_cellCache
pointer to cellcache
Location & getLocationRef()
Gets reference of current location of instance.
ModelCoordinate getLayerCoordinates() const
Gets cell precision layer coordinates set to this location.
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 getMinMaxCoordinates(ModelCoordinate &min, ModelCoordinate &max, const Layer *layer=0) const
Retrieves the minimum/maximum coordinates of instances on 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.
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.
CellGrid * getCellGrid() const
Get the Cellgrid.
void addInstance(Instance *instance)
Adds an instance to the quad tree.
PathingStrategy getPathingStrategy() const
Gets pathing strategy for the layer.
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
bool m_interact
is interact true/false
PathingStrategy
Defines how pathing can be performed on this layer.
const std::string & getId() const
Get the id of this layer.
SortingStrategy getSortingStrategy() const
Gets sorting strategy for the layer.
std::vector< Instance * > m_instances
all the instances on this layer
LayerChangeListener * getCellCacheChangeListener()
Returns change listener.
InstanceChangeInfo update()
Updates the instance related to the current action.
const std::vector< Instance * > & getInstances() const
Get the list of instances on this layer.
bool cellContainsBlockingInstance(const ModelCoordinate &cellCoordinate)
Determines if a given cell on the layer contains a blocking instance.
void removeInteractLayer(Layer *layer)
Removes a interact layer from the walkable layer.
std::vector< Layer * > m_interacts
all assigned interact layers
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
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