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
spatial_query_system.hpp
Go to the documentation of this file.
1
10
16
17#ifndef FOOLSENGINE_SPATIALQUERYSYSTEM_H
18#define FOOLSENGINE_SPATIALQUERYSYSTEM_H
19
20#include <memory>
21#include <array>
22
24#include "scene_system.hpp"
25#include "core/ecs_world.hpp"
26#include "model.hpp"
27#include "light.hpp"
28
29namespace ToyMaker {
30
40 class SpatialQuerySystem: public System<SpatialQuerySystem, std::tuple<Transform, ObjectBounds>, std::tuple<SceneHierarchyData, AxisAlignedBounds>> {
41 public:
42 explicit SpatialQuerySystem(std::weak_ptr<ECSWorld> world):
43 System<SpatialQuerySystem, std::tuple<Transform, ObjectBounds>, std::tuple<SceneHierarchyData, AxisAlignedBounds>>{world}
44 {}
45
52 static std::string getSystemTypeName() { return "SpatialQuerySystem"; }
53
58 class StaticModelBoundsComputeSystem: public System<StaticModelBoundsComputeSystem, std::tuple<std::shared_ptr<StaticModel>>, std::tuple<ObjectBounds>> {
59 public:
60 explicit StaticModelBoundsComputeSystem(std::weak_ptr<ECSWorld> world):
62 {}
63
69 static std::string getSystemTypeName() { return "SpatialQuerySystem::StaticModelBoundsComputeSystem"; }
70 private:
76 void onEntityEnabled(EntityID entityID) override;
77
83 void onEntityUpdated(EntityID entityID) override;
84
90 void recomputeObjectBounds(EntityID entityID);
91 };
92
100 class LightBoundsComputeSystem: public System<LightBoundsComputeSystem, std::tuple<LightEmissionData>, std::tuple<ObjectBounds>> {
101 public:
102 explicit LightBoundsComputeSystem(std::weak_ptr<ECSWorld> world):
104 {}
110 static std::string getSystemTypeName() { return "SpatialQuerySystem::LightBoundsComputeSystem"; }
111 private:
117 void onEntityEnabled(EntityID entityID) override;
118
124 void onEntityUpdated(EntityID entityID) override;
125
131 void recomputeObjectBounds(EntityID entityID);
132 };
133
140 std::vector<std::pair<EntityID, AxisAlignedBounds>> findEntitiesOverlapping(const AxisAlignedBounds& searchBounds) const;
141
148 std::vector<std::pair<EntityID, AxisAlignedBounds>> findEntitiesOverlapping(const Ray& ray) const;
149
156 std::vector<std::shared_ptr<SceneNodeCore>> findNodesOverlapping(const Ray& searchRay);
157
164 std::vector<std::shared_ptr<SceneNodeCore>> findNodesOverlapping(const AxisAlignedBounds& searchBounds);
165
166 private:
172 void updateBounds(EntityID entity);
173
178 void rebuildOctree();
179
184 void onSimulationActivated() override;
185
191 void onSimulationStep(uint32_t timestepMillis) override;
192
198 void onEntityEnabled(EntityID entityID) override;
199
205 void onEntityDisabled(EntityID entityID) override;
206
212 void onEntityUpdated(EntityID entityID) override;
213
218 std::unique_ptr<Octree> mOctree { nullptr };
219
224 std::set<EntityID> mComputeQueue {};
225
231 };
232
233 // Prevent enabling and disabling of spatial query related systems, leave their management entirely to
234 // the scene system
235 template <>
236 inline void SceneNodeCore::setEnabled<SpatialQuerySystem>(bool) {/* pass */}
237 template <>
239 template <>
241
242 template <>
243 inline void SceneNodeCore::updateComponent<AxisAlignedBounds>(const AxisAlignedBounds& axisAlignedBoxBounds) {
244 (void)axisAlignedBoxBounds; // prevent unused parameter warnings
245 assert(false && "Cannot update a scene node's WorldBounds component");
246 }
247 template<>
248 inline void SceneNodeCore::updateComponent<ObjectBounds>(const ObjectBounds& objectBounds) {
249 (void)objectBounds; // prevent unused parameter warnings
250 assert(false && "Cannot update a scene node's ObjectBounds component");
251 }
252 template <>
254 assert(false && "Cannot remove a scene node's AABBTreeNode component");
255 }
256 template <>
258 assert(false && "Cannot remove a scene node's ObjectBounds component");
259 }
260}
261
262#endif
An object containing a coarse simplified representation, AABB, of spatially queryable objects.
Definition spatial_query_math.hpp:317
void updateComponent(const TComponent &component)
Updates the value of a component of this node (to what it should be at the start of the next simulati...
Definition scene_system.hpp:1897
void setEnabled(bool state)
Sets whether or not a given system should be able to influence this scene object.
Definition scene_system.hpp:1921
void removeComponent()
Removes a component present on this node.
Definition scene_system.hpp:1911
void onEntityUpdated(EntityID entityID) override
Updates a light entity's bounds when its position or emissive properties were updated.
Definition spatial_query_system.cpp:121
void onEntityEnabled(EntityID entityID) override
Updates a light entity's bounds when it has just been made active.
Definition spatial_query_system.cpp:117
void recomputeObjectBounds(EntityID entityID)
The method responsible for actually recomputing the light entity's object bounds.
Definition spatial_query_system.cpp:125
static std::string getSystemTypeName()
Gets the system type string associated with this class.
Definition spatial_query_system.hpp:110
void onEntityEnabled(EntityID entityID) override
Computes object bounds for an entity as soon as its enabled for this system.
Definition spatial_query_system.cpp:51
void onEntityUpdated(EntityID entityID) override
Computes object bounds for an entity when it has moved or been scaled.
Definition spatial_query_system.cpp:55
static std::string getSystemTypeName()
The system type string for this class.
Definition spatial_query_system.hpp:69
void recomputeObjectBounds(EntityID entityID)
The method responsible for actually recomputing an entity's object bounds.
Definition spatial_query_system.cpp:59
std::set< EntityID > mComputeQueue
A list of entities whose AABBs should be recomputed at the next simulation step.
Definition spatial_query_system.hpp:224
std::vector< std::pair< EntityID, AxisAlignedBounds > > findEntitiesOverlapping(const AxisAlignedBounds &searchBounds) const
Returns a list of entities (by their IDs) overlapping a search AABB.
Definition spatial_query_system.cpp:35
static std::string getSystemTypeName()
Gets the system type string associated with this class.
Definition spatial_query_system.hpp:52
void rebuildOctree()
Triggers the destruction of any presently existing octree and replaces it with a new one.
Definition spatial_query_system.cpp:154
void onSimulationStep(uint32_t timestepMillis) override
Initializes the tree if necessary, and recomputes octree position for entities whose ObjectBounds wer...
Definition spatial_query_system.cpp:197
void onSimulationActivated() override
Marks this system as requiring initialization on the nearest update.
Definition spatial_query_system.cpp:193
void updateBounds(EntityID entity)
Updates the axis aligned bounds of an entity, based on its ObjectBounds.
Definition spatial_query_system.cpp:140
void onEntityEnabled(EntityID entityID) override
Marks this entity as requiring an octree update on the nearest simulation step.
Definition spatial_query_system.cpp:180
bool mRequiresInitialization
Whether a fresh Octree should be built for this system as soon as possible.
Definition spatial_query_system.hpp:230
void onEntityUpdated(EntityID entityID) override
Marks this entity as requiring an octree update on the nearest simulation step.
Definition spatial_query_system.cpp:189
std::vector< std::shared_ptr< SceneNodeCore > > findNodesOverlapping(const Ray &searchRay)
Gets a list of nodes (by their base class pointers) intersecting a search ray.
Definition spatial_query_system.cpp:8
void onEntityDisabled(EntityID entityID) override
Removes this entity from the Octree.
Definition spatial_query_system.cpp:184
std::unique_ptr< Octree > mOctree
Pointer to the octree, the data structure responsible for spatially indexing scene objects.
Definition spatial_query_system.hpp:218
A system template that disables systems with this form of declaration.
Definition ecs_world.hpp:1062
ToyMaker Engine's implementation of an ECS system.
Classes, constructors for this engine's representation of 3D models.
std::uint64_t EntityID
A single unsigned integer used as a name for an entity managed by an ECS system.
Definition ecs_world.hpp:68
A file that contains definitions for different types of lights, as components to entities,...
Namespace containing all class definitions and functions related to the ToyMaker engine.
Definition camera_system.hpp:20
System classes relating to the SceneSystem, which in some ways lies at the heart of the engine.
Data structures, functions, and methods relating to the hierarchical organization and representation ...
A component defining the true bounds of a spatially queryable object situated somewhere in the world.
Definition spatial_query_math.hpp:130
A set of numbers describing a ray with its source at some finite point in the world,...
Definition spatial_query_basic_types.hpp:374