From 75bd822935be06d8e0e9a53493e5d28382f2fa41 Mon Sep 17 00:00:00 2001 From: OusmBlueNinja <89956790+OusmBlueNinja@users.noreply.github.com> Date: Sat, 10 May 2025 15:18:21 -0500 Subject: [PATCH] Added Scene Saving to Project --- imgui.ini | 36 +++++----- remake/build.log | 3 +- src/src/Engine.cpp | 29 +++++--- src/src/core/functions/ProjectManager.cpp | 86 +++++++++-------------- 4 files changed, 72 insertions(+), 82 deletions(-) diff --git a/imgui.ini b/imgui.ini index 94954b8..92b3ede 100644 --- a/imgui.ini +++ b/imgui.ini @@ -10,24 +10,24 @@ Collapsed=1 [Window][WindowOverViewport_11111111] Pos=0,19 -Size=1280,701 +Size=1920,1158 Collapsed=0 [Window][Inspector] -Pos=913,19 -Size=367,163 +Pos=1553,19 +Size=367,537 Collapsed=0 DockId=0x0000001B,0 [Window][Scene Tree] Pos=0,19 -Size=341,268 +Size=341,444 Collapsed=0 DockId=0x0000000F,0 [Window][Viewport] Pos=343,19 -Size=568,202 +Size=1208,659 Collapsed=0 DockId=0x00000017,0 @@ -36,14 +36,14 @@ Size=1280,19 Collapsed=0 [Window][Performance Info] -Pos=1107,223 -Size=173,268 +Pos=1628,680 +Size=292,268 Collapsed=0 DockId=0x00000019,0 [Window][Console] -Pos=343,223 -Size=716,497 +Pos=343,680 +Size=1206,497 Collapsed=0 DockId=0x00000013,0 @@ -78,8 +78,8 @@ Collapsed=0 DockId=0x00000015,1 [Window][Color Correction] -Pos=1107,493 -Size=173,227 +Pos=1628,950 +Size=292,227 Collapsed=0 DockId=0x0000001A,0 @@ -113,8 +113,8 @@ Collapsed=0 DockId=0x0000000E,0 [Window][Audio Output] -Pos=1061,223 -Size=44,497 +Pos=1551,680 +Size=75,497 Collapsed=0 DockId=0x00000012,0 @@ -125,8 +125,8 @@ Collapsed=0 DockId=0x0000000D,0 [Window][Resources] -Pos=0,289 -Size=341,431 +Pos=0,465 +Size=341,712 Collapsed=0 DockId=0x00000010,0 @@ -136,8 +136,8 @@ Size=550,695 Collapsed=0 [Window][Lua Globals] -Pos=913,184 -Size=367,37 +Pos=1553,558 +Size=367,120 Collapsed=0 DockId=0x0000001C,0 @@ -181,7 +181,7 @@ Column 1 Width=86 Column 2 Weight=1.0000 [Docking][Data] -DockSpace ID=0x11111111 Window=0x1BBC0F80 Pos=0,19 Size=1280,701 Split=X +DockSpace ID=0x11111111 Window=0x1BBC0F80 Pos=0,19 Size=1920,1158 Split=X DockNode ID=0x00000005 Parent=0x11111111 SizeRef=989,1158 Split=X DockNode ID=0x00000001 Parent=0x00000005 SizeRef=341,701 Split=Y Selected=0x12EF0F59 DockNode ID=0x00000003 Parent=0x00000001 SizeRef=342,637 Split=Y Selected=0x12EF0F59 diff --git a/remake/build.log b/remake/build.log index ae69871..12a85b0 100644 --- a/remake/build.log +++ b/remake/build.log @@ -1,3 +1,2 @@ -[COMPILE] g++ -std=c++20 -Wall -g -DGLM_ENABLE_EXPERIMENTAL -O2 -static -static-libstdc++ -static-libgcc -Isrc/include -Isrc/include/lua -Isrc/vendor -Isrc/vendor/imgui -Isrc/vendor/box2d -Isrc/vendor/xxhash -Isrc/vendor/miniaudio -Isrc/vendor/imguizmo -IC:/msys64/mingw64/include -IC:\msys64\mingw64\lib\libyaml-cpp.a -Isrc\vendor\imgui -MMD -MP -c src\src\core\audio\AudioEngine.cpp -o src\build\core\audio\AudioEngine.o +[COMPILE] g++ -std=c++20 -Wall -g -DGLM_ENABLE_EXPERIMENTAL -O2 -static -static-libstdc++ -static-libgcc -Isrc/include -Isrc/include/lua -Isrc/vendor -Isrc/vendor/imgui -Isrc/vendor/box2d -Isrc/vendor/xxhash -Isrc/vendor/miniaudio -Isrc/vendor/imguizmo -IC:/msys64/mingw64/include -Isrc\vendor\imgui -IC:\msys64\mingw64\lib\libyaml-cpp.a -MMD -MP -c src\src\core\functions\ProjectManager.cpp -o src\build\core\functions\ProjectManager.o [LINK] g++ src\build\Engine.o src\build\main.o src\build\Renderer.o src\build\Components\AnimationComponent.o src\build\Components\AudioPlayerComponent.o src\build\Components\CameraComponent.o src\build\Components\LightComponent.o src\build\Components\ParticleComponent.o src\build\Components\PathFollowerComponent.o src\build\Components\PhysicsComponent.o src\build\Components\ScriptComponent.o src\build\Components\SpriteComponent.o src\build\Components\TextComonent.o src\build\Components\TilemapComponent.o src\build\core\audio\AudioEngine.o src\build\core\functions\Prefab.o src\build\core\functions\ProjectManager.o src\build\core\functions\ScenePacker.o src\build\core\functions\SceneSerializer.o src\build\core\scripts\LuaGlobalBridge.o src\build\core\scripts\ScriptCore.o src\build\core\utils\AssetManager.o src\build\core\utils\EngineConfig.o src\build\core\utils\ExceptionHandler.o src\build\core\utils\FileDialog.o src\build\core\utils\input.o src\build\core\utils\LoadingWindow.o src\build\core\utils\Logging.o src\build\core\utils\Popup.o src\build\core\utils\Profiler.o src\build\core\utils\Texture.o src\build\core\utils\utils.o src\build\editor\utils\Themes.o src\build\editor\windows\AssetBrowser.o src\build\editor\windows\AudioInfo.o src\build\editor\windows\Inspector.o src\build\editor\windows\LuaGlobals.o src\build\editor\windows\SceneTree.o src\build\Entitys\Object.o src\build\utils\GameObjectsList.o src\build\utils\Shader.o src\build\utils\UID.o src\build\lapi.o src\build\lauxlib.o src\build\lbaselib.o src\build\lcode.o src\build\lcorolib.o src\build\lctype.o src\build\ldblib.o src\build\ldebug.o src\build\ldo.o src\build\ldump.o src\build\lfunc.o src\build\lgc.o src\build\linit.o src\build\liolib.o src\build\llex.o src\build\lmathlib.o src\build\lmem.o src\build\loadlib.o src\build\lobject.o src\build\lopcodes.o src\build\loslib.o src\build\lparser.o src\build\lstate.o src\build\lstring.o src\build\lstrlib.o src\build\ltable.o src\build\ltablib.o src\build\ltm.o src\build\lua.o src\build\luac.o src\build\lundump.o src\build\lutf8lib.o src\build\lvm.o src\build\lzio.o src\build\imgui.o src\build\imgui_demo.o src\build\imgui_draw.o src\build\imgui_impl_glfw.o src\build\imgui_impl_opengl3.o src\build\imgui_tables.o src\build\imgui_widgets.o src\build\aabb.o src\build\arena_allocator.o src\build\array.o src\build\bitset.o src\build\body.o src\build\broad_phase.o src\build\constraint_graph.o src\build\contact.o src\build\contact_solver.o src\build\core.o src\build\distance.o src\build\distance_joint.o src\build\dynamic_tree.o src\build\geometry.o src\build\hull.o src\build\id_pool.o src\build\island.o src\build\joint.o src\build\manifold.o src\build\math_functions.o src\build\motor_joint.o src\build\mouse_joint.o src\build\mover.o src\build\prismatic_joint.o src\build\revolute_joint.o src\build\sensor.o src\build\shape.o src\build\solver.o src\build\solver_set.o src\build\table.o src\build\timer.o src\build\types.o src\build\weld_joint.o src\build\wheel_joint.o src\build\world.o src\build\xxhash.o src\build\miniaudio.o src\build\ImGuizmo.o -o src\build\app.exe -LC:\msys64\mingw64\lib -lglfw3 -lglew32 -lopengl32 -lgdi32 -lyaml-cpp -lcomdlg32 -lssl -lcrypto -ldbghelp -lz -lfreetype -[ERROR] Interrupted by user. diff --git a/src/src/Engine.cpp b/src/src/Engine.cpp index 6d88530..5686022 100644 --- a/src/src/Engine.cpp +++ b/src/src/Engine.cpp @@ -20,12 +20,10 @@ #include "core/utils/EngineConfig.h" - #include "core/functions/Prefab.h" #include "core/functions/ProjectManager.h" #include "core/functions/SceneSerializer.h" - #include "utils/GameObjectsList.h" #include "core/utils/Profiler.h" #include "core/utils/utils.h" @@ -726,13 +724,19 @@ void Engine::Run() if (ImGui::BeginMenu("File")) { - if (ImGui::MenuItem("Save Scene")) + if (ImGui::MenuItem("Save Scene to Project")) + { + std::string path = ProjectManager::GetCurrentAssetsPath() + "/Scenes/" + + ProjectManager::GetCurrentProjectName() + ".cene"; + SceneLoader::SaveScene(path); + } + if (ImGui::MenuItem("Save Scene As")) { std::string file = CreateFileDialog(FileDialogType::Scenes); if (!file.empty()) SceneLoader::SaveScene(file); - selected = nullptr; } + if (ImGui::MenuItem("Load Scene")) { std::string file = OpenFileDialog(FileDialogType::Scenes); @@ -871,7 +875,18 @@ void Engine::Run() ImGui::Text("%s", selected->GetName().c_str()); ImGui::Separator(); - if (ImGui::Button("Delete")) + bool confirm = false; + bool cancel = false; + + if (ImGui::IsWindowFocused(ImGuiFocusedFlags_RootAndChildWindows)) + { + if (ImGui::IsKeyPressed(ImGuiKey_Escape)) + cancel = true; + if (ImGui::IsKeyPressed(ImGuiKey_Enter)) + confirm = true; + } + + if (ImGui::Button("Delete") || confirm) { pendingDeletion.push_back(selected); selected = nullptr; @@ -880,7 +895,7 @@ void Engine::Run() ImGui::SameLine(); - if (ImGui::Button("Cancel")) + if (ImGui::Button("Cancel") || cancel) { ImGui::CloseCurrentPopup(); } @@ -1590,8 +1605,6 @@ void Engine::Run() } } - - void Engine::SaveState() { YAML::Emitter out; diff --git a/src/src/core/functions/ProjectManager.cpp b/src/src/core/functions/ProjectManager.cpp index bc609ff..a42d7dc 100644 --- a/src/src/core/functions/ProjectManager.cpp +++ b/src/src/core/functions/ProjectManager.cpp @@ -6,7 +6,6 @@ #include "../../Engine.h" #include "SceneSerializer.h" - #include #include #include @@ -18,9 +17,7 @@ std::string ProjectManager::s_currentProjectPath; std::string ProjectManager::s_currentProjectName; std::string ProjectManager::s_defaultScene; - - -bool CreateDirectories(const fs::path& baseDir) +bool CreateDirectories(const fs::path &baseDir) { static const std::vector subdirs = { "Prefabs", @@ -31,14 +28,14 @@ bool CreateDirectories(const fs::path& baseDir) "Shaders", "Scripts", "Videos", - + }; std::error_code ec; bool allOk = true; fs::path assetsRoot = baseDir / "Assets"; - for (const auto& name : subdirs) + for (const auto &name : subdirs) { Logger::LogVerbose("Creating Folder: '%s'", name.c_str()); fs::create_directories(assetsRoot / name, ec); @@ -54,9 +51,9 @@ bool CreateDirectories(const fs::path& baseDir) return allOk; } -std::string ProjectManager::ResolveResPath(const std::string& resPath) +std::string ProjectManager::ResolveResPath(const std::string &resPath) { - constexpr const char* prefix = "res://"; + constexpr const char *prefix = "res://"; if (resPath.rfind(prefix, 0) != 0) return resPath; @@ -73,10 +70,6 @@ std::string ProjectManager::ResolveResPath(const std::string& resPath) return fullPath.lexically_normal().string(); } - - - - bool ProjectManager::Init() { s_currentProjectPath.clear(); @@ -86,10 +79,10 @@ bool ProjectManager::Init() return true; } -bool ProjectManager::LoadProject(const std::string& projectPath, - const std::string& projectName) +bool ProjectManager::LoadProject(const std::string &projectPath, + const std::string &projectName) { - fs::path baseDir = fs::path(projectPath) / projectName; + fs::path baseDir = fs::path(projectPath) / projectName; fs::path projFile = baseDir / (projectName + ".cproj"); if (!fs::exists(projFile)) @@ -100,35 +93,32 @@ bool ProjectManager::LoadProject(const std::string& projectPath, } YAML::Node config; - try { + try + { config = YAML::LoadFile(projFile.string()); } - catch (const YAML::Exception& e) { + catch (const YAML::Exception &e) + { Logger::LogError("Failed to parse project file '%s': %s", projFile.string().c_str(), e.what()); return false; } - std::string savedName = config["Name"].as(projectName); + std::string savedName = config["Name"].as(projectName); std::string createdDate = config["CreatedDate"].as("unknown"); std::string s_defaultScene = config["s_defaultScene"].as("s_defaultScene"); + Logger::LogInfo("Loading Project: '%s", savedName.c_str()); s_currentProjectPath = projectPath; s_currentProjectName = savedName; - - - - - - std::string resScenePath = config["s_defaultScene"].as(""); if (!resScenePath.empty()) { - s_defaultScene = ResolveResPath(resScenePath); - Logger::LogInfo("Loading Scene: %s", s_defaultScene.c_str()); + s_defaultScene = ResolveResPath(resScenePath); + Logger::LogDebug("Loading Scene: %s", s_defaultScene.c_str()); if (!std::filesystem::exists(s_defaultScene)) { @@ -136,27 +126,20 @@ bool ProjectManager::LoadProject(const std::string& projectPath, return false; } - SceneLoader::LoadScene(s_defaultScene); + SceneLoader::LoadScene(s_defaultScene); } - - - Logger::LogInfo("Loaded project '%s' at '%s' (created %s)", - savedName.c_str(), - projectPath.c_str(), - createdDate.c_str()); - - + Logger::LogInfo("Loaded project '%s'", savedName.c_str()); CreateDirectories(baseDir); return true; } -bool ProjectManager::SaveProject(const std::string& projectPath, - const std::string& projectName) +bool ProjectManager::SaveProject(const std::string &projectPath, + const std::string &projectName) { - fs::path baseDir = fs::path(projectPath) / projectName; + fs::path baseDir = fs::path(projectPath) / projectName; fs::path projFile = baseDir / (projectName + ".cproj"); std::error_code ec; @@ -169,22 +152,20 @@ bool ProjectManager::SaveProject(const std::string& projectPath, YAML::Emitter out; out << YAML::BeginMap; - out << YAML::Key << "Name" << YAML::Value << projectName; + out << YAML::Key << "Name" << YAML::Value << projectName; out << YAML::Key << "EngineVersion" << YAML::Value << g_engineConfig.version; fs::path relPath = fs::relative(s_defaultScene, - fs::path(s_currentProjectPath) / s_currentProjectName); -out << YAML::Key << "s_defaultScene" << YAML::Value << ("res://" + relPath.generic_string()); - - + fs::path(s_currentProjectPath) / s_currentProjectName); + out << YAML::Key << "s_defaultScene" << YAML::Value << ("res://" + relPath.generic_string()); auto now = std::chrono::system_clock::now(); - auto t = std::chrono::system_clock::to_time_t(now); + auto t = std::chrono::system_clock::to_time_t(now); std::tm tm{}; - #if defined(_WIN32) +#if defined(_WIN32) gmtime_s(&tm, &t); - #else +#else gmtime_r(&t, &tm); - #endif +#endif char buf[32]; std::strftime(buf, sizeof(buf), "%Y-%m-%dT%H:%M:%SZ", &tm); out << YAML::Key << "CreatedDate" << YAML::Value << buf; @@ -205,28 +186,25 @@ out << YAML::Key << "s_defaultScene" << YAML::Value << ("res://" + relPath.gener CreateDirectories(baseDir); - s_currentProjectPath = projectPath; s_currentProjectName = projectName; return true; } -const std::string& ProjectManager::GetCurrentProjectPath() +const std::string &ProjectManager::GetCurrentProjectPath() { return s_currentProjectPath; } -const std::string& ProjectManager::GetCurrentProjectName() +const std::string &ProjectManager::GetCurrentProjectName() { return s_currentProjectName; } -const std::string& ProjectManager::GetCurrentAssetsPath() +const std::string &ProjectManager::GetCurrentAssetsPath() { static std::string assetsPath; - fs::path p = fs::path(s_currentProjectPath) - / s_currentProjectName - / "Assets"; + fs::path p = fs::path(s_currentProjectPath) / s_currentProjectName / "Assets"; assetsPath = p.string(); return assetsPath; }