Runtime now working

This commit is contained in:
Antoine Pilote
2023-08-08 14:24:17 -04:00
parent 88bf953102
commit 35940b3356
9 changed files with 188 additions and 72 deletions

View File

@@ -1,46 +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");
Ref<Scene> 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();
}
}

View File

@@ -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);

View File

@@ -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);

View File

@@ -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);
}
}

View File

@@ -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;
}
}

View File

@@ -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;
};
}

61
NuakeRuntime/Runtime.cpp Normal file
View File

@@ -0,0 +1,61 @@
#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;
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> 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();
}
}

83
Runtime/Runtime.cpp Normal file
View 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();
}
}

View File

@@ -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