FIFE  be64c707dea6b3250bd4355bf5c825d25920087d
FIFE::InstanceTree Class Reference

#include <instancetree.h>

+ Inheritance diagram for FIFE::InstanceTree:
+ Collaboration diagram for FIFE::InstanceTree:

Public Types

typedef std::list< Instance * > InstanceList
 
typedef QuadTree< InstanceList, MIN_TREE_SIZEInstanceQuadTree
 
typedef InstanceQuadTree::Node InstanceTreeNode
 

Public Member Functions

 InstanceTree ()
 Constructor. More...
 
virtual ~InstanceTree ()
 Destructor. More...
 
void addInstance (Instance *instance)
 Adds an instance to the quad tree. More...
 
void removeInstance (Instance *instance)
 Removes an instance from the quad tree. More...
 
void findInstances (const ModelCoordinate &point, int32_t w, int32_t h, InstanceList &list)
 Find all instances in a given area. More...
 
template<typename Visitor >
void applyVisitor (Visitor &visitor)
 See QuadNode::apply_visitor. More...
 
- Public Member Functions inherited from FIFE::FifeClass
 FifeClass ()
 
virtual ~FifeClass ()
 
fifeid_t getFifeId ()
 Gets unique id of this instance inside the engine. More...
 

Static Public Attributes

static const int32_t MIN_TREE_SIZE = 2
 

Private Attributes

InstanceQuadTree m_tree
 
std::map< Instance *, InstanceTreeNode * > m_reverse
 

Detailed Description

Definition at line 42 of file instancetree.h.

Member Typedef Documentation

◆ InstanceList

Definition at line 46 of file instancetree.h.

◆ InstanceQuadTree

◆ InstanceTreeNode

Constructor & Destructor Documentation

◆ InstanceTree()

FIFE::InstanceTree::InstanceTree ( )

Constructor.

Definition at line 42 of file instancetree.cpp.

◆ ~InstanceTree()

FIFE::InstanceTree::~InstanceTree ( )
virtual

Destructor.

Definition at line 45 of file instancetree.cpp.

Member Function Documentation

◆ addInstance()

void FIFE::InstanceTree::addInstance ( Instance instance)

Adds an instance to the quad tree.

Adds an instance to the quad tree based upon it's location on the layer and it's area.

Parameters
instanceA pointer to the instance to add.
Note
In case you added the instance before this will throw.

Definition at line 48 of file instancetree.cpp.

References FIFE::_log, FIFE::QuadNode< DataType, MinimumSize >::data(), FIFE::QuadTree< DataType, MinimumSize >::find_container(), FL_WARN, FIFE::Location::getLayerCoordinates(), FIFE::Instance::getLocationRef(), m_reverse, m_tree, FIFE::PointType3D< T >::x, and FIFE::PointType3D< T >::y.

Referenced by FIFE::Layer::addInstance(), FIFE::Layer::createInstance(), and FIFE::Instance::setLocation().

+ Here is the caller graph for this function:

◆ applyVisitor()

template<typename Visitor >
void FIFE::InstanceTree::applyVisitor ( Visitor &  visitor)
inline

See QuadNode::apply_visitor.

Definition at line 93 of file instancetree.h.

References FIFE::QuadTree< DataType, MinimumSize >::apply_visitor(), and m_tree.

Referenced by FIFE::QuadTreeRenderer::render().

+ Here is the caller graph for this function:

◆ findInstances()

void FIFE::InstanceTree::findInstances ( const ModelCoordinate point,
int32_t  w,
int32_t  h,
InstanceTree::InstanceList list 
)

Find all instances in a given area.

Takes a box as an area then returns a vector filled with all instances that intersect with that box.

Parameters
pointA ModelCoordinate representing the upper left part of the search area.
wThe width of the search area in Model Units.
hThe height of the search area in Model Units.
listvector reference that will be filled with all instances within that space.

Definition at line 98 of file instancetree.cpp.

References FIFE::RectType< T >::contains(), FIFE::QuadTree< DataType, MinimumSize >::find_container(), m_tree, FIFE::PointType3D< T >::x, and FIFE::PointType3D< T >::y.

Referenced by FIFE::CellCache::addInteractOnRuntime(), FIFE::Layer::cellContainsBlockingInstance(), FIFE::CellCache::createCells(), FIFE::Layer::getBlockingInstances(), FIFE::Layer::getInstancesIn(), FIFE::Layer::getInstancesInCircle(), FIFE::Layer::getInstancesInLine(), FIFE::CellCache::removeInteractOnRuntime(), and FIFE::CellCache::resize().

+ Here is the caller graph for this function:

◆ removeInstance()

void FIFE::InstanceTree::removeInstance ( Instance instance)

Removes an instance from the quad tree.

Locates an instance in the quad tree then removes it.

Parameters
instanceA pointer to the instance to find and remove.
Note
In case you did not add the instance before this will throw.

Definition at line 60 of file instancetree.cpp.

References FIFE::_log, FL_WARN, and m_reverse.

Referenced by FIFE::Layer::deleteInstance(), FIFE::Layer::removeInstance(), and FIFE::Instance::setLocation().

+ Here is the caller graph for this function:

Member Data Documentation

◆ m_reverse

std::map<Instance*,InstanceTreeNode*> FIFE::InstanceTree::m_reverse
private

Definition at line 100 of file instancetree.h.

Referenced by addInstance(), and removeInstance().

◆ m_tree

InstanceQuadTree FIFE::InstanceTree::m_tree
private

Definition at line 99 of file instancetree.h.

Referenced by addInstance(), applyVisitor(), and findInstances().

◆ MIN_TREE_SIZE

const int32_t FIFE::InstanceTree::MIN_TREE_SIZE = 2
static

Definition at line 44 of file instancetree.h.


The documentation for this class was generated from the following files: