From 0d32d28b8276cf5479f326e1783516582f59628f Mon Sep 17 00:00:00 2001 From: Antoine Pilote Date: Sat, 22 Jul 2023 03:22:08 -0400 Subject: [PATCH 1/5] Added runtime --- Editor/Runtime.cpp | 75 +++++++++++++++++++++ Nuake/Engine.cpp | 6 +- Nuake/src/Rendering/Shaders/ShaderManager.h | 4 +- premake5.lua | 71 +++++++++++++++++++ 4 files changed, 151 insertions(+), 5 deletions(-) create mode 100644 Editor/Runtime.cpp diff --git a/Editor/Runtime.cpp b/Editor/Runtime.cpp new file mode 100644 index 00000000..1c9c408e --- /dev/null +++ b/Editor/Runtime.cpp @@ -0,0 +1,75 @@ +#include +#include +#include + +#include "src/Rendering/Shaders/ShaderManager.h" +#include "src/Rendering/Renderer.h" +#include +#include +#include + +void main(int argc, char* argv[]) +{ + for (uint32_t i = 0; i < argc; i++) + { + char* arg = argv[i]; + std::string projectPath; + if (argc == 1) + { + return; + } + + projectPath = std::string(argv[1]); + + using namespace Nuake; + + Nuake::Engine::Init(); + Engine::GetCurrentWindow()->SetSize({ 1920, 1080 }); + + Ref window = Nuake::Engine::GetCurrentWindow(); + window->SetTitle("Nuake Runtime"); + + FileSystem::SetRootDirectory(FileSystem::GetParentPath(projectPath)); + + auto project = Project::New(); + auto projectFileData = FileSystem::ReadFile(projectPath, true); + try + { + project->Deserialize(projectFileData); + project->FullPath = projectPath; + + Engine::LoadProject(project); + } + catch (std::exception exception) + { + Logger::Log("Error loading project: " + projectPath, "editor", CRITICAL); + Logger::Log(exception.what()); + } + + glClearColor(0.2f, 0.3f, 0.3f, 1.0f); + Engine::EnterPlayMode(); + glViewport(0, 0, 100, 100); + while (!window->ShouldClose()) + { + Nuake::Engine::Tick(); + Nuake::Engine::Draw(); + + Timestep ts = Nuake::Engine::GetTimestep(); + + //ImGui::Render(); + //ImGui_ImplOpenGL3_RenderDrawData(ImGui::GetDrawData()); + + Nuake::Vector2 WindowSize = window->GetSize(); + glViewport(0, 0, WindowSize.x, WindowSize.y); + glClear(GL_COLOR_BUFFER_BIT); + auto shader = ShaderManager::GetShader("resources/Shaders/copy.shader"); + shader->SetUniformTex("u_Source", Engine::GetCurrentScene()->mSceneRenderer->GetTexture().get()); + Renderer::DrawQuad(Matrix4()); + + glfwSwapBuffers(window->GetHandle()); + glfwPollEvents(); + } + } + + Nuake::Engine::Close(); +} \ No newline at end of file diff --git a/Nuake/Engine.cpp b/Nuake/Engine.cpp index cea54337..cc2b288e 100644 --- a/Nuake/Engine.cpp +++ b/Nuake/Engine.cpp @@ -112,9 +112,9 @@ namespace Nuake Nuake::RenderCommand::Clear(); // Start imgui frame - ImGui_ImplOpenGL3_NewFrame(); - ImGui_ImplGlfw_NewFrame(); - ImGui::NewFrame(); + //ImGui_ImplOpenGL3_NewFrame(); + //ImGui_ImplGlfw_NewFrame(); + //ImGui::NewFrame(); // Draw scene Window::Get()->Draw(); diff --git a/Nuake/src/Rendering/Shaders/ShaderManager.h b/Nuake/src/Rendering/Shaders/ShaderManager.h index 6f987dc9..4b373e5a 100644 --- a/Nuake/src/Rendering/Shaders/ShaderManager.h +++ b/Nuake/src/Rendering/Shaders/ShaderManager.h @@ -7,8 +7,8 @@ namespace Nuake { - - class ShaderManager { + class ShaderManager + { private: static std::map> m_Shaders; diff --git a/premake5.lua b/premake5.lua index 98745469..9d9d752e 100644 --- a/premake5.lua +++ b/premake5.lua @@ -81,6 +81,77 @@ project "Nuake" runtime "Release" optimize "on" +project "NuakeRuntime" + location "Editor" + kind "ConsoleApp" + language "C++" + + targetdir ("bin/" .. outputdir .. "/%{prj.name}") + objdir ("bin-int/" .. outputdir .. "/%{prj.name}") + debugdir ("Editor") + + files + { + "Editor/Runtime.cpp" + } + + includedirs + { + "%{prj.name}/../Nuake", + "%{prj.name}/../Nuake/src/Vendors", + "%{prj.name}/../Nuake/Dependencies/GLEW/include", + "%{prj.name}/../Nuake/Dependencies/GLFW/include", + "%{prj.name}/../Nuake/Dependencies/assimp/include", + "%{prj.name}/../Nuake/Dependencies/build", + "%{prj.name}/../Nuake/src/Vendors/msdfgen", + "%{prj.name}/../Nuake/Dependencies/JoltPhysics", + "%{prj.name}/../Nuake/Dependencies/build", + "%{prj.name}/../Nuake/Dependencies/soloud/include" + } + + libdirs + { + "%{prj.name}/../Nuake/dependencies/GLEW/lib/Release/x64", + "%{prj.name}/../Nuake/dependencies/assimp/lib/", + "%{prj.name}/../Nuake/dependencies/freetype-windows-binaries/release static/win64", + "%{prj.name}/../bin/%{cfg.buildcfg}-%{cfg.system}-%{cfg.architecture}/Nuake/", + "%{prj.name}/../Nuake/dependencies/freetype/include", + "%{prj.name}/../Nuake/src/Vendors/msdfgen/freetype/win64", + "%{prj.name}/../Nuake/src/Vendors/msdfgen", + "%{prj.name}/../Nuake/src/Vendors/wren/src/include", + "%{prj.name}/../Nuake/dependencies/JoltPhysics/bin/%{cfg.buildcfg}-%{cfg.system}-%{cfg.architecture}/JoltPhysics/", + "%{prj.name}/../Nuake/dependencies/soloud/bin/%{cfg.buildcfg}-%{cfg.system}-%{cfg.architecture}" + } + + links + { + "Nuake", + "GLFW", + "assimp", + "glew32s.lib", + "opengl32.lib", + "Freetype", + "JoltPhysics", + "soloud" + } + + filter "system:windows" + cppdialect "C++17" + staticruntime "On" + + filter "configurations:Debug" + runtime "Debug" + symbols "on" + + filter "configurations:Release" + runtime "Release" + optimize "on" + + -- copy a file from the objects directory to the target directory + postbuildcommands { + --"{COPY} "Nuake/dependencies/GLFW/lib-vc2019/glfw3.dll" " .. "./bin/" .. outputdir .. "/%{prj.name}/glfw3.dll" + } + project "Editor" location "Editor" kind "ConsoleApp" From aed3bb688aa7a487c520282bdb5505005847552e Mon Sep 17 00:00:00 2001 From: Antoine Pilote Date: Sat, 22 Jul 2023 13:08:04 -0400 Subject: [PATCH 2/5] Runtime progress --- Editor/Editor.cpp | 1 - Editor/Runtime.cpp | 126 ++++++++++++++++++++++----------------------- Nuake/Engine.cpp | 6 +-- premake5.lua | 5 +- 4 files changed, 68 insertions(+), 70 deletions(-) diff --git a/Editor/Editor.cpp b/Editor/Editor.cpp index c0e165f4..fd4e16f2 100644 --- a/Editor/Editor.cpp +++ b/Editor/Editor.cpp @@ -33,7 +33,6 @@ #include - const std::string WindowTitle = "Nuake Editor"; int main(int argc, char* argv[]) diff --git a/Editor/Runtime.cpp b/Editor/Runtime.cpp index 1c9c408e..ce641fdc 100644 --- a/Editor/Runtime.cpp +++ b/Editor/Runtime.cpp @@ -1,75 +1,73 @@ +#include +#include + + #include #include -#include +#include +#include -#include "src/Rendering/Shaders/ShaderManager.h" -#include "src/Rendering/Renderer.h" -#include +#include #include -#include + +void CheckError() +{ + GLenum err; + while ((err = glGetError()) != GL_NO_ERROR) + { + // Process/log the error. + std::cout << "OPENGL ERROR: " << err << std::endl; + } +} void main(int argc, char* argv[]) { - for (uint32_t i = 0; i < argc; i++) + std::string projectPath; + if (argc == 1) { - char* arg = argv[i]; - std::string projectPath; - if (argc == 1) - { - return; - } - - projectPath = std::string(argv[1]); - - using namespace Nuake; - - Nuake::Engine::Init(); - Engine::GetCurrentWindow()->SetSize({ 1920, 1080 }); - - Ref window = Nuake::Engine::GetCurrentWindow(); - window->SetTitle("Nuake Runtime"); - - FileSystem::SetRootDirectory(FileSystem::GetParentPath(projectPath)); - - auto project = Project::New(); - auto projectFileData = FileSystem::ReadFile(projectPath, true); - try - { - project->Deserialize(projectFileData); - project->FullPath = projectPath; - - Engine::LoadProject(project); - } - catch (std::exception exception) - { - Logger::Log("Error loading project: " + projectPath, "editor", CRITICAL); - Logger::Log(exception.what()); - } - - glClearColor(0.2f, 0.3f, 0.3f, 1.0f); - Engine::EnterPlayMode(); - glViewport(0, 0, 100, 100); - while (!window->ShouldClose()) - { - Nuake::Engine::Tick(); - Nuake::Engine::Draw(); - - Timestep ts = Nuake::Engine::GetTimestep(); - - //ImGui::Render(); - //ImGui_ImplOpenGL3_RenderDrawData(ImGui::GetDrawData()); - - Nuake::Vector2 WindowSize = window->GetSize(); - glViewport(0, 0, WindowSize.x, WindowSize.y); - glClear(GL_COLOR_BUFFER_BIT); - auto shader = ShaderManager::GetShader("resources/Shaders/copy.shader"); - shader->SetUniformTex("u_Source", Engine::GetCurrentScene()->mSceneRenderer->GetTexture().get()); - Renderer::DrawQuad(Matrix4()); - - glfwSwapBuffers(window->GetHandle()); - glfwPollEvents(); - } + return; } - Nuake::Engine::Close(); + projectPath = std::string(argv[1]); + + using namespace Nuake; + Nuake::Engine::Init(); + + Ref window = Nuake::Engine::GetCurrentWindow(); + window->SetTitle("asdasd"); + + FileSystem::SetRootDirectory(FileSystem::GetParentPath(projectPath)); + auto project = Project::New(); + auto scene = Scene::New(); + auto projectFileData = FileSystem::ReadFile(projectPath, true); + try + { + project->Deserialize(projectFileData); + project->FullPath = projectPath; + Engine::LoadProject(project); + } + catch (std::exception exception) + { + Logger::Log("Error loading project: " + projectPath, "editor", CRITICAL); + Logger::Log(exception.what()); + } + + //Engine::EnterPlayMode(); + + while (!window->ShouldClose()) + { + Nuake::Engine::Tick(); + Nuake::Engine::Draw(); + + ImGui::Begin("test"); + + ImGui::End(); + const auto& WindowSize = window->GetSize(); + glViewport(0, 0, WindowSize.x, WindowSize.y); + + RenderCommand::SetClearColor({ 0.1, 0.1 ,0.1, 1.0 }); + RenderCommand::Clear(); + + Nuake::Engine::EndDraw(); + } } \ No newline at end of file diff --git a/Nuake/Engine.cpp b/Nuake/Engine.cpp index cc2b288e..cea54337 100644 --- a/Nuake/Engine.cpp +++ b/Nuake/Engine.cpp @@ -112,9 +112,9 @@ namespace Nuake Nuake::RenderCommand::Clear(); // Start imgui frame - //ImGui_ImplOpenGL3_NewFrame(); - //ImGui_ImplGlfw_NewFrame(); - //ImGui::NewFrame(); + ImGui_ImplOpenGL3_NewFrame(); + ImGui_ImplGlfw_NewFrame(); + ImGui::NewFrame(); // Draw scene Window::Get()->Draw(); diff --git a/premake5.lua b/premake5.lua index 9d9d752e..50dc6cb9 100644 --- a/premake5.lua +++ b/premake5.lua @@ -163,8 +163,9 @@ project "Editor" files { - "%{prj.name}/**.h", - "%{prj.name}/**.cpp", + "%{prj.name}/Editor.cpp", + "%{prj.name}/src/**.cpp", + "%{prj.name}/src/**.h", "%{prj.name}/resources/*.rc", "%{prj.name}/resources/**.ico" } From a5227cfb12f80378d8e3870a09131f59e3997a2c Mon Sep 17 00:00:00 2001 From: Antoine Pilote Date: Sat, 22 Jul 2023 20:14:06 -0400 Subject: [PATCH 3/5] r --- Editor/Runtime.cpp | 51 +++++++++++----------------------------------- 1 file changed, 12 insertions(+), 39 deletions(-) diff --git a/Editor/Runtime.cpp b/Editor/Runtime.cpp index ce641fdc..636c7c45 100644 --- a/Editor/Runtime.cpp +++ b/Editor/Runtime.cpp @@ -1,14 +1,12 @@ + +#include +#include + #include #include - -#include -#include -#include -#include - #include -#include +#include void CheckError() { @@ -22,52 +20,27 @@ void CheckError() void main(int argc, char* argv[]) { - std::string projectPath; - if (argc == 1) - { - return; - } - - projectPath = std::string(argv[1]); - using namespace Nuake; - Nuake::Engine::Init(); + Engine::Init(); - Ref window = Nuake::Engine::GetCurrentWindow(); + auto window = Nuake::Engine::GetCurrentWindow(); window->SetTitle("asdasd"); - FileSystem::SetRootDirectory(FileSystem::GetParentPath(projectPath)); - auto project = Project::New(); - auto scene = Scene::New(); - auto projectFileData = FileSystem::ReadFile(projectPath, true); - try - { - project->Deserialize(projectFileData); - project->FullPath = projectPath; - Engine::LoadProject(project); - } - catch (std::exception exception) - { - Logger::Log("Error loading project: " + projectPath, "editor", CRITICAL); - Logger::Log(exception.what()); - } - - //Engine::EnterPlayMode(); + Ref scene = Scene::New(); + Engine::LoadScene(scene); while (!window->ShouldClose()) { Nuake::Engine::Tick(); - Nuake::Engine::Draw(); - ImGui::Begin("test"); - - ImGui::End(); const auto& WindowSize = window->GetSize(); glViewport(0, 0, WindowSize.x, WindowSize.y); RenderCommand::SetClearColor({ 0.1, 0.1 ,0.1, 1.0 }); RenderCommand::Clear(); - Nuake::Engine::EndDraw(); + Engine::Draw(); + Renderer::DrawLine(Vector3(0, 0, 0), Vector3(10, 10, 0), Color(1, 0, 0, 1)); + Engine::EndDraw(); } } \ No newline at end of file From 35940b3356ec5549d047295a3702f38f155f4e32 Mon Sep 17 00:00:00 2001 From: Antoine Pilote Date: Tue, 8 Aug 2023 14:24:17 -0400 Subject: [PATCH 4/5] Runtime now working --- Editor/Runtime.cpp | 46 ------------- Nuake/src/Core/FileSystem.cpp | 5 ++ Nuake/src/Core/FileSystem.h | 1 + Nuake/src/Rendering/Textures/Material.h | 21 ++++-- Nuake/src/Rendering/Textures/Texture.cpp | 14 ++++ Nuake/src/Rendering/Textures/Texture.h | 25 +++---- NuakeRuntime/Runtime.cpp | 61 +++++++++++++++++ Runtime/Runtime.cpp | 83 ++++++++++++++++++++++++ premake5.lua | 4 +- 9 files changed, 188 insertions(+), 72 deletions(-) delete mode 100644 Editor/Runtime.cpp create mode 100644 NuakeRuntime/Runtime.cpp create mode 100644 Runtime/Runtime.cpp diff --git a/Editor/Runtime.cpp b/Editor/Runtime.cpp deleted file mode 100644 index 636c7c45..00000000 --- a/Editor/Runtime.cpp +++ /dev/null @@ -1,46 +0,0 @@ - -#include -#include - -#include -#include - -#include -#include - -void CheckError() -{ - GLenum err; - while ((err = glGetError()) != GL_NO_ERROR) - { - // Process/log the error. - std::cout << "OPENGL ERROR: " << err << std::endl; - } -} - -void main(int argc, char* argv[]) -{ - using namespace Nuake; - Engine::Init(); - - auto window = Nuake::Engine::GetCurrentWindow(); - window->SetTitle("asdasd"); - - Ref scene = Scene::New(); - - Engine::LoadScene(scene); - while (!window->ShouldClose()) - { - Nuake::Engine::Tick(); - - const auto& WindowSize = window->GetSize(); - glViewport(0, 0, WindowSize.x, WindowSize.y); - - RenderCommand::SetClearColor({ 0.1, 0.1 ,0.1, 1.0 }); - RenderCommand::Clear(); - - Engine::Draw(); - Renderer::DrawLine(Vector3(0, 0, 0), Vector3(10, 10, 0), Color(1, 0, 0, 1)); - Engine::EndDraw(); - } -} \ No newline at end of file diff --git a/Nuake/src/Core/FileSystem.cpp b/Nuake/src/Core/FileSystem.cpp index 0298be94..c7d15487 100644 --- a/Nuake/src/Core/FileSystem.cpp +++ b/Nuake/src/Core/FileSystem.cpp @@ -120,6 +120,11 @@ namespace Nuake return fs::relative(absolutePath, rootPath).generic_string(); } + std::string FileSystem::RelativeToAbsolute(const std::string& path) + { + return Root + path; + } + std::string FileSystem::GetParentPath(const std::string& fullPath) { std::filesystem::path pathObj(fullPath); diff --git a/Nuake/src/Core/FileSystem.h b/Nuake/src/Core/FileSystem.h index f337058f..8327e343 100644 --- a/Nuake/src/Core/FileSystem.h +++ b/Nuake/src/Core/FileSystem.h @@ -30,6 +30,7 @@ namespace Nuake static void Scan(); static std::string AbsoluteToRelative(const std::string& path); + static std::string RelativeToAbsolute(const std::string& path); static std::string GetParentPath(const std::string& fullPath); static Ref GetFileTree(); static Ref GetFile(const std::string& path); diff --git a/Nuake/src/Rendering/Textures/Material.h b/Nuake/src/Rendering/Textures/Material.h index 2be3f4aa..1413b45e 100644 --- a/Nuake/src/Rendering/Textures/Material.h +++ b/Nuake/src/Rendering/Textures/Material.h @@ -132,7 +132,7 @@ namespace Nuake { if (j.contains("Path")) { - this->Path = j["Path"]; + Path = FileSystem::RelativeToAbsolute(j["Path"]); if (FileSystem::FileExists(Path)) { std::string content = FileSystem::ReadFile(Path); @@ -143,37 +143,44 @@ namespace Nuake { if (j.contains("Albedo")) { - Ref albedoTexture = TextureManager::Get()->GetTexture(j["Albedo"]["Path"]); + const auto& texturePath = j["Albedo"]["Path"]; + const std::string absolutePath = FileSystem::RelativeToAbsolute(texturePath); + Ref albedoTexture = TextureManager::Get()->GetTexture(absolutePath); SetAlbedo(albedoTexture); } if (j.contains("Normal")) { - Ref normalTexture = TextureManager::Get()->GetTexture(j["Normal"]["Path"]); + const std::string absolutePath = FileSystem::RelativeToAbsolute(j["Normal"]["Path"]); + Ref normalTexture = TextureManager::Get()->GetTexture(absolutePath); SetMetalness(normalTexture); } if (j.contains("AO")) { - Ref aoTexture = TextureManager::Get()->GetTexture(j["AO"]["Path"]); + const std::string absolutePath = FileSystem::RelativeToAbsolute(j["AO"]["Path"]); + Ref aoTexture = TextureManager::Get()->GetTexture(absolutePath); SetAO(aoTexture); } if (j.contains("Metalness")) { - Ref metalTexture = TextureManager::Get()->GetTexture(j["Metalness"]["Path"]); + const std::string absolutePath = FileSystem::RelativeToAbsolute(j["Metalness"]["Path"]); + Ref metalTexture = TextureManager::Get()->GetTexture(absolutePath); SetMetalness(metalTexture); } if (j.contains("Roughness")) { - Ref metalTexture = TextureManager::Get()->GetTexture(j["Roughness"]["Path"]); + const std::string absolutePath = FileSystem::RelativeToAbsolute(j["Roughness"]["Path"]); + Ref metalTexture = TextureManager::Get()->GetTexture(absolutePath); SetRoughness(metalTexture); } if (j.contains("Displacement")) { - Ref displacementTexture = TextureManager::Get()->GetTexture(j["Displacement"]["Path"]); + const std::string absolutePath = FileSystem::RelativeToAbsolute(j["Normal"]["Path"]); + Ref displacementTexture = TextureManager::Get()->GetTexture(absolutePath); SetDisplacement(displacementTexture); } } diff --git a/Nuake/src/Rendering/Textures/Texture.cpp b/Nuake/src/Rendering/Textures/Texture.cpp index 3a793c42..15dfc212 100644 --- a/Nuake/src/Rendering/Textures/Texture.cpp +++ b/Nuake/src/Rendering/Textures/Texture.cpp @@ -155,4 +155,18 @@ namespace Nuake glTextureParameteri(GL_TEXTURE_2D, param, value); Unbind(); } + + json Texture::Serialize() + { + BEGIN_SERIALIZE(); + const std::string& relativePath = FileSystem::AbsoluteToRelative(m_FilePath); + j["Path"] = relativePath; + END_SERIALIZE(); + } + + bool Texture::Deserialize(const json& j) + { + if (j.contains("Path")) + return false; + } } diff --git a/Nuake/src/Rendering/Textures/Texture.h b/Nuake/src/Rendering/Textures/Texture.h index c24d7dfc..5654da0b 100644 --- a/Nuake/src/Rendering/Textures/Texture.h +++ b/Nuake/src/Rendering/Textures/Texture.h @@ -1,11 +1,14 @@ #pragma once -#include "stb_image/stb_image.h" -#include #include "src/Core/Maths.h" -#include "msdfgen/core/BitmapRef.hpp" #include "src/Resource/Serializable.h" +#include "stb_image/stb_image.h" +#include "msdfgen/core/BitmapRef.hpp" + +#include + + namespace Nuake { typedef unsigned int GLenum; @@ -45,19 +48,7 @@ namespace Nuake inline int GetHeight() const { return m_Height; } inline Vector2 GetSize() const { return Vector2(m_Width, m_Height); } - json Serialize() override - { - BEGIN_SERIALIZE(); - j["Path"] = this->m_FilePath; - END_SERIALIZE(); - } - - bool Deserialize(const json& j) override - { - if (j.contains("Path")) - return false; - - - } + json Serialize() override; + bool Deserialize(const json& j) override; }; } diff --git a/NuakeRuntime/Runtime.cpp b/NuakeRuntime/Runtime.cpp new file mode 100644 index 00000000..22fad402 --- /dev/null +++ b/NuakeRuntime/Runtime.cpp @@ -0,0 +1,61 @@ +#include + +#include +#include + +#include + +void main(int argc, char* argv[]) +{ + using namespace Nuake; + + Engine::Init(); + + auto window = Nuake::Engine::GetCurrentWindow(); + + const std::string projectPath = "./game.project"; + FileSystem::SetRootDirectory(FileSystem::GetParentPath(projectPath)); + + Ref project = Nuake::Project::New(); + project->FullPath = projectPath; + project->Deserialize(json::parse(FileSystem::ReadFile(projectPath, true))); + + window->SetTitle(project->Name); + + Nuake::Engine::LoadProject(project); + Nuake::Engine::EnterPlayMode(); + + while (!window->ShouldClose()) + { + Nuake::Engine::Tick(); + Engine::Draw(); + + const auto& WindowSize = window->GetSize(); + glViewport(0, 0, WindowSize.x, WindowSize.y); + Nuake::Renderer2D::BeginDraw(WindowSize); + + ImGuiViewport* viewport = ImGui::GetMainViewport(); + ImGui::SetNextWindowPos(viewport->Pos); + ImGui::SetNextWindowSize(viewport->Size); + ImGui::SetNextWindowViewport(viewport->ID); + + const auto& windowSize = Vector2(viewport->Size.x, viewport->Size.y); + Ref framebuffer = Engine::GetCurrentWindow()->GetFrameBuffer(); + if (framebuffer->GetSize() != windowSize) + { + framebuffer->QueueResize(windowSize); + } + + ImGui::PushStyleVar(ImGuiStyleVar_WindowRounding, 0.0f); + + ImGui::Begin("Game", 0, ImGuiWindowFlags_NoDecoration | ImGuiWindowFlags_NoResize); + { + ImGui::Image((void*)Window::Get()->GetFrameBuffer()->GetTexture()->GetID(), ImGui::GetContentRegionAvail(), ImVec2(0, 1), ImVec2(1, 0)); + } + ImGui::End(); + + ImGui::PopStyleVar(); + + Engine::EndDraw(); + } +} diff --git a/Runtime/Runtime.cpp b/Runtime/Runtime.cpp new file mode 100644 index 00000000..7b1bce05 --- /dev/null +++ b/Runtime/Runtime.cpp @@ -0,0 +1,83 @@ +#include + +#include +#include + +#include + +void main(int argc, char* argv[]) +{ + using namespace Nuake; + + Engine::Init(); + + auto window = Nuake::Engine::GetCurrentWindow(); + + const std::string projectPath = "./game.project"; + FileSystem::SetRootDirectory(FileSystem::GetParentPath(projectPath)); + + Ref project = Nuake::Project::New(); + project->FullPath = projectPath; + + if (!FileSystem::FileExists(projectPath)) + { + Logger::Log("game.project not found", "runtime", CRITICAL); + return; + } + + const std::string& projectfileContent = FileSystem::ReadFile(projectPath, true); + if (projectfileContent.empty()) + { + Logger::Log("game.project was empty", "runtime", CRITICAL); + return; + } + + try + { + project->Deserialize(json::parse(projectfileContent)); + } + catch(...) + { + Logger::Log("Failed to deserialize project", "runtime", CRITICAL); + return; + } + + window->SetTitle(project->Name); + + Nuake::Engine::LoadProject(project); + Nuake::Engine::EnterPlayMode(); + + while (!window->ShouldClose()) + { + Nuake::Engine::Tick(); + Engine::Draw(); + + const auto& WindowSize = window->GetSize(); + glViewport(0, 0, WindowSize.x, WindowSize.y); + Nuake::Renderer2D::BeginDraw(WindowSize); + + ImGuiViewport* viewport = ImGui::GetMainViewport(); + ImGui::SetNextWindowPos(viewport->Pos); + ImGui::SetNextWindowSize(viewport->Size); + ImGui::SetNextWindowViewport(viewport->ID); + + const auto& windowSize = Vector2(viewport->Size.x, viewport->Size.y); + Ref framebuffer = Engine::GetCurrentWindow()->GetFrameBuffer(); + if (framebuffer->GetSize() != windowSize) + { + framebuffer->QueueResize(windowSize); + } + + ImGui::PushStyleVar(ImGuiStyleVar_WindowRounding, 0.0f); + ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, { 0, 0 }); + ImGui::Begin("Game", 0, ImGuiWindowFlags_NoDecoration | ImGuiWindowFlags_NoResize); + { + ImGui::Image((void*)Window::Get()->GetFrameBuffer()->GetTexture()->GetID(), ImGui::GetContentRegionAvail(), ImVec2(0, 1), ImVec2(1, 0)); + } + ImGui::End(); + + ImGui::PopStyleVar(2); + + Engine::EndDraw(); + } +} diff --git a/premake5.lua b/premake5.lua index bdd5b314..31c388ce 100644 --- a/premake5.lua +++ b/premake5.lua @@ -82,7 +82,7 @@ project "Nuake" optimize "on" project "NuakeRuntime" - location "Editor" + location "Runtime" kind "ConsoleApp" language "C++" @@ -92,7 +92,7 @@ project "NuakeRuntime" files { - "Editor/Runtime.cpp" + "Runtime/Runtime.cpp" } includedirs From 63cd8c7d5a394eafb0f00f772ec86fedb8d4db4c Mon Sep 17 00:00:00 2001 From: Antoine Pilote Date: Tue, 8 Aug 2023 14:35:41 -0400 Subject: [PATCH 5/5] Removed extra file --- NuakeRuntime/Runtime.cpp | 61 ---------------------------------------- 1 file changed, 61 deletions(-) delete mode 100644 NuakeRuntime/Runtime.cpp diff --git a/NuakeRuntime/Runtime.cpp b/NuakeRuntime/Runtime.cpp deleted file mode 100644 index 22fad402..00000000 --- a/NuakeRuntime/Runtime.cpp +++ /dev/null @@ -1,61 +0,0 @@ -#include - -#include -#include - -#include - -void main(int argc, char* argv[]) -{ - using namespace Nuake; - - Engine::Init(); - - auto window = Nuake::Engine::GetCurrentWindow(); - - const std::string projectPath = "./game.project"; - FileSystem::SetRootDirectory(FileSystem::GetParentPath(projectPath)); - - Ref project = Nuake::Project::New(); - project->FullPath = projectPath; - project->Deserialize(json::parse(FileSystem::ReadFile(projectPath, true))); - - window->SetTitle(project->Name); - - Nuake::Engine::LoadProject(project); - Nuake::Engine::EnterPlayMode(); - - while (!window->ShouldClose()) - { - Nuake::Engine::Tick(); - Engine::Draw(); - - const auto& WindowSize = window->GetSize(); - glViewport(0, 0, WindowSize.x, WindowSize.y); - Nuake::Renderer2D::BeginDraw(WindowSize); - - ImGuiViewport* viewport = ImGui::GetMainViewport(); - ImGui::SetNextWindowPos(viewport->Pos); - ImGui::SetNextWindowSize(viewport->Size); - ImGui::SetNextWindowViewport(viewport->ID); - - const auto& windowSize = Vector2(viewport->Size.x, viewport->Size.y); - Ref framebuffer = Engine::GetCurrentWindow()->GetFrameBuffer(); - if (framebuffer->GetSize() != windowSize) - { - framebuffer->QueueResize(windowSize); - } - - ImGui::PushStyleVar(ImGuiStyleVar_WindowRounding, 0.0f); - - ImGui::Begin("Game", 0, ImGuiWindowFlags_NoDecoration | ImGuiWindowFlags_NoResize); - { - ImGui::Image((void*)Window::Get()->GetFrameBuffer()->GetTexture()->GetID(), ImGui::GetContentRegionAvail(), ImVec2(0, 1), ImVec2(1, 0)); - } - ImGui::End(); - - ImGui::PopStyleVar(); - - Engine::EndDraw(); - } -}