summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJonathan Bradley <jcb@pikum.xyz>2025-04-07 16:25:11 -0400
committerJonathan Bradley <jcb@pikum.xyz>2025-04-07 16:25:11 -0400
commit8c0dbef6b21a0331916ae96ea5cd3b5613e50b6b (patch)
treebfbc487de4bc212c00f57e1ba38e08cccac6978d
parent7b43a9b51d9df0bc0e18102415f877772031f440 (diff)
pke: temp load scene by file path
-rw-r--r--editor/editor.cpp2
-rw-r--r--src/game.cpp12
-rw-r--r--src/scene.cpp18
-rw-r--r--src/scene.hpp1
-rw-r--r--src/window.cpp1
5 files changed, 30 insertions, 4 deletions
diff --git a/editor/editor.cpp b/editor/editor.cpp
index 72f35f6..6eb7f35 100644
--- a/editor/editor.cpp
+++ b/editor/editor.cpp
@@ -108,7 +108,7 @@ void PkeEditor_Tick(double delta) {
"pke-runtime",
"--plugin", pkeSettings.args.pluginPath == nullptr ? "libpke-example.o" : pkeSettings.args.pluginPath,
"--project", pkeSettings.args.projectPath == nullptr ? PKE_PROJ_DEFAULT_FILENAME : pkeSettings.args.projectPath,
- "--scene", (editor_mstr.active_scene != nullptr && editor_mstr.active_scene->name[0] != '\0') ? editor_mstr.active_scene->name : PKE_PROJ_DEFAULT_FILENAME ,
+ "--scene", (editor_mstr.active_scene != nullptr && editor_mstr.active_scene->file_path.length > 0) ? editor_mstr.active_scene->file_path.val : PKE_PROJ_DEFAULT_FILENAME ,
NULL,
};
status = execvp("pke-runtime", const_cast<char **>(argv));
diff --git a/src/game.cpp b/src/game.cpp
index f5afa82..03ea495 100644
--- a/src/game.cpp
+++ b/src/game.cpp
@@ -149,10 +149,15 @@ void Game_Main(PKEWindowProperties windowProps, const char *executablePath) {
// if we were passed only a scene name, create a faux level.
if (!pkeSettings.args.levelName && pkeSettings.args.sceneName) {
- pkeSettings.rt.nextLevel = PkeLevel_Create("faux-level")->levelHandle;
- PkeLevel *lvl = PkeLevel_Get(pkeSettings.rt.nextLevel);
+ PkeLevel *lvl = PkeLevel_Create("faux-level");
+ pkeSettings.rt.nextLevel = lvl->levelHandle;
scene_instance si{};
- si.scene_handle = pke_scene_get_by_name(pkeSettings.args.sceneName)->scene_handle;
+ pke_scene *scn = pke_scene_get_by_path(pkeSettings.args.sceneName);
+ if (scn == nullptr) {
+ fprintf(stdout, "[Game_Main] Did not find scene by name: '%s'\n", pkeSettings.args.sceneName);
+ goto GAME_SHUTDOWN;
+ }
+ si.scene_handle = scn->scene_handle;
pk_arr_append_t(&lvl->scene_instances, si);
}
@@ -281,6 +286,7 @@ void Game_Main(PKEWindowProperties windowProps, const char *executablePath) {
} catch (...) {
fprintf(stderr, "Game_Main UNHANDLED EXCEPTION\n");
}
+GAME_SHUTDOWN:
fprintf(stdout, "Game_Main SHUTDOWN INITIATED\n");
#ifndef NDEBUG
pk_memory_debug_print();
diff --git a/src/scene.cpp b/src/scene.cpp
index f4df916..58e9c44 100644
--- a/src/scene.cpp
+++ b/src/scene.cpp
@@ -2,7 +2,10 @@
#include "scene.hpp"
#include "bucketed-array.hpp"
#include "ecs.hpp"
+#include "serialization.hpp"
+#include "game-settings.hpp"
+#include <fstream>
#include <string.h>
#include <filesystem>
@@ -49,6 +52,21 @@ struct pke_scene *pke_scene_get_by_handle(SceneHandle scene_handle) {
return &scene_mstr.bc.buckets[scene_handle.bucketIndex][scene_handle.itemIndex];
}
+ // TODO remove me? Need to decide if we always read from files or if we should have a serialized representation of a scene
+struct pke_scene *pke_scene_get_by_path(const char *file_path) {
+ std::ifstream f(file_path);
+ if (!f.is_open()) {
+ fprintf(stderr, "[pke_scene_get_by_name] Scene not found in memory nor filesystem: '%s'\n", file_path);
+ return nullptr;
+ }
+ srlztn_deserialize_helper *h = pke_deserialize_init(pkeSettings.mem.bkt);
+ h->i = &f;
+ h->scene = pke_scene_create(file_path);
+ pke_deserialize_file_scene(h);
+ pke_deserialize_teardown(h);
+ return h->scene;
+}
+
struct pke_scene *pke_scene_get_by_name(const char *scene_name) {
assert(scene_name != nullptr);
NULL_CHAR_ARR(safe_name, SCENE_NAME_MAX_LEN + 1);
diff --git a/src/scene.hpp b/src/scene.hpp
index 46d406c..b34f7f7 100644
--- a/src/scene.hpp
+++ b/src/scene.hpp
@@ -11,6 +11,7 @@ void pke_scene_master_teardown();
struct pke_scene *pke_scene_create(const char *scene_name);
struct pke_scene *pke_scene_get_by_handle(SceneHandle scene_handle);
struct pke_scene *pke_scene_get_by_name(const char *scene_name);
+struct pke_scene *pke_scene_get_by_path(const char *file_path);
pk_handle_bucket_index_T pke_scene_get_bucket_count();
struct pke_scene *pke_scene_get_scenes(pk_handle_bucket_index_T bucket_index, pk_handle_item_index_T *item_count);
void pke_scene_remove(SceneHandle handle);
diff --git a/src/window.cpp b/src/window.cpp
index 4a97d56..85ea8d3 100644
--- a/src/window.cpp
+++ b/src/window.cpp
@@ -1244,6 +1244,7 @@ void CreateSwapchain() {
assert(vkResult == VK_SUCCESS);
assert(swapchainLength >= surfaceCapabilities.minImageCount);
assert(surfaceCapabilities.maxImageCount == 0 || swapchainLength <= surfaceCapabilities.maxImageCount);
+ if (prevSwapchainLength == 0) prevSwapchainLength = swapchainLength;
pkvk_present.images = pk_new<VkImage>(swapchainLength, MemBkt_Vulkan);
vkResult = vkGetSwapchainImagesKHR(vkDevice, vkSwapchainKHR, &swapchainLength, pkvk_present.images);
assert(vkResult == VK_SUCCESS);