Kemena3D
Loading...
Searching...
No Matches
kworld.h
Go to the documentation of this file.
1
5
6#ifndef KWORLD_H
7#define KWORLD_H
8
9#include <string>
10#include <iostream>
11#include <vector>
12
13#include "kdatatype.h"
14#include "kassetmanager.h"
15#include "kscene.h"
16#include "kcamera.h"
17#include "kscriptmanager.h"
18
19// Export macro
20#ifdef _WIN32
21#ifdef KEMENA3D_STATIC
22#define KEMENA3D_API
23#elif defined(KEMENA3D_EXPORTS)
24#define KEMENA3D_API __declspec(dllexport)
25#else
26#define KEMENA3D_API __declspec(dllimport)
27#endif
28#else
29#define KEMENA3D_API
30#endif
31
32namespace kemena
33{
34 class kScene;
35 class kPhysicsManager;
36
54 {
55 public:
58
60 virtual ~kWorld();
61
67
72 void setUuid(kString newUuid);
73
80 kScene *createScene(kString sceneName, kString sceneUuid = "");
81
87 void addScene(kScene *scene, kString sceneUuid = "");
88
97 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 = "");
98
104 void addCamera(kCamera *camera, kString objectUuid = "");
105
111
116 void setMainCamera(kCamera *camera);
117
123
129
134 void removeCamera(kCamera *camera);
135
140 void removeScene(kScene *scene);
141
146 std::vector<kScene *> getScenes();
147
152 std::vector<kCamera *> getCameras();
153
154 // --- Scripting -------------------------------------------------------
155
163
172
178
183 void updateScripts(float deltaTime);
184
189 void fixedUpdateScripts(float fixedDeltaTime);
190
192 bool getScriptsRunning() const { return scriptsRunning; }
193
194 // --- Physics lifecycle (standalone runtime) -------------------------
195
205
207 void updatePhysics(float deltaTime);
208
211
213 bool getPhysicsRunning() const { return physicsRunning; }
214
220 virtual json serialize(int startScene = 0);
221
226 virtual void deserialize(json data);
227
243 bool loadFromFile(const kString &path);
244
245 protected:
246 private:
248 std::vector<kObject *> collectAllObjects();
250 kString resolveScriptAsset(kScript &component);
251
252 kAssetManager *assetManager = nullptr;
253
254 std::vector<kScene *> scenes;
255 std::vector<kCamera *> cameras;
256
257 kCamera *mainCamera = nullptr;
258
259 kScriptManager *scriptManager = nullptr;
260 bool scriptsRunning = false;
261
262 kPhysicsManager *physicsManager = nullptr;
263 bool physicsRunning = false;
264 std::vector<kObject *> physicsBodies;
265 std::vector<kObject *> characterBodies;
266
267 kString uuid;
268 };
269}
270
271#endif // KWORLD_H
Central asset-loading and cache manager.
Definition kassetmanager.h:55
Scene-graph camera node.
Definition kcamera.h:33
Owns the Jolt PhysicsSystem and manages the lifecycle of all physics bodies.
Definition kphysicsmanager.h:57
Holds all objects, lights, and rendering settings for one scene.
Definition kscene.h:36
Manages the AngelScript engine, a registry of script assets, and the live per-object script module in...
Definition kscriptmanager.h:176
std::vector< kCamera * > getCameras()
Returns all cameras registered in this world.
bool getPhysicsRunning() const
Returns true between startPhysics() and stopPhysics().
Definition kworld.h:213
kCamera * getMainCamera()
Returns the camera used by the renderer for the main view.
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.
kScene * createScene(kString sceneName, kString sceneUuid="")
Creates a new scene and registers it in this world.
void setUuid(kString newUuid)
Sets the UUID of this world.
bool getScriptsRunning() const
Returns true between startScripts() and stopScripts().
Definition kworld.h:192
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.
void updatePhysics(float deltaTime)
Steps the simulation and syncs transforms back into nodes.
kAssetManager * getAssetManager()
Returns the asset manager.
void updateScripts(float deltaTime)
Dispatches Update() then LateUpdate() to all running scripts.
kWorld()
Constructs an empty world and creates its script manager.
void startPhysics()
Spawns physics bodies and character controllers from every object's editor-authored descriptor,...
void stopPhysics()
Destroys all bodies/characters and shuts the simulation down.
void addCamera(kCamera *camera, kString objectUuid="")
Registers an existing camera in this world.
void stopScripts()
Stops script execution: dispatches OnDestroy() and releases every script instance....
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.
virtual ~kWorld()
Destroys the world, releasing owned scenes, cameras, and managers.
bool loadFromFile(const kString &path)
Loads a world from a serialized scene.world file, standalone.
void addScene(kScene *scene, kString sceneUuid="")
Registers an existing scene in this world.
void startScripts()
Starts script execution across every active scene.
virtual json serialize(int startScene=0)
Serialises the world to JSON.
kScriptManager * getScriptManager()
Returns the world's AngelScript manager.
kString getUuid()
Returns the UUID of this world.
void fixedUpdateScripts(float fixedDeltaTime)
Dispatches FixedUpdate() to all running scripts.
std::vector< kScene * > getScenes()
Returns all scenes registered in this world.
virtual void deserialize(json data)
Restores the world from a JSON object.
Loads and manages textures, meshes, shaders, materials, and animations.
Perspective camera node (free-look or look-at).
Core type aliases, enumerations, structs, and utility functions used throughout the engine.
#define KEMENA3D_API
Definition kexport.h:35
nlohmann::json json
Definition kobject.h:30
Container for a self-contained scene (objects, lights, skybox).
AngelScript engine wrapper: script-asset registry, text/bytecode compilation, and per-object script i...
Top-level Kemena3D engine namespace.
Definition kanimation.h:23
kCameraType
Camera behaviour mode.
Definition kdatatype.h:97
@ CAMERA_TYPE_FREE
Free-fly; position and orientation are set independently.
Definition kdatatype.h:98
std::string kString
Standard string alias.
Definition kdatatype.h:42
glm::vec3 kVec3
3-component float vector.
Definition kdatatype.h:33
Per-object script component descriptor.
Definition kscriptmanager.h:79