Kemena3D
Loading...
Searching...
No Matches
kemena::kScriptManager Class Reference
module nullptr

Manages the AngelScript engine, a registry of script assets, and the live per-object script module instances. More...

#include <kscriptmanager.h>

Public Member Functions

 kScriptManager ()
 Creates and initialises the AngelScript engine and shared context.
virtual ~kScriptManager ()
 Destroys all instances and shuts down the engine (see destroy()).
asIScriptEngine * getEngine ()
 Returns the underlying AngelScript engine (for binding setup).
void registerScriptAsset (const kString &uuid, const kString &sourcePath, kScriptSourceType type=K_SCRIPT_TEXT, const kString &bytecodePath="")
 Registers (or updates) a script asset.
kScriptAssetgetScriptAsset (const kString &uuid)
 Returns the asset for uuid, or nullptr if unregistered.
void unregisterScriptAsset (const kString &uuid)
 Removes a script asset from the registry.
void setBytecodePath (const kString &uuid, const kString &bytecodePath)
 Records the bytecode path for an already-registered asset.
bool compileToBytecode (const kString &scriptUuid, const kString &outPath, bool stripDebug=false)
 Compiles a registered asset's source to AngelScript bytecode.
bool compileFileToBytecode (const kString &sourcePath, const kString &outPath, bool stripDebug=false)
 Compiles a source file to bytecode without touching the registry.
kScriptInstancecreateInstance (const kString &componentUuid, const kString &scriptUuid)
 Builds a private module instance for one object's script slot.
kScriptInstancegetInstance (const kString &componentUuid)
 Returns the instance for componentUuid, or nullptr.
void destroyInstance (const kString &componentUuid)
 Destroys one instance and discards its module.
void destroyAllInstances ()
 Destroys every live instance (e.g. when Play stops).
void setActiveObject (kObject *obj)
 Sets the object scripts see as their owner during dispatch.
kObjectgetActiveObject () const
 Returns the object set by setActiveObject().
void setDeltaTime (float dt)
 Sets the frame delta time exposed to scripts via host bindings.
float getDeltaTime () const
 Returns the current frame delta time.
void setFixedDeltaTime (float dt)
 Sets the fixed (physics) delta time exposed to scripts.
float getFixedDeltaTime () const
 Returns the current fixed delta time.
bool callEvent (kScriptInstance *inst, kScriptEvent evt)
 Invokes one lifecycle function on an instance, if it defines it.
void registerGlobalFunction (const kString &declaration, asSFuncPtr func)
 Registers a native C function callable from every script.
void destroy ()
 Shuts down the engine and releases all resources.

Detailed Description

Manages the AngelScript engine, a registry of script assets, and the live per-object script module instances.

Typical engine-side flow:

mgr.registerScriptAsset("uuid-1", "Assets/player.as");
mgr.compileToBytecode("uuid-1", "Library/Scripts/uuid-1.kbc");
kScriptInstance *inst = mgr.createInstance("comp-1", "uuid-1");
mgr.setActiveObject(playerObject);
bool callEvent(kScriptInstance *inst, kScriptEvent evt)
Invokes one lifecycle function on an instance, if it defines it.
bool compileToBytecode(const kString &scriptUuid, const kString &outPath, bool stripDebug=false)
Compiles a registered asset's source to AngelScript bytecode.
void setActiveObject(kObject *obj)
Sets the object scripts see as their owner during dispatch.
Definition kscriptmanager.h:264
kScriptInstance * createInstance(const kString &componentUuid, const kString &scriptUuid)
Builds a private module instance for one object's script slot.
void registerScriptAsset(const kString &uuid, const kString &sourcePath, kScriptSourceType type=K_SCRIPT_TEXT, const kString &bytecodePath="")
Registers (or updates) a script asset.
kScriptManager()
Creates and initialises the AngelScript engine and shared context.
@ K_SCRIPT_START
void Start() — once, on the first frame.
Definition kscriptmanager.h:58
A live, per-object compiled script module.
Definition kscriptmanager.h:107

Constructor & Destructor Documentation

◆ kScriptManager()

kemena::kScriptManager::kScriptManager ( )

Creates and initialises the AngelScript engine and shared context.

◆ ~kScriptManager()

virtual kemena::kScriptManager::~kScriptManager ( )
virtual

Destroys all instances and shuts down the engine (see destroy()).

Member Function Documentation

◆ callEvent()

bool kemena::kScriptManager::callEvent ( kScriptInstance * inst,
kScriptEvent evt )

Invokes one lifecycle function on an instance, if it defines it.

Parameters
instInstance to dispatch to.
evtLifecycle event.
Returns
true if the function existed and finished without exception.

◆ compileFileToBytecode()

bool kemena::kScriptManager::compileFileToBytecode ( const kString & sourcePath,
const kString & outPath,
bool stripDebug = false )

Compiles a source file to bytecode without touching the registry.

Parameters
sourcePathPath to the .as source.
outPathDestination bytecode file.
stripDebugStrip debug info.
Returns
true on success.

◆ compileToBytecode()

bool kemena::kScriptManager::compileToBytecode ( const kString & scriptUuid,
const kString & outPath,
bool stripDebug = false )

Compiles a registered asset's source to AngelScript bytecode.

Parameters
scriptUuidAsset UUID (must be registered).
outPathDestination bytecode file.
stripDebugStrip debug info for a smaller/faster build.
Returns
true on success; updates the asset's bytecodePath and checksum.

◆ createInstance()

kScriptInstance * kemena::kScriptManager::createInstance ( const kString & componentUuid,
const kString & scriptUuid )

Builds a private module instance for one object's script slot.

Prefers loading the asset's bytecode; if absent or stale, compiles the source text directly. Safe to call again with the same componentUuid — the previous instance is destroyed first.

Parameters
componentUuidThe owning kScript::uuid.
scriptUuidThe script asset to instantiate.
Returns
Instance pointer (owned by the manager), or nullptr on failure.

◆ destroy()

void kemena::kScriptManager::destroy ( )

Shuts down the engine and releases all resources.

◆ destroyAllInstances()

void kemena::kScriptManager::destroyAllInstances ( )

Destroys every live instance (e.g. when Play stops).

◆ destroyInstance()

void kemena::kScriptManager::destroyInstance ( const kString & componentUuid)

Destroys one instance and discards its module.

◆ getActiveObject()

kObject * kemena::kScriptManager::getActiveObject ( ) const
inline

Returns the object set by setActiveObject().

◆ getDeltaTime()

float kemena::kScriptManager::getDeltaTime ( ) const
inline

Returns the current frame delta time.

◆ getEngine()

asIScriptEngine * kemena::kScriptManager::getEngine ( )
inline

Returns the underlying AngelScript engine (for binding setup).

◆ getFixedDeltaTime()

float kemena::kScriptManager::getFixedDeltaTime ( ) const
inline

Returns the current fixed delta time.

◆ getInstance()

kScriptInstance * kemena::kScriptManager::getInstance ( const kString & componentUuid)

Returns the instance for componentUuid, or nullptr.

◆ getScriptAsset()

kScriptAsset * kemena::kScriptManager::getScriptAsset ( const kString & uuid)

Returns the asset for uuid, or nullptr if unregistered.

◆ registerGlobalFunction()

void kemena::kScriptManager::registerGlobalFunction ( const kString & declaration,
asSFuncPtr func )

Registers a native C function callable from every script.

Parameters
declarationAngelScript declaration string.
funcNative function pointer (use the FUNCTION macro).

◆ registerScriptAsset()

void kemena::kScriptManager::registerScriptAsset ( const kString & uuid,
const kString & sourcePath,
kScriptSourceType type = K_SCRIPT_TEXT,
const kString & bytecodePath = "" )

Registers (or updates) a script asset.

Parameters
uuidScript asset UUID.
sourcePathPath to the .as source file.
typeText or node-graph origin.
bytecodePathOptional path to precompiled bytecode.

◆ setActiveObject()

void kemena::kScriptManager::setActiveObject ( kObject * obj)
inline

Sets the object scripts see as their owner during dispatch.

Call immediately before callEvent() so bound host functions (e.g. getSelf()) resolve to the correct object.

◆ setBytecodePath()

void kemena::kScriptManager::setBytecodePath ( const kString & uuid,
const kString & bytecodePath )

Records the bytecode path for an already-registered asset.

◆ setDeltaTime()

void kemena::kScriptManager::setDeltaTime ( float dt)
inline

Sets the frame delta time exposed to scripts via host bindings.

◆ setFixedDeltaTime()

void kemena::kScriptManager::setFixedDeltaTime ( float dt)
inline

Sets the fixed (physics) delta time exposed to scripts.

◆ unregisterScriptAsset()

void kemena::kScriptManager::unregisterScriptAsset ( const kString & uuid)

Removes a script asset from the registry.


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