diff options
| author | Jonathan Bradley <jcb@pikum.xyz> | 2025-04-07 11:27:00 -0400 |
|---|---|---|
| committer | Jonathan Bradley <jcb@pikum.xyz> | 2025-04-07 11:27:00 -0400 |
| commit | ff63a4b2bf9f096f8cf8c6824e826b3b4d79e747 (patch) | |
| tree | bc5834ffecfa87ad70aac530a14acf38245c515b /editor | |
| parent | 2f57eefb01c478ffe62845b8051bc82036cbb819 (diff) | |
pke: saving and loading scenes works
Diffstat (limited to 'editor')
| -rw-r--r-- | editor/editor-io.cpp | 6 | ||||
| -rw-r--r-- | editor/editor.cpp | 33 |
2 files changed, 28 insertions, 11 deletions
diff --git a/editor/editor-io.cpp b/editor/editor-io.cpp index 1a80d2d..7b93b51 100644 --- a/editor/editor-io.cpp +++ b/editor/editor-io.cpp @@ -8,7 +8,6 @@ #include <fstream> void pke_editor_scene_save(const char *file_path) { - std::ostringstream stream{}; srlztn_serialize_helper *helper = pke_serialize_init(pkeSettings.mem.bkt); bool failed = false; @@ -27,7 +26,7 @@ void pke_editor_scene_save(const char *file_path) { if (!f.is_open()) { failed = true; } else { - f << stream.str(); + f << helper->o.str(); } f.flush(); f.close(); @@ -39,7 +38,7 @@ void pke_editor_scene_save(const char *file_path) { strncpy(errFileName + strlen(file_path), ".err", 256 - strlen(file_path)); std::ofstream errF(file_path); if (errF.is_open()) { - errF << stream.str(); + errF << helper->o.str(); errF.flush(); errF.close(); fprintf(stderr, "Failed to save scene file '%s', partial output saved to '%s'\n", file_path, errFileName); @@ -57,6 +56,7 @@ void pke_editor_scene_load(const char *file_path) { return; } srlztn_deserialize_helper *helper = pke_deserialize_init(pkeSettings.mem.bkt); + helper->i = &f; // TODO scene name is in the file? helper->scene = pke_scene_get_by_name(file_path); if (helper->scene == nullptr) { diff --git a/editor/editor.cpp b/editor/editor.cpp index 48e5cc1..17a2913 100644 --- a/editor/editor.cpp +++ b/editor/editor.cpp @@ -189,6 +189,15 @@ void PkeEditor_Tick(double delta) { } else { sprintf(file_path, "%.16s", editor_mstr.active_scene->name); } + int len = strlen(file_path); + if (strstr(file_path, ".pstf") == nullptr && len < 251) { + file_path[len+0] = '.'; + file_path[len+1] = 'p'; + file_path[len+2] = 's'; + file_path[len+3] = 't'; + file_path[len+4] = 'f'; + file_path[len+5] = '\0'; + } pke_editor_scene_save(file_path); shouldRebuildProjectDir = true; } @@ -1093,19 +1102,22 @@ void RecordImGuiAssets() { } void RecordImGuiCameras() { - CompInstance *activeInst = nullptr; - // CompInstance *activeTargetInst = nullptr; + CompInstance *active_inst = nullptr; if (!ImGui::Begin("Cameras")) { ImGui::End(); return; } - activeInst = ECS_GetInstance(ActiveCamera->phys.instHandle); - // activeTargetInst = ECS_GetInstance(ActiveCamera->phys.targetInstHandle); + active_inst = ECS_GetInstance(ActiveCamera->phys.instHandle); if (ImGui::Button("Create")) { InstPos instPos{}; instPos.mass = 1.f; - activeInst->bt.motionState->getWorldTransform(instPos.posRot); - instPos.scale = activeInst->bt.rigidBody->getCollisionShape()->getLocalScaling(); + if (active_inst == nullptr) { + instPos.posRot.setIdentity(); + instPos.scale = btVector3(1, 1, 1); + } else { + active_inst->bt.motionState->getWorldTransform(instPos.posRot); + instPos.scale = active_inst->bt.rigidBody->getCollisionShape()->getLocalScaling(); + } auto &cam = PkeCamera_Register(pk_uuid_zed, instPos); cam.phys.targetInstHandle = ActiveCamera->phys.targetInstHandle; cam.type = ActiveCamera->type; @@ -1168,8 +1180,13 @@ void RecordImGuiCameras() { if (ImGui::Button("Update Position")) { InstPos instPos{}; instPos.mass = 1.f; - activeInst->bt.motionState->getWorldTransform(instPos.posRot); - instPos.scale = activeInst->bt.rigidBody->getCollisionShape()->getLocalScaling(); + if (active_inst == nullptr) { + NullCameraInstance.bt.motionState->getWorldTransform(instPos.posRot); + instPos.scale = NullCameraInstance.bt.rigidBody->getCollisionShape()->getLocalScaling(); + } else { + active_inst->bt.motionState->getWorldTransform(instPos.posRot); + instPos.scale = active_inst->bt.rigidBody->getCollisionShape()->getLocalScaling(); + } CompInstance *camInst = ECS_GetInstance(cam.phys.instHandle); ECS_UpdateInstance(camInst, instPos, true); } |
