ToyMaker Game Engine 0.0.2
ToyMaker is a game engine developed and maintained by Zoheb Shujauddin.
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 <system.hpp>

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

Classes

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...
class  LightBoundsComputeSystem
 A subsystem of the spatial query system responsible for tracking light volumes and recomputing their ObjectBounds accordingly. More...

Public Member Functions

 SpatialQuerySystem (std::weak_ptr< ECSWorld > world)
std::vector< std::pair< EntityID, AxisAlignedBounds > > findEntitiesOverlappingCoarse (const AxisAlignedBounds &searchBounds, InteractionLayerMask interactionMask=std::numeric_limits< InteractionLayerMask >::max()) const
 Returns a list of entities (by their IDs) whose AABBs overlap a search AABB.
std::vector< std::pair< EntityID, AxisAlignedBounds > > findEntitiesOverlappingCoarse (const Ray &ray, InteractionLayerMask interactionMask=std::numeric_limits< InteractionLayerMask >::max()) const
 Returns a list of entities (by their IDs) whose AABBs intersect a search ray.
std::vector< std::shared_ptr< SceneNodeCore > > findNodesOverlappingCoarse (const Ray &searchRay, InteractionLayerMask interactionMask=std::numeric_limits< InteractionLayerMask >::max())
 Gets a list of nodes (by their base class pointers) whose AABBs intersect a search ray.
std::vector< std::shared_ptr< SceneNodeCore > > findNodesOverlappingCoarse (const AxisAlignedBounds &searchBounds, InteractionLayerMask interactionMask=std::numeric_limits< InteractionLayerMask >::max())
 Gets a list of nodes whose AABBs overlap some search region (in the form of an AABB).
void updateBoundingVolume (EntityID entity, ObjectBounds::TrueVolumeType volumeType, const ObjectBounds::TrueVolume &volume, const glm::vec3 &positionOffset, const glm::quat &orientationOffset)
 Manually updates the volume component of an entity.
void updateBounds (const std::shared_ptr< SceneNodeCore > &sceneNode, ObjectBounds::TrueVolumeType volumeType, const ObjectBounds::TrueVolume &volume, const glm::vec3 &positionOffset, const glm::quat &orientationOffset)
 Manually updates the object bounds component of a scene object.
void resetBoundsOverride (EntityID entity)
 Allows bounds to be computed by spatial bounds compute systems.

Static Public Member Functions

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

Private Member Functions

void updateBounds (EntityID entity, bool forceUpdateFromTransform=false)
 Updates the axis aligned bounds of an entity based on its ObjectBounds.
void updateTransform (EntityID entity)
 Updates the world transform of an entity based on its objects bounds.
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 onSimulationPostStep (uint32_t timestepMillis) override
 Initializes the tree if necessary, and recomputes octree position for entities whose ObjectBounds were updated.
void onPostTransformUpdate (uint32_t timestepMillis) override
 Uses latest transforms to update object bounds if required.
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, ComponentType updatedComponent) 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< EntityIDmUpdateQueueAABB {}
 A list of entities whose AABBs should be recomputed at the next simulation step.
std::set< EntityIDmUpdateQueueTransform {}
 A list of entities whose transforms 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

◆ findEntitiesOverlappingCoarse() [1/2]

std::vector< std::pair< EntityID, AxisAlignedBounds > > SpatialQuerySystem::findEntitiesOverlappingCoarse ( const AxisAlignedBounds & searchBounds,
InteractionLayerMask interactionMask = std::numeric_limits<InteractionLayerMask>::max() ) const

Returns a list of entities (by their IDs) whose AABBs overlap a search AABB.

Parameters
searchBoundsThe AABB defining the search region.
interactionMaskInteraction layers in which entities are being searched for
Returns
std::vector<std::pair<EntityID, AxisAlignedBounds>> The list of entities overlapping with the search region.

◆ findEntitiesOverlappingCoarse() [2/2]

std::vector< std::pair< EntityID, AxisAlignedBounds > > SpatialQuerySystem::findEntitiesOverlappingCoarse ( const Ray & ray,
InteractionLayerMask interactionMask = std::numeric_limits<InteractionLayerMask>::max() ) const

Returns a list of entities (by their IDs) whose AABBs intersect a search ray.

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

◆ findNodesOverlappingCoarse() [1/2]

std::vector< std::shared_ptr< SceneNodeCore > > SpatialQuerySystem::findNodesOverlappingCoarse ( const AxisAlignedBounds & searchBounds,
InteractionLayerMask interactionMask = std::numeric_limits<InteractionLayerMask>::max() )

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

Parameters
searchBoundsThe search region (as an AABB).
interactionMaskA list of layers in which entities are being searched for
Returns
std::vector<std::shared_ptr<SceneNodeCore>> The list of nodes contained by or overlapping the search region.

◆ findNodesOverlappingCoarse() [2/2]

std::vector< std::shared_ptr< SceneNodeCore > > SpatialQuerySystem::findNodesOverlappingCoarse ( const Ray & searchRay,
InteractionLayerMask interactionMask = std::numeric_limits<InteractionLayerMask>::max() )

Gets a list of nodes (by their base class pointers) whose AABBs intersect a search ray.

Parameters
searchRayThe ray intersecting which a list of nodes should be found.
interactionMaskA list of layers in which entities are being searched for
Returns
std::vector<std::shared_ptr<SceneNodeCore>> A list of nodes intersecting the search ray.

◆ getSystemTypeName()

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,
ComponentType updatedComponent )
overrideprivate

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

Parameters
entityIDThe entity in need of an AABB update.

◆ onPostTransformUpdate()

void SpatialQuerySystem::onPostTransformUpdate ( uint32_t timestepMillis)
overrideprivate

Uses latest transforms to update object bounds if required.

Parameters
timestepMillisThe time by which the simulation will be advanced this step

◆ onSimulationPostStep()

void SpatialQuerySystem::onSimulationPostStep ( 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() [1/2]

void ToyMaker::SpatialQuerySystem::updateBounds ( const std::shared_ptr< SceneNodeCore > & sceneNode,
ObjectBounds::TrueVolumeType volumeType,
const ObjectBounds::TrueVolume & volume,
const glm::vec3 & positionOffset,
const glm::quat & orientationOffset )
inline

Manually updates the object bounds component of a scene object.

Does not change the value of the origin of the bounds.

◆ updateBounds() [2/2]

void SpatialQuerySystem::updateBounds ( EntityID entity,
bool forceUpdateFromTransform = false )
private

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

Transform-based updates are forced during spatial query system initialization.

Parameters
entityThe entity whose axis aligned bounds are being updated.
forceUpdateFromTransformWhether transform should influence bounds location regardless of bounds settings

◆ updateTransform()

void SpatialQuerySystem::updateTransform ( EntityID entity)
private

Updates the world transform of an entity based on its objects bounds.

Parameters
entityThe entity whose transform must be updated.
Warning
This works assuming that the entity has had its position updated via its ObjectBounds component. The only system (for now) which will perform such an update is the physics system.

The documentation for this class was generated from the following files:
  • ToyMaker_Main/include/toymaker/engine/spatial_query/system.hpp
  • ToyMaker_Main/src/spatial_query/system.cpp