mirror of
https://github.com/antopilo/Nuake.git
synced 2026-09-09 20:08:57 +03:00
Merge pull request #58 from antopilo/feature/NK-138-nuake-runtime
Feature/NK-138 Nuake runtime
This commit is contained in:
@@ -33,7 +33,6 @@
|
||||
#include <src/Rendering/SceneRenderer.h>
|
||||
|
||||
|
||||
|
||||
const std::string WindowTitle = "Nuake Editor";
|
||||
|
||||
int main(int argc, char* argv[])
|
||||
|
||||
@@ -1,42 +0,0 @@
|
||||
#include <Engine.h>
|
||||
#include <src/Rendering/SceneRenderer.h>
|
||||
|
||||
#include <dependencies/GLEW/include/GL/glew.h>
|
||||
#include <dependencies/glfw/include/GLFW/glfw3.h>
|
||||
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
|
||||
/*
|
||||
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();
|
||||
}
|
||||
}*/
|
||||
@@ -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);
|
||||
|
||||
@@ -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<Directory> GetFileTree();
|
||||
static Ref<File> GetFile(const std::string& path);
|
||||
|
||||
@@ -7,8 +7,8 @@
|
||||
|
||||
namespace Nuake
|
||||
{
|
||||
|
||||
class ShaderManager {
|
||||
class ShaderManager
|
||||
{
|
||||
private:
|
||||
static std::map<std::string, Scope<Shader>> m_Shaders;
|
||||
|
||||
|
||||
@@ -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<Texture> albedoTexture = TextureManager::Get()->GetTexture(j["Albedo"]["Path"]);
|
||||
const auto& texturePath = j["Albedo"]["Path"];
|
||||
const std::string absolutePath = FileSystem::RelativeToAbsolute(texturePath);
|
||||
Ref<Texture> albedoTexture = TextureManager::Get()->GetTexture(absolutePath);
|
||||
SetAlbedo(albedoTexture);
|
||||
}
|
||||
|
||||
if (j.contains("Normal"))
|
||||
{
|
||||
Ref<Texture> normalTexture = TextureManager::Get()->GetTexture(j["Normal"]["Path"]);
|
||||
const std::string absolutePath = FileSystem::RelativeToAbsolute(j["Normal"]["Path"]);
|
||||
Ref<Texture> normalTexture = TextureManager::Get()->GetTexture(absolutePath);
|
||||
SetMetalness(normalTexture);
|
||||
}
|
||||
|
||||
if (j.contains("AO"))
|
||||
{
|
||||
Ref<Texture> aoTexture = TextureManager::Get()->GetTexture(j["AO"]["Path"]);
|
||||
const std::string absolutePath = FileSystem::RelativeToAbsolute(j["AO"]["Path"]);
|
||||
Ref<Texture> aoTexture = TextureManager::Get()->GetTexture(absolutePath);
|
||||
SetAO(aoTexture);
|
||||
}
|
||||
|
||||
if (j.contains("Metalness"))
|
||||
{
|
||||
Ref<Texture> metalTexture = TextureManager::Get()->GetTexture(j["Metalness"]["Path"]);
|
||||
const std::string absolutePath = FileSystem::RelativeToAbsolute(j["Metalness"]["Path"]);
|
||||
Ref<Texture> metalTexture = TextureManager::Get()->GetTexture(absolutePath);
|
||||
SetMetalness(metalTexture);
|
||||
}
|
||||
|
||||
if (j.contains("Roughness"))
|
||||
{
|
||||
Ref<Texture> metalTexture = TextureManager::Get()->GetTexture(j["Roughness"]["Path"]);
|
||||
const std::string absolutePath = FileSystem::RelativeToAbsolute(j["Roughness"]["Path"]);
|
||||
Ref<Texture> metalTexture = TextureManager::Get()->GetTexture(absolutePath);
|
||||
SetRoughness(metalTexture);
|
||||
}
|
||||
|
||||
if (j.contains("Displacement"))
|
||||
{
|
||||
Ref<Texture> displacementTexture = TextureManager::Get()->GetTexture(j["Displacement"]["Path"]);
|
||||
const std::string absolutePath = FileSystem::RelativeToAbsolute(j["Normal"]["Path"]);
|
||||
Ref<Texture> displacementTexture = TextureManager::Get()->GetTexture(absolutePath);
|
||||
SetDisplacement(displacementTexture);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,11 +1,14 @@
|
||||
#pragma once
|
||||
|
||||
#include "stb_image/stb_image.h"
|
||||
#include <string>
|
||||
#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 <string>
|
||||
|
||||
|
||||
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;
|
||||
};
|
||||
}
|
||||
|
||||
83
Runtime/Runtime.cpp
Normal file
83
Runtime/Runtime.cpp
Normal file
@@ -0,0 +1,83 @@
|
||||
#include <Engine.h>
|
||||
|
||||
#include <dependencies/GLEW/include/GL/glew.h>
|
||||
#include <src/Vendors/imgui/imgui.h>
|
||||
|
||||
#include <string>
|
||||
|
||||
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<Nuake::Project> 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> 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();
|
||||
}
|
||||
}
|
||||
71
premake5.lua
71
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"
|
||||
|
||||
Reference in New Issue
Block a user