summaryrefslogtreecommitdiff
path: root/editor
diff options
context:
space:
mode:
authorJonathan Bradley <jcb@pikum.xyz>2023-12-19 13:32:31 -0500
committerJonathan Bradley <jcb@pikum.xyz>2023-12-23 11:41:03 -0500
commit04f5688a37030aa8598ded416f05d0cc979c37d6 (patch)
treece0bec713c49d6dda66a28f1246e1443d271b8f2 /editor
parentc7c678651a30db30e449e965e6c82ad0dcb871e6 (diff)
loading scenes and projects can now be done via args
Diffstat (limited to 'editor')
-rw-r--r--editor/editor.cpp74
1 files changed, 33 insertions, 41 deletions
diff --git a/editor/editor.cpp b/editor/editor.cpp
index 4170ac9..7bb972c 100644
--- a/editor/editor.cpp
+++ b/editor/editor.cpp
@@ -71,16 +71,12 @@ EntityType entityTypeToCreate{};
CameraHandle selectedCamera = CameraHandle_MAX;
const char* const newSceneName = "newScene.pstf";
-const char *sceneName = nullptr;
bool shouldOpenLoadSceneDialog = false;
bool shouldOpenSaveSceneDialog = false;
bool shouldOpenNewScene = false;
-bool shouldLoadScene = false;
-bool shouldSaveScene = false;
bool shouldSaveProjectFile = false;
bool shouldRunCurrentScene = false;
bool subProgramRunning = false;
-LevelHandle levelHandle = LevelHandle_MAX;
glm::vec3 unproject(glm::vec3 windowCoords) {
double xDevNorm = (2.0f * windowCoords.x) / Extent.width - 1.0f;
@@ -105,12 +101,11 @@ void PkeEditor_Tick(double delta) {
PkeThreads_Enqueue(threadPoolHandle, std::packaged_task<void()>( [] {
auto pid = fork();
if (pid == 0) {
- char pluginOpt[128];
- pluginOpt[127] = '\n';
- sprintf(pluginOpt, "--plugin %s", pkeSettings.pluginPath == nullptr ? "example.o" : pkeSettings.pluginPath);
int status = -1;
const char *argv[] = {
- pluginOpt,
+ "--plugin", pkeSettings.args.pluginPath == nullptr ? "example.o" : pkeSettings.args.pluginPath,
+ "--project", pkeSettings.args.projectPath == nullptr ? PKE_PROJ_DEFAULT_FILENAME : pkeSettings.args.projectPath,
+ "--scene", pkeSettings.rt.sceneName == nullptr ? PKE_PROJ_DEFAULT_FILENAME : pkeSettings.rt.sceneName,
NULL,
};
status = execvp("pke_runtime", const_cast<char **>(argv));
@@ -135,12 +130,12 @@ void PkeEditor_Tick(double delta) {
}
if (shouldOpenNewScene) {
shouldOpenNewScene = false;
- if (levelHandle != LevelHandle_MAX) {
- PkeLevel_Remove(levelHandle);
- ActiveCamera = &NullCamera;
- }
- levelHandle = PkeLevel_Create("editorLevel");
- sceneName = newSceneName;
+ // queues unloading
+ pkeSettings.rt.previousLevel = pkeSettings.rt.activeLevel;
+ // bypasses loading a level by setting a new active one
+ pkeSettings.rt.activeLevel = PkeLevel_Create("editorLevel");
+ pkeSettings.rt.sceneName = newSceneName;
+ ActiveCamera = &NullCamera;
}
if (shouldSaveProjectFile) {
shouldSaveProjectFile = false;
@@ -152,35 +147,27 @@ void PkeEditor_Tick(double delta) {
const char * patterns[1] = {"*.pstf"};
char *selectedScene = tinyfd_openFileDialog(nullptr, "cafebabe.pstf", 1, patterns, "Pke Scene Text File", 0);
if (selectedScene != nullptr) {
- sceneName = selectedScene;
- shouldLoadScene = true;
+ pkeSettings.rt.sceneName = selectedScene;
+ pkeSettings.rt.shouldLoadScene = true;
+ ActiveCamera = &NullCamera;
}
}));
}
- if (shouldLoadScene && sceneName) {
- shouldLoadScene = false;
- if (levelHandle != LevelHandle_MAX) {
- PkeLevel_Remove(levelHandle);
- ActiveCamera = &NullCamera;
- }
- levelHandle = PkeLevel_Create("editorLevel");
- Game_LoadSceneFile(levelHandle, sceneName);
- }
if (shouldOpenSaveSceneDialog) {
shouldOpenSaveSceneDialog = false;
PkeThreads_Enqueue(threadPoolHandle, std::packaged_task<void()>( [] {
const char * patterns[1] = {"*.pstf"};
- char *selectedScene = tinyfd_saveFileDialog(nullptr, sceneName, 1, patterns, "Pke Scene Text File");
+ char *selectedScene = tinyfd_saveFileDialog(nullptr, pkeSettings.rt.sceneName, 1, patterns, "Pke Scene Text File");
if (selectedScene != nullptr) {
- sceneName = selectedScene;
- shouldSaveScene = true;
+ pkeSettings.rt.sceneName = selectedScene;
+ pkeSettings.rt.shouldSaveScene = true;
}
}));
}
- if (shouldSaveScene && sceneName) {
- shouldSaveScene = false;
- Game_SaveSceneFile(sceneName);
+ if (pkeSettings.rt.shouldSaveScene && pkeSettings.rt.sceneName) {
+ pkeSettings.rt.shouldSaveScene = false;
+ Game_SaveSceneFile(pkeSettings.rt.sceneName);
shouldRebuildProjectDir = true;
}
@@ -449,20 +436,20 @@ void RecordImGuiEditorWrapper() {
* - the goal is not to prevent a specific scene name,
* I just want to know if they clicked the "New Scene" button
*/
- ImGui::BeginDisabled(sceneName == newSceneName);
+ ImGui::BeginDisabled(pkeSettings.rt.sceneName == newSceneName);
if (ImGui::MenuItem("Save")) {
shouldSaveProjectFile = true;
- shouldSaveScene = true;
+ pkeSettings.rt.shouldSaveScene = true;
}
- if (sceneName) {
+ if (pkeSettings.rt.sceneName) {
ImGui::SameLine();
int offset = 0;
- const auto *slash = strrchr(sceneName, '\\');
- slash = slash != nullptr ? slash : strrchr(sceneName, '/');
+ const auto *slash = strrchr(pkeSettings.rt.sceneName, '\\');
+ slash = slash != nullptr ? slash : strrchr(pkeSettings.rt.sceneName, '/');
if (slash != nullptr) {
- offset = slash - sceneName;
+ offset = slash - pkeSettings.rt.sceneName;
}
- ImGui::Text("%s", sceneName + offset);
+ ImGui::Text("%s", pkeSettings.rt.sceneName + offset);
}
ImGui::EndDisabled();
if (ImGui::MenuItem("Save As...")) {
@@ -581,13 +568,14 @@ void RecordImGuiCameras() {
cam.target = ActiveCamera->target;
cam.type = ActiveCamera->type;
cam.orientation = ActiveCamera->orientation;
+ cam.isPrimary = false;
}
static ImGuiTableFlags tableFlags{
ImGuiTableFlags_Borders |
ImGuiTableFlags_RowBg
};
- if (ImGui::BeginTable("Entities", 8, tableFlags)) {
+ if (ImGui::BeginTable("Entities", 9, tableFlags)) {
ImGui::TableSetupColumn("Interact");
ImGui::TableSetupColumn("CameraHandle");
ImGui::TableSetupColumn("Pos");
@@ -596,6 +584,7 @@ void RecordImGuiCameras() {
ImGui::TableSetupColumn("Type");
ImGui::TableSetupColumn("Orientation");
ImGui::TableSetupColumn("Stale");
+ ImGui::TableSetupColumn("IsPrimary");
ImGui::TableHeadersRow();
int64_t cameraBucketCount = PkeCamera_GetBucketCount();
@@ -631,6 +620,8 @@ void RecordImGuiCameras() {
ImGui::Text("%hhu", cam.orientation);
ImGui::TableSetColumnIndex(7);
ImGui::Text("%hhu", cam.stale);
+ ImGui::TableSetColumnIndex(8);
+ ImGui::Text("%i", cam.isPrimary);
ImGui::PopID();
}
ImGui::PopID();
@@ -961,8 +952,9 @@ void BuildDirRecursive(const std::filesystem::directory_entry &de, fsEntry *dirF
void BuildProjectMenuRecursive(fsEntry &entry) {
if (entry.type == 1) {
if (ImGui::Selectable(entry.name, false, ImGuiSelectableFlags_AllowDoubleClick) && ImGui::IsMouseDoubleClicked(0)) {
- sceneName = entry.name;
- shouldLoadScene = true;
+ pkeSettings.rt.sceneName = entry.name;
+ pkeSettings.rt.shouldLoadScene = true;
+ ActiveCamera = &NullCamera;
}
} else if (entry.type == 0) {
if (ImGui::TreeNode(entry.name)) {