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

Dynamic AABB tree for broadphase queries. Based on Erin Catto's dynamic tree in Box2D (http://www.box2d.org) which is in turn inspired by Nathanael Presson's btDbvt. (https://pybullet.org/wordpress/) More...

#include <DynamicTreeSystem.hpp>

Inheritance diagram for xy::DynamicTreeSystem:
xy::System

Public Member Functions

 DynamicTreeSystem (xy::MessageBus &)
 
void process (float) override
 Implement this for system specific processing to entities.
 
void onEntityAdded (xy::Entity) override
 Optional callback performed when an entity is added.
 
void onEntityRemoved (xy::Entity) override
 Optional callback performed when an entity is removed.
 
std::vector< xy::Entityquery (sf::FloatRect area, std::uint64_t filter=std::numeric_limits< std::uint64_t >::max()) const
 returns a list of entities whose broadphase bounds intersect the given query area. More...
 
- 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)
 

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

Dynamic AABB tree for broadphase queries. Based on Erin Catto's dynamic tree in Box2D (http://www.box2d.org) which is in turn inspired by Nathanael Presson's btDbvt. (https://pybullet.org/wordpress/)

Dynamic trees can perform 33%-50% faster on a scene containing a lot of moving objects compared to a Quad Tree (in personal bench marks at least). On the other hand a Quad Tree is usually more optimal for a scene with a lot of static geometry (such as a platformer game). One or the other should usually be chosen based on the type of scene to which it is applied - although bench marking will give the most accurate results. Using both in a single scene is generally considered redundant.

Member Function Documentation

◆ query()

std::vector<xy::Entity> xy::DynamicTreeSystem::query ( sf::FloatRect  area,
std::uint64_t  filter = std::numeric_limits< std::uint64_t >::max() 
) const

returns a list of entities whose broadphase bounds intersect the given query area.

Parameters
areaArea in world coordinates to query
filterOnly entities with BroadphaseComponents matching the given bit flags are returned. Defaults to all flags set.