xyginext  0.2.0
Second generation of xygine game creation framework
Public Member Functions | Static Public Attributes | List of all members
xy::QuadTree Class Referencefinal

Partition system for entities with QuadTreeItem components. Entities are sorted in a tree hierarchy which can be queried with a given area to return a set of entities which are contained or intersect said area. Generally more useful for scenes with a lot of static entities such as a platform game with fixed scenery. If using a scene with a lot of dynamic objects consider using xy::DynamicTreeSystem instead. More...

#include <QuadTree.hpp>

Inheritance diagram for xy::QuadTree:
xy::System

Public Member Functions

 QuadTree (xy::MessageBus &, sf::FloatRect rootArea)
 Constructor. More...
 
void process (float) override
 Implement this for system specific processing to entities.
 
std::vector< xy::EntityqueryArea (sf::FloatRect area, std::uint64_t=std::numeric_limits< std::uint64_t >::max()) const
 Queries the QuadTree with the given area. Returns a vector of entities whose QuadTreeItems are contained in tree nodes which intersect the given area. /param area The area to query /param filterFlags Only entities with QuadTreeItems matching the given bit flags are returns. Defaults to all flags set.
 
std::vector< xy::EntityqueryPoint (sf::Vector2f, std::uint64_t=std::numeric_limits< std::uint64_t >::max()) const
 Queries the quad tree with the given position. Returns a vector of entities whose QuadTreeItems are contained in tree nodes which also contain the given point /param area The area to query /param filterFlags Only entities with QuadTreeItems matching the given bit flags are returns. Defaults to all flags set.
 
sf::FloatRect getRootArea () const
 Returns the area with which the QuadTree was created.
 
const std::vector< xy::Entity > & getOutsideRootEnts () const
 Returns a vector of any entities which fall outside of the root area.
 
std::vector< xy::Entity > & getOutsideRootEnts ()
 
std::size_t getEntityCount () const
 Returns the total number of entities which fall within the root area.
 
- Public Member Functions inherited from xy::System
 System (MessageBus &mb, UniqueType t)
 Constructor. Pass in a reference to the concrete implementation to generate a unique type ID for this system.
 
UniqueType getType () const
 Returns the unique type ID of the system.
 
const std::vector< Entity > & getEntities () const
 Returns a list of entities that this system is currently interested in.
 
void addEntity (Entity)
 Adds an entity to the list to process.
 
void removeEntity (Entity)
 Removes an entity from the list to process.
 
const ComponentMask & getComponentMask () const
 Returns the component mask used to mask entities with corresponding components for this system to process.
 
virtual void handleMessage (const Message &)
 Used to process any incoming system messages.
 
bool isActive () const
 Returns true if the system is currently active. Systems can be activeated and deactivated with Scene::setSystemActive()
 
template<typename T >
void requireComponent ()
 
template<typename T >
T * postMessage (Message::ID id)
 

Static Public Attributes

static constexpr sf::Int32 MinNodeEntities = 3
 
static constexpr std::size_t MaxNodeEntities = 6u
 
static constexpr sf::Int32 MaxLevels = 40u
 

Additional Inherited Members

- Public Types inherited from xy::System
using Ptr = std::unique_ptr< System >
 
- Protected Member Functions inherited from xy::System
template<typename T >
void requireComponent ()
 Adds a component type to the list of components required by the system for it to be interested in a particular entity. This should only be used in the constructor of the System else types will not be registered.
 
std::vector< Entity > & getEntities ()
 
template<typename T >
T * postMessage (Message::ID id)
 Posts a message on the system wide message bus.
 
MessageBusgetMessageBus ()
 Returns a reference to the MessageBus.
 
void setScene (Scene &)
 
ScenegetScene ()
 Returns a pointer to the scene to which this system belongs.
 

Detailed Description

Partition system for entities with QuadTreeItem components. Entities are sorted in a tree hierarchy which can be queried with a given area to return a set of entities which are contained or intersect said area. Generally more useful for scenes with a lot of static entities such as a platform game with fixed scenery. If using a scene with a lot of dynamic objects consider using xy::DynamicTreeSystem instead.

See also
DynamicTreeSystem

Constructor & Destructor Documentation

◆ QuadTree()

xy::QuadTree::QuadTree ( xy::MessageBus ,
sf::FloatRect  rootArea 
)

Constructor.

Parameters
rootAreaArea in world coordinates for the root node of the tree. All subsequent nodes are contained within this area