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

Drives the per-frame lifecycle of all native scripts within a scene. More...

#include <ScriptRuntime.h>

Static Public Member Functions

static void OnRuntimeStart (Ref< Scene > scene)
 Instantiates and initialises all enabled scripts in the scene.
static void OnRuntimeUpdate (Ref< Scene > scene, float ts)
 Calls OnUpdate on every non-faulted, enabled script instance.
static void OnRuntimeStop (Ref< Scene > scene)
 Destroys all script instances and clears the scene script context.
static ScriptBaseCreateInstance (std::string_view className)
 Constructs a script instance by class name using the registered factory.
static void DestroyInstance (ScriptBase *instance)
 Destroys a script instance created by CreateInstance.
static void OnCreate (ScriptBase *instance, ScriptComponent *script)
 Invokes ScriptBase::OnCreate on an instance, guarded by SEH.
static void OnUpdate (ScriptBase *instance, float dt, ScriptComponent *script)
 Invokes ScriptBase::OnUpdate on an instance, guarded by SEH.
static void OnDestroy (ScriptBase *instance, ScriptComponent *script)
 Invokes ScriptBase::OnDestroy on an instance, guarded by SEH.
static std::vector< std::string_view > GetRegisteredClassNames ()
 Returns the names of all script classes currently registered in the DLL.

Detailed Description

Drives the per-frame lifecycle of all native scripts within a scene.

ScriptRuntime is stateless; every method is static and operates on the scene or script instance passed in. It bridges the ECS (iterating ScriptComponent entities) and the registered script types held by ScriptRegistry.

SEH (__try / __except) guards wrap every user-script call so that a faulting script is marked as Faulted and isolated without crashing the engine.

Member Function Documentation

◆ CreateInstance()

ScriptBase * Raven::ScriptRuntime::CreateInstance ( std::string_view className)
static

Constructs a script instance by class name using the registered factory.

Parameters
classNameFully-qualified script class name as registered in the DLL.
Returns
Heap-allocated ScriptBase derived instance, or nullptr if the class is unknown or has no factory.

◆ DestroyInstance()

void Raven::ScriptRuntime::DestroyInstance ( ScriptBase * instance)
static

Destroys a script instance created by CreateInstance.

Parameters
instanceInstance to destroy. No-op if nullptr.

◆ GetRegisteredClassNames()

std::vector< std::string_view > Raven::ScriptRuntime::GetRegisteredClassNames ( )
static

Returns the names of all script classes currently registered in the DLL.

Returns
Vector of non-owning string views into the type registry storage. Invalidated on hot-reload.

◆ OnCreate()

void Raven::ScriptRuntime::OnCreate ( ScriptBase * instance,
ScriptComponent * script )
static

Invokes ScriptBase::OnCreate on an instance, guarded by SEH.

If an unhandled exception is raised inside user code, the script is marked as Faulted and subsequent lifecycle calls are skipped.

Parameters
instanceScript instance to call. Must not be nullptr.
scriptComponent owning the instance; used for fault tracking.

◆ OnDestroy()

void Raven::ScriptRuntime::OnDestroy ( ScriptBase * instance,
ScriptComponent * script )
static

Invokes ScriptBase::OnDestroy on an instance, guarded by SEH.

Parameters
instanceScript instance to call. Must not be nullptr.
scriptComponent owning the instance; used for fault tracking.

◆ OnRuntimeStart()

void Raven::ScriptRuntime::OnRuntimeStart ( Ref< Scene > scene)
static

Instantiates and initialises all enabled scripts in the scene.

For each entity with an enabled ScriptComponent:

  1. Creates a script instance via CreateInstance.
  2. Applies any serialised field overrides via ScriptFieldSerializer.
  3. Sets the instance's EntityID and Scene context pointers.
  4. Calls OnCreate.
Parameters
sceneThe scene entering play mode.

◆ OnRuntimeStop()

void Raven::ScriptRuntime::OnRuntimeStop ( Ref< Scene > scene)
static

Destroys all script instances and clears the scene script context.

For each entity with a live ScriptComponent instance:

  1. Calls OnDestroy.
  2. Calls DestroyInstance.
  3. Nulls out the instance pointer and scene context.
Parameters
sceneThe scene leaving play mode.

◆ OnRuntimeUpdate()

void Raven::ScriptRuntime::OnRuntimeUpdate ( Ref< Scene > scene,
float ts )
static

Calls OnUpdate on every non-faulted, enabled script instance.

Parameters
sceneThe currently running scene.
tsTime elapsed since the previous frame (seconds).

◆ OnUpdate()

void Raven::ScriptRuntime::OnUpdate ( ScriptBase * instance,
float dt,
ScriptComponent * script )
static

Invokes ScriptBase::OnUpdate on an instance, guarded by SEH.

Parameters
instanceScript instance to call. Must not be nullptr.
dtDelta time in seconds.
scriptComponent owning the instance; used for fault tracking.

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