Kemena3D
Loading...
Searching...
No Matches
kemena::kWorld Class Reference

Root container for the entire simulation environment. More...

#include <kworld.h>

Public Member Functions

 kWorld ()
 Constructs an empty world and creates its script manager.
virtual ~kWorld ()
 Destroys the world, releasing owned scenes, cameras, and managers.
kString getUuid ()
 Returns the UUID of this world.
void setUuid (kString newUuid)
 Sets the UUID of this world.
kScenecreateScene (kString sceneName, kString sceneUuid="")
 Creates a new scene and registers it in this world.
void addScene (kScene *scene, kString sceneUuid="")
 Registers an existing scene in this world.
kCameraaddCamera (kVec3 position=kVec3(0.0f, 0.0f, 0.0f), kVec3 lookAt=kVec3(0.0f, 0.0f, 0.0f), kCameraType type=kCameraType::CAMERA_TYPE_FREE, kString objectUuid="")
 Creates and registers a camera in this world.
void addCamera (kCamera *camera, kString objectUuid="")
 Registers an existing camera in this world.
kCameragetMainCamera ()
 Returns the camera used by the renderer for the main view.
void setMainCamera (kCamera *camera)
 Sets the main camera used by the renderer.
void setAssetManager (kAssetManager *manager)
 Assigns the asset manager used by scenes in this world.
kAssetManagergetAssetManager ()
 Returns the asset manager.
void removeCamera (kCamera *camera)
 Removes a camera from this world's camera list.
void removeScene (kScene *scene)
 Removes a scene from this world's scene list.
std::vector< kScene * > getScenes ()
 Returns all scenes registered in this world.
std::vector< kCamera * > getCameras ()
 Returns all cameras registered in this world.
kScriptManagergetScriptManager ()
 Returns the world's AngelScript manager.
void startScripts ()
 Starts script execution across every active scene.
void stopScripts ()
 Stops script execution: dispatches OnDestroy() and releases every script instance. Call when gameplay ends.
void updateScripts (float deltaTime)
 Dispatches Update() then LateUpdate() to all running scripts.
void fixedUpdateScripts (float fixedDeltaTime)
 Dispatches FixedUpdate() to all running scripts.
bool getScriptsRunning () const
 Returns true between startScripts() and stopScripts().
void startPhysics ()
 Spawns physics bodies and character controllers from every object's editor-authored descriptor, seeded at its current world transform. Call once when gameplay begins.
void updatePhysics (float deltaTime)
 Steps the simulation and syncs transforms back into nodes.
void stopPhysics ()
 Destroys all bodies/characters and shuts the simulation down.
bool getPhysicsRunning () const
 Returns true between startPhysics() and stopPhysics().
virtual json serialize (int startScene=0)
 Serialises the world to JSON.
virtual void deserialize (json data)
 Restores the world from a JSON object.
bool loadFromFile (const kString &path)
 Loads a world from a serialized scene.world file, standalone.

Detailed Description

Root container for the entire simulation environment.

A kWorld owns one or more kScene instances and a camera list. The renderer iterates over active scenes and draws them through the main camera returned by getMainCamera().

Typical setup:

kWorld world;
world.setAssetManager(&assetMgr);
kScene *scene = world.createScene("Main");
kCamera *cam = world.addCamera(kVec3(0,0,5));
world.setMainCamera(cam);
Scene-graph camera node.
Definition kcamera.h:33
Holds all objects, lights, and rendering settings for one scene.
Definition kscene.h:36
kScene * createScene(kString sceneName, kString sceneUuid="")
Creates a new scene and registers it in this world.
void setAssetManager(kAssetManager *manager)
Assigns the asset manager used by scenes in this world.
void setMainCamera(kCamera *camera)
Sets the main camera used by the renderer.
kWorld()
Constructs an empty world and creates its script manager.
kCamera * addCamera(kVec3 position=kVec3(0.0f, 0.0f, 0.0f), kVec3 lookAt=kVec3(0.0f, 0.0f, 0.0f), kCameraType type=kCameraType::CAMERA_TYPE_FREE, kString objectUuid="")
Creates and registers a camera in this world.
glm::vec3 kVec3
3-component float vector.
Definition kdatatype.h:33

Constructor & Destructor Documentation

◆ kWorld()

kemena::kWorld::kWorld ( )

Constructs an empty world and creates its script manager.

◆ ~kWorld()

virtual kemena::kWorld::~kWorld ( )
virtual

Destroys the world, releasing owned scenes, cameras, and managers.

Member Function Documentation

◆ addCamera() [1/2]

void kemena::kWorld::addCamera ( kCamera * camera,
kString objectUuid = "" )

Registers an existing camera in this world.

Parameters
cameraPre-constructed camera to add.
objectUuidOptional UUID override.

◆ addCamera() [2/2]

kCamera * kemena::kWorld::addCamera ( kVec3 position = kVec3(0.0f, 0.0f, 0.0f),
kVec3 lookAt = kVec3(0.0f, 0.0f, 0.0f),
kCameraType type = kCameraType::CAMERA_TYPE_FREE,
kString objectUuid = "" )

Creates and registers a camera in this world.

Parameters
positionWorld-space initial position.
lookAtInitial look-at target (for locked cameras).
typeCamera mode (free or locked).
objectUuidOptional UUID for the camera node.
Returns
Pointer to the newly created kCamera.

◆ addScene()

void kemena::kWorld::addScene ( kScene * scene,
kString sceneUuid = "" )

Registers an existing scene in this world.

Parameters
scenePre-constructed scene to add.
sceneUuidOptional UUID override.

◆ createScene()

kScene * kemena::kWorld::createScene ( kString sceneName,
kString sceneUuid = "" )

Creates a new scene and registers it in this world.

Parameters
sceneNameHuman-readable name for the scene.
sceneUuidOptional UUID; auto-generated if empty.
Returns
Pointer to the newly created kScene.

◆ deserialize()

virtual void kemena::kWorld::deserialize ( json data)
virtual

Restores the world from a JSON object.

Parameters
dataJSON produced by serialize().

◆ fixedUpdateScripts()

void kemena::kWorld::fixedUpdateScripts ( float fixedDeltaTime)

Dispatches FixedUpdate() to all running scripts.

Parameters
fixedDeltaTimeSeconds of the fixed (physics) step.

◆ getAssetManager()

kAssetManager * kemena::kWorld::getAssetManager ( )

Returns the asset manager.

Returns
Pointer to the asset manager, or nullptr if not set.

◆ getCameras()

std::vector< kCamera * > kemena::kWorld::getCameras ( )

Returns all cameras registered in this world.

Returns
Copy of the internal camera vector.

◆ getMainCamera()

kCamera * kemena::kWorld::getMainCamera ( )

Returns the camera used by the renderer for the main view.

Returns
Pointer to the main camera, or nullptr if not set.

◆ getPhysicsRunning()

bool kemena::kWorld::getPhysicsRunning ( ) const
inline

Returns true between startPhysics() and stopPhysics().

◆ getScenes()

std::vector< kScene * > kemena::kWorld::getScenes ( )

Returns all scenes registered in this world.

Returns
Copy of the internal scene vector.

◆ getScriptManager()

kScriptManager * kemena::kWorld::getScriptManager ( )

Returns the world's AngelScript manager.

Created automatically with the world; used to register script assets, compile bytecode, and dispatch lifecycle events.

◆ getScriptsRunning()

bool kemena::kWorld::getScriptsRunning ( ) const
inline

Returns true between startScripts() and stopScripts().

◆ getUuid()

kString kemena::kWorld::getUuid ( )

Returns the UUID of this world.

Returns
UUID v4 kString.

◆ loadFromFile()

bool kemena::kWorld::loadFromFile ( const kString & path)

Loads a world from a serialized scene.world file, standalone.

Reconstructs every scene and object (meshes, lights, cameras, empties) with their transforms and components (physics, character, navigation, scripts), resolving mesh references and script bytecode relative to the file's folder. Designed for a built game running without the editor.

Requires setAssetManager() to have been called first. Picks the first camera found as the main camera.

Parameters
pathPath to scene.world; asset data is resolved relative to its parent folder (Library/ImportedAssets, Library/Scripts).
Returns
true on success.

◆ removeCamera()

void kemena::kWorld::removeCamera ( kCamera * camera)

Removes a camera from this world's camera list.

Parameters
cameraCamera to remove.

◆ removeScene()

void kemena::kWorld::removeScene ( kScene * scene)

Removes a scene from this world's scene list.

Parameters
sceneScene to remove.

◆ serialize()

virtual json kemena::kWorld::serialize ( int startScene = 0)
virtual

Serialises the world to JSON.

Parameters
startSceneIndex of the first scene to include (default 0).
Returns
JSON object with UUID, scenes, and cameras.

◆ setAssetManager()

void kemena::kWorld::setAssetManager ( kAssetManager * manager)

Assigns the asset manager used by scenes in this world.

Parameters
managerAsset manager instance; must outlive the world.

◆ setMainCamera()

void kemena::kWorld::setMainCamera ( kCamera * camera)

Sets the main camera used by the renderer.

Parameters
cameraPointer to the desired camera.

◆ setUuid()

void kemena::kWorld::setUuid ( kString newUuid)

Sets the UUID of this world.

Parameters
newUuidUUID v4 kString.

◆ startPhysics()

void kemena::kWorld::startPhysics ( )

Spawns physics bodies and character controllers from every object's editor-authored descriptor, seeded at its current world transform. Call once when gameplay begins.

The editor drives physics itself; this is for a built game running the world directly.

◆ startScripts()

void kemena::kWorld::startScripts ( )

Starts script execution across every active scene.

Builds a private module instance for each active script component (preferring compiled bytecode), then dispatches Awake() to all instances followed by Start(). Call once when gameplay begins.

◆ stopPhysics()

void kemena::kWorld::stopPhysics ( )

Destroys all bodies/characters and shuts the simulation down.

◆ stopScripts()

void kemena::kWorld::stopScripts ( )

Stops script execution: dispatches OnDestroy() and releases every script instance. Call when gameplay ends.

◆ updatePhysics()

void kemena::kWorld::updatePhysics ( float deltaTime)

Steps the simulation and syncs transforms back into nodes.

◆ updateScripts()

void kemena::kWorld::updateScripts ( float deltaTime)

Dispatches Update() then LateUpdate() to all running scripts.

Parameters
deltaTimeSeconds since the last frame.

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