Dragonfly 4.20
A text-based game engine
Public Member Functions | Private Member Functions | Private Attributes | List of all members
df::QuadtreeNode Class Reference

Public Member Functions

 QuadtreeNode (QuadtreeNode *p_parent, int depth, Box boundary)
 
 ~QuadtreeNode ()
 
ObjectList getObjects () const
 
Box getBoundary () const
 
int getDepth () const
 
int insertObject (Object *p_o)
 
int removeObject (Object *p_o)
 
int split ()
 
QuadtreeNodefindOwner (Object *p_o)
 
QuadtreeNodefindOwner (Object *p_o, Vector where)
 
QuadtreeNodefindOwner (Object *p_o, Box b)
 
ObjectList getCollisions (Object *p_o, Vector where) const
 
std::string toString () const
 

Private Member Functions

ObjectList getCollisions (Object *p_o, Vector where, int delta, bool self) const
 

Private Attributes

int m_depth
 
Box m_boundary
 
QuadtreeNodem_p_parent
 
ObjectList m_objects
 
bool m_split
 
QuadtreeNodem_p_child [4]
 

Constructor & Destructor Documentation

◆ QuadtreeNode()

df::QuadtreeNode::QuadtreeNode ( QuadtreeNode p_parent,
int  depth,
Box  boundary 
)

Construct new node with given parent, depth and boundary.

◆ ~QuadtreeNode()

df::QuadtreeNode::~QuadtreeNode ( )

Destructor, free up child nodes.

Member Function Documentation

◆ findOwner() [1/3]

QuadtreeNode * df::QuadtreeNode::findOwner ( Object p_o)

Return node in hierarchy where Object should be placed.

Return NULL if error.

◆ findOwner() [2/3]

QuadtreeNode * df::QuadtreeNode::findOwner ( Object p_o,
Box  b 
)

Return node in hierarchy where Object should be placed if has new bounding box.

Return NULL if error.

◆ findOwner() [3/3]

QuadtreeNode * df::QuadtreeNode::findOwner ( Object p_o,
Vector  where 
)

Return node in hierarchy where Object should be placed if moved to 'where'.

Return NULL if error.

◆ getBoundary()

Box df::QuadtreeNode::getBoundary ( ) const

Get boundary.

◆ getCollisions()

ObjectList df::QuadtreeNode::getCollisions ( Object p_o,
Vector  where 
) const

Return all Objects that collide at given location.

List is empty if none.

◆ getDepth()

int df::QuadtreeNode::getDepth ( ) const

Get depth.

◆ getObjects()

ObjectList df::QuadtreeNode::getObjects ( ) const

Return list of Objects at this node.

◆ insertObject()

int df::QuadtreeNode::insertObject ( Object p_o)

Insert Object at this node and split if count > threshold.

Return 0 if ok, else -1.

◆ removeObject()

int df::QuadtreeNode::removeObject ( Object p_o)

Remove Object from this node.

Return 0 if ok (found), else -1.

◆ split()

int df::QuadtreeNode::split ( )

Split this node if it hasn't already.

Return 0 if ok, else -1.

◆ toString()

std::string df::QuadtreeNode::toString ( ) const

Return current node as string.

Member Data Documentation

◆ m_boundary

Box df::QuadtreeNode::m_boundary
private

Bounding box of this node.

◆ m_depth

int df::QuadtreeNode::m_depth
private

Depth of this node.

◆ m_objects

ObjectList df::QuadtreeNode::m_objects
private

Objects contained in this node.

◆ m_p_child

QuadtreeNode* df::QuadtreeNode::m_p_child[4]
private

Child nodes (NULL when none).

◆ m_p_parent

QuadtreeNode* df::QuadtreeNode::m_p_parent
private

Parent node (NULL if root).

◆ m_split

bool df::QuadtreeNode::m_split
private

True if already split children.