diff options
| author | Jonathan Bradley <jcb@pikum.xyz> | 2023-12-13 15:53:52 -0500 |
|---|---|---|
| committer | Jonathan Bradley <jcb@pikum.xyz> | 2023-12-23 11:41:03 -0500 |
| commit | 064e9ba16e390b13566d0007ef367dcb1adacc8d (patch) | |
| tree | 359be3c8de88da8544646bfc9a84a8c8b3f383cd /src/game.cpp | |
| parent | a527dd1b773f14df140d3ac6a167339d7dc39e33 (diff) | |
checkpoint - add PkeLevel - editor removes on scene load
Diffstat (limited to 'src/game.cpp')
| -rw-r--r-- | src/game.cpp | 22 |
1 files changed, 16 insertions, 6 deletions
diff --git a/src/game.cpp b/src/game.cpp index bf30cfe..4dde008 100644 --- a/src/game.cpp +++ b/src/game.cpp @@ -8,6 +8,8 @@ #include "game-settings.hpp" #include "helpers.hpp" #include "imgui.h" +#include "level-types.hpp" +#include "level.hpp" #include "math-helpers.hpp" #include "physics.hpp" #include "player-input.hpp" @@ -137,7 +139,7 @@ void SerializeInstance(std::ofstream &stream, const CompInstance &comp) { } } -void ParseCamera(std::ifstream &stream) { +void ParseCamera(LevelHandle levelHandle, std::ifstream &stream) { PkeCamera cam{}; while (stream.getline(readLine, readLineLength)) { if (strcmp(readLine, PKE_FILE_OBJ_END) == 0) { @@ -147,6 +149,9 @@ void ParseCamera(std::ifstream &stream) { rCam.target = cam.target; rCam.type = cam.type; rCam.orientation = cam.orientation; + if (levelHandle != LevelHandle_MAX) { + PkeLevel_RegisterCamera(levelHandle, rCam.handle); + } return; } if (strncmp(readLine, PKE_FILE_CAMERA_POS, strlen(PKE_FILE_CAMERA_POS)) == 0) { @@ -210,7 +215,7 @@ void ParseCamera(std::ifstream &stream) { } } -void ParseInstance(std::ifstream &stream) { +void ParseInstance(EntityHandle parentEntHandle, std::ifstream &stream) { CompInstance comp{}; InstPos instPos{}; instPos.posRot = btTransform{}; @@ -231,7 +236,7 @@ void ParseInstance(std::ifstream &stream) { break; } const auto &et = GlobalEntityTypes[existingEntityTypeIndex]; - auto entityHandle = ECS_CreateEntity(); + auto entityHandle = ECS_CreateEntity(parentEntHandle); auto &compInst = ECS_CreateInstance(entityHandle, et.entityHandle); compInst.physicsLayer = comp.physicsLayer; @@ -380,21 +385,26 @@ void Game_SaveSceneFile(const char *sceneFilePath) { f.close(); } -void Game_LoadSceneFile(const char *sceneFilePath) { +void Game_LoadSceneFile(LevelHandle levelHandle, const char *sceneFilePath) { std::ifstream f(sceneFilePath); if (!f.is_open()) { fprintf(stderr, "Failed to load requested scene file: %s\n", sceneFilePath); return; } memset(readLine, '\0', readLineLength); + EntityHandle parentEntHandle = EntityHandle_MAX; + if (levelHandle != LevelHandle_MAX) { + parentEntHandle = ECS_CreateEntity(); + PkeLevel_RegisterWrappingEntity(levelHandle, parentEntHandle); + } while (f.getline(readLine, readLineLength)) { if (strcmp(PKE_FILE_OBJ_CAMERA, readLine) == 0) { - ParseCamera(f); + ParseCamera(levelHandle, f); continue; } if (strcmp(PKE_FILE_OBJ_INSTANCE, readLine) == 0) { - ParseInstance(f); + ParseInstance(parentEntHandle, f); continue; } } |
