Raven Engine v0.1
A modern 3D Game Engine
Loading...
Searching...
No Matches
Raven::Scene Class Reference

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 SceneCameraGetPrimaryCamera ()
 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).
RegistryGetRegistry ()
 Returns a mutable reference to the ECS registry.
void SetPaused (bool paused)
 Pauses or unpauses the scene. No-op outside of play mode.
const LightEnvironmentGetLightEnvironment () const
 Returns the aggregated light environment built during Scene::RenderScene.
std::vector< EntityGetAllEntities ()
 Returns all entities currently in the scene.
template<typename First, typename... Rest>
std::vector< EntityGetAllEntitiesWith ()
 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< SceneCopy (Ref< Scene > other, SceneRenderer &renderer)
 Deep-copies all entities and components from other into a new scene.

Detailed Description

Owns all entities and drives their lifecycle, physics, and rendering for one scene.

Constructor & Destructor Documentation

◆ Scene()

Raven::Scene::Scene ( SceneRenderer & renderer)
explicit

Constructs a scene and registers all known component types in the registry.

Parameters
rendererReference to the SceneRenderer that will render this scene. The renderer must outlive the scene.

◆ ~Scene()

Raven::Scene::~Scene ( )
default

Member Function Documentation

◆ ConsumeStep()

bool Raven::Scene::ConsumeStep ( )

Consumes one pending step, returning true if the simulation should advance.

Returns
true if a step was available and was consumed.

◆ Copy()

Ref< Scene > Raven::Scene::Copy ( Ref< Scene > other,
SceneRenderer & renderer )
static

Deep-copies all entities and components from other into a new scene.

Parameters
otherSource scene to copy.
rendererRenderer to bind to the new scene.
Returns
A new Ref<Scene> with duplicated registry contents.

◆ CreateEntity()

Entity Raven::Scene::CreateEntity ( const std::string & name = "")

Creates an entity with a TagComponent and a default TransformComponent.

Parameters
nameDisplay name for the entity. Defaults to the localised unnamed-entity string.
Returns
The newly created Entity.

◆ CreateEntityWithUUID()

Entity Raven::Scene::CreateEntityWithUUID ( UUID uuid,
const std::string & name )

Creates an entity with an explicit UUID and a TagComponent.

Used during scene deserialisation to restore stable entity identities.

Parameters
uuidThe UUID to assign.
nameDisplay name for the entity.
Returns
The newly created Entity.

◆ DestroyEntity()

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.

Parameters
entityEntity to destroy.

◆ DrawDebugPhysics()

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.

◆ GetAllEntities()

std::vector< Entity > Raven::Scene::GetAllEntities ( )
inline

Returns all entities currently in the scene.

Returns
Vector of all Entity handles.

◆ GetAllEntitiesWith()

template<typename First, typename... Rest>
std::vector< Entity > Raven::Scene::GetAllEntitiesWith ( )
inline

Returns all entities that possess every listed component type.

Template Parameters
FirstFirst required component type.
RestAdditional required component types.
Returns
Vector of matching Entity handles.

◆ GetLightEnvironment()

const LightEnvironment & Raven::Scene::GetLightEnvironment ( ) const
inlinenodiscard

Returns the aggregated light environment built during Scene::RenderScene.

◆ GetPrimaryCamera()

const SceneCamera * Raven::Scene::GetPrimaryCamera ( )

Returns the first camera entity marked as primary, or nullptr if none exists.

Returns
Non-owning pointer to the primary SceneCamera, or nullptr.

◆ GetRegistry()

Registry & Raven::Scene::GetRegistry ( )
inlinenodiscard

Returns a mutable reference to the ECS registry.

◆ IsPaused()

bool Raven::Scene::IsPaused ( ) const
inlinenodiscard

Returns true if the scene is paused (play mode only).

◆ IsRunning()

bool Raven::Scene::IsRunning ( ) const
inlinenodiscard

Returns true if the scene is currently in play mode.

◆ OnComponentAdded() [1/10]

template<>
void Raven::Scene::OnComponentAdded ( const Entity & entity,
CameraComponent & component )
inline

◆ OnComponentAdded() [2/10]

template<>
void Raven::Scene::OnComponentAdded ( const Entity & entity,
DirectionalLightComponent & component )
inline

◆ OnComponentAdded() [3/10]

template<>
void Raven::Scene::OnComponentAdded ( const Entity & entity,
PointLightComponent & component )
inline

◆ OnComponentAdded() [4/10]

template<>
void Raven::Scene::OnComponentAdded ( const Entity & entity,
RigidBodyComponent & component )
inline

◆ OnComponentAdded() [5/10]

template<>
void Raven::Scene::OnComponentAdded ( const Entity & entity,
ScriptComponent & component )
inline

◆ OnComponentAdded() [6/10]

template<>
void Raven::Scene::OnComponentAdded ( const Entity & entity,
SkylightComponent & component )
inline

◆ OnComponentAdded() [7/10]

template<>
void Raven::Scene::OnComponentAdded ( const Entity & entity,
StaticMeshComponent & component )
inline

◆ OnComponentAdded() [8/10]

template<typename T>
void Raven::Scene::OnComponentAdded ( const Entity & entity,
T & component )
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.

Template Parameters
TComponent type that was just added.
Parameters
entityThe entity that received the component.
componentReference to the newly added component.

◆ OnComponentAdded() [9/10]

template<>
void Raven::Scene::OnComponentAdded ( const Entity & entity,
TagComponent & component )
inline

◆ OnComponentAdded() [10/10]

template<>
void Raven::Scene::OnComponentAdded ( const Entity & entity,
TransformComponent & component )
inline

◆ OnRuntimeStart()

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.

◆ OnRuntimeStop()

void Raven::Scene::OnRuntimeStop ( )

Leaves play mode: shuts down the physics world.

◆ OnUpdateEditor()

void Raven::Scene::OnUpdateEditor ( Timestep ts)

Editor-mode update: rebuilds dirty collision shapes and renders the scene.

Parameters
tsElapsed time since the last frame (unused beyond passing to sub-systems).

◆ OnUpdateRuntime()

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).

Parameters
tsElapsed time since the last frame (seconds).
steppedtrue if the physics simulation should advance this frame.

◆ Phyiscs_AddAngularImpulse()

void Raven::Scene::Phyiscs_AddAngularImpulse ( u64 entityID,
const Crux::vec3 & impulse )

Applies an angular impulse to an entity's physics body.

See also
PhysicsWorld::AddAngularImpulse
Note
The method name contains a typo (Phyiscs_) retained for ABI compatibility.

◆ Physics_AddForce()

void Raven::Scene::Physics_AddForce ( u64 entityID,
const Crux::vec3 & force )

Applies a continuous force to an entity's physics body.

See also
PhysicsWorld::AddForce

◆ Physics_AddImpulse()

void Raven::Scene::Physics_AddImpulse ( u64 entityID,
const Crux::vec3 & impulse )

Applies a linear impulse to an entity's physics body.

See also
PhysicsWorld::AddImpulse

◆ Physics_AddLinearVelocity()

void Raven::Scene::Physics_AddLinearVelocity ( u64 entityID,
const Crux::vec3 & velocity )

Adds a velocity delta to an entity's physics body.

See also
PhysicsWorld::AddLinearVelocity

◆ Physics_AddTorque()

void Raven::Scene::Physics_AddTorque ( u64 entityID,
const Crux::vec3 & torque )

Applies a continuous torque to an entity's physics body.

See also
PhysicsWorld::AddTorque

◆ Physics_GetAngularVelocity()

Crux::vec3 Raven::Scene::Physics_GetAngularVelocity ( u64 entityID) const

Returns the angular velocity of an entity's physics body.

See also
PhysicsWorld::GetAngularVelocity

◆ Physics_GetLinearVelocity()

Crux::vec3 Raven::Scene::Physics_GetLinearVelocity ( u64 entityID) const

Returns the linear velocity of an entity's physics body.

See also
PhysicsWorld::GetLinearVelocity

◆ Physics_SetActive()

void Raven::Scene::Physics_SetActive ( u64 entityID,
bool active )

Activates or deactivates an entity's physics body.

See also
PhysicsWorld::SetActive

◆ Physics_SetAngularVelocity()

void Raven::Scene::Physics_SetAngularVelocity ( u64 entityID,
const Crux::vec3 & velocity )

Overwrites the angular velocity of an entity's physics body.

See also
PhysicsWorld::SetAngularVelocity

◆ Physics_SetGravityFactor()

void Raven::Scene::Physics_SetGravityFactor ( u64 entityID,
float factor )

Scales the gravity vector for an entity's physics body.

See also
PhysicsWorld::SetGravityFactor

◆ Physics_SetLinearVelocity()

void Raven::Scene::Physics_SetLinearVelocity ( u64 entityID,
const Crux::vec3 & velocity )

Overwrites the linear velocity of an entity's physics body.

See also
PhysicsWorld::SetLinearVelocity

◆ SetPaused()

void Raven::Scene::SetPaused ( bool paused)
inline

Pauses or unpauses the scene. No-op outside of play mode.

◆ Shutdown()

void Raven::Scene::Shutdown ( )

Releases any scene-owned resources.

◆ Step()

void Raven::Scene::Step ( int frames)

Schedules frames additional simulation steps while paused.

Parameters
framesNumber of frames to advance.

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