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