Merge pull request #23 from antopilo/cleanup/code-autoformatting

Cleanup/code autoformatting
This commit is contained in:
Antoine Pilote
2023-07-10 16:01:36 -04:00
committed by GitHub
27 changed files with 412 additions and 399 deletions

View File

@@ -1,6 +1,5 @@
#include <Engine.h>
#include <src/Core/Maths.h>
#include <src/Core/Input.h>
#include <src/Scene/Scene.h>
#include <src/Scene/Entities/Entity.h>
@@ -28,6 +27,8 @@
#include "src/Misc/GizmoDrawer.h"
#include "src/Windows/FileSystemUI.h"
#include <src/Core/Maths.h>
const std::string WindowTitle = "Nuake Editor";
int main(int argc, char* argv[])
@@ -183,7 +184,7 @@ int main(int argc, char* argv[])
camera = currentScene->m_EditorCamera;
}
if (currentScene && !Nuake::Engine::IsPlayMode && editor.ShouldDrawAxis())
if (currentScene && !Nuake::Engine::IsPlayMode() && editor.ShouldDrawAxis())
{
gizmoDrawer.DrawGizmos(currentScene);
}

View File

@@ -94,7 +94,7 @@ namespace Nuake {
float needed = half - used;
ImGui::PushStyleVar(ImGuiStyleVar_ItemSpacing, ImVec2(0, 0));
if (ImGui::Button(ICON_FA_PLAY, ImVec2(30, 30)) || (Input::IsKeyPressed(GLFW_KEY_F5) && !Engine::IsPlayMode))
if (ImGui::Button(ICON_FA_PLAY, ImVec2(30, 30)) || (Input::IsKeyPressed(GLFW_KEY_F5) && !Engine::IsPlayMode()))
{
SceneSnapshot = Engine::GetCurrentScene()->Copy();
Engine::EnterPlayMode();
@@ -172,14 +172,14 @@ namespace Nuake {
ImGuizmo::AllowAxisFlip(true);
ImGuizmo::SetRect(imagePos.x + 8.0, imagePos.y + 30.0, viewportPanelSize.x, viewportPanelSize.y);
if (m_DrawGrid && !Engine::IsPlayMode)
if (m_DrawGrid && !Engine::IsPlayMode())
{
ImGuizmo::DrawGrid(glm::value_ptr(Engine::GetCurrentScene()->GetCurrentCamera()->GetTransform()),
glm::value_ptr(Engine::GetCurrentScene()->GetCurrentCamera()->GetPerspective()),
glm::value_ptr(glm::identity<glm::mat4>()), 100.f);
}
if (Selection.Type == EditorSelectionType::Entity && !Engine::IsPlayMode)
if (Selection.Type == EditorSelectionType::Entity && !Engine::IsPlayMode())
{
TransformComponent& tc = Selection.Entity.GetComponent<TransformComponent>();
ParentComponent& parent = Selection.Entity.GetComponent<ParentComponent>();
@@ -1498,7 +1498,7 @@ namespace Nuake {
void EditorInterface::Update(float ts)
{
if (!Engine::GetCurrentScene() || Engine::IsPlayMode)
if (!Engine::GetCurrentScene() || Engine::IsPlayMode())
{
return;
}

View File

@@ -15,16 +15,16 @@
namespace Nuake
{
Ref<Project> Engine::CurrentProject;
Ref<Window> Engine::CurrentWindow;
Ref<Project> Engine::s_CurrentProject;
Ref<Window> Engine::s_CurrentWindow;
float Engine::m_LastFrameTime = 0.0f;
float Engine::m_FixedUpdateRate = 1.0f / 90.0f;
float Engine::m_FixedUpdateDifference = 0.f;
float Engine::m_Time = 0.f;
Timestep Engine::m_TimeStep = 0.f;
bool Engine::s_IsPlayMode = false;
bool Engine::IsPlayMode = false;
float Engine::s_LastFrameTime = 0.0f;
float Engine::s_FixedUpdateRate = 1.0f / 90.0f;
float Engine::s_FixedUpdateDifference = 0.f;
float Engine::s_Time = 0.f;
Timestep Engine::s_TimeStep = 0.f;
void Engine::Init()
{
@@ -39,7 +39,7 @@ namespace Nuake
Logger::Log("Physics initialized");
// Creates the window
CurrentWindow = Window::Get();
s_CurrentWindow = Window::Get();
Logger::Log("Window initialized");
Input::Init();
@@ -52,33 +52,33 @@ namespace Nuake
void Engine::Tick()
{
m_Time = (float)glfwGetTime();
m_TimeStep = m_Time - m_LastFrameTime;
m_LastFrameTime = m_Time;
s_Time = (float)glfwGetTime();
s_TimeStep = s_Time - s_LastFrameTime;
s_LastFrameTime = s_Time;
m_TimeStep = std::min((float)m_TimeStep, 0.5f);
s_TimeStep = std::min((float)s_TimeStep, 0.5f);
// Dont update if no scene is loaded.
if (CurrentWindow->GetScene())
if (s_CurrentWindow->GetScene())
{
CurrentWindow->Update(m_TimeStep);
s_CurrentWindow->Update(s_TimeStep);
// Play mode update all the entities, Editor does not.
if (Engine::IsPlayMode)
if (Engine::IsPlayMode())
{
m_FixedUpdateDifference += m_TimeStep;
s_FixedUpdateDifference += s_TimeStep;
// Fixed update
while (m_FixedUpdateDifference >= m_FixedUpdateRate)
while (s_FixedUpdateDifference >= s_FixedUpdateRate)
{
CurrentWindow->FixedUpdate(m_FixedUpdateDifference);
s_CurrentWindow->FixedUpdate(s_FixedUpdateDifference);
m_FixedUpdateDifference -= m_FixedUpdateRate;
s_FixedUpdateDifference -= s_FixedUpdateRate;
}
}
else
{
GetCurrentScene()->EditorUpdate(m_TimeStep);
GetCurrentScene()->EditorUpdate(s_TimeStep);
}
}
@@ -88,7 +88,7 @@ namespace Nuake
void Engine::EnterPlayMode()
{
// Dont trigger init if already in player mode.
if (IsPlayMode)
if (IsPlayMode())
{
Logger::Log("Cannot enter play mode if is already in play mode.", WARNING);
return;
@@ -96,7 +96,7 @@ namespace Nuake
if (GetCurrentScene()->OnInit())
{
IsPlayMode = true;
s_IsPlayMode = true;
}
else
{
@@ -108,11 +108,11 @@ namespace Nuake
void Engine::ExitPlayMode()
{
// Dont trigger exit if already not in play mode.
if (IsPlayMode)
if (IsPlayMode())
{
GetCurrentScene()->OnExit();
Input::ShowMouse();
IsPlayMode = false;
s_IsPlayMode = false;
}
}
@@ -141,24 +141,24 @@ namespace Nuake
Ref<Scene> Engine::GetCurrentScene()
{
return CurrentWindow->GetScene();
return s_CurrentWindow->GetScene();
}
bool Engine::LoadScene(Ref<Scene> scene)
{
return CurrentWindow->SetScene(scene);
return s_CurrentWindow->SetScene(scene);
}
Ref<Project> Engine::GetProject()
{
return CurrentProject;
return s_CurrentProject;
}
bool Engine::LoadProject(Ref<Project> project)
{
CurrentProject = project;
s_CurrentProject = project;
if (!Engine::LoadScene(CurrentProject->DefaultScene))
if (!Engine::LoadScene(s_CurrentProject->DefaultScene))
{
return false;
}
@@ -169,6 +169,6 @@ namespace Nuake
Ref<Window> Engine::GetCurrentWindow()
{
return CurrentWindow;
return s_CurrentWindow;
}
}

View File

@@ -17,20 +17,22 @@
// Welcome to the Nuake source code.
namespace Nuake
{
class Engine {
class Engine
{
private:
static Ref<Window> CurrentWindow;
static Ref<Project> CurrentProject;
static Ref<Scene> CurrentScene;
static Ref<Window> s_CurrentWindow;
static Ref<Project> s_CurrentProject;
static Ref<Scene> s_CurrentScene;
static bool s_IsPlayMode;
static float s_LastFrameTime;
static float s_FixedUpdateRate;
static float s_FixedUpdateDifference;
static float s_Time;
static Timestep s_TimeStep;
static float m_LastFrameTime;
static float m_FixedUpdateRate;
static float m_FixedUpdateDifference;
static float m_Time;
static Timestep m_TimeStep;
public:
static bool IsPlayMode; // Is currently in runtime..
static void Init(); // Initialize the engine.
static void Tick(); // Updates everything, called everyframe.
static void Close(); // Shutdown the engine.
@@ -41,8 +43,12 @@ namespace Nuake
// Custom drawing should happen in between these two
static void Draw(); // Start new frame
static void EndDraw(); // Swap buffer
static inline float GetTime() { return m_Time; }
static inline Timestep GetTimestep() { return m_TimeStep; }
static bool IsPlayMode() { return s_IsPlayMode; }
static inline float GetTime() { return s_Time; }
static inline Timestep GetTimestep() { return s_TimeStep; }
static Ref<Window> GetCurrentWindow();
static bool LoadScene(Ref<Scene> scene);

View File

@@ -1,10 +1,11 @@
#pragma once
#include "Core.h"
#include "String.h"
#include <string>
#include <filesystem>
#include "Core.h"
#include <iostream>
#include <fstream>
#include "String.h"
namespace Nuake
{

View File

@@ -1,5 +1,5 @@
#include "Input.h"
#include "../Window.h"
#include "src/Window.h"
#include <Imgui/imgui_impl_glfw.h>
#include <GLFW/glfw3.h>

View File

@@ -1,7 +1,8 @@
#pragma once
#include <utility>
#include "../Core/Maths.h"
#include "src/Core/Maths.h"
#include <map>
#include <utility>
struct GLFWwindow;

View File

@@ -1,4 +1,5 @@
#include "Logger.h"
#include <iostream>
#include <chrono>
#include <string>
@@ -6,7 +7,7 @@
namespace Nuake
{
std::vector<LogEntry> Logger::m_Logs = std::vector<LogEntry>();
std::vector<LogEntry> Logger::m_Logs = std::vector<LogEntry>();
void Logger::Log(const std::string& log, LOG_TYPE type)
{

View File

@@ -20,11 +20,12 @@ namespace Nuake
class Logger
{
public:
static void Log(const std::string& log, LOG_TYPE type = VERBOSE);
static std::vector<LogEntry> GetLogs();
private:
static const int MAX_LOG = 64;
static std::vector<LogEntry> m_Logs;
public:
static void Log(const std::string& log, LOG_TYPE type = VERBOSE);
static std::vector<LogEntry> GetLogs();
};
}

View File

@@ -2,11 +2,14 @@
#include <iostream>
#include <sstream>
namespace Nuake {
namespace Nuake
{
bool String::BeginsWith(const std::string& string, const std::string& begin)
{
if (string.rfind(begin, 0) == 0)
{
return true;
}
return false;
}
@@ -14,9 +17,11 @@ namespace Nuake {
bool String::EndsWith(const std::string& string, const std::string& end)
{
if (string.length() >= end.length())
{
return (0 == string.compare(string.length() - end.length(), end.length(), end));
else
return false;
}
return false;
}
bool String::IsDigit(const char& character)

View File

@@ -6,8 +6,10 @@
This class purpose is to provide helper methods related to strings.
It is not meant to be a replacement for std::string.
*/
namespace Nuake {
class String {
namespace Nuake
{
class String
{
public:
static bool BeginsWith(const std::string& string, const std::string& begin);
static bool EndsWith(const std::string& string, const std::string& end);

View File

@@ -2,7 +2,8 @@
namespace Nuake
{
class Timestep {
class Timestep
{
private:
float m_Time;

View File

@@ -2,23 +2,24 @@
#include <cstdint>
#include <xhash>
namespace Nuake {
namespace Nuake
{
class UUID
{
private:
uint64_t m_UUID;
public:
UUID();
UUID(uint64_t uuid);
UUID(const UUID&) = default;
operator uint64_t() const { return m_UUID; }
private:
uint64_t m_UUID;
};
}
namespace std {
namespace std
{
template<>
struct hash<Nuake::UUID>
{

View File

@@ -1,8 +1,10 @@
#pragma once
#include "src/Scripting/WrenScript.h"
#include "src/Resource/Serializable.h"
#include "src/Core/FileSystem.h"
namespace Nuake {
namespace Nuake
{
class WrenScriptComponent
{
public:

View File

@@ -244,7 +244,7 @@ namespace Nuake {
Ref<Camera> Scene::GetCurrentCamera()
{
if (Engine::IsPlayMode)
if (Engine::IsPlayMode())
{
Ref<Camera> cam = nullptr;
{

View File

@@ -1,5 +1,4 @@
#pragma once
#include <vector>
#include "src/Core/Core.h"
#include "src/Core/Maths.h"
@@ -15,9 +14,9 @@
#include "src/Scene/Systems/System.h"
#include "src/Resource/UUID.h"
#include "src/Resource/Resource.h"
namespace Nuake {
namespace Nuake
{
class Entity;
class SceneRenderer;

View File

@@ -50,8 +50,10 @@ namespace Nuake
void PhysicsSystem::Update(Timestep ts)
{
if (!Engine::IsPlayMode)
if (!Engine::IsPlayMode())
{
return;
}
auto brushes = m_Scene->m_Registry.view<TransformComponent, BSPBrushComponent>();
for (auto e : brushes)
@@ -114,7 +116,7 @@ namespace Nuake
void PhysicsSystem::FixedUpdate(Timestep ts)
{
if (!Engine::IsPlayMode)
if (!Engine::IsPlayMode())
return;
PhysicsManager::Get().Step(ts);

View File

@@ -40,7 +40,7 @@ namespace Nuake {
void ScriptingSystem::Update(Timestep ts)
{
if (!Engine::IsPlayMode)
if (!Engine::IsPlayMode())
return;
auto entities = m_Scene->m_Registry.view<WrenScriptComponent>();

View File

@@ -115,7 +115,7 @@ namespace Nuake {
if (ent.HasComponent<WrenScriptComponent>())
{
wrenSetSlotHandle(vm, 0, ent.GetComponent<WrenScriptComponent>().mWrenScript->m_Instance);
wrenSetSlotHandle(vm, 0, ent.GetComponent<WrenScriptComponent>().mWrenScript->GetWrenInstanceHandle());
}
}

View File

@@ -1,12 +1,13 @@
#include "ScriptingEngine.h"
#include "WrenScript.h"
#include "../Core/FileSystem.h"
#include <src/Scripting/Modules/ScriptModule.h>
#include <src/Scripting/Modules/EngineModule.h>
#include <src/Scripting/Modules/SceneModule.h>
#include <src/Scripting/Modules/MathModule.h>
#include <src/Scripting/Modules/InputModule.h>
#include <src/Scripting/Modules/PhysicsModule.h>
#include "src/Core/FileSystem.h"
#include "src/Scripting/Modules/ScriptModule.h"
#include "src/Scripting/Modules/EngineModule.h"
#include "src/Scripting/Modules/SceneModule.h"
#include "src/Scripting/Modules/MathModule.h"
#include "src/Scripting/Modules/InputModule.h"
#include "src/Scripting/Modules/PhysicsModule.h"
namespace Nuake {
WrenVM* ScriptingEngine::m_WrenVM;
@@ -161,7 +162,6 @@ namespace Nuake {
config.errorFn = &errorFn;
config.writeFn = &writeFn;
config.bindForeignMethodFn = &bindForeignMethod;
m_WrenVM = wrenNewVM(&config);
Logger::Log("Registing Scripting Modules");

View File

@@ -1,15 +1,18 @@
#pragma once
#include "src/Core/Core.h"
#include "src/Core/Timestep.h"
#include <string>
#include <vector>
#include <map>
#include "src/Core/Core.h"
#include "src/Vendors/wren/src/include/wren.hpp"
#include "src/Core/Timestep.h"
namespace Nuake
{
class WrenScript;
class ScriptModule;
class ScriptingEngine
{
private:
@@ -18,7 +21,12 @@ namespace Nuake
static std::vector<std::string> m_LoadedScripts;
static std::map<std::string, Ref<WrenScript>> m_Scripts;
static std::map<std::string, Ref<ScriptModule>> Modules;
public:
static void Init();
static void RunCode(const std::string& code);
static void Close();
static Ref<WrenScript> RegisterScript(const std::string& path, const std::string& mod);
static bool IsScriptImported(const std::string& path);
static void ImportScript(const std::string& path);
@@ -26,11 +34,6 @@ namespace Nuake
static void InitScript(Ref<WrenScript> script);
static void UpdateScript(Ref<WrenScript> script, Timestep timestep);
static void ExitScript(Ref<WrenScript> script);
static void Init();
static void RunCode(const std::string& code);
static void Close();
static WrenForeignMethodFn bindForeignMethod(
WrenVM* vm,

View File

@@ -1,16 +0,0 @@
#include "VM.h"
namespace Nuake {
VM::VM()
{
WrenConfiguration config;
wrenInitConfiguration(&config);
//config.loadModuleFn = &myLoadModule;
//config.errorFn = &errorFn;
//config.writeFn = &writeFn;
//config.bindForeignMethodFn = &bindForeignMethod;
m_VM = wrenNewVM(&config);
}
}

View File

@@ -1,13 +0,0 @@
#pragma once
#include <src/Vendors/wren/src/include/wren.h>
namespace Nuake {
class VM
{
VM();
inline WrenVM* GetVM();
private:
WrenVM* m_VM;
};
}

View File

@@ -2,14 +2,16 @@
#include "src/Core/Logger.h"
#include "src/Core/String.h"
#include "src/Core/FileSystem.h"
#include <src/Vendors/wren/src/include/wren.h>
namespace Nuake {
WrenScript::WrenScript(Ref<File> file, bool isEntity)
namespace Nuake
{
WrenScript::WrenScript(Ref<File> file, bool isEntityScript)
{
mFile = file;
IsEntity = isEntity;
m_IsEntityScript = isEntityScript;
ParseModules();
}
@@ -30,45 +32,42 @@ namespace Nuake {
if (s == "class" && i + 1 < splits.size() && !hasFoundModule)
{
std::string moduleFound = splits[i + 1];
mModules.push_back(moduleFound);
m_Modules.push_back(moduleFound);
hasFoundModule = true;
}
}
}
// Close the file
MyReadFile.close();
}
std::vector<std::string> WrenScript::GetModules()
std::vector<std::string> WrenScript::GetModules() const
{
return mModules;
return m_Modules;
}
void WrenScript::Build(unsigned int moduleId, bool isEntity)
{
WrenVM* vm = ScriptingEngine::GetWrenVM();
std::string relativePath = mFile->GetRelativePath();
const std::string& relativePath = mFile->GetRelativePath();
// Can't import twice the same script, otherwise gives a compile error.
if (!ScriptingEngine::IsScriptImported(relativePath))
{
std::string source = "import \"" + relativePath + "\" for " + GetModules()[moduleId];
const std::string& source = "import \"" + relativePath + "\" for " + GetModules()[moduleId];
WrenInterpretResult result = wrenInterpret(vm, "main", source.c_str());
Logger::Log("Wren result: " + std::to_string(result));
if (result == WREN_RESULT_SUCCESS)
{
Logger::Log("Wren result success: " + std::to_string(result));
CompiledSuccesfully = true;
Logger::Log("[ScriptingEngine] Compiled succesfully: " + std::to_string(result));
m_HasCompiledSuccesfully = true;
ScriptingEngine::ImportScript(relativePath);
}
else
{
Logger::Log("Wren result failed: " + std::to_string(result));
CompiledSuccesfully = false;
Logger::Log("[ScriptingEngine] Compiled failed: " + std::to_string(result));
m_HasCompiledSuccesfully = false;
return;
}
}
@@ -94,12 +93,12 @@ namespace Nuake {
if (isEntity)
this->m_SetEntityIDHandle = wrenMakeCallHandle(vm, "SetEntityId(_)");
CompiledSuccesfully = true;
m_HasCompiledSuccesfully = true;
}
void WrenScript::CallInit()
{
if (!CompiledSuccesfully) return;
if (!m_HasCompiledSuccesfully) return;
WrenVM* vm = ScriptingEngine::GetWrenVM();
wrenSetSlotHandle(vm, 0, this->m_Instance);
@@ -108,7 +107,7 @@ namespace Nuake {
void WrenScript::CallUpdate(float timestep)
{
if (!CompiledSuccesfully) return;
if (!m_HasCompiledSuccesfully) return;
WrenVM* vm = ScriptingEngine::GetWrenVM();
wrenEnsureSlots(vm, 2);
@@ -119,7 +118,7 @@ namespace Nuake {
void WrenScript::CallFixedUpdate(float timestep)
{
if (!CompiledSuccesfully) return;
if (!m_HasCompiledSuccesfully) return;
WrenVM* vm = ScriptingEngine::GetWrenVM();
wrenEnsureSlots(vm, 2);
@@ -130,7 +129,7 @@ namespace Nuake {
void WrenScript::CallExit()
{
if (!CompiledSuccesfully || !m_Instance)
if (!m_HasCompiledSuccesfully || !m_Instance)
return;
WrenVM* vm = ScriptingEngine::GetWrenVM();
@@ -141,7 +140,7 @@ namespace Nuake {
void WrenScript::RegisterMethod(const std::string& signature)
{
if (!CompiledSuccesfully)
if (!m_HasCompiledSuccesfully)
return;
WrenVM* vm = ScriptingEngine::GetWrenVM();
@@ -151,7 +150,7 @@ namespace Nuake {
void WrenScript::CallMethod(const std::string& signature)
{
if (!CompiledSuccesfully)
if (!m_HasCompiledSuccesfully)
return;
WrenVM* vm = ScriptingEngine::GetWrenVM();
@@ -167,7 +166,7 @@ namespace Nuake {
void WrenScript::SetScriptableEntityID(int id)
{
if (!CompiledSuccesfully)
if (!m_HasCompiledSuccesfully)
return;
WrenVM* vm = ScriptingEngine::GetWrenVM();

View File

@@ -1,21 +1,21 @@
#pragma once
#include "ScriptingEngine.h"
#include "src/Core/FileSystem.h"
#include <map>
#include <string>
struct WrenHandle;
namespace Nuake {
namespace Nuake
{
class File;
class WrenScript
{
private:
bool CompiledSuccesfully;
bool IsEntity = false;
std::vector<std::string> mModules;
bool m_HasCompiledSuccesfully;
bool m_IsEntityScript = false;
std::vector<std::string> m_Modules;
public:
Ref<File> mFile;
std::map <std::string, WrenHandle*> methods;
@@ -26,12 +26,11 @@ namespace Nuake {
WrenHandle* m_OnExitHandle;
WrenHandle* m_SetEntityIDHandle;
// Building
WrenScript(Ref<File> file, bool isEntity);
public:
WrenScript(Ref<File> file, bool isEntityScript);
void ParseModules();
std::vector<std::string> GetModules();
void Build(unsigned int moduleId, bool isEntity = false);
void Build(unsigned int moduleId, bool isEntityScript = false);
// Method calls
void CallInit();
@@ -43,7 +42,10 @@ namespace Nuake {
void CallMethod(const std::string& signature);
void SetScriptableEntityID(int id);
bool HasCompiledSuccesfully() const { return m_HasCompiledSuccesfully; }
bool HasCompiledSuccesfully() { return CompiledSuccesfully; }
std::vector<std::string> GetModules() const;
WrenHandle* GetWrenInstanceHandle() const { return m_Instance; }
};
}

View File

@@ -1,49 +1,42 @@
#include <GL\glew.h>
#include "Window.h"
#include <GLFW/glfw3.h>
#include <iostream>
#include "Rendering/Shaders/Shader.h"
#include <imgui\imgui.h>
#include "Rendering/Renderer.h"
#include "Scene/Entities/Entity.h"
#include <imgui\imgui_impl_glfw.h>
#include <imgui\imgui_impl_opengl3.h>
#include "Scene/Entities/ImGuiHelper.h"
#include "Core/Physics/PhysicsManager.h"
#include "imgui/ImGuizmo.h"
#include <GL/glew.h>
#include <GLFW/glfw3.h>
#include "Engine.h"
#include "src/Core/Maths.h"
#include "src/Rendering/Renderer.h"
#include "src/Rendering/Buffers/Framebuffer.h"
#include "src/Scene/Scene.h"
#include <glm/gtc/type_ptr.hpp>
#include <glm/gtx/matrix_decompose.hpp>
#include "Resource/FontAwesome5.h"
#include "Engine.h"
#include <src/Scene/Components/InterfaceComponent.h>
namespace Nuake {
Ref<Window> Window::s_Instance;
#include <imgui/imgui.h>
#include <imgui/imgui_impl_glfw.h>
#include <imgui/imgui_impl_opengl3.h>
namespace Nuake
{
Window::Window()
{
m_Title = DEFAULT_TITLE;
m_Width = DEFAULT_WIDTH;
m_Height = DEFAULT_HEIGHT;
Init();
Renderer::Init();
}
Window::~Window() { }
Ref<Window> Window::Get()
{
if (s_Instance == nullptr)
s_Instance = CreateRef<Window>();
static Ref<Window> instance;
if (instance == nullptr)
{
instance = CreateRef<Window>();
}
return s_Instance;
}
bool Window::ShouldClose()
{
return glfwWindowShouldClose(m_Window);
return instance;
}
GLFWwindow* Window::GetHandle()
@@ -51,26 +44,118 @@ namespace Nuake {
return m_Window;
}
bool Window::SetScene(Ref<Scene> scene)
bool Window::ShouldClose()
{
m_Scene = scene;
return true;
return glfwWindowShouldClose(m_Window);
}
Ref<Scene> Window::GetScene()
int Window::Init()
{
return m_Scene;
if (!glfwInit())
{
Logger::Log("glfw initialization failed.", CRITICAL);
return -1;
}
m_Window = glfwCreateWindow(m_Width, m_Height, m_Title.c_str(), NULL, NULL);
if (!m_Window)
{
Logger::Log("Window creation failed.", CRITICAL);
return -1;
}
SetWindowIcon("resources/Images/nuake-logo.png");
glfwMakeContextCurrent(m_Window);
SetVSync(0);
Logger::Log((char*)glGetString(GL_VERSION));
if (glewInit() != GLEW_OK)
{
Logger::Log("GLEW initialization failed!", CRITICAL);
return -1;
}
// TODO: Move this to renderer init. The window shouldnt have to do gl calls.
glfwWindowHint(GLFW_SAMPLES, 4);
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE); // To make MacOS happy; should not be needed
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
// TODO: have clear color in environnement.
glClearColor(0.f, 0.f, 0.f, 1.0f);
glEnable(GL_TEXTURE_CUBE_MAP_SEAMLESS);
glEnable(GL_DEPTH_TEST);
glEnable(GL_MULTISAMPLE);
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
//glEnable(GL_CULL_FACE);
// Create viewports
m_Framebuffer = CreateRef<FrameBuffer>(true, glm::vec2(1920, 1080));
m_Framebuffer->SetTexture(CreateRef<Texture>(glm::vec2(1920, 1080), GL_RGB));
InitImgui();
return 0;
}
void Window::SetTitle(const std::string& title)
void Window::Update(Timestep ts)
{
m_Title = title;
glfwSetWindowTitle(m_Window, m_Title.c_str());
m_Scene->Update(ts);
}
std::string Window::GetTitle()
void Window::FixedUpdate(Timestep ts)
{
return m_Title;
m_Scene->FixedUpdate(ts);
}
void Window::Draw()
{
// Dont render if no scene is loaded.
if (!m_Scene)
{
return;
}
// Dont render if no cam is found.
Ref<Camera> cam = m_Scene->GetCurrentCamera();
if (!cam)
{
return;
}
// We cannot render to a framebuffer that is smaller than 1x1.
Vector2 size = m_Framebuffer->GetSize();
size.x = std::max(size.x, 1.0f);
size.y = std::max(size.y, 1.0f);
cam->AspectRatio = size.x / size.y;
m_Scene->m_EditorCamera->OnWindowResize(size.x, size.y);
if (Engine::IsPlayMode())
{
m_Scene->Draw(*m_Framebuffer.get());
}
else
{
m_Scene->Draw(*m_Framebuffer.get(), m_Scene->m_EditorCamera->GetPerspective(), m_Scene->m_EditorCamera->GetTransform());
}
glEnable(GL_DEPTH_TEST);
Renderer::EndDraw();
}
void Window::EndDraw()
{
ImGui::Render();
ImGui_ImplOpenGL3_RenderDrawData(ImGui::GetDrawData());
glfwSwapBuffers(m_Window);
glfwPollEvents();
}
Ref<FrameBuffer> Window::GetFrameBuffer() const
@@ -105,206 +190,128 @@ namespace Nuake {
}
}
int Window::Init()
Ref<Scene> Window::GetScene()
{
if (!glfwInit())
{
Logger::Log("glfw initialization failed.", CRITICAL);
return -1;
}
{ // Create window
m_Window = glfwCreateWindow(m_Width, m_Height, m_Title.c_str(), NULL, NULL);
if (!m_Window)
{
Logger::Log("Window creation failed.", CRITICAL);
return -1;
}
GLFWimage images[1];
images[0].pixels = stbi_load("resources/Images/nuake-logo.png", &images[0].width, &images[0].height, 0, 4); //rgba channels
glfwSetWindowIcon(m_Window, 1, images);
stbi_image_free(images[0].pixels);
glfwMakeContextCurrent(m_Window);
glfwSwapInterval(1);
Logger::Log((char*)glGetString(GL_VERSION));
if (glewInit() != GLEW_OK)
{
Logger::Log("GLEW initialization failed!", CRITICAL);
return -1;
}
// TODO: Move this to renderer init. The window shouldnt have to do gl calls.
glfwWindowHint(GLFW_SAMPLES, 4);
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE); // To make MacOS happy; should not be needed
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
// TODO: have clear color in environnement.
glClearColor(0.f, 0.f, 0.f, 1.0f);
glEnable(GL_TEXTURE_CUBE_MAP_SEAMLESS);
glEnable(GL_DEPTH_TEST);
glEnable(GL_MULTISAMPLE);
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
//glEnable(GL_CULL_FACE);
}
// Create viewports
m_Framebuffer = CreateRef<FrameBuffer>(true, glm::vec2(1920, 1080));
m_Framebuffer->SetTexture(CreateRef<Texture>(glm::vec2(1920, 1080), GL_RGB));
// ImGui init
{
ImGui::CreateContext();
ImGuiIO& io = ImGui::GetIO(); (void)io;
//io.Fonts->AddFontDefault();
io.Fonts->AddFontFromFileTTF("resources/Fonts/OpenSans-Regular.ttf", 16.0);
io.ConfigFlags |= ImGuiConfigFlags_DockingEnable;
ImGui::StyleColorsDark();
ImGuiStyle& s = ImGui::GetStyle();
s.FrameRounding = 2.0f;
s.GrabRounding = 2.0f;
s.CellPadding = ImVec2(8, 8);
s.WindowPadding = ImVec2(8, 8);
s.ScrollbarRounding = 9.0f;
s.TabRounding = 0;
s.WindowRounding = 0;
s.ChildRounding = 0;
s.FrameRounding = 0;
s.GrabRounding = 0;
s.FramePadding = ImVec2(8, 4);
s.ItemSpacing = ImVec2(8, 4);
s.ItemInnerSpacing = ImVec2(4, 4);
s.TabRounding = 4.0f;
s.WindowBorderSize = 0.0f;
s.ChildBorderSize = 0.0f;
ImVec4* colors = ImGui::GetStyle().Colors;
colors[ImGuiCol_Text] = ImVec4(1.00f, 1.00f, 1.00f, 1.00f);
colors[ImGuiCol_TextDisabled] = ImVec4(0.50f, 0.50f, 0.50f, 1.00f);
colors[ImGuiCol_WindowBg] = ImVec4(0.08f, 0.08f, 0.08f, 1.00f);
colors[ImGuiCol_ChildBg] = ImVec4(0.15f, 0.15f, 0.15f, 1.00f);
colors[ImGuiCol_PopupBg] = ImVec4(0.08f, 0.08f, 0.08f, 0.94f);
colors[ImGuiCol_Border] = ImVec4(0.11f, 0.11f, 0.11f, 1.00f);
colors[ImGuiCol_BorderShadow] = ImVec4(0.00f, 0.00f, 0.00f, 0.00f);
colors[ImGuiCol_FrameBg] = ImVec4(0.06f, 0.06f, 0.06f, 1.00f);
colors[ImGuiCol_FrameBgHovered] = ImVec4(0.09f, 0.09f, 0.09f, 1.00f);
colors[ImGuiCol_FrameBgActive] = ImVec4(0.13f, 0.13f, 0.13f, 1.00f);
colors[ImGuiCol_TitleBg] = ImVec4(0.08f, 0.08f, 0.08f, 1.00f);
colors[ImGuiCol_TitleBgActive] = ImVec4(0.00f, 0.00f, 0.00f, 1.00f);
colors[ImGuiCol_TitleBgCollapsed] = ImVec4(0.00f, 0.00f, 0.00f, 0.51f);
colors[ImGuiCol_MenuBarBg] = ImVec4(0.08f, 0.08f, 0.08f, 1.00f);
colors[ImGuiCol_ScrollbarBg] = ImVec4(0.08f, 0.08f, 0.08f, 1.00f);
colors[ImGuiCol_ScrollbarGrab] = ImVec4(0.34f, 0.34f, 0.34f, 1.00f);
colors[ImGuiCol_ScrollbarGrabHovered] = ImVec4(0.29f, 0.29f, 0.29f, 1.00f);
colors[ImGuiCol_ScrollbarGrabActive] = ImVec4(0.16f, 0.16f, 0.16f, 1.00f);
colors[ImGuiCol_CheckMark] = ImVec4(0.55f, 0.76f, 0.29f, 1.00f);
colors[ImGuiCol_SliderGrab] = ImVec4(0.55f, 0.76f, 0.29f, 1.00f);
colors[ImGuiCol_SliderGrabActive] = ImVec4(0.55f, 0.76f, 0.29f, 1.00f);
colors[ImGuiCol_Button] = ImVec4(0.22f, 0.22f, 0.22f, 1.00f);
colors[ImGuiCol_ButtonHovered] = ImVec4(0.19f, 0.19f, 0.19f, 1.00f);
colors[ImGuiCol_ButtonActive] = ImVec4(0.16f, 0.16f, 0.16f, 1.00f);
colors[ImGuiCol_Header] = ImVec4(0.18f, 0.18f, 0.18f, 1.00f);
colors[ImGuiCol_HeaderHovered] = ImVec4(0.16f, 0.16f, 0.16f, 1.00f);
colors[ImGuiCol_HeaderActive] = ImVec4(0.12f, 0.12f, 0.12f, 1.00f);
colors[ImGuiCol_Separator] = ImVec4(0.08f, 0.08f, 0.08f, 1.00f);
colors[ImGuiCol_SeparatorHovered] = ImVec4(0.10f, 0.10f, 0.10f, 0.78f);
colors[ImGuiCol_SeparatorActive] = ImVec4(0.00f, 0.00f, 0.00f, 1.00f);
colors[ImGuiCol_ResizeGrip] = ImVec4(0.26f, 0.59f, 0.98f, 0.00f);
colors[ImGuiCol_ResizeGripHovered] = ImVec4(0.26f, 0.59f, 0.98f, 0.00f);
colors[ImGuiCol_ResizeGripActive] = ImVec4(0.26f, 0.59f, 0.98f, 0.00f);
colors[ImGuiCol_Tab] = ImVec4(0.08f, 0.08f, 0.08f, 1.00f);
colors[ImGuiCol_TabHovered] = ImVec4(0.19f, 0.19f, 0.19f, 1.00f);
colors[ImGuiCol_TabActive] = ImVec4(0.15f, 0.15f, 0.15f, 1.00f);
colors[ImGuiCol_TabUnfocused] = ImVec4(0.08f, 0.08f, 0.08f, 1.00f);
colors[ImGuiCol_TabUnfocusedActive] = ImVec4(0.15f, 0.15f, 0.15f, 1.00f);
colors[ImGuiCol_DockingPreview] = ImVec4(0.55f, 0.76f, 0.29f, 1.00f);
colors[ImGuiCol_DockingEmptyBg] = ImVec4(0.20f, 0.20f, 0.20f, 1.00f);
colors[ImGuiCol_PlotLines] = ImVec4(0.61f, 0.61f, 0.61f, 1.00f);
colors[ImGuiCol_PlotLinesHovered] = ImVec4(1.00f, 0.43f, 0.35f, 1.00f);
colors[ImGuiCol_PlotHistogram] = ImVec4(0.90f, 0.70f, 0.00f, 1.00f);
colors[ImGuiCol_PlotHistogramHovered] = ImVec4(1.00f, 0.60f, 0.00f, 1.00f);
colors[ImGuiCol_TableHeaderBg] = ImVec4(0.19f, 0.19f, 0.19f, 1.00f);
colors[ImGuiCol_TableBorderStrong] = ImVec4(0.11f, 0.11f, 0.11f, 1.00f);
colors[ImGuiCol_TableBorderLight] = ImVec4(0.11f, 0.11f, 0.11f, 1.00f);
colors[ImGuiCol_TableRowBg] = ImVec4(0.11f, 0.11f, 0.11f, 1.00f);
colors[ImGuiCol_TableRowBgAlt] = ImVec4(0.93f, 0.27f, 0.27f, 0.00f);
colors[ImGuiCol_TextSelectedBg] = ImVec4(0.08f, 0.49f, 0.97f, 0.28f);
colors[ImGuiCol_DragDropTarget] = ImVec4(0.55f, 0.76f, 0.29f, 1.00f);
colors[ImGuiCol_NavHighlight] = ImVec4(0.26f, 0.59f, 0.98f, 1.00f);
colors[ImGuiCol_NavWindowingHighlight] = ImVec4(1.00f, 1.00f, 1.00f, 0.70f);
colors[ImGuiCol_NavWindowingDimBg] = ImVec4(0.80f, 0.80f, 0.80f, 0.20f);
colors[ImGuiCol_ModalWindowDimBg] = ImVec4(0.80f, 0.80f, 0.80f, 0.35f);
ImGui_ImplGlfw_InitForOpenGL(m_Window, true);
ImGui_ImplOpenGL3_Init("#version 330");
}
return 0;
return m_Scene;
}
void Window::Update(Timestep ts)
bool Window::SetScene(Ref<Scene> scene)
{
m_Scene->Update(ts);
m_Scene = scene;
return true;
}
void Window::FixedUpdate(Timestep ts)
void Window::SetTitle(const std::string& title)
{
m_Scene->FixedUpdate(ts);
m_Title = title;
glfwSetWindowTitle(m_Window, m_Title.c_str());
}
void Window::Draw()
std::string Window::GetTitle()
{
// Dont render if no scene is loaded.
if (!m_Scene)
return;
// Dont render if no cam is found.
Ref<Camera> cam = m_Scene->GetCurrentCamera();
if (!cam)
return;
Vector2 size = m_Framebuffer->GetSize();
if (size.x < 1 || size.y < 1)
{
size.x = 1.0;
size.y = 1.0;
}
cam->AspectRatio = size.x / size.y;
m_Scene->m_EditorCamera->OnWindowResize(size.x, size.y);
if (Engine::IsPlayMode)
{
m_Scene->Draw(*m_Framebuffer.get());
}
else
{
m_Scene->Draw(*m_Framebuffer.get(), m_Scene->m_EditorCamera->GetPerspective(), m_Scene->m_EditorCamera->GetTransform());
}
glEnable(GL_DEPTH_TEST);
Renderer::EndDraw();
return m_Title;
}
void Window::SetWindowIcon(const std::string& path)
{
GLFWimage images[1];
images[0].pixels = stbi_load("resources/Images/nuake-logo.png", &images[0].width, &images[0].height, 0, 4); //rgba channels
glfwSetWindowIcon(m_Window, 1, images);
stbi_image_free(images[0].pixels);
}
void Window::EndDraw()
void Window::SetVSync(bool enabled)
{
ImGui::Render();
ImGui_ImplOpenGL3_RenderDrawData(ImGui::GetDrawData());
glfwSwapBuffers(m_Window);
glfwPollEvents();
glfwSwapInterval(enabled ? 0 : 1);
}
void Window::InitImgui()
{
ImGui::CreateContext();
ImGuiIO& io = ImGui::GetIO(); (void)io;
//io.Fonts->AddFontDefault();
io.Fonts->AddFontFromFileTTF("resources/Fonts/OpenSans-Regular.ttf", 16.0);
io.ConfigFlags |= ImGuiConfigFlags_DockingEnable;
ImGui::StyleColorsDark();
ImGuiStyle& s = ImGui::GetStyle();
s.FrameRounding = 2.0f;
s.GrabRounding = 2.0f;
s.CellPadding = ImVec2(8, 8);
s.WindowPadding = ImVec2(8, 8);
s.ScrollbarRounding = 9.0f;
s.TabRounding = 0;
s.WindowRounding = 0;
s.ChildRounding = 0;
s.FrameRounding = 0;
s.GrabRounding = 0;
s.FramePadding = ImVec2(8, 4);
s.ItemSpacing = ImVec2(8, 4);
s.ItemInnerSpacing = ImVec2(4, 4);
s.TabRounding = 4.0f;
s.WindowBorderSize = 0.0f;
s.ChildBorderSize = 0.0f;
ImVec4* colors = ImGui::GetStyle().Colors;
colors[ImGuiCol_Text] = ImVec4(1.00f, 1.00f, 1.00f, 1.00f);
colors[ImGuiCol_TextDisabled] = ImVec4(0.50f, 0.50f, 0.50f, 1.00f);
colors[ImGuiCol_WindowBg] = ImVec4(0.08f, 0.08f, 0.08f, 1.00f);
colors[ImGuiCol_ChildBg] = ImVec4(0.15f, 0.15f, 0.15f, 1.00f);
colors[ImGuiCol_PopupBg] = ImVec4(0.08f, 0.08f, 0.08f, 0.94f);
colors[ImGuiCol_Border] = ImVec4(0.11f, 0.11f, 0.11f, 1.00f);
colors[ImGuiCol_BorderShadow] = ImVec4(0.00f, 0.00f, 0.00f, 0.00f);
colors[ImGuiCol_FrameBg] = ImVec4(0.06f, 0.06f, 0.06f, 1.00f);
colors[ImGuiCol_FrameBgHovered] = ImVec4(0.09f, 0.09f, 0.09f, 1.00f);
colors[ImGuiCol_FrameBgActive] = ImVec4(0.13f, 0.13f, 0.13f, 1.00f);
colors[ImGuiCol_TitleBg] = ImVec4(0.08f, 0.08f, 0.08f, 1.00f);
colors[ImGuiCol_TitleBgActive] = ImVec4(0.00f, 0.00f, 0.00f, 1.00f);
colors[ImGuiCol_TitleBgCollapsed] = ImVec4(0.00f, 0.00f, 0.00f, 0.51f);
colors[ImGuiCol_MenuBarBg] = ImVec4(0.08f, 0.08f, 0.08f, 1.00f);
colors[ImGuiCol_ScrollbarBg] = ImVec4(0.08f, 0.08f, 0.08f, 1.00f);
colors[ImGuiCol_ScrollbarGrab] = ImVec4(0.34f, 0.34f, 0.34f, 1.00f);
colors[ImGuiCol_ScrollbarGrabHovered] = ImVec4(0.29f, 0.29f, 0.29f, 1.00f);
colors[ImGuiCol_ScrollbarGrabActive] = ImVec4(0.16f, 0.16f, 0.16f, 1.00f);
colors[ImGuiCol_CheckMark] = ImVec4(0.55f, 0.76f, 0.29f, 1.00f);
colors[ImGuiCol_SliderGrab] = ImVec4(0.55f, 0.76f, 0.29f, 1.00f);
colors[ImGuiCol_SliderGrabActive] = ImVec4(0.55f, 0.76f, 0.29f, 1.00f);
colors[ImGuiCol_Button] = ImVec4(0.22f, 0.22f, 0.22f, 1.00f);
colors[ImGuiCol_ButtonHovered] = ImVec4(0.19f, 0.19f, 0.19f, 1.00f);
colors[ImGuiCol_ButtonActive] = ImVec4(0.16f, 0.16f, 0.16f, 1.00f);
colors[ImGuiCol_Header] = ImVec4(0.18f, 0.18f, 0.18f, 1.00f);
colors[ImGuiCol_HeaderHovered] = ImVec4(0.16f, 0.16f, 0.16f, 1.00f);
colors[ImGuiCol_HeaderActive] = ImVec4(0.12f, 0.12f, 0.12f, 1.00f);
colors[ImGuiCol_Separator] = ImVec4(0.08f, 0.08f, 0.08f, 1.00f);
colors[ImGuiCol_SeparatorHovered] = ImVec4(0.10f, 0.10f, 0.10f, 0.78f);
colors[ImGuiCol_SeparatorActive] = ImVec4(0.00f, 0.00f, 0.00f, 1.00f);
colors[ImGuiCol_ResizeGrip] = ImVec4(0.26f, 0.59f, 0.98f, 0.00f);
colors[ImGuiCol_ResizeGripHovered] = ImVec4(0.26f, 0.59f, 0.98f, 0.00f);
colors[ImGuiCol_ResizeGripActive] = ImVec4(0.26f, 0.59f, 0.98f, 0.00f);
colors[ImGuiCol_Tab] = ImVec4(0.08f, 0.08f, 0.08f, 1.00f);
colors[ImGuiCol_TabHovered] = ImVec4(0.19f, 0.19f, 0.19f, 1.00f);
colors[ImGuiCol_TabActive] = ImVec4(0.15f, 0.15f, 0.15f, 1.00f);
colors[ImGuiCol_TabUnfocused] = ImVec4(0.08f, 0.08f, 0.08f, 1.00f);
colors[ImGuiCol_TabUnfocusedActive] = ImVec4(0.15f, 0.15f, 0.15f, 1.00f);
colors[ImGuiCol_DockingPreview] = ImVec4(0.55f, 0.76f, 0.29f, 1.00f);
colors[ImGuiCol_DockingEmptyBg] = ImVec4(0.20f, 0.20f, 0.20f, 1.00f);
colors[ImGuiCol_PlotLines] = ImVec4(0.61f, 0.61f, 0.61f, 1.00f);
colors[ImGuiCol_PlotLinesHovered] = ImVec4(1.00f, 0.43f, 0.35f, 1.00f);
colors[ImGuiCol_PlotHistogram] = ImVec4(0.90f, 0.70f, 0.00f, 1.00f);
colors[ImGuiCol_PlotHistogramHovered] = ImVec4(1.00f, 0.60f, 0.00f, 1.00f);
colors[ImGuiCol_TableHeaderBg] = ImVec4(0.19f, 0.19f, 0.19f, 1.00f);
colors[ImGuiCol_TableBorderStrong] = ImVec4(0.11f, 0.11f, 0.11f, 1.00f);
colors[ImGuiCol_TableBorderLight] = ImVec4(0.11f, 0.11f, 0.11f, 1.00f);
colors[ImGuiCol_TableRowBg] = ImVec4(0.11f, 0.11f, 0.11f, 1.00f);
colors[ImGuiCol_TableRowBgAlt] = ImVec4(0.93f, 0.27f, 0.27f, 0.00f);
colors[ImGuiCol_TextSelectedBg] = ImVec4(0.08f, 0.49f, 0.97f, 0.28f);
colors[ImGuiCol_DragDropTarget] = ImVec4(0.55f, 0.76f, 0.29f, 1.00f);
colors[ImGuiCol_NavHighlight] = ImVec4(0.26f, 0.59f, 0.98f, 1.00f);
colors[ImGuiCol_NavWindowingHighlight] = ImVec4(1.00f, 1.00f, 1.00f, 0.70f);
colors[ImGuiCol_NavWindowingDimBg] = ImVec4(0.80f, 0.80f, 0.80f, 0.20f);
colors[ImGuiCol_ModalWindowDimBg] = ImVec4(0.80f, 0.80f, 0.80f, 0.35f);
ImGui_ImplGlfw_InitForOpenGL(m_Window, true);
ImGui_ImplOpenGL3_Init("#version 330");
}
}

View File

@@ -1,34 +1,34 @@
#pragma once
#include "Core/Timestep.h"
#include "Rendering/Buffers/Framebuffer.h"
#include "Scene/Scene.h"
#include "Core/Core.h"
#include "Core/Timestep.h"
#include "Core/Maths.h"
struct GLFWwindow;
namespace Nuake
{
class Scene;
class FrameBuffer;
class Window
{
private:
const std::string DEFAULT_TITLE = "Untitled Window";
static Ref<Window> s_Instance;
std::string m_Title;
int m_Width = 1280;
int m_Height = 720;
const uint32_t DEFAULT_WIDTH = 1280;
const uint32_t DEFAULT_HEIGHT = 720;
GLFWwindow* m_Window;
std::string m_Title;
uint32_t m_Width;
uint32_t m_Height;
Ref<FrameBuffer> m_Framebuffer;
Ref<Scene> m_Scene;
Vector2 m_FramebufferOffset;
public:
Window();
~Window();
~Window() = default;
static Ref<Window> Get(); // Get the window instance
GLFWwindow* GetHandle();
@@ -36,12 +36,15 @@ namespace Nuake
bool ShouldClose();
int Init();
void Update(Timestep ts);
void FixedUpdate(Timestep ts);
void Draw();
void EndDraw();
Ref<FrameBuffer> GetFrameBuffer() const;
Vector2 GetSize() const;
void SetSize(const Vector2& size);
@@ -52,6 +55,11 @@ namespace Nuake
void SetTitle(const std::string& title);
std::string GetTitle();
void SetWindowIcon(const std::string& path);
void SetVSync(bool enabled);
private:
void InitImgui();
};
}