Owns all entities and drives their lifecycle, physics, and rendering for one scene. More...
#include <Scene.h>
Inherits Raven::RefCounted.
Public Member Functions | |
| FRAMEWORK_API | Scene (SceneRenderer &renderer) |
| Constructs a scene and registers all known component types in the registry. | |
| ~Scene ()=default | |
| FRAMEWORK_API void | Shutdown () |
| Releases any scene-owned resources. | |
| FRAMEWORK_API Entity | CreateEntity (const std::string &name="") |
Creates an entity with a TagComponent and a default TransformComponent. | |
| FRAMEWORK_API Entity | CreateEntityWithUUID (UUID uuid, const std::string &name) |
Creates an entity with an explicit UUID and a TagComponent. | |
| FRAMEWORK_API void | DestroyEntity (const Entity &entity) |
| Enqueues destruction of an entity at the end of the current frame. | |
| FRAMEWORK_API void | OnRuntimeStart () |
| Enters play mode: initialises the physics world and creates all rigid bodies. | |
| FRAMEWORK_API void | OnRuntimeStop () |
| Leaves play mode: shuts down the physics world. | |
| FRAMEWORK_API void | OnUpdateEditor (Timestep ts) |
| Editor-mode update: rebuilds dirty collision shapes and renders the scene. | |
| FRAMEWORK_API void | OnUpdateRuntime (Timestep ts, bool stepped) |
| Runtime update: steps physics, syncs transforms, updates cameras, and renders. | |
| FRAMEWORK_API void | Step (int frames) |
Schedules frames additional simulation steps while paused. | |
| FRAMEWORK_API bool | ConsumeStep () |
Consumes one pending step, returning true if the simulation should advance. | |
| FRAMEWORK_API const SceneCamera * | GetPrimaryCamera () |
Returns the first camera entity marked as primary, or nullptr if none exists. | |
| bool | IsRunning () const |
Returns true if the scene is currently in play mode. | |
| bool | IsPaused () const |
Returns true if the scene is paused (play mode only). | |
| Registry & | GetRegistry () |
| Returns a mutable reference to the ECS registry. | |
| void | SetPaused (bool paused) |
| Pauses or unpauses the scene. No-op outside of play mode. | |
| const LightEnvironment & | GetLightEnvironment () const |
| Returns the aggregated light environment built during Scene::RenderScene. | |
| std::vector< Entity > | GetAllEntities () |
| Returns all entities currently in the scene. | |
| template<typename First, typename... Rest> | |
| std::vector< Entity > | GetAllEntitiesWith () |
| Returns all entities that possess every listed component type. | |
| template<typename T> | |
| void | OnComponentAdded (const Entity &entity, T &component) |
| Hook called by the registry immediately after a component is added to an entity. | |
| FRAMEWORK_API void | DrawDebugPhysics () |
Draws debug wireframes for all RigidBodyComponent colliders. | |
| FRAMEWORK_API void | Physics_AddImpulse (u64 entityID, const Crux::vec3 &impulse) |
| Applies a linear impulse to an entity's physics body. | |
| FRAMEWORK_API void | Physics_AddForce (u64 entityID, const Crux::vec3 &force) |
| Applies a continuous force to an entity's physics body. | |
| FRAMEWORK_API void | Physics_AddTorque (u64 entityID, const Crux::vec3 &torque) |
| Applies a continuous torque to an entity's physics body. | |
| FRAMEWORK_API void | Physics_AddLinearVelocity (u64 entityID, const Crux::vec3 &velocity) |
| Adds a velocity delta to an entity's physics body. | |
| FRAMEWORK_API void | Physics_SetLinearVelocity (u64 entityID, const Crux::vec3 &velocity) |
| Overwrites the linear velocity of an entity's physics body. | |
| FRAMEWORK_API Crux::vec3 | Physics_GetLinearVelocity (u64 entityID) const |
| Returns the linear velocity of an entity's physics body. | |
| FRAMEWORK_API void | Phyiscs_AddAngularImpulse (u64 entityID, const Crux::vec3 &impulse) |
| Applies an angular impulse to an entity's physics body. | |
| FRAMEWORK_API void | Physics_SetAngularVelocity (u64 entityID, const Crux::vec3 &velocity) |
| Overwrites the angular velocity of an entity's physics body. | |
| FRAMEWORK_API Crux::vec3 | Physics_GetAngularVelocity (u64 entityID) const |
| Returns the angular velocity of an entity's physics body. | |
| FRAMEWORK_API void | Physics_SetGravityFactor (u64 entityID, float factor) |
| Scales the gravity vector for an entity's physics body. | |
| FRAMEWORK_API void | Physics_SetActive (u64 entityID, bool active) |
| Activates or deactivates an entity's physics body. | |
| template<> | |
| void | OnComponentAdded (const Entity &entity, TagComponent &component) |
| template<> | |
| void | OnComponentAdded (const Entity &entity, TransformComponent &component) |
| template<> | |
| void | OnComponentAdded (const Entity &entity, CameraComponent &component) |
| template<> | |
| void | OnComponentAdded (const Entity &entity, StaticMeshComponent &component) |
| template<> | |
| void | OnComponentAdded (const Entity &entity, PointLightComponent &component) |
| template<> | |
| void | OnComponentAdded (const Entity &entity, DirectionalLightComponent &component) |
| template<> | |
| void | OnComponentAdded (const Entity &entity, SkylightComponent &component) |
| template<> | |
| void | OnComponentAdded (const Entity &entity, ScriptComponent &component) |
| template<> | |
| void | OnComponentAdded (const Entity &entity, RigidBodyComponent &component) |
| Public Member Functions inherited from Raven::RefCounted | |
| RefCounted () | |
| virtual | ~RefCounted () |
| void | IncRefCount () |
| void | DecRefCount () |
| u32 | GetRefCount () const |
Static Public Member Functions | |
| static FRAMEWORK_API Ref< Scene > | Copy (Ref< Scene > other, SceneRenderer &renderer) |
Deep-copies all entities and components from other into a new scene. | |
Owns all entities and drives their lifecycle, physics, and rendering for one scene.
|
explicit |
Constructs a scene and registers all known component types in the registry.
| renderer | Reference to the SceneRenderer that will render this scene. The renderer must outlive the scene. |
|
default |
| bool Raven::Scene::ConsumeStep | ( | ) |
Consumes one pending step, returning true if the simulation should advance.
true if a step was available and was consumed.
|
static |
Deep-copies all entities and components from other into a new scene.
| other | Source scene to copy. |
| renderer | Renderer to bind to the new scene. |
| Entity Raven::Scene::CreateEntity | ( | const std::string & | name = "" | ) |
Creates an entity with a TagComponent and a default TransformComponent.
| name | Display name for the entity. Defaults to the localised unnamed-entity string. |
Creates an entity with an explicit UUID and a TagComponent.
Used during scene deserialisation to restore stable entity identities.
| uuid | The UUID to assign. |
| name | Display name for the entity. |
| void Raven::Scene::DestroyEntity | ( | const Entity & | entity | ) |
Enqueues destruction of an entity at the end of the current frame.
Deferred to avoid invalidating iterators mid-frame.
| entity | Entity to destroy. |
| void Raven::Scene::DrawDebugPhysics | ( | ) |
Draws debug wireframes for all RigidBodyComponent colliders.
In play mode, reads live Jolt body transforms. In editor mode, uses the entity's TransformComponent directly. Color-coded by motion type: green = static, orange = dynamic, blue = kinematic.
|
inline |
Returns all entities currently in the scene.
|
inline |
Returns all entities that possess every listed component type.
| First | First required component type. |
| Rest | Additional required component types. |
|
inlinenodiscard |
Returns the aggregated light environment built during Scene::RenderScene.
| const SceneCamera * Raven::Scene::GetPrimaryCamera | ( | ) |
Returns the first camera entity marked as primary, or nullptr if none exists.
nullptr.
|
inlinenodiscard |
Returns a mutable reference to the ECS registry.
|
inlinenodiscard |
Returns true if the scene is paused (play mode only).
|
inlinenodiscard |
Returns true if the scene is currently in play mode.
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
Hook called by the registry immediately after a component is added to an entity.
Specialisations handle one-time initialisation per component type (e.g. building the collision shape for RigidBodyComponent). The primary template is intentionally left undefined to catch unregistered component types at compile time.
| T | Component type that was just added. |
| entity | The entity that received the component. |
| component | Reference to the newly added component. |
|
inline |
|
inline |
| void Raven::Scene::OnRuntimeStart | ( | ) |
Enters play mode: initialises the physics world and creates all rigid bodies.
Iterates all RigidBodyComponent + TransformComponent entities and calls PhysicsWorld::CreateBody for each.
| void Raven::Scene::OnRuntimeStop | ( | ) |
Leaves play mode: shuts down the physics world.
| void Raven::Scene::OnUpdateEditor | ( | Timestep | ts | ) |
Editor-mode update: rebuilds dirty collision shapes and renders the scene.
| ts | Elapsed time since the last frame (unused beyond passing to sub-systems). |
| void Raven::Scene::OnUpdateRuntime | ( | Timestep | ts, |
| bool | stepped ) |
Runtime update: steps physics, syncs transforms, updates cameras, and renders.
Physics is only stepped when stepped is true (controlled by ConsumeStep in stepped-pause mode).
| ts | Elapsed time since the last frame (seconds). |
| stepped | true if the physics simulation should advance this frame. |
| void Raven::Scene::Phyiscs_AddAngularImpulse | ( | u64 | entityID, |
| const Crux::vec3 & | impulse ) |
Applies an angular impulse to an entity's physics body.
Phyiscs_) retained for ABI compatibility. | void Raven::Scene::Physics_AddForce | ( | u64 | entityID, |
| const Crux::vec3 & | force ) |
Applies a continuous force to an entity's physics body.
| void Raven::Scene::Physics_AddImpulse | ( | u64 | entityID, |
| const Crux::vec3 & | impulse ) |
Applies a linear impulse to an entity's physics body.
| void Raven::Scene::Physics_AddLinearVelocity | ( | u64 | entityID, |
| const Crux::vec3 & | velocity ) |
Adds a velocity delta to an entity's physics body.
| void Raven::Scene::Physics_AddTorque | ( | u64 | entityID, |
| const Crux::vec3 & | torque ) |
Applies a continuous torque to an entity's physics body.
| Crux::vec3 Raven::Scene::Physics_GetAngularVelocity | ( | u64 | entityID | ) | const |
Returns the angular velocity of an entity's physics body.
| Crux::vec3 Raven::Scene::Physics_GetLinearVelocity | ( | u64 | entityID | ) | const |
Returns the linear velocity of an entity's physics body.
| void Raven::Scene::Physics_SetActive | ( | u64 | entityID, |
| bool | active ) |
Activates or deactivates an entity's physics body.
| void Raven::Scene::Physics_SetAngularVelocity | ( | u64 | entityID, |
| const Crux::vec3 & | velocity ) |
Overwrites the angular velocity of an entity's physics body.
| void Raven::Scene::Physics_SetGravityFactor | ( | u64 | entityID, |
| float | factor ) |
Scales the gravity vector for an entity's physics body.
| void Raven::Scene::Physics_SetLinearVelocity | ( | u64 | entityID, |
| const Crux::vec3 & | velocity ) |
Overwrites the linear velocity of an entity's physics body.
|
inline |
Pauses or unpauses the scene. No-op outside of play mode.
| void Raven::Scene::Shutdown | ( | ) |
Releases any scene-owned resources.
| void Raven::Scene::Step | ( | int | frames | ) |
Schedules frames additional simulation steps while paused.
| frames | Number of frames to advance. |