FIFE
be64c707dea6b3250bd4355bf5c825d25920087d
|
#include <quadtree.h>
Public Member Functions | |
QuadNode (QuadNode *parent, int32_t x, int32_t y, int32_t size) | |
Create a new QuadNode. More... | |
~QuadNode () | |
QuadNode * | find_container (int32_t x, int32_t y, int32_t w, int32_t h) |
Find a container node for a given rectangle. More... | |
QuadNode * | find_container (const Rect &rect) |
template<typename Visitor > | |
void | apply_visitor (Visitor &visitor, int32_t d=0) |
Apply a visitor recursively to the QuadTree A visitor is an object which has a visit method which takes as parameters a pointer to a QuadNode and an integer. More... | |
int32_t | x () const |
Return the X position of the node. More... | |
int32_t | y () const |
Return the Y position of the node. More... | |
int32_t | size () const |
Return the size (width and height) of the node. More... | |
DataType & | data () |
Return a reference to the data of the node. More... | |
bool | contains (int32_t x, int32_t y, int32_t w, int32_t h) const |
Check whether a rectangle is contained in the node. More... | |
void | splice () |
Expand the subnodes - only needed for debugging/profiling worst cases. More... | |
QuadNode * | parent () |
Return the parent node. More... | |
QuadNode * | create_parent (int32_t x, int32_t y, int32_t w, int32_t h) |
Create a new parent node for a rectangle This will create a new parent node end expand the tree so that the given rectangle will eventually be contained after enough calls of this function. More... | |
Protected Member Functions | |
int32_t | subnode (int32_t x, int32_t y, int32_t w, int32_t h) const |
Protected Attributes | |
QuadNode * | m_parent |
QuadNode * | m_nodes [4] |
int32_t | m_x |
int32_t | m_y |
int32_t | m_size |
DataType | m_data |
QuadTree Node.
Definition at line 41 of file quadtree.h.
|
inline |
Create a new QuadNode.
parent | The parent QuadNode this node is contained in or null. |
x | The X position of this QuadNode. |
y | The Y position of this QuadNode. |
size | The width and height of this QuadNode. |
Definition at line 55 of file quadtree.h.
Referenced by FIFE::QuadNode< DataType, MinimumSize >::create_parent().
|
inline |
Definition at line 60 of file quadtree.h.
References FIFE::QuadNode< DataType, MinimumSize >::find_container(), FIFE::QuadNode< DataType, MinimumSize >::x(), and FIFE::QuadNode< DataType, MinimumSize >::y().
|
inline |
Apply a visitor recursively to the QuadTree A visitor is an object which has a visit
method which takes as parameters a pointer to a QuadNode
and an integer.
The integer is the depth of the given node. If the method returns true
it is applied recursivly to all existing subnodes with a depth increased by one. The application happens in Z order (top left, top right, bottom left and finally bottom right).
Definition at line 93 of file quadtree.h.
References FIFE::QuadNode< DataType, MinimumSize >::apply_visitor().
Referenced by FIFE::QuadNode< DataType, MinimumSize >::apply_visitor(), and FIFE::LayerCache::collect().
|
inline |
Check whether a rectangle is contained in the node.
A rectangle is contained in a node, iff:
That is the top and left borders are inclusive, but the right and bottom borders are exclusive.
Definition at line 211 of file quadtree.h.
References FIFE::QuadNode< DataType, MinimumSize >::m_size, FIFE::QuadNode< DataType, MinimumSize >::m_x, and FIFE::QuadNode< DataType, MinimumSize >::m_y.
Referenced by FIFE::QuadNode< DataType, MinimumSize >::create_parent(), FIFE::QuadNode< DataType, MinimumSize >::data(), and FIFE::QuadNode< DataType, MinimumSize >::find_container().
QuadNode< DataType, MinimumSize > * FIFE::QuadNode< DataType, MinimumSize >::create_parent | ( | int32_t | x, |
int32_t | y, | ||
int32_t | w, | ||
int32_t | h | ||
) |
Create a new parent node for a rectangle This will create a new parent node end expand the tree so that the given rectangle will eventually be contained after enough calls of this function.
Definition at line 298 of file quadtree.h.
References FIFE::QuadNode< DataType, MinimumSize >::contains(), FIFE::QuadNode< DataType, MinimumSize >::m_nodes, FIFE::QuadNode< DataType, MinimumSize >::m_parent, FIFE::QuadNode< DataType, MinimumSize >::m_size, FIFE::QuadNode< DataType, MinimumSize >::m_x, FIFE::QuadNode< DataType, MinimumSize >::m_y, and FIFE::QuadNode< DataType, MinimumSize >::QuadNode().
Referenced by FIFE::QuadTree< InstanceList, MIN_TREE_SIZE >::find_container(), and FIFE::QuadNode< DataType, MinimumSize >::parent().
|
inline |
Return a reference to the data of the node.
Definition at line 116 of file quadtree.h.
References FIFE::QuadNode< DataType, MinimumSize >::contains(), FIFE::QuadNode< DataType, MinimumSize >::m_data, and FIFE::QuadNode< DataType, MinimumSize >::splice().
Referenced by FIFE::InstanceTree::addInstance(), FIFE::LayerCache::updatePosition(), and FIFE::CacheTreeCollector::visit().
QuadNode< DataType, MinimumSize > * FIFE::QuadNode< DataType, MinimumSize >::find_container | ( | int32_t | x, |
int32_t | y, | ||
int32_t | w, | ||
int32_t | h | ||
) |
Find a container node for a given rectangle.
This guarantees to return a Node with the following properties: 1.) The node contains the rectangle (as defined by the contains function). 2.) All subnodes can not contain the rectangle or it has the MinimumSize. 3.) In case these properties can only be fulfilled by extending the tree upwards, that is by creating a new root node - this function will return null.
This function will extend the tree automatically so that this guarantee can be fulfilled.
Definition at line 254 of file quadtree.h.
References FIFE::QuadNode< DataType, MinimumSize >::contains(), FIFE::QuadNode< DataType, MinimumSize >::find_container(), FIFE::QuadNode< DataType, MinimumSize >::m_nodes, FIFE::QuadNode< DataType, MinimumSize >::m_parent, FIFE::QuadNode< DataType, MinimumSize >::m_size, FIFE::QuadNode< DataType, MinimumSize >::m_x, FIFE::QuadNode< DataType, MinimumSize >::m_y, and FIFE::QuadNode< DataType, MinimumSize >::subnode().
Referenced by FIFE::LayerCache::collect(), FIFE::QuadNode< DataType, MinimumSize >::find_container(), FIFE::QuadTree< InstanceList, MIN_TREE_SIZE >::find_container(), FIFE::LayerCache::updatePosition(), FIFE::QuadNode< DataType, MinimumSize >::~QuadNode(), and FIFE::QuadTree< InstanceList, MIN_TREE_SIZE >::~QuadTree().
|
inline |
Definition at line 79 of file quadtree.h.
References FIFE::QuadNode< DataType, MinimumSize >::find_container(), FIFE::RectType< T >::h, FIFE::RectType< T >::w, FIFE::RectType< T >::x, and FIFE::RectType< T >::y.
|
inline |
Return the parent node.
Definition at line 133 of file quadtree.h.
References FIFE::QuadNode< DataType, MinimumSize >::create_parent(), FIFE::QuadNode< DataType, MinimumSize >::m_parent, and FIFE::QuadNode< DataType, MinimumSize >::subnode().
Referenced by FIFE::LayerCache::collect().
|
inline |
Return the size (width and height) of the node.
Definition at line 112 of file quadtree.h.
References FIFE::QuadNode< DataType, MinimumSize >::m_size.
Referenced by FIFE::RenderVisitor::visit(), and FIFE::CacheTreeCollector::visit().
void FIFE::QuadNode< DataType, MinimumSize >::splice | ( | ) |
Expand the subnodes - only needed for debugging/profiling worst cases.
Definition at line 339 of file quadtree.h.
References FIFE::QuadNode< DataType, MinimumSize >::m_nodes, FIFE::QuadNode< DataType, MinimumSize >::m_size, FIFE::QuadNode< DataType, MinimumSize >::m_x, and FIFE::QuadNode< DataType, MinimumSize >::m_y.
Referenced by FIFE::QuadNode< DataType, MinimumSize >::data().
|
inlineprotected |
Definition at line 225 of file quadtree.h.
References FIFE::QuadNode< DataType, MinimumSize >::m_size, FIFE::QuadNode< DataType, MinimumSize >::m_x, and FIFE::QuadNode< DataType, MinimumSize >::m_y.
Referenced by FIFE::QuadNode< DataType, MinimumSize >::find_container(), and FIFE::QuadNode< DataType, MinimumSize >::parent().
|
inline |
Return the X position of the node.
Definition at line 104 of file quadtree.h.
References FIFE::QuadNode< DataType, MinimumSize >::m_x.
Referenced by FIFE::QuadTree< InstanceList, MIN_TREE_SIZE >::QuadTree(), FIFE::RenderVisitor::visit(), FIFE::CacheTreeCollector::visit(), FIFE::QuadNode< DataType, MinimumSize >::~QuadNode(), and FIFE::QuadTree< InstanceList, MIN_TREE_SIZE >::~QuadTree().
|
inline |
Return the Y position of the node.
Definition at line 108 of file quadtree.h.
References FIFE::QuadNode< DataType, MinimumSize >::m_y.
Referenced by FIFE::QuadTree< InstanceList, MIN_TREE_SIZE >::QuadTree(), FIFE::RenderVisitor::visit(), FIFE::CacheTreeCollector::visit(), FIFE::QuadNode< DataType, MinimumSize >::~QuadNode(), and FIFE::QuadTree< InstanceList, MIN_TREE_SIZE >::~QuadTree().
|
protected |
Definition at line 46 of file quadtree.h.
Referenced by FIFE::QuadNode< DataType, MinimumSize >::data().
|
protected |
Definition at line 44 of file quadtree.h.
Referenced by FIFE::QuadNode< DataType, MinimumSize >::create_parent(), FIFE::QuadNode< DataType, MinimumSize >::find_container(), and FIFE::QuadNode< DataType, MinimumSize >::splice().
|
protected |
Definition at line 43 of file quadtree.h.
Referenced by FIFE::QuadNode< DataType, MinimumSize >::create_parent(), FIFE::QuadNode< DataType, MinimumSize >::find_container(), and FIFE::QuadNode< DataType, MinimumSize >::parent().
|
protected |
Definition at line 45 of file quadtree.h.
Referenced by FIFE::QuadNode< DataType, MinimumSize >::contains(), FIFE::QuadNode< DataType, MinimumSize >::create_parent(), FIFE::QuadNode< DataType, MinimumSize >::find_container(), FIFE::QuadNode< DataType, MinimumSize >::size(), FIFE::QuadNode< DataType, MinimumSize >::splice(), and FIFE::QuadNode< DataType, MinimumSize >::subnode().
|
protected |
Definition at line 45 of file quadtree.h.
Referenced by FIFE::QuadNode< DataType, MinimumSize >::contains(), FIFE::QuadNode< DataType, MinimumSize >::create_parent(), FIFE::QuadNode< DataType, MinimumSize >::find_container(), FIFE::QuadNode< DataType, MinimumSize >::splice(), FIFE::QuadNode< DataType, MinimumSize >::subnode(), and FIFE::QuadNode< DataType, MinimumSize >::x().
|
protected |
Definition at line 45 of file quadtree.h.
Referenced by FIFE::QuadNode< DataType, MinimumSize >::contains(), FIFE::QuadNode< DataType, MinimumSize >::create_parent(), FIFE::QuadNode< DataType, MinimumSize >::find_container(), FIFE::QuadNode< DataType, MinimumSize >::splice(), FIFE::QuadNode< DataType, MinimumSize >::subnode(), and FIFE::QuadNode< DataType, MinimumSize >::y().