Working In Project System

This commit is contained in:
OusmBlueNinja 2025-05-10 13:11:50 -05:00
parent 137d8e86f7
commit ea372550fe
10 changed files with 1012 additions and 848 deletions

View File

@ -10,24 +10,24 @@ Collapsed=1
[Window][WindowOverViewport_11111111]
Pos=0,19
Size=1920,1158
Size=1280,701
Collapsed=0
[Window][Inspector]
Pos=1553,19
Size=367,537
Pos=913,19
Size=367,163
Collapsed=0
DockId=0x0000001B,0
[Window][Scene Tree]
Pos=0,19
Size=341,444
Size=341,268
Collapsed=0
DockId=0x0000000F,0
[Window][Viewport]
Pos=343,19
Size=1208,659
Size=568,202
Collapsed=0
DockId=0x00000017,0
@ -36,14 +36,14 @@ Size=1280,19
Collapsed=0
[Window][Performance Info]
Pos=1628,680
Size=292,268
Pos=1107,223
Size=173,268
Collapsed=0
DockId=0x00000019,0
[Window][Console]
Pos=343,680
Size=1232,497
Pos=343,223
Size=731,497
Collapsed=0
DockId=0x00000013,0
@ -78,8 +78,8 @@ Collapsed=0
DockId=0x00000015,1
[Window][Color Correction]
Pos=1628,950
Size=292,227
Pos=1107,493
Size=173,227
Collapsed=0
DockId=0x0000001A,0
@ -113,8 +113,8 @@ Collapsed=0
DockId=0x0000000E,0
[Window][Audio Output]
Pos=1577,680
Size=49,497
Pos=1076,223
Size=29,497
Collapsed=0
DockId=0x00000012,0
@ -125,8 +125,8 @@ Collapsed=0
DockId=0x0000000D,0
[Window][Resources]
Pos=0,465
Size=341,712
Pos=0,289
Size=341,431
Collapsed=0
DockId=0x00000010,0
@ -136,8 +136,8 @@ Size=550,695
Collapsed=0
[Window][Lua Globals]
Pos=1553,558
Size=367,120
Pos=913,184
Size=367,37
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=1920,1158 Split=X
DockSpace ID=0x11111111 Window=0x1BBC0F80 Pos=0,19 Size=1280,701 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

View File

@ -0,0 +1,4 @@
[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\editor\windows\SceneTree.cpp -o src\build\editor\windows\SceneTree.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\Prefab.cpp -o src\build\core\functions\Prefab.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\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
[RUN] Executed app.exe successfully.

File diff suppressed because it is too large Load Diff

View File

@ -901,6 +901,8 @@ static int Lua_KeyDown(lua_State *L)
return 1;
}
static core::types::Vec3 GetLuaVector3(lua_State *L, int index)
{
if (luaL_testudata(L, index, LUA_VECTOR3_MT))

View File

@ -523,19 +523,16 @@ void Engine::Init()
Renderer::Init();
Logger::LogVerbose("Init Sound Core");
AudioEngine::Init();
Logger::LogVerbose("Init Input Core");
Input::Init(window);
Logger::LogVerbose("Init ProjectManager");
Logger::LogVerbose("Init Project Core");
ProjectManager::Init();
Logger::LogVerbose("Init Script Core");
ScriptCore::Init();
Logger::LogVerbose("Resverving Objects");
// These values were AI Generated.
m_toDraw.reserve(2048); // ~2K sprites per frame (including UI, particles, objects)
@ -545,13 +542,13 @@ void Engine::Init()
m_animationsUpdates.reserve(512); // ~500 animated objects (characters, FX, etc.)
m_PathUpdates.reserve(16);
auto obj = std::make_shared<Object>("Hello, Create");
objects.push_back(obj);
selected = obj;
Logger::LogOk("Engine Core");
ProjectManager::CreateProject("C:/Users/spenc/OneDrive/Desktop", "TestProject");
}
core::types::Vec2 ScreenToWorld(const core::types::Vec2 &screenPos, const core::types::Vec2 &viewportSize, const core::types::Vec2 &cameraPos, float zoom)
@ -733,7 +730,6 @@ void Engine::Run()
SaveScene(file);
selected = nullptr;
}
if (ImGui::MenuItem("Load Scene"))
{
std::string file = OpenFileDialog(FileDialogType::Scenes);
@ -742,12 +738,9 @@ void Engine::Run()
LoadScene(file);
selected = nullptr;
}
ImGui::Separator();
if (ImGui::MenuItem("Clear Scene"))
ImGui::OpenPopup("ConfirmClearScene");
ImGui::EndMenu();
}
@ -759,7 +752,8 @@ void Engine::Run()
ImGui::Checkbox("Enable Gizmos", &g_engineConfig.settings.draw_gizmos);
if (ImGui::BeginMenu("Defaults"))
{
ImGui::Checkbox("Prompt Outdated Scenes", &g_engineConfig.settings.ignore_invalid_versions_popups);
ImGui::Checkbox("Prompt Outdated Scenes",
&g_engineConfig.settings.ignore_invalid_versions_popups);
ImGui::EndMenu();
}
if (ImGui::BeginMenu("Profiling"))
@ -779,8 +773,6 @@ void Engine::Run()
#else
ImGui::Checkbox("Deep Profiling", &g_engineConfig.settings.profile_deep);
#endif
// ImGui::Checkbox("GPU Profiling", &g_engineConfig.settings.profile_gpu);
}
ImGui::EndMenu();
}
@ -795,22 +787,56 @@ void Engine::Run()
ImGui::Checkbox("Performance Info", &g_engineConfig.settings.show_performance_window);
ImGui::Checkbox("Audio Viewer", &g_engineConfig.settings.show_audio_window);
ImGui::Checkbox("Lua Globals Viewer", &g_engineConfig.settings.show_lua_globals_window);
ImGui::EndMenu();
}
ImGui::EndMenu();
}
const char *version_fmt = "Create Engine v%s";
char buf[64];
std::snprintf(buf, sizeof(buf), version_fmt, g_engineConfig.version.c_str());
{
ImGuiStyle &style = ImGui::GetStyle();
float barW = ImGui::GetWindowSize().x;
float lh = ImGui::GetTextLineHeightWithSpacing();
float padX = style.FramePadding.x;
float padY = style.FramePadding.y;
float textWidth = ImGui::CalcTextSize(buf).x;
float avail = ImGui::GetWindowSize().x - ImGui::GetCursorPosX();
ImGuiStyle &style = ImGui::GetStyle();
ImGui::SameLine(avail - textWidth - style.FramePadding.x);
ImGui::TextUnformatted(buf);
float gap = style.ItemSpacing.x * 9.0f;
const std::string &proj = ProjectManager::GetCurrentProjectName();
char versionBuf[64];
std::snprintf(versionBuf, sizeof(versionBuf),
"Create Engine v%s",
g_engineConfig.version.c_str());
float projW = proj.empty() ? 0.0f : ImGui::CalcTextSize(proj.c_str()).x;
float versionW = ImGui::CalcTextSize(versionBuf).x;
float totalW = (projW > 0.0f ? projW + padX * 2.0f : 0.0f) + (projW > 0.0f ? gap : 0.0f) + versionW + style.WindowPadding.x;
float startX = barW - totalW;
ImGui::SameLine(startX);
if (!proj.empty())
{
ImVec2 pos = ImGui::GetCursorScreenPos();
ImVec2 size = {projW + padX * 2.0f, lh + padY * 2.0f};
ImGui::GetWindowDrawList()->AddRectFilled(
pos,
{pos.x + size.x, pos.y + size.y},
ImGui::GetColorU32(ImGuiCol_Header));
ImGui::PushStyleColor(ImGuiCol_Text, ImGui::GetColorU32(ImGuiCol_Text));
ImGui::SetCursorScreenPos({pos.x + padX, pos.y + padY});
ImGui::TextUnformatted(proj.c_str());
ImGui::PopStyleColor();
ImGui::SetCursorScreenPos({pos.x + size.x + gap, pos.y + padY});
}
// draw version
ImGui::TextUnformatted(versionBuf);
}
ImGui::EndMainMenuBar();
}

View File

@ -1,8 +1,9 @@
#include "Prefab.h"
#include "ProjectManager.h"
#include "../utils/Logging.h"
#include "../utils/utils.h"
#include "../../Entitys/Object.h"
#include "../../core/utils/AssetManager.h"
#include "../../core/utils/utils.h"
#include "../../Entitys/Object.h"
#include <yaml-cpp/yaml.h>
#include <fstream>
@ -12,61 +13,67 @@
#include <sstream>
namespace fs = std::filesystem;
std::string Prefab::CreatePrefab(const std::shared_ptr<Object>& obj)
{
if (!obj)
return "";
// Clean filename
// sanitize the prefab filename
std::string filename = obj->GetName().empty() ? "Unnamed" : obj->GetName();
for (auto& ch : filename)
if (ch == '/' || ch == '\\' || ch == ':' || ch == '*' || ch == '?' || ch == '\"' || ch == '<' || ch == '>' || ch == '|')
if (ch == '/' || ch == '\\' || ch == ':' || ch == '*' || ch == '?' ||
ch == '\"' || ch == '<' || ch == '>' || ch == '|')
ch = '_';
std::string path = "C:/Users/spenc/OneDrive/Desktop/" + filename + ".cpfb";
// build path: <projectRoot>/<projectName>/asset/Prefabs
fs::path prefabDir =
fs::path(ProjectManager::GetCurrentAssetsPath()) / "Prefabs";
std::error_code ec;
fs::create_directories(prefabDir, ec);
if (ec)
Logger::LogError("[Prefab] Could not create prefab directory '%s': %s",
prefabDir.string().c_str(), ec.message().c_str());
fs::path fullPath = prefabDir / (filename + ".cpfb");
// Serialize Object to string
YAML::Emitter objectOut;
objectOut.SetIndent(2);
obj->Save(objectOut);
// Parse the object YAML string back into a real node
YAML::Node objectNode;
try {
objectNode = YAML::Load(objectOut.c_str());
} catch (const YAML::Exception& e) {
Logger::LogError("[Prefab] Failed to parse object YAML for prefab: %s", e.what());
Logger::LogError("[Prefab] Failed to parse object YAML: %s", e.what());
return "";
}
// Write the outer asset structure
YAML::Emitter out;
out.SetIndent(2);
out << YAML::BeginMap;
out << YAML::Key << "uaid" << YAML::Value << AssetManager::GenerateUAID();
out << YAML::Key << "filename" << YAML::Value << filename + ".cpfb";
out << YAML::Key << "filetype" << YAML::Value << "cpfb";
out << YAML::Key << "type" << YAML::Value << "Prefab";
out << YAML::Key << "prefabName" << YAML::Value << obj->GetName();
out << YAML::Key << "hash" << YAML::Value << "";
out << YAML::Key << "lastModified" << YAML::Value << GetFileLastWrite(path);
out << YAML::Key << "prefabYAML" << YAML::Value << objectNode;
out << YAML::Key << "uaid" << YAML::Value << AssetManager::GenerateUAID();
out << YAML::Key << "filename" << YAML::Value << (filename + ".cpfb");
out << YAML::Key << "filetype" << YAML::Value << "cpfb";
out << YAML::Key << "type" << YAML::Value << "Prefab";
out << YAML::Key << "prefabName" << YAML::Value << obj->GetName();
out << YAML::Key << "hash" << YAML::Value << "";
out << YAML::Key << "lastModified" << YAML::Value << GetFileLastWrite(fullPath.string());
out << YAML::Key << "prefabYAML" << YAML::Value << objectNode;
out << YAML::EndMap;
std::ofstream file(path);
if (file.is_open())
{
file << out.c_str();
file.close();
Logger::LogInfo("[Prefab] Saved prefab: %s", path.c_str());
}
else
{
Logger::LogError("[Prefab] Failed to write prefab file: %s (%s)", path.c_str(), std::strerror(errno));
// write out the file
std::ofstream file(fullPath);
if (!file.is_open()) {
Logger::LogError("[Prefab] Failed to write prefab file: %s",
fullPath.string().c_str());
return "";
}
file << out.c_str();
file.close();
return path;
Logger::LogInfo("Saved prefab to Project ");
return fullPath.string();
}

View File

@ -1,23 +1,135 @@
// ProjectManager.cpp
#include "ProjectManager.h"
#include "../../core/types/all.h"
#include "../../core/utils/AssetManager.h"
#include "../../core/utils/EngineConfig.h"
#include "../../core/utils/Logging.h"
#include "../../core/utils/AssetManager.h"
#include <yaml-cpp/yaml.h>
#include <fstream>
#include <chrono>
std::vector<AssetInfo> ProjectManager::m_resources;
namespace fs = std::filesystem;
std::string ProjectManager::s_currentProjectPath;
std::string ProjectManager::s_currentProjectName;
bool ProjectManager::Init()
{
m_resources.clear();
Logger::LogOk("Project Core");
s_currentProjectPath.clear();
s_currentProjectName.clear();
Logger::LogOk("Project Core initialized");
return true;
}
bool ProjectManager::SaveResource()
{
//Todo: Implement this
Logger::LogWarning("Not Implemented (#21)");
return false;
}
}
bool ProjectManager::CreateProject(const std::string &projectPath,
const std::string &projectName)
{
fs::path baseDir = fs::path(projectPath) / projectName;
fs::path projFile = baseDir / (projectName + ".cproj");
std::error_code ec;
if (fs::exists(projFile))
{
YAML::Node config;
try
{
config = YAML::LoadFile(projFile.string());
}
catch (const YAML::Exception &e)
{
Logger::LogError("Failed to parse existing project file '%s': %s",
projFile.string().c_str(), e.what());
return false;
}
std::string savedName = config["Name"].as<std::string>(projectName);
std::string createdDate = config["CreatedDate"].as<std::string>("unknown");
Logger::LogInfo("Loaded project '%s' at '%s' (created %s)",
savedName.c_str(),
projectPath.c_str(),
createdDate.c_str());
s_currentProjectPath = projectPath;
s_currentProjectName = savedName;
fs::create_directories(baseDir / "asset" / "Prefabs", ec);
if (ec)
Logger::LogError("Could not ensure Prefabs dir: %s",
ec.message().c_str());
return true;
}
if (!fs::create_directories(baseDir, ec) && ec)
{
Logger::LogError("Failed to create project directory '%s': %s",
projectPath.c_str(), ec.message().c_str());
return false;
}
YAML::Emitter out;
out << YAML::BeginMap;
out << YAML::Key << "Name" << YAML::Value << projectName;
out << YAML::Key << "EngineVersion" << YAML::Value << g_engineConfig.version;
auto now = std::chrono::system_clock::now();
auto t = std::chrono::system_clock::to_time_t(now);
std::tm tm{};
#if defined(_WIN32)
gmtime_s(&tm, &t);
#else
gmtime_r(&t, &tm);
#endif
char buf[32];
std::strftime(buf, sizeof(buf), "%Y-%m-%dT%H:%M:%SZ", &tm);
out << YAML::Key << "CreatedDate" << YAML::Value << buf;
out << YAML::EndMap;
std::ofstream fout(projFile);
if (!fout.is_open())
{
Logger::LogError("Could not open project file for writing: %s",
projFile.string().c_str());
return false;
}
fout << out.c_str();
fout.close();
Logger::LogOk("Created new project '%s' at '%s'",
projectName.c_str(), projectPath.c_str());
fs::create_directories(baseDir / "asset" / "Prefabs", ec);
if (ec)
Logger::LogError("Could not create Prefabs dir: %s",
ec.message().c_str());
s_currentProjectPath = projectPath;
s_currentProjectName = projectName;
return true;
}
const std::string &ProjectManager::GetCurrentProjectPath()
{
return s_currentProjectPath;
}
const std::string &ProjectManager::GetCurrentProjectName()
{
return s_currentProjectName;
}
const std::string &ProjectManager::GetCurrentAssetsPath()
{
static std::string assetsPath;
// <projectPath>/<projectName>/Assets
fs::path p = fs::path(s_currentProjectPath) / s_currentProjectName / "Assets";
assetsPath = p.string();
return assetsPath;
}

View File

@ -1,15 +1,29 @@
// ProjectManager.h
#pragma once
#include <string>
#include <vector>
class AssetInfo;
#include <filesystem>
#include "../../core/types/all.h"
class ProjectManager
{
public:
static bool Init();
static bool SaveResource();
static bool CreateProject(const std::string& projectPath,
const std::string& projectName);
static const std::string& GetCurrentProjectPath();
static const std::string& GetCurrentProjectName();
static const std::string& GetCurrentAssetsPath();
private:
static std::vector<AssetInfo> m_resources;
};
static std::string s_currentProjectPath;
static std::string s_currentProjectName;
};

View File

@ -20,6 +20,7 @@ public:
static void CallAllInits();
static void CallAllUpdates(float dt);
// New features:
static void ReloadAllScripts();
static void PrintScriptDiagnostics();

View File

@ -63,10 +63,8 @@ void DrawObjectNode(const std::shared_ptr<Object> &obj)
if (ImGui::MenuItem("Convert to Prefab"))
{
std::string path = Prefab::CreatePrefab(obj);
if (!path.empty())
Logger::LogInfo("[Prefab] Saved prefab to: %s", path.c_str());
else
Logger::LogError("[Prefab] Failed to create prefab.");
if (path.empty())
Logger::LogError("Failed to create prefab.");
}
ImGui::EndPopup();