From e14a2f18d9b164803d607fbf588bd0b8c5591ee2 Mon Sep 17 00:00:00 2001 From: Antoine Pilote Date: Wed, 19 May 2021 21:16:30 -0400 Subject: [PATCH] Serialization project and scene --- Editor/Editor.cpp | 34 ++- Editor/src/EditorInterface.cpp | 251 +++++++++++++----- Editor/src/EditorInterface.h | 2 + Nuake/Engine.cpp | 27 +- Nuake/Engine.h | 4 +- Nuake/src/Core/FileSystem.cpp | 44 ++- Nuake/src/Core/FileSystem.h | 8 +- Nuake/src/Core/Input.h | 2 +- Nuake/src/Core/MaterialManager.h | 2 +- Nuake/src/Core/Physics/BulletDebugDrawer.cpp | 6 +- Nuake/src/Core/Physics/PhysicsShapes.h | 6 +- Nuake/src/Core/TextureManager.h | 2 +- Nuake/src/Core/Timestep.h | 2 +- Nuake/src/Rendering/Camera.cpp | 8 + Nuake/src/Rendering/Camera.h | 4 +- Nuake/src/Rendering/ImGuiAPI.h | 2 +- Nuake/src/Rendering/Mesh/Mesh.h | 2 +- Nuake/src/Rendering/ProceduralSky.h | 12 +- Nuake/src/Rendering/Textures/Material.h | 2 +- Nuake/src/Rendering/Textures/Texture.h | 2 +- Nuake/src/Resource/TrenchbroomMap.h | 18 +- .../Entities/Components/CameraComponent.cpp | 2 - .../Entities/Components/CameraComponent.h | 7 + .../Entities/Components/LightComponent.h | 7 +- .../Scene/Entities/Components/MeshComponent.h | 2 +- .../Entities/Components/ModelComponent.h | 2 +- .../Scene/Entities/Components/NameComponent.h | 7 + .../Entities/Components/ParentComponent.h | 6 + .../Scene/Entities/Components/QuakeMap.cpp | 8 +- .../src/Scene/Entities/Components/QuakeMap.h | 10 +- .../Entities/Components/RigidbodyComponent.h | 4 +- .../Entities/Components/TransformComponent.h | 13 +- Nuake/src/Scene/Entities/Entity.cpp | 14 +- Nuake/src/Scene/Entities/Entity.h | 2 +- Nuake/src/Scene/Entities/ScriptableEntity.h | 8 - Nuake/src/Scene/Scene.cpp | 80 ++++-- Nuake/src/Scene/Scene.h | 4 +- Nuake/src/Window.h | 4 +- premake5.lua | 38 ++- 39 files changed, 479 insertions(+), 179 deletions(-) diff --git a/Editor/Editor.cpp b/Editor/Editor.cpp index 50b147a4..fbbfbffb 100644 --- a/Editor/Editor.cpp +++ b/Editor/Editor.cpp @@ -12,6 +12,7 @@ #include "../Core/Input.h" #include #include +#include class FPSCamScript : public ScriptableEntity @@ -56,12 +57,12 @@ public: if (Pitch < -89.0f) Pitch = -89.0f; - Ref cam = GetComponent().CameraInstance; - cam->cameraDirection.x = cos(glm::radians(Yaw)) * cos(glm::radians(Pitch)); - cam->cameraDirection.y = sin(glm::radians(Pitch)); - cam->cameraDirection.z = sin(glm::radians(Yaw)) * cos(glm::radians(Pitch)); - cam->cameraFront = glm::normalize(cam->cameraDirection); - cam->cameraRight = glm::normalize(glm::cross(cam->up, cam->cameraFront)); + //Ref cam = GetComponent().CameraInstance; + //cam->cameraDirection.x = cos(glm::radians(Yaw)) * cos(glm::radians(Pitch)); + //cam->cameraDirection.y = sin(glm::radians(Pitch)); + //cam->cameraDirection.z = sin(glm::radians(Yaw)) * cos(glm::radians(Pitch)); + //cam->cameraFront = glm::normalize(cam->cameraDirection); + //cam->cameraRight = glm::normalize(glm::cross(cam->up, cam->cameraFront)); } }; @@ -105,14 +106,7 @@ public: right.y = .0f; glm::vec3 result = velocity.z * glm::normalize(front) + velocity.x * normalize(right); - CharacterControllerComponent& ccc = GetComponent(); - - if (ccc.CharacterController->IsOnGround && Input::IsKeyPress(GLFW_KEY_SPACE)) - { - velocity.y = 100.0f; - } - - ccc.CharacterController->MoveAndSlide(result); + } }; @@ -133,7 +127,7 @@ public: { if (nextFlip < deltaTime) { - GetComponent().Strength = isOn * strength; + //GetComponent().Strength = isOn * strength; isOn = !isOn; nextFlip = deltaTime + 1.0f; } @@ -148,9 +142,9 @@ void CreateScene() // Main map entity auto mapEntity = scene->CreateEntity("Map"); - mapEntity.AddComponent(); - mapEntity.GetComponent().Load("Res/Maps/texture_test.map", true); - mapEntity.GetComponent().HasCollisions = true; + mapEntity.AddComponent(); + mapEntity.GetComponent().Load("Res/Maps/texture_test.map", true); + mapEntity.GetComponent().HasCollisions = true; // Light entity auto lightEntity = scene->CreateEntity("Light"); @@ -163,6 +157,7 @@ void CreateScene() auto player = scene->CreateEntity("Player"); player.GetComponent().Translation.y = 10.f; player.AddComponent(); + player.AddComponent().Bind(); // Add cam child @@ -178,6 +173,8 @@ int main() { Engine::Init(); + // ScriptingEngine::UpdateScript("test.lua"); + EditorInterface editor; editor.BuildFonts(); @@ -193,6 +190,7 @@ int main() editor.Draw(); Engine::EndDraw(); + Engine::Tick(); } diff --git a/Editor/src/EditorInterface.cpp b/Editor/src/EditorInterface.cpp index 5a0d3573..06c3fc81 100644 --- a/Editor/src/EditorInterface.cpp +++ b/Editor/src/EditorInterface.cpp @@ -17,6 +17,8 @@ #include #include #include "src/Resource/Project.h" +#include +#include ImFont* normalFont; ImFont* bigIconFont; @@ -35,8 +37,8 @@ void EditorInterface::Init() void EditorInterface::DrawViewport() { - ImGui::Begin("ShadowMap"); - { + if(ImGui::Begin("ShadowMap")) + { ImVec2 regionAvail = ImGui::GetContentRegionAvail(); glm::vec2 viewportPanelSize = glm::vec2(regionAvail.x, regionAvail.y); if (m_IsEntitySelected && m_SelectedEntity.HasComponent()) { @@ -47,9 +49,10 @@ void EditorInterface::DrawViewport() else { ImGui::Text("Please select a light entity"); } - ImGui::End(); + } - ImGui::Begin("Viewport"); + ImGui::End(); + if(ImGui::Begin("Viewport")) { Overlay(); ImGuizmo::BeginFrame(); @@ -64,14 +67,14 @@ void EditorInterface::DrawViewport() ImGuizmo::SetDrawlist(); ImGuizmo::SetRect(ImGui::GetWindowPos().x, ImGui::GetWindowPos().y, ImGui::GetWindowWidth(), ImGui::GetWindowHeight()); - if (m_DrawGrid) + if (m_DrawGrid && !Engine::IsPlayMode) { ImGuizmo::DrawGrid(glm::value_ptr(Engine::GetCurrentScene()->GetCurrentCamera()->GetTransform()), glm::value_ptr(Engine::GetCurrentScene()->GetCurrentCamera()->GetPerspective()), glm::value_ptr(glm::identity()), 100.f); } - if (m_IsEntitySelected) + if (m_IsEntitySelected && !Engine::IsPlayMode) { TransformComponent& tc = m_SelectedEntity.GetComponent(); glm::mat4 oldTransform = tc.GetTransform(); @@ -97,12 +100,12 @@ void EditorInterface::DrawViewport() tc.Rotation = glm::vec3(glm::degrees(euler.x), glm::degrees(euler.y), glm::degrees(euler.z)); tc.Scale = scale; } - } - ImGui::End(); + } + ImGui::End(); } static int selected = 0; @@ -203,9 +206,10 @@ void EditorInterface::DrawSceneTree() ImGui::DragFloat("Volumetric scattering", &env->VolumetricFog, .01f, 0.0f, 1.0f); ImGui::DragFloat("Volumetric step count", &env->VolumetricStepCount, 1.f, 0.0f); } + } - - ImGui::Begin("Scene"); + ImGui::End(); + if(ImGui::Begin("Scene")) { // Buttons to add and remove entity. ImGui::BeginChild("Buttons", ImVec2(300, 20), false); @@ -260,7 +264,7 @@ void EditorInterface::DrawSceneTree() // ImGui::EndPopup(); } - ImGui::End(); + } ImGui::End(); } @@ -269,7 +273,7 @@ void EditorInterface::DrawSceneTree() void EditorInterface::DrawEntityPropreties() { - ImGui::Begin("Propreties"); + if(ImGui::Begin("Propreties")) { if (!m_IsEntitySelected) { @@ -297,14 +301,16 @@ void EditorInterface::DrawEntityPropreties() } if (ImGui::BeginPopup("add_component_popup")) { + if (ImGui::MenuItem("Lua script") && !m_SelectedEntity.HasComponent()) + m_SelectedEntity.AddComponent(); if (ImGui::MenuItem("Light Component") && !m_SelectedEntity.HasComponent()) m_SelectedEntity.AddComponent(); if (ImGui::MenuItem("Mesh Component") && !m_SelectedEntity.HasComponent()) m_SelectedEntity.AddComponent(); if (ImGui::MenuItem("Camera Component") && !m_SelectedEntity.HasComponent()) m_SelectedEntity.AddComponent(); - if (ImGui::MenuItem("Quake map Component") && !m_SelectedEntity.HasComponent()) - m_SelectedEntity.AddComponent(); + if (ImGui::MenuItem("Quake map Component") && !m_SelectedEntity.HasComponent()) + m_SelectedEntity.AddComponent(); if (ImGui::MenuItem("Rigidbody Component") && !m_SelectedEntity.HasComponent()) { m_SelectedEntity.AddComponent(); @@ -348,6 +354,34 @@ void EditorInterface::DrawEntityPropreties() } + if (m_SelectedEntity.HasComponent()) { + std::string icon = ICON_FA_FILE; + if (ImGui::CollapsingHeader((icon + " " + "Lua script").c_str(), ImGuiTreeNodeFlags_DefaultOpen)) + { + auto& component = m_SelectedEntity.GetComponent(); + std::string path = component.Script; + + + char pathBuffer[256]; + memset(pathBuffer, 0, sizeof(pathBuffer)); + std::strncpy(pathBuffer, path.c_str(), sizeof(pathBuffer)); + if (ImGui::InputText("##ScriptPath", pathBuffer, sizeof(pathBuffer))) + { + path = std::string(pathBuffer); + } + ImGui::SameLine(); + if (ImGui::Button("Browse")) + { + path = FileDialog::OpenFile(".map"); + } + + component.Script = path; + + ImGui::Separator(); + } + + } + if (m_SelectedEntity.HasComponent()) { std::string icon = ICON_FA_LIGHTBULB; @@ -414,12 +448,12 @@ void EditorInterface::DrawEntityPropreties() ImGui::Separator(); } } - if (m_SelectedEntity.HasComponent()) + if (m_SelectedEntity.HasComponent()) { std::string icon = ICON_FA_BROOM ; if (ImGui::CollapsingHeader((icon + " " + "Quake map").c_str(), ImGuiTreeNodeFlags_DefaultOpen)) { - auto& component = m_SelectedEntity.GetComponent(); + auto& component = m_SelectedEntity.GetComponent(); std::string path = component.Path; @@ -446,8 +480,9 @@ void EditorInterface::DrawEntityPropreties() } ImGui::PopFont(); - ImGui::End(); + } + ImGui::End(); } void EditorInterface::DrawGizmos() { @@ -492,7 +527,9 @@ void EditorInterface::EditorInterfaceDrawFiletree(Ref dir) void EditorInterface::DrawFileSystem() { Ref rootDirectory = FileSystem::GetFileTree(); - ImGui::Begin("Tree browser"); + if (!rootDirectory) + return; + if(ImGui::Begin("Tree browser")) { if (ImGui::BeginPopupContextItem("item context menu")) { @@ -518,8 +555,9 @@ void EditorInterface::DrawFileSystem() ImGui::TreePop(); } - ImGui::End(); + } + ImGui::End(); } @@ -590,9 +628,8 @@ void EditorInterface::DrawFile(Ref file) void EditorInterface::DrawDirectoryExplorer() { - ImGui::Begin("File browser"); + if(ImGui::Begin("File browser")) { - // Wrapping. int width = ImGui::GetWindowWidth(); ImVec2 buttonSize = ImVec2(100, 100); @@ -610,6 +647,7 @@ void EditorInterface::DrawDirectoryExplorer() // Increment item per row tracker. i++; } + // Exit if no current directory. if (!m_CurrentDirectory) { ImGui::EndTable(); @@ -628,8 +666,6 @@ void EditorInterface::DrawDirectoryExplorer() ImGui::TableNextRow(); i++; } - - } if (m_CurrentDirectory && m_CurrentDirectory->Files.size() > 0) { @@ -644,23 +680,25 @@ void EditorInterface::DrawDirectoryExplorer() } } - ImGui::EndTable(); } - - - - - // Display directories first. - - - // Then files. - - - ImGui::End(); } + ImGui::End(); +} + +void EditorInterface::DrawLogger() +{ + if (ImGui::Begin("Logger")) + { + for (auto l : Logger::GetLogs()) + { + ImGui::Text(l.c_str()); + } + + } + ImGui::End(); } @@ -699,6 +737,8 @@ void EditorInterface::Overlay() if (m_ShowOverlay && ImGui::MenuItem("Close")) m_ShowOverlay = false; ImGui::EndPopup(); } + + } ImGui::End(); } @@ -708,7 +748,7 @@ void EditorInterface::DrawRessourceWindow() { std::map> materials = MaterialManager::Get()->GetAllMaterials(); - ImGui::Begin("Materials"); + if(ImGui::Begin("Materials")) { int width = ImGui::GetWindowWidth(); ImVec2 buttonSize = ImVec2(100, 100); @@ -743,10 +783,10 @@ void EditorInterface::DrawRessourceWindow() } } - ImGui::End(); + } - - ImGui::Begin("Material property"); + ImGui::End(); + if(ImGui::Begin("Material property")) { if (m_IsMaterialSelected) { @@ -832,50 +872,132 @@ void EditorInterface::DrawRessourceWindow() ImGui::Text("No material selected."); } - ImGui::End(); + } + ImGui::End(); +} + +void NewProject() +{ + if (Engine::GetProject()) + Engine::GetProject()->Save(); + + // Parse the project and load it. + std::string selectedProject = FileDialog::SaveFile(".project") + ".project"; + + + Ref project = Project::New("Unnamed project", "no description", selectedProject); + project->FullPath = selectedProject; + Engine::LoadProject(project); + + Ref scene = Scene::New(); + Engine::LoadScene(scene); + + +} + + +void OpenProject() +{ + // Parse the project and load it. + std::string projectPath = FileDialog::OpenFile(".project"); + + FileSystem::SetRootDirectory(projectPath + "/../"); + Ref project = Project::New(); + if (!project->Deserialize(FileSystem::ReadFile(projectPath, true))) + { + Logger::Log("Error loading project: " + projectPath); + return; + } + project->FullPath = projectPath; + Engine::LoadProject(project); +} + +void OpenScene() +{ } +void EditorInterface::DrawInit() +{ + +} void EditorInterface::Draw() { Init(); + auto flags = ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoResize | ImGuiWindowFlags_AlwaysAutoResize; + + if (ImGui::BeginPopupModal("Welcome", NULL, flags)) + { + ImGui::Text("Welcome to"); + ImGui::Text("Nuake engine"); + + ImGui::Text("Would you like to"); + if (ImGui::Button("Start a new project")) + NewProject(); + + ImGui::SameLine(); + if (ImGui::Button("Open a project")) + OpenProject(); + + ImGui::EndPopup(); + } + if (!Engine::GetProject()) + { + ImGui::OpenPopup("Welcome"); + } + if (ImGui::BeginMainMenuBar()) { if (ImGui::BeginMenu("File")) { if (ImGui::MenuItem("New project", "CTRL+N")) { - if(Engine::GetProject()) - Engine::GetProject()->Save(); + NewProject(); - // Parse the project and load it. - std::string selectedProject = FileDialog::SaveFile(".project") + ".project"; - - Ref project = Project::New("Unnamed project", "no description", selectedProject); - Engine::LoadProject(project); - - Ref scene = Scene::New(); - Engine::LoadScene(scene); + m_IsEntitySelected = false; } if (ImGui::MenuItem("Open...", "CTRL+O")) { - // Parse the project and load it. - std::string selectedProject = FileDialog::OpenFile(".project"); - Ref project = Project::Load(selectedProject); - Engine::LoadProject(project); + OpenProject(); + + m_IsEntitySelected = false; } if (ImGui::MenuItem("Save", "CTRL+S")) { Engine::GetProject()->Save(); Engine::GetCurrentScene()->Save(); + + m_IsEntitySelected = false; } if (ImGui::MenuItem("Save as...", "CTRL+SHIFT+S")) { std::string savePath = FileDialog::SaveFile("*.project"); Engine::GetProject()->SaveAs(savePath); + + m_IsEntitySelected = false; } + ImGui::Separator(); + if (ImGui::MenuItem("Open scene...", "CTRL+O")) + { + OpenScene(); + m_IsEntitySelected = false; + } + if (ImGui::MenuItem("Save scene", "CTRL+S")) + { + Engine::GetCurrentScene()->Save(); + + m_IsEntitySelected = false; + } + if (ImGui::MenuItem("Save scene as...", "CTRL+SHIFT+S")) + { + std::string savePath = FileDialog::SaveFile("*.scene"); + Engine::GetCurrentScene()->SaveAs(savePath); + + m_IsEntitySelected = false; + } + ImGui::EndMenu(); } if (ImGui::BeginMenu("Edit")) @@ -927,7 +1049,7 @@ void EditorInterface::Draw() if (ImGui::MenuItem("Trenchbroom map")) { auto ent = Engine::GetCurrentScene()->CreateEntity("Trenchbroom map"); - ent.AddComponent(); + ent.AddComponent(); } if (ImGui::MenuItem("Mesh")) { auto ent = Engine::GetCurrentScene()->CreateEntity("Mesh"); @@ -956,17 +1078,17 @@ void EditorInterface::Draw() DrawGizmos(); - DrawRessourceWindow(); - DrawViewport(); - DrawSceneTree(); - DrawFileSystem(); - DrawDirectoryExplorer(); - DrawEntityPropreties(); - + DrawRessourceWindow(); + DrawViewport(); + DrawSceneTree(); + DrawFileSystem(); + DrawDirectoryExplorer(); + DrawEntityPropreties(); + DrawLogger(); if(m_ShowImGuiDemo) ImGui::ShowDemoWindow(); - ImGui::Begin("Physics"); + if(ImGui::Begin("Toolbar")) { if (ImGui::Button(ICON_FA_HAND_POINTER)) CurrentOperation = ImGuizmo::OPERATION::TRANSLATE; @@ -990,8 +1112,9 @@ void EditorInterface::Draw() Engine::ExitPlayMode(); } - ImGui::End(); + } + ImGui::End(); } diff --git a/Editor/src/EditorInterface.h b/Editor/src/EditorInterface.h index a63bd887..95294646 100644 --- a/Editor/src/EditorInterface.h +++ b/Editor/src/EditorInterface.h @@ -33,10 +33,12 @@ public: void DrawGizmos(); void DrawFileSystem(); void DrawDirectoryExplorer(); + void DrawLogger(); void DrawDirectory(Ref directory); bool EntityContainsItself(Entity ent1, Entity ent2); void DrawFile(Ref file); void DrawRessourceWindow(); + void DrawInit(); void EditorInterfaceDrawFiletree(Ref dir); void Overlay(); }; \ No newline at end of file diff --git a/Nuake/Engine.cpp b/Nuake/Engine.cpp index d9551c6e..968297ab 100644 --- a/Nuake/Engine.cpp +++ b/Nuake/Engine.cpp @@ -2,6 +2,12 @@ #include "src/Core/Physics/PhysicsManager.h" #include #include "src/Core/FileSystem.h" +#include "src/Scripting/ScriptingEngine.h" + +#include "../Rendering/Renderer.h" +#include +#include + float Engine::m_LastFrameTime = 0.0f; Ref Engine::CurrentWindow; @@ -9,15 +15,21 @@ bool Engine::IsPlayMode = false; Ref Engine::CurrentProject; -#include "../Rendering/Renderer.h" -#include -#include void Engine::Init() { + Logger::Log("Engine initialization..."); + PhysicsManager::Get()->Init(); - FileSystem::Scan(); + Logger::Log("Physics initialized"); + + + ScriptingEngine::Init(); + Logger::Log("Scripting engine initialized"); CurrentWindow = std::make_shared(); + Logger::Log("Window initialized"); + + Logger::Log("Engine initialized succesfully..."); } void Engine::Tick() @@ -73,6 +85,7 @@ void Engine::Run() void Engine::Close() { + ScriptingEngine::Close(); glfwTerminate(); } @@ -95,10 +108,8 @@ Ref Engine::GetProject() bool Engine::LoadProject(Ref project) { CurrentProject = project; - - Ref newScene = CreateRef(); - Engine::LoadScene(newScene); - + Engine::LoadScene(CurrentProject->DefaultScene); + FileSystem::SetRootDirectory(project->FullPath + "/../"); return true; } diff --git a/Nuake/Engine.h b/Nuake/Engine.h index 622c690d..29363c3a 100644 --- a/Nuake/Engine.h +++ b/Nuake/Engine.h @@ -3,6 +3,8 @@ #include "src/Window.h" #include "src/Scene/Scene.h" #include "src/Resource/Project.h" +#include "src/Scripting/ScriptLoader.h" +#include "src/Core/Logger.h" class Engine { private: @@ -30,4 +32,4 @@ public: static Ref GetProject(); static bool LoadProject(Ref project); -}; \ No newline at end of file +}; diff --git a/Nuake/src/Core/FileSystem.cpp b/Nuake/src/Core/FileSystem.cpp index 93088fbf..3bdce5b4 100644 --- a/Nuake/src/Core/FileSystem.cpp +++ b/Nuake/src/Core/FileSystem.cpp @@ -1,5 +1,5 @@ #include "FileSystem.h" - +#include #include "../../Engine.h" #define GLFW_EXPOSE_NATIVE_WIN32 @@ -10,6 +10,8 @@ #include #include +namespace fs = std::filesystem; + std::string FileDialog::OpenFile(const char* filter) { @@ -50,9 +52,10 @@ std::string FileDialog::SaveFile(const char* filter) return std::string(); } -std::string FileSystem::Root = "resources\\"; +std::string FileSystem::Root = ""; Ref FileSystem::RootDirectory; + void FileSystem::ScanDirectory(Ref directory) { for (const auto& entry : std::filesystem::directory_iterator(directory->fullPath)) @@ -79,10 +82,18 @@ void FileSystem::ScanDirectory(Ref directory) } } } + bool FileSystem::DirectoryExists(const std::string path) { return false; } + +void FileSystem::SetRootDirectory(const std::string path) +{ + Root = path; + Scan(); +} + void FileSystem::Scan() { RootDirectory = CreateRef(); @@ -93,6 +104,35 @@ void FileSystem::Scan() ScanDirectory(RootDirectory); } +std::string FileSystem::AbsoluteToRelative(const std::string& path) +{ + const fs::path rootPath(Root); + const fs::path absolutePath(path); + return fs::relative(absolutePath, rootPath).generic_string(); +} + +std::string FileSystem::ReadFile(const std::string& path, bool absolute) +{ + std::string finalPath = path; + if (!absolute) + finalPath = Root + path; + + std::ifstream MyReadFile(finalPath); + std::string fileContent = ""; + std::string allFile = ""; + + // Use a while loop together with the getline() function to read the file line by line + while (getline(MyReadFile, fileContent)) + { + allFile.append(fileContent); + } + + // Close the file + MyReadFile.close(); + return allFile; +} + + Ref FileSystem::GetFileTree() { return RootDirectory; diff --git a/Nuake/src/Core/FileSystem.h b/Nuake/src/Core/FileSystem.h index 78fa1163..82990f65 100644 --- a/Nuake/src/Core/FileSystem.h +++ b/Nuake/src/Core/FileSystem.h @@ -3,7 +3,7 @@ #include #include "Core.h" -class __declspec(dllexport) FileDialog +class FileDialog { public: static std::string OpenFile(const char* filter); @@ -36,7 +36,10 @@ public: static Ref RootDirectory; + static void SetRootDirectory(const std::string path); + static void Scan(); + static std::string AbsoluteToRelative(const std::string& path); static Ref GetFileTree(); static void ScanDirectory(Ref directory); static void GetDirectories(); @@ -44,5 +47,8 @@ public: static bool DirectoryExists(const std::string path); static bool FileExists(const std::string path); + static std::string ReadFile(const std::string& path, bool absolute = false); + + }; \ No newline at end of file diff --git a/Nuake/src/Core/Input.h b/Nuake/src/Core/Input.h index 631f2c76..382b6d86 100644 --- a/Nuake/src/Core/Input.h +++ b/Nuake/src/Core/Input.h @@ -2,7 +2,7 @@ #include -class __declspec(dllexport) Input +class Input { public: static bool IsKeyPressed(int keycode); diff --git a/Nuake/src/Core/MaterialManager.h b/Nuake/src/Core/MaterialManager.h index afda1dce..e25fa4b6 100644 --- a/Nuake/src/Core/MaterialManager.h +++ b/Nuake/src/Core/MaterialManager.h @@ -5,7 +5,7 @@ class Material; -class __declspec(dllexport) MaterialManager { +class MaterialManager { private: static Ref s_Instance; diff --git a/Nuake/src/Core/Physics/BulletDebugDrawer.cpp b/Nuake/src/Core/Physics/BulletDebugDrawer.cpp index 629ed79a..1ac80ad7 100644 --- a/Nuake/src/Core/Physics/BulletDebugDrawer.cpp +++ b/Nuake/src/Core/Physics/BulletDebugDrawer.cpp @@ -11,9 +11,9 @@ void BulletDebugDrawer::drawLine(const btVector3& from, const btVector3& to, con tc.Rotation = glm::vec3(0.0f); glBegin(GL_LINES); - glColor3f(color.x(), color.y(), color.z()); - glVertex3f(from.x(), from.y(), from.z()); - glVertex3f(to.x(), to.y(), to.z()); + glColor3f((float)(color.x()), (float)(color.y()), (float)(color.z())); + glVertex3f((float)(from.x()), (float)(from.y()), (float)(from.z())); + glVertex3f((float)(to.x()), (float)(to.y()), (float)(to.z())); glEnd(); //Renderer::DrawCube(tc, glm::vec4(color.x(), color.y(), color.z(), 1.0f)); diff --git a/Nuake/src/Core/Physics/PhysicsShapes.h b/Nuake/src/Core/Physics/PhysicsShapes.h index 0cc2054e..384df63e 100644 --- a/Nuake/src/Core/Physics/PhysicsShapes.h +++ b/Nuake/src/Core/Physics/PhysicsShapes.h @@ -17,7 +17,7 @@ namespace Physics { }; - class __declspec(dllexport) Box : public PhysicShape { + class Box : public PhysicShape { private: glm::vec3 Size; btCollisionShape* bShape; @@ -30,7 +30,7 @@ namespace Physics { btCollisionShape* GetBulletShape() override; }; - class __declspec(dllexport) Sphere : public PhysicShape { + class Sphere : public PhysicShape { private: float Radius; btCollisionShape* bShape; @@ -43,7 +43,7 @@ namespace Physics { btCollisionShape* GetBulletShape() override; }; - class __declspec(dllexport) MeshShape : public PhysicShape { + class MeshShape : public PhysicShape { private: Ref m_Mesh; btCollisionShape* bShape; diff --git a/Nuake/src/Core/TextureManager.h b/Nuake/src/Core/TextureManager.h index 625a1b9c..d720a26f 100644 --- a/Nuake/src/Core/TextureManager.h +++ b/Nuake/src/Core/TextureManager.h @@ -4,7 +4,7 @@ #include "../Core/Core.h" class Texture; -class __declspec(dllexport) TextureManager +class TextureManager { private: static TextureManager* s_Instance; diff --git a/Nuake/src/Core/Timestep.h b/Nuake/src/Core/Timestep.h index 529ddfce..d5ec99a1 100644 --- a/Nuake/src/Core/Timestep.h +++ b/Nuake/src/Core/Timestep.h @@ -1,6 +1,6 @@ #pragma once -class __declspec(dllexport) Timestep { +class Timestep { public: Timestep(float time = 0.0f) : m_Time(time) { } operator float() const { return m_Time; } diff --git a/Nuake/src/Rendering/Camera.cpp b/Nuake/src/Rendering/Camera.cpp index e16f9af7..154422ea 100644 --- a/Nuake/src/Rendering/Camera.cpp +++ b/Nuake/src/Rendering/Camera.cpp @@ -14,6 +14,7 @@ Camera::Camera(CAMERA_TYPE type, glm::vec3 position) { up = glm::vec3(0.0f, 1.0f, 0.0f); cameraRight = glm::normalize(glm::cross(up, cameraDirection)); cameraUp = glm::cross(cameraDirection, cameraRight); + cameraFront = cameraDirection; } Camera::Camera() { @@ -77,6 +78,13 @@ json Camera::Serialize() bool Camera::Deserialize(const std::string& str) { + BEGIN_DESERIALIZE(); + j = j["CameraInstance"]; + this->m_Type = (CAMERA_TYPE)j["m_Type"]; + this->AspectRatio = j["AspectRatio"]; + this->Fov = j["Fov"]; + this->Exposure = j["Exposure"]; + this->Speed = j["Speed"]; return false; } diff --git a/Nuake/src/Rendering/Camera.h b/Nuake/src/Rendering/Camera.h index db695aac..6722c44a 100644 --- a/Nuake/src/Rendering/Camera.h +++ b/Nuake/src/Rendering/Camera.h @@ -31,8 +31,8 @@ private: float mouseLastY = 0; public: - glm::vec3 up; // = glm::vec3(0.0f, 1.0f, 0.0f); - glm::vec3 cameraFront; // = glm::vec3(0.0f, 0.0f, 1.0f); + glm::vec3 up = glm::vec3(0.0f, 1.0f, 0.0f); + glm::vec3 cameraFront = glm::vec3(0.0f, 0.0f, 1.0f); glm::vec3 cameraTarget; // = glm::vec3(0.0f, 0.0f, 0.0f); glm::vec3 cameraDirection; // = glm::normalize(Translation - cameraTarget); diff --git a/Nuake/src/Rendering/ImGuiAPI.h b/Nuake/src/Rendering/ImGuiAPI.h index 701862bf..707f4664 100644 --- a/Nuake/src/Rendering/ImGuiAPI.h +++ b/Nuake/src/Rendering/ImGuiAPI.h @@ -1,7 +1,7 @@ #pragma once #include "imgui/imgui.h" -__declspec(dllexport) class ImGUI +class ImGUI { }; \ No newline at end of file diff --git a/Nuake/src/Rendering/Mesh/Mesh.h b/Nuake/src/Rendering/Mesh/Mesh.h index 4c52ec80..909ebf9f 100644 --- a/Nuake/src/Rendering/Mesh/Mesh.h +++ b/Nuake/src/Rendering/Mesh/Mesh.h @@ -11,7 +11,7 @@ struct MeshVertex }; -class __declspec(dllexport) Mesh +class Mesh { public: std::vector m_Textures; diff --git a/Nuake/src/Rendering/ProceduralSky.h b/Nuake/src/Rendering/ProceduralSky.h index fd16fbee..10582376 100644 --- a/Nuake/src/Rendering/ProceduralSky.h +++ b/Nuake/src/Rendering/ProceduralSky.h @@ -7,14 +7,14 @@ class Camera; class ProceduralSky : ISerializable { public: - float SurfaceRadius = 6360e3; - float AtmosphereRadius = 6380e3; - glm::vec3 RayleighScattering = glm::vec3(58e-7, 135e-7, 331e-7); - glm::vec3 MieScattering = glm::vec3(2e-5); + float SurfaceRadius = 6360e3f; + float AtmosphereRadius = 6380e3f; + glm::vec3 RayleighScattering = glm::vec3(58e-7f, 135e-7f, 331e-7f); + glm::vec3 MieScattering = glm::vec3(2e-5f); float SunIntensity = 100.0; - glm::vec3 CenterPoint = glm::vec3(0, -SurfaceRadius, 0); - glm::vec3 SunDirection = glm::vec3(0.20000, 0.95917, 0.20000); + glm::vec3 CenterPoint = glm::vec3(0.f, -SurfaceRadius, 0.f); + glm::vec3 SunDirection = glm::vec3(0.20000f, 0.95917f, 0.20000f); unsigned int VAO; unsigned int VBO; ProceduralSky(); diff --git a/Nuake/src/Rendering/Textures/Material.h b/Nuake/src/Rendering/Textures/Material.h index 1a424542..050ad18e 100644 --- a/Nuake/src/Rendering/Textures/Material.h +++ b/Nuake/src/Rendering/Textures/Material.h @@ -3,7 +3,7 @@ #include "Texture.h" #include #include "../Core/Core.h" -class __declspec(dllexport) Material +class Material { private: std::string m_Name; diff --git a/Nuake/src/Rendering/Textures/Texture.h b/Nuake/src/Rendering/Textures/Texture.h index f7cb1f0d..6101fbf7 100644 --- a/Nuake/src/Rendering/Textures/Texture.h +++ b/Nuake/src/Rendering/Textures/Texture.h @@ -4,7 +4,7 @@ #include "glm/vec2.hpp" typedef unsigned int GLenum; -class __declspec(dllexport) Texture +class Texture { private: unsigned int m_RendererId; diff --git a/Nuake/src/Resource/TrenchbroomMap.h b/Nuake/src/Resource/TrenchbroomMap.h index da84e0ac..54ffb1cc 100644 --- a/Nuake/src/Resource/TrenchbroomMap.h +++ b/Nuake/src/Resource/TrenchbroomMap.h @@ -3,4 +3,20 @@ class TrenchbroomMap { -}; \ No newline at end of file +}; + + +struct Vec3 +{ + float x; + float y; + float z; +}; + +struct Vec4 +{ + float x; + float y; + float z; + float w; +}; diff --git a/Nuake/src/Scene/Entities/Components/CameraComponent.cpp b/Nuake/src/Scene/Entities/Components/CameraComponent.cpp index 688fd16b..315ba1f5 100644 --- a/Nuake/src/Scene/Entities/Components/CameraComponent.cpp +++ b/Nuake/src/Scene/Entities/Components/CameraComponent.cpp @@ -12,6 +12,4 @@ void CameraComponent::DrawEditor() { ImGui::SliderFloat("Exposure", &CameraInstance->Exposure, 0.0f, 2.0f, "%.2f", 1.0f); ImGui::SliderFloat("FOV", &CameraInstance->Fov, 1.0f, 180.0f, "%.2f", 1.0f); ImGui::SliderFloat("Speed", &CameraInstance->Speed, 0.1f, 5.0f, "%.2f", 1.0f); - - } \ No newline at end of file diff --git a/Nuake/src/Scene/Entities/Components/CameraComponent.h b/Nuake/src/Scene/Entities/Components/CameraComponent.h index 2ba0f051..9a30f33e 100644 --- a/Nuake/src/Scene/Entities/Components/CameraComponent.h +++ b/Nuake/src/Scene/Entities/Components/CameraComponent.h @@ -17,4 +17,11 @@ public: SERIALIZE_OBJECT(CameraInstance); END_SERIALIZE(); } + + bool Deserialize(std::string str) + { + CameraInstance = CreateRef(); + + return CameraInstance->Deserialize(str); + } }; \ No newline at end of file diff --git a/Nuake/src/Scene/Entities/Components/LightComponent.h b/Nuake/src/Scene/Entities/Components/LightComponent.h index a9908cea..30b3478b 100644 --- a/Nuake/src/Scene/Entities/Components/LightComponent.h +++ b/Nuake/src/Scene/Entities/Components/LightComponent.h @@ -4,7 +4,7 @@ #include "TransformComponent.h" #include "../Rendering/Camera.h" #include "../../../Rendering/Framebuffer.h" -#include "BaseComponent.h"; +#include "BaseComponent.h" #include "../Resource/Serializable.h" enum LightType { @@ -214,4 +214,9 @@ public: SERIALIZE_VAL(CastShadows); END_SERIALIZE(); } + + bool Deserialize(std::string str) + { + return true; + } }; \ No newline at end of file diff --git a/Nuake/src/Scene/Entities/Components/MeshComponent.h b/Nuake/src/Scene/Entities/Components/MeshComponent.h index 33a4f835..e225f923 100644 --- a/Nuake/src/Scene/Entities/Components/MeshComponent.h +++ b/Nuake/src/Scene/Entities/Components/MeshComponent.h @@ -1,7 +1,7 @@ #pragma once #include "../../../Rendering/Textures/Material.h" #include -#include "BaseComponent.h"; +#include "BaseComponent.h" class MeshComponent { diff --git a/Nuake/src/Scene/Entities/Components/ModelComponent.h b/Nuake/src/Scene/Entities/Components/ModelComponent.h index 01f0db90..0d1262b6 100644 --- a/Nuake/src/Scene/Entities/Components/ModelComponent.h +++ b/Nuake/src/Scene/Entities/Components/ModelComponent.h @@ -6,7 +6,7 @@ #include "assimp/Importer.hpp" #include #include -class __declspec(dllexport) ModelComponent +class ModelComponent { public: ModelComponent() diff --git a/Nuake/src/Scene/Entities/Components/NameComponent.h b/Nuake/src/Scene/Entities/Components/NameComponent.h index 038ec979..cea42e9d 100644 --- a/Nuake/src/Scene/Entities/Components/NameComponent.h +++ b/Nuake/src/Scene/Entities/Components/NameComponent.h @@ -11,4 +11,11 @@ public: SERIALIZE_VAL(Name); END_SERIALIZE(); } + + bool Deserialize(const std::string& str) + { + BEGIN_DESERIALIZE(); + Name = j["Name"]; + return true; + } }; \ No newline at end of file diff --git a/Nuake/src/Scene/Entities/Components/ParentComponent.h b/Nuake/src/Scene/Entities/Components/ParentComponent.h index 13a1bb61..a314d83f 100644 --- a/Nuake/src/Scene/Entities/Components/ParentComponent.h +++ b/Nuake/src/Scene/Entities/Components/ParentComponent.h @@ -16,4 +16,10 @@ struct ParentComponent SERIALIZE_VAL_LBL("Parent", Parent.GetHandle()); END_SERIALIZE(); } + + bool Deserialize(std::string str) + { + return true; + + } }; \ No newline at end of file diff --git a/Nuake/src/Scene/Entities/Components/QuakeMap.cpp b/Nuake/src/Scene/Entities/Components/QuakeMap.cpp index 00fda216..497132da 100644 --- a/Nuake/src/Scene/Entities/Components/QuakeMap.cpp +++ b/Nuake/src/Scene/Entities/Components/QuakeMap.cpp @@ -8,7 +8,7 @@ extern "C" { #include } -void QuakeMap::Draw() +void QuakeMapComponent::Draw() { for (auto m : m_Meshes) { m->Draw(); @@ -17,7 +17,7 @@ void QuakeMap::Draw() -void QuakeMap::Load(std::string path, bool collisions) +void QuakeMapComponent::Load(std::string path, bool collisions) { if (Path == path) return; @@ -27,7 +27,7 @@ void QuakeMap::Load(std::string path, bool collisions) Build(); } -void QuakeMap::Build() +void QuakeMapComponent::Build() { m_Meshes.clear(); map_parser_load(Path.c_str()); @@ -125,7 +125,7 @@ void QuakeMap::Build() } } } -void QuakeMap::DrawEditor() +void QuakeMapComponent::DrawEditor() { } \ No newline at end of file diff --git a/Nuake/src/Scene/Entities/Components/QuakeMap.h b/Nuake/src/Scene/Entities/Components/QuakeMap.h index 3fe9e0f4..86cde411 100644 --- a/Nuake/src/Scene/Entities/Components/QuakeMap.h +++ b/Nuake/src/Scene/Entities/Components/QuakeMap.h @@ -5,7 +5,7 @@ #include "../Resource/TrenchbroomMap.h" #include "../Resource/Serializable.h" -class QuakeMap { +class QuakeMapComponent { private: @@ -27,4 +27,12 @@ public: SERIALIZE_VAL(Path); END_SERIALIZE(); } + + bool Deserialize(std::string str) + { + BEGIN_DESERIALIZE(); + this->Path = j["Path"]; + + return true; + } }; \ No newline at end of file diff --git a/Nuake/src/Scene/Entities/Components/RigidbodyComponent.h b/Nuake/src/Scene/Entities/Components/RigidbodyComponent.h index 400aea30..3e312bc9 100644 --- a/Nuake/src/Scene/Entities/Components/RigidbodyComponent.h +++ b/Nuake/src/Scene/Entities/Components/RigidbodyComponent.h @@ -1,14 +1,14 @@ #pragma once #include "TransformComponent.h" -#include "BaseComponent.h"; +#include "BaseComponent.h" #include "../Core/Core.h" namespace Physics{ class RigidBody; }; -class __declspec(dllexport) RigidBodyComponent +class RigidBodyComponent { public: float mass = 0.0f; diff --git a/Nuake/src/Scene/Entities/Components/TransformComponent.h b/Nuake/src/Scene/Entities/Components/TransformComponent.h index ed19b09f..3dea79d1 100644 --- a/Nuake/src/Scene/Entities/Components/TransformComponent.h +++ b/Nuake/src/Scene/Entities/Components/TransformComponent.h @@ -1,7 +1,8 @@ #pragma once #include -#include "BaseComponent.h"; +#include "BaseComponent.h" #include "../Resource/Serializable.h" + class TransformComponent { public: glm::vec3 Translation; @@ -22,4 +23,14 @@ public: SERIALIZE_VEC3(Scale); END_SERIALIZE(); } + + bool Deserialize(std::string str) + { + BEGIN_DESERIALIZE(); + this->Translation = glm::vec3(j["Translation"]["x"], j["Translation"]["y"], j["Translation"]["z"]); + this->Rotation = glm::vec3(j["Rotation"]["x"], j["Rotation"]["y"], j["Rotation"]["z"]); + this->Scale = glm::vec3(j["Scale"]["x"], j["Scale"]["y"], j["Scale"]["z"]); + return true; + + } }; \ No newline at end of file diff --git a/Nuake/src/Scene/Entities/Entity.cpp b/Nuake/src/Scene/Entities/Entity.cpp index dd3717f8..69937b51 100644 --- a/Nuake/src/Scene/Entities/Entity.cpp +++ b/Nuake/src/Scene/Entities/Entity.cpp @@ -7,6 +7,7 @@ #include "Components/CameraComponent.h" #include "Components/QuakeMap.h" #include "Components/LightComponent.h" +#include "Components/QuakeMap.h" void Entity::AddChild(Entity ent) { if ((int)m_EntityHandle != ent.GetHandle()) @@ -26,8 +27,8 @@ json Entity::Serialize() SERIALIZE_OBJECT_REF_LBL("TransformComponent", GetComponent()); if(HasComponent()) SERIALIZE_OBJECT_REF_LBL("CameraComponent", GetComponent()); - if(HasComponent()) - SERIALIZE_OBJECT_REF_LBL("QuakemapComponent", GetComponent()); + if(HasComponent()) + SERIALIZE_OBJECT_REF_LBL("QuakeMapComponent", GetComponent()); if (HasComponent()) SERIALIZE_OBJECT_REF_LBL("LightComponent", GetComponent()); END_SERIALIZE(); @@ -35,7 +36,14 @@ json Entity::Serialize() bool Entity::Deserialize(const std::string& str) { - return false; + BEGIN_DESERIALIZE(); + DESERIALIZE_COMPONENT(TransformComponent); + DESERIALIZE_COMPONENT(NameComponent); + DESERIALIZE_COMPONENT(ParentComponent); + DESERIALIZE_COMPONENT(CameraComponent); + DESERIALIZE_COMPONENT(QuakeMapComponent); + DESERIALIZE_COMPONENT(LightComponent); + return true; } Entity::Entity(entt::entity handle, Scene* scene) diff --git a/Nuake/src/Scene/Entities/Entity.h b/Nuake/src/Scene/Entities/Entity.h index 0196427d..228b869e 100644 --- a/Nuake/src/Scene/Entities/Entity.h +++ b/Nuake/src/Scene/Entities/Entity.h @@ -5,7 +5,7 @@ #include "Components/BaseComponent.h" #include "../Resource/Serializable.h" -class __declspec(dllexport) Entity : public ISerializable +class Entity : public ISerializable { public: Entity(entt::entity handle, Scene* scene); diff --git a/Nuake/src/Scene/Entities/ScriptableEntity.h b/Nuake/src/Scene/Entities/ScriptableEntity.h index a91659f5..64df2995 100644 --- a/Nuake/src/Scene/Entities/ScriptableEntity.h +++ b/Nuake/src/Scene/Entities/ScriptableEntity.h @@ -7,17 +7,9 @@ class ScriptableEntity { public: - template - T& GetComponent() - { - return m_Entity.GetComponent(); - } - virtual void OnCreate() {} virtual void OnDestroy() {} virtual void OnUpdate(Timestep ts){} - Entity m_Entity; - friend class Scene; }; \ No newline at end of file diff --git a/Nuake/src/Scene/Scene.cpp b/Nuake/src/Scene/Scene.cpp index 2c889423..191b961b 100644 --- a/Nuake/src/Scene/Scene.cpp +++ b/Nuake/src/Scene/Scene.cpp @@ -10,7 +10,7 @@ #include "Entities/Components/BoxCollider.h" #include "../../Engine.h" #include "../Core/FileSystem.h" - +#include "../Scene/Entities/Components/LuaScriptComponent.h" #include #include @@ -21,9 +21,6 @@ Ref Scene::New() Scene::Scene() { - auto camEntity = CreateEntity("Camera"); - camEntity.AddComponent().transformComponent = &camEntity.GetComponent(); - m_EditorCamera = CreateRef(); m_Environement = CreateRef(); } @@ -82,10 +79,10 @@ void Scene::OnInit() PhysicsManager::Get()->RegisterCharacterController(cc.CharacterController); } - auto quakeMapview = m_Registry.view(); + auto quakeMapview = m_Registry.view(); for (auto e : quakeMapview) { - auto [transform, quake] = quakeMapview.get(e); + auto [transform, quake] = quakeMapview.get(e); if (quake.HasCollisions) { @@ -100,14 +97,9 @@ void Scene::OnInit() // Instanciate scripts. { - m_Registry.view().each([=](auto entity, auto& nsc) + m_Registry.view().each([=](auto entity, auto& nsc) { - if (!nsc.Instance) - { - nsc.Instance = nsc.InstantiateScript(); - nsc.Instance->m_Entity = Entity{ entity, this }; - } - nsc.Instance->OnCreate(); + }); } } @@ -163,7 +155,7 @@ void Scene::DrawShadows() { auto modelView = m_Registry.view(); - auto quakeView = m_Registry.view(); + auto quakeView = m_Registry.view(); auto view = m_Registry.view(); Ref cam = nullptr; @@ -202,7 +194,7 @@ void Scene::DrawShadows() } for (auto e : quakeView) { - auto [transform, model] = quakeView.get(e); + auto [transform, model] = quakeView.get(e); glm::vec3 pos = lightTransform.Translation; glm::mat4 lightView = glm::lookAt(pos, pos - light.GetDirection(), glm::vec3(0.0f, 1.0f, 0.0f)); @@ -317,9 +309,9 @@ void Scene::Draw() model.Draw(); } - auto quakeView = m_Registry.view(); + auto quakeView = m_Registry.view(); for (auto e : quakeView) { - auto [transform, model, parent] = quakeView.get(e); + auto [transform, model, parent] = quakeView.get(e); TransformComponent copyT = transform; if (parent.HasParent) @@ -395,9 +387,6 @@ void Scene::EditorDraw() { Renderer::m_Shader->SetUniform1f("u_Exposure", m_EditorCamera->Exposure); - - - auto view = m_Registry.view(); for (auto e : view) { auto [transform, model, parent] = view.get(e); @@ -423,9 +412,9 @@ void Scene::EditorDraw() model.Draw(); } - auto quakeView = m_Registry.view(); + auto quakeView = m_Registry.view(); for (auto e : quakeView) { - auto [transform, model, parent] = quakeView.get(e); + auto [transform, model, parent] = quakeView.get(e); TransformComponent copyT = transform; @@ -511,7 +500,7 @@ void Scene::EditorDraw() std::vector Scene::GetAllEntities() { std::vector allEntities; - auto view = m_Registry.view(); + auto view = m_Registry.view(); for (auto e : view) { allEntities.push_back(Entity(e, this)); } @@ -543,6 +532,11 @@ Entity Scene::GetEntity(const std::string& name) } } +Entity Scene::CreateEmptyEntity(const std::string& name) { + Entity entity = { m_Registry.create(), this }; + return entity; +} + Entity Scene::CreateEntity(const std::string& name) { Entity entity = { m_Registry.create(), this }; @@ -554,8 +548,7 @@ Entity Scene::CreateEntity(const std::string& name) { ParentComponent& parentComponent = entity.AddComponent(); - std::string str = "Created entity: " + nameComponent.Name + "\n"; - printf(str.c_str()); + Logger::Log("Created entity: " + nameComponent.Name + "\n"); return entity; } @@ -590,7 +583,7 @@ Ref Scene::GetEnvironment() { bool Scene::Save() { if (Path == "") - Path = FileDialog::SaveFile("*.scene") + ".scene"; + Path = FileSystem::AbsoluteToRelative(FileDialog::SaveFile("*.scene") + ".scene"); return SaveAs(Path); } @@ -598,9 +591,11 @@ bool Scene::Save() bool Scene::SaveAs(const std::string& path) { std::ofstream sceneFile; - sceneFile.open(path); + sceneFile.open(FileSystem::Root + path); sceneFile << Serialize().dump(4); sceneFile.close(); + + Logger::Log("Scene saved successfully"); return true; } @@ -620,5 +615,34 @@ json Scene::Serialize() bool Scene::Deserialize(const std::string& str) { - return false; + if (str == "") + return false; + + BEGIN_DESERIALIZE(); + if (!j.contains("Name")) + return false; + + Name = j["Name"]; + + m_Environement = CreateRef(); + if (j.contains("m_Environement")) + { + m_Environement = CreateRef(); + std::string env = j["m_Environement"].dump(); + m_Environement->Deserialize(env); + } + + // Parse entities + { + if (j.contains("Entities")) + { + for (json e : j["Entities"]) + { + std::string name = e["NameComponent"]["Name"]; + Entity ent = CreateEmptyEntity(name); + ent.Deserialize(e.dump()); + } + } + } + return true; } diff --git a/Nuake/src/Scene/Scene.h b/Nuake/src/Scene/Scene.h index 75f7569d..ee806a51 100644 --- a/Nuake/src/Scene/Scene.h +++ b/Nuake/src/Scene/Scene.h @@ -20,9 +20,10 @@ private: entt::registry m_Registry; Ref m_EditorCamera; std::string Name; - std::string Path = ""; + bool has_changed = true; public: + std::string Path = ""; static Ref New(); Scene(); ~Scene(); @@ -45,6 +46,7 @@ public: std::vector GetAllEntities(); glm::vec3 GetGlobalPosition(Entity ent); Entity GetEntity(const std::string& name); + Entity CreateEmptyEntity(const std::string& name); Entity CreateEntity(const std::string& name); void DestroyEntity(Entity entity); diff --git a/Nuake/src/Window.h b/Nuake/src/Window.h index b2dcc275..d4c942a2 100644 --- a/Nuake/src/Window.h +++ b/Nuake/src/Window.h @@ -4,7 +4,7 @@ #include "Scene/Scene.h" #include "Core/Core.h" struct GLFWwindow; -class __declspec(dllexport) Window +class Window { private: static Window* s_Instance; @@ -22,8 +22,6 @@ public: static Window* Get(); GLFWwindow* GetHandle(); - - int Init(); void Update(Timestep ts); void Draw(); diff --git a/premake5.lua b/premake5.lua index 733cec89..1e9e74cb 100644 --- a/premake5.lua +++ b/premake5.lua @@ -9,6 +9,33 @@ workspace "Nuake" outputdir = "%{cfg.buildcfg}-%{cfg.system}-%{cfg.architecture}" +project "DemoModule" + location "DemoModule" + kind "SharedLib" + language "C++" + targetdir ("bin/" .. outputdir .. "/%{prj.name}") + objdir ("bin-int/" .. outputdir .. "/%{prj.name}") + + filter "system:windows" + cppdialect "C++17" + + includedirs + { + "%{prj.name}/../Nuake", + "%{prj.name}/../Nuake/src/Vendors", + "%{prj.name}/../Nuake/Dependencies/GLEW/include", + "%{prj.name}/../Nuake/Dependencies/GLFW/x64/include", + "%{prj.name}/../Nuake/Dependencies/bullet/src", + "%{prj.name}/../Nuake/Dependencies/assimp/include" + } + + + files + { + "%{prj.name}/**.h", + "%{prj.name}/**.cpp" + } + project "Nuake" location "Nuake" kind "StaticLib" @@ -37,11 +64,12 @@ project "Nuake" includedirs { - "%{prj.name}/src/Vendors", - "%{prj.name}/Dependencies/GLEW/include", - "%{prj.name}/Dependencies/GLFW/x64/include", - "%{prj.name}/Dependencies/bullet/src", - "%{prj.name}/Dependencies/assimp/include" + "%{prj.name}/../Nuake", + "%{prj.name}/../Nuake/src/Vendors", + "%{prj.name}/../Nuake/Dependencies/GLEW/include", + "%{prj.name}/../Nuake/Dependencies/GLFW/x64/include", + "%{prj.name}/../Nuake/Dependencies/bullet/src", + "%{prj.name}/../Nuake/Dependencies/assimp/include" } filter "system:windows"