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 deleted file mode 100644 index 97f5d50f..00000000 --- a/Editor/Runtime.cpp +++ /dev/null @@ -1,42 +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"); - - 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(); - - Nuake::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/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/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/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 73cfe316..31c388ce 100644 --- a/premake5.lua +++ b/premake5.lua @@ -81,6 +81,77 @@ project "Nuake" runtime "Release" optimize "on" +project "NuakeRuntime" + location "Runtime" + kind "ConsoleApp" + language "C++" + + targetdir ("bin/" .. outputdir .. "/%{prj.name}") + objdir ("bin-int/" .. outputdir .. "/%{prj.name}") + debugdir ("Editor") + + files + { + "Runtime/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"