diff options
| author | Jonathan Bradley <jcb@pikum.xyz> | 2023-12-19 13:32:31 -0500 |
|---|---|---|
| committer | Jonathan Bradley <jcb@pikum.xyz> | 2023-12-23 11:41:03 -0500 |
| commit | 04f5688a37030aa8598ded416f05d0cc979c37d6 (patch) | |
| tree | ce0bec713c49d6dda66a28f1246e1443d271b8f2 /src/game.cpp | |
| parent | c7c678651a30db30e449e965e6c82ad0dcb871e6 (diff) | |
loading scenes and projects can now be done via args
Diffstat (limited to 'src/game.cpp')
| -rw-r--r-- | src/game.cpp | 42 |
1 files changed, 39 insertions, 3 deletions
diff --git a/src/game.cpp b/src/game.cpp index 7dfca42..20e67a0 100644 --- a/src/game.cpp +++ b/src/game.cpp @@ -53,6 +53,7 @@ const char *PKE_FILE_CAMERA_ROT = "Cam::Rot: "; const char *PKE_FILE_CAMERA_TARGET = "Cam::Target: "; const char *PKE_FILE_CAMERA_TYPE = "Cam::Type: "; const char *PKE_FILE_CAMERA_ORIENTATION = "Cam::Orientation: "; +const char *PKE_FILE_CAMERA_IS_PRIMARY = "Cam::IsPrimary: "; void SerializeCamera(std::ofstream &stream, const PkeCamera &cam) { PkeCamera c{}; @@ -81,6 +82,9 @@ void SerializeCamera(std::ofstream &stream, const PkeCamera &cam) { if (cam.orientation != c.orientation) { stream << PKE_FILE_CAMERA_ORIENTATION << int(static_cast<PkeCameraOrientation_T>(cam.orientation)) << std::endl; } + if (cam.isPrimary != c.isPrimary) { + stream << PKE_FILE_CAMERA_IS_PRIMARY << cam.isPrimary << std::endl; + } } void SerializeInstance(std::ofstream &stream, const CompInstance &comp) { @@ -149,9 +153,13 @@ void ParseCamera(LevelHandle levelHandle, std::ifstream &stream) { rCam.target = cam.target; rCam.type = cam.type; rCam.orientation = cam.orientation; + rCam.isPrimary = cam.isPrimary; if (levelHandle != LevelHandle_MAX) { PkeLevel_RegisterCamera(levelHandle, rCam.handle); } + if (rCam.isPrimary == true) { + ActiveCamera = &rCam; + } return; } if (strncmp(readLine, PKE_FILE_CAMERA_POS, strlen(PKE_FILE_CAMERA_POS)) == 0) { @@ -212,6 +220,14 @@ void ParseCamera(LevelHandle levelHandle, std::ifstream &stream) { cam.orientation = PkeCameraOrientation{handle_t}; continue; } + if (strncmp(readLine, PKE_FILE_CAMERA_IS_PRIMARY, strlen(PKE_FILE_CAMERA_IS_PRIMARY)) == 0) { + uint64_t prefixLen = strlen(PKE_FILE_CAMERA_IS_PRIMARY); + uint8_t isPrimary; + STR2NUM_ERROR result = str2num(isPrimary, readLine + prefixLen); + assert(result == STR2NUM_ERROR::SUCCESS); + cam.isPrimary = bool(isPrimary); + continue; + } } } @@ -451,6 +467,26 @@ void Game_RecordImGui() { void Game_Tick(double delta) { Pke_ResetBucket(pkeSettings.mem.bkt); + + // TODO this should be removed in favor of storing the scene details inside a level definition + if (pkeSettings.rt.shouldLoadScene && pkeSettings.rt.sceneName) { + pkeSettings.rt.shouldLoadScene = false; + if (pkeSettings.rt.activeLevel != LevelHandle_MAX) { + pkeSettings.rt.previousLevel = pkeSettings.rt.activeLevel; + } + pkeSettings.rt.nextLevel = PkeLevel_Create(pkeSettings.rt.sceneName); + } + if (pkeSettings.rt.nextLevel != LevelHandle_MAX) { + // TODO async this + Game_LoadSceneFile(pkeSettings.rt.nextLevel, pkeSettings.rt.sceneName); + pkeSettings.rt.activeLevel = pkeSettings.rt.nextLevel; + pkeSettings.rt.nextLevel = LevelHandle_MAX; + } + if (pkeSettings.rt.previousLevel != LevelHandle_MAX) { + PkeLevel_Remove(pkeSettings.rt.previousLevel); + pkeSettings.rt.previousLevel = LevelHandle_MAX; + } + /* * ECS_Tick() gets called first because it updates the public * `EntitiesToBeRemoved` for all other ticks to use. @@ -481,13 +517,13 @@ void Game_Main(PKEWindowProperties windowProps, const char *executablePath) { CreateWindow(windowProps); PkeInput_Init(); EntityType_Init(); - if (pkeSettings.pluginPath) { - Pke_LoadPlugin(pkeSettings.pluginPath); + if (pkeSettings.args.pluginPath) { + Pke_LoadPlugin(pkeSettings.args.pluginPath); } if (pkePlugin.OnInit) { pkePlugin.OnInit(); } - PkeProject_Load(); + PkeProject_Load(pkeSettings.args.projectPath); GameTimePoint lastTimePoint = pkeSettings.steadyClock.now(); double deltaTillNextRender = pkeSettings.deltaPerFrame; |
