diff options
| author | Jonathan Bradley <jcb@pikum.xyz> | 2023-12-07 23:12:47 -0500 |
|---|---|---|
| committer | Jonathan Bradley <jcb@pikum.xyz> | 2023-12-07 23:12:47 -0500 |
| commit | 6e76f8342ad4d1f9a576f25bfb992aac6e4d2eee (patch) | |
| tree | 36c17a12914f62ba1a3c2e8863a322be6c14cad4 /editor | |
| parent | b6e7a0c2f7ef0bcb6d5ed0806c851b5312a68b13 (diff) | |
project browser checkpoint
Diffstat (limited to 'editor')
| -rw-r--r-- | editor/editor.cpp | 137 |
1 files changed, 124 insertions, 13 deletions
diff --git a/editor/editor.cpp b/editor/editor.cpp index 8107ee3..2130e0f 100644 --- a/editor/editor.cpp +++ b/editor/editor.cpp @@ -15,20 +15,29 @@ #include "vendor/tinyfiledialogs//tinyfiledialogs.h" #include "imgui.h" +#include <filesystem> #include <future> - -const char *dbgCtrl_CameraLeft = "debug-camera-left"; -const char *dbgCtrl_CameraRight = "debug-camera-right"; -const char *dbgCtrl_CameraForward = "debug-camera-forward"; -const char *dbgCtrl_CameraBack = "debug-camera-back"; -const char *dbgCtrl_CameraUp = "debug-camera-up"; -const char *dbgCtrl_CameraDown = "debug-camera-down"; -const char *dbgCtrl_CameraRotCC = "debug-camera-rot-counter-clockwise"; -const char *dbgCtrl_CameraRotC = "debug-camera-rot-clockwise"; -const char *dbgCtrl_CameraRot = "debug-camera-rot"; -const char *dbgCtrl_CameraButtonMask = "debug-camera-button-mask"; -const char *dbgCtrl_SelectHovered = "debug-select-hovered"; -const char *dbgCtrl_ClearSelection = "debug-clear-selection"; +#include <regex> + +#ifdef WIN32 + // TODO +#else + #include <unistd.h> + #include <sys/wait.h> +#endif + +const char* const dbgCtrl_CameraLeft = "debug-camera-left"; +const char* const dbgCtrl_CameraRight = "debug-camera-right"; +const char* const dbgCtrl_CameraForward = "debug-camera-forward"; +const char* const dbgCtrl_CameraBack = "debug-camera-back"; +const char* const dbgCtrl_CameraUp = "debug-camera-up"; +const char* const dbgCtrl_CameraDown = "debug-camera-down"; +const char* const dbgCtrl_CameraRotCC = "debug-camera-rot-counter-clockwise"; +const char* const dbgCtrl_CameraRotC = "debug-camera-rot-clockwise"; +const char* const dbgCtrl_CameraRot = "debug-camera-rot"; +const char* const dbgCtrl_CameraButtonMask = "debug-camera-button-mask"; +const char* const dbgCtrl_SelectHovered = "debug-select-hovered"; +const char* const dbgCtrl_ClearSelection = "debug-clear-selection"; ThreadPoolHandle threadPoolHandle = ThreadPoolHandle_MAX; @@ -44,6 +53,7 @@ PkeCamera cameraDbg { InputActionSetHandle debugControlsHandle = InputActionSetHandle_MAX; bool shouldSetupEditor = true; bool shouldDisableEditor = false; +bool shouldRebuildProjectDir = true; struct EntityTypeInstanceCreateInfo { EntityHandle entityTypeEntityHandle; @@ -61,6 +71,8 @@ bool shouldOpenSaveSceneDialog = false; bool shouldLoadScene = false; bool shouldSaveScene = false; bool shouldSaveProjectFile = false; +bool shouldRunCurrentScene = false; +bool subProgramRunning = false; glm::vec3 unproject(glm::vec3 windowCoords) { double xDevNorm = (2.0f * windowCoords.x) / Extent.width - 1.0f; @@ -79,6 +91,26 @@ glm::vec3 unproject(glm::vec3 windowCoords) { } void PkeEditor_Tick(double delta) { + if (shouldRunCurrentScene) { + shouldRunCurrentScene = false; + subProgramRunning = true; + PkeThreads_Enqueue(threadPoolHandle, std::packaged_task<void()>( [] { + auto pid = fork(); + if (pid == 0) { + const char *argv[] = { + NULL, + }; + int status = execvp("pke_runtime", const_cast<char **>(argv)); + fprintf(stderr, "pke_runtime exited with a status of %i\n", status); + subProgramRunning = false; + } else { + int status; + waitpid(pid, &status, 0); + fprintf(stdout, "pke_runtime exited cleanly with a status of %i\n", status); + subProgramRunning = false; + } + })); + } if (shouldSetupEditor) { PkeEditor_Setup(); } @@ -389,6 +421,12 @@ void RecordImGuiEditorWrapper() { ImGui::EndMenu(); } + ImGui::Spacing(); + ImGui::BeginDisabled(subProgramRunning); + if (ImGui::Button("▶️")) { + shouldRunCurrentScene = true; + } + ImGui::EndDisabled(); ImGui::EndMainMenuBar(); } @@ -746,6 +784,78 @@ void RecordImGuiProjectSettingsEditor() { ImGui::End(); } +struct fsEntry { + int type = 0; + char *name = nullptr; + char *path = nullptr; + DynArray<fsEntry> children{0, nullptr}; +}; +DynArray<fsEntry> fsEntries{0, nullptr}; +std::regex reg_sceneFile(".+\\.ps[tb]f$", std::regex_constants::icase); +void BuildDirRecursive(const std::filesystem::directory_entry &de, fsEntry *dirFsEntry) { + auto &entry = dirFsEntry == nullptr ? fsEntries.Push() : dirFsEntry->children.Push(); + auto len = strlen(de.path().c_str()) + 1; + entry.path = Pke_New<char>(len); + memset(entry.path, '\0', len); + memcpy(entry.path, de.path().c_str(), len - 1); + len = strlen(de.path().filename().c_str()); + entry.name = Pke_New<char>(len); + memset(entry.name, '\0', len); + memcpy(entry.name, de.path().filename().c_str(), len - 1); + + if (de.is_regular_file()) { + if (std::regex_search(de.path().c_str(), reg_sceneFile)) { + entry.type = 1; + } + } else if (de.is_directory()) { + entry.type = 0; + std::filesystem::directory_iterator di{de.path()}; + for (const std::filesystem::directory_entry &sde : di) { + if (sde.is_directory() + || (sde.is_regular_file() && std::regex_search(sde.path().c_str(), reg_sceneFile)) + ) { + BuildDirRecursive(sde, &entry); + } + } + } +} +void BuildProjectMenuRecursive(fsEntry &entry) { + if (entry.type == 1) { + if (ImGui::Selectable(entry.name, false, ImGuiSelectableFlags_AllowDoubleClick)) { + sceneName = entry.name; + shouldLoadScene = true; + } + } else if (entry.type == 0) { + if (ImGui::TreeNode(entry.name)) { + for (long i = 0; i < entry.children.Count(); ++i) { + BuildProjectMenuRecursive(entry.children[i]); + } + ImGui::TreePop(); + } + } +} +void RecordImGuiProjectBrowser() { + if (!ImGui::Begin("ProjectBrowser")) { + ImGui::End(); + return; + } + if (shouldRebuildProjectDir == true) { + shouldRebuildProjectDir = false; + std::filesystem::directory_iterator di{"."}; + for (const std::filesystem::directory_entry &sde : di) { + if (sde.is_directory() + || (sde.is_regular_file() && std::regex_search(sde.path().c_str(), reg_sceneFile)) + ) { + BuildDirRecursive(sde, nullptr); + } + } + } + for (long i = 0; i < fsEntries.Count(); ++i) { + BuildProjectMenuRecursive(fsEntries[i]); + } + ImGui::End(); +} + void RecordImGuiSceneEditor() { if (!ImGui::Begin("SceneEditorEntityTypes", &pkeSettings.editorSettings.isShowingSceneEditor)) { ImGui::End(); @@ -787,6 +897,7 @@ void PkeEditor_RecordImGui() { if (pkeSettings.isShowingEditor) { RecordImGuiEditorWrapper(); RecordImGuiProjectSettingsEditor(); + RecordImGuiProjectBrowser(); RecordImGuiEntityList(); RecordImGuiSceneEditor(); RecordImGuiUBO(); |
