Game of Ur 0.3.3
This is a computer adaptation of Game of Ur, written in C++ mainly using SDL and OpenGL.
Loading...
Searching...
No Matches
ToyMaker::SpatialQuerySystem Class Reference

The spatial query system, an ECS System that tracks and updates spatial query data for objects in the scene, and which exposes spatial query methods. More...

#include <spatial_query_system.hpp>

Inheritance diagram for ToyMaker::SpatialQuerySystem:
ToyMaker::System< SpatialQuerySystem, std::tuple< Transform, ObjectBounds >, std::tuple< SceneHierarchyData, AxisAlignedBounds > >

Classes

class  LightBoundsComputeSystem
 A subsystem of the spatial query system responsible for tracking light volumes and recomputing their ObjectBounds accordingly. More...
 
class  StaticModelBoundsComputeSystem
 A subsystem of the SpatialQuery system which tracks StaticModel objects in the scene and updates the position and shapes of their associated object bounds accordingly. More...
 

Public Member Functions

 SpatialQuerySystem (std::weak_ptr< ECSWorld > world)
 
std::vector< std::pair< EntityID, AxisAlignedBounds > > findEntitiesOverlapping (const AxisAlignedBounds &searchBounds) const
 Returns a list of entities (by their IDs) overlapping a search AABB.
 
std::vector< std::pair< EntityID, AxisAlignedBounds > > findEntitiesOverlapping (const Ray &ray) const
 Returns a list of entities (by their IDs) intersecting a search ray.
 
std::vector< std::shared_ptr< SceneNodeCore > > findNodesOverlapping (const Ray &searchRay)
 Gets a list of nodes (by their base class pointers) intersecting a search ray.
 
std::vector< std::shared_ptr< SceneNodeCore > > findNodesOverlapping (const AxisAlignedBounds &searchBounds)
 Gets a list of nodes which overlap some search region (in the form of an AABB).
 

Static Public Member Functions

static std::string getSystemTypeName ()
 Gets the system type string associated with this class.
 

Private Member Functions

void updateBounds (EntityID entity)
 Updates the axis aligned bounds of an entity, based on its ObjectBounds.
 
void rebuildOctree ()
 Triggers the destruction of any presently existing octree and replaces it with a new one.
 
void onSimulationActivated () override
 Marks this system as requiring initialization on the nearest update.
 
void onSimulationStep (uint32_t timestepMillis) override
 Initializes the tree if necessary, and recomputes octree position for entities whose ObjectBounds were updated.
 
void onEntityEnabled (EntityID entityID) override
 Marks this entity as requiring an octree update on the nearest simulation step.
 
void onEntityDisabled (EntityID entityID) override
 Removes this entity from the Octree.
 
void onEntityUpdated (EntityID entityID) override
 Marks this entity as requiring an octree update on the nearest simulation step.
 

Private Attributes

std::unique_ptr< OctreemOctree { nullptr }
 Pointer to the octree, the data structure responsible for spatially indexing scene objects.
 
std::set< EntityIDmComputeQueue {}
 A list of entities whose AABBs should be recomputed at the next simulation step.
 
bool mRequiresInitialization { true }
 Whether a fresh Octree should be built for this system as soon as possible.
 

Detailed Description

The spatial query system, an ECS System that tracks and updates spatial query data for objects in the scene, and which exposes spatial query methods.

It is presently implemented as an octree, and only answers questions that take the form of a Ray or an AABB.

Todo
SceneHierarchyData isn't required by this system, as far as I can tell.

Member Function Documentation

◆ findEntitiesOverlapping() [1/2]

std::vector< std::pair< EntityID, AxisAlignedBounds > > SpatialQuerySystem::findEntitiesOverlapping ( const AxisAlignedBounds & searchBounds) const

Returns a list of entities (by their IDs) overlapping a search AABB.

Parameters
searchBoundsThe AABB defining the search region.
Returns
std::vector<std::pair<EntityID, AxisAlignedBounds>> The list of entities overlapping with the search region.

◆ findEntitiesOverlapping() [2/2]

std::vector< std::pair< EntityID, AxisAlignedBounds > > SpatialQuerySystem::findEntitiesOverlapping ( const Ray & ray) const

Returns a list of entities (by their IDs) intersecting a search ray.

Parameters
rayThe ray intersecting which a list of entities should be found.
Returns
std::vector<std::pair<EntityID, AxisAlignedBounds>> A list of entities intersected by the query ray.

◆ findNodesOverlapping() [1/2]

std::vector< std::shared_ptr< SceneNodeCore > > SpatialQuerySystem::findNodesOverlapping ( const AxisAlignedBounds & searchBounds)

Gets a list of nodes which overlap some search region (in the form of an AABB).

Parameters
searchBoundsThe search region (as an AABB).
Returns
std::vector<std::shared_ptr<SceneNodeCore>> The list of nodes contained by or overlapping the search region.

◆ findNodesOverlapping() [2/2]

std::vector< std::shared_ptr< SceneNodeCore > > SpatialQuerySystem::findNodesOverlapping ( const Ray & searchRay)

Gets a list of nodes (by their base class pointers) intersecting a search ray.

Parameters
searchRayThe ray intersecting which a list of nodes should be found.
Returns
std::vector<std::shared_ptr<SceneNodeCore>> A list of nodes intersecting the search ray.

◆ getSystemTypeName()

static std::string ToyMaker::SpatialQuerySystem::getSystemTypeName ( )
inlinestatic

Gets the system type string associated with this class.

Returns
std::string This class' system type string.

◆ onEntityDisabled()

void SpatialQuerySystem::onEntityDisabled ( EntityID entityID)
overrideprivate

Removes this entity from the Octree.

Parameters
entityIDThe entity being removed.

◆ onEntityEnabled()

void SpatialQuerySystem::onEntityEnabled ( EntityID entityID)
overrideprivate

Marks this entity as requiring an octree update on the nearest simulation step.

Parameters
entityIDThe entity in need of an update.

◆ onEntityUpdated()

void SpatialQuerySystem::onEntityUpdated ( EntityID entityID)
overrideprivate

Marks this entity as requiring an octree update on the nearest simulation step.

Parameters
entityIDThe entity in need of an AABB update.

◆ onSimulationStep()

void SpatialQuerySystem::onSimulationStep ( uint32_t timestepMillis)
overrideprivate

Initializes the tree if necessary, and recomputes octree position for entities whose ObjectBounds were updated.

Parameters
timestepMillisThe time by which the simulation will be advanced this simulation frame.

◆ updateBounds()

void SpatialQuerySystem::updateBounds ( EntityID entity)
private

Updates the axis aligned bounds of an entity, based on its ObjectBounds.

Parameters
entityThe entity whose axis aligned bounds are being updated.

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