diff --git a/Editor/Editor.cpp b/Editor/Editor.cpp index b15649f2..c1d33b85 100644 --- a/Editor/Editor.cpp +++ b/Editor/Editor.cpp @@ -1,6 +1,5 @@ #include -#include #include #include #include @@ -28,6 +27,8 @@ #include "src/Misc/GizmoDrawer.h" #include "src/Windows/FileSystemUI.h" +#include + 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); } diff --git a/Editor/src/Windows/EditorInterface.cpp b/Editor/src/Windows/EditorInterface.cpp index 67ec3268..292dbe6b 100644 --- a/Editor/src/Windows/EditorInterface.cpp +++ b/Editor/src/Windows/EditorInterface.cpp @@ -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()), 100.f); } - if (Selection.Type == EditorSelectionType::Entity && !Engine::IsPlayMode) + if (Selection.Type == EditorSelectionType::Entity && !Engine::IsPlayMode()) { TransformComponent& tc = Selection.Entity.GetComponent(); ParentComponent& parent = Selection.Entity.GetComponent(); @@ -1498,7 +1498,7 @@ namespace Nuake { void EditorInterface::Update(float ts) { - if (!Engine::GetCurrentScene() || Engine::IsPlayMode) + if (!Engine::GetCurrentScene() || Engine::IsPlayMode()) { return; } diff --git a/Nuake/Engine.cpp b/Nuake/Engine.cpp index b02ef9e5..05d72b37 100644 --- a/Nuake/Engine.cpp +++ b/Nuake/Engine.cpp @@ -15,16 +15,16 @@ namespace Nuake { - Ref Engine::CurrentProject; - Ref Engine::CurrentWindow; + Ref Engine::s_CurrentProject; + Ref 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 Engine::GetCurrentScene() { - return CurrentWindow->GetScene(); + return s_CurrentWindow->GetScene(); } bool Engine::LoadScene(Ref scene) { - return CurrentWindow->SetScene(scene); + return s_CurrentWindow->SetScene(scene); } Ref Engine::GetProject() { - return CurrentProject; + return s_CurrentProject; } bool Engine::LoadProject(Ref 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 Engine::GetCurrentWindow() { - return CurrentWindow; + return s_CurrentWindow; } } diff --git a/Nuake/Engine.h b/Nuake/Engine.h index 2a30f0a7..0daac3cf 100644 --- a/Nuake/Engine.h +++ b/Nuake/Engine.h @@ -17,20 +17,22 @@ // Welcome to the Nuake source code. namespace Nuake { - class Engine { + class Engine + { private: - static Ref CurrentWindow; - static Ref CurrentProject; - static Ref CurrentScene; + static Ref s_CurrentWindow; + static Ref s_CurrentProject; + static Ref 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 GetCurrentWindow(); static bool LoadScene(Ref scene); diff --git a/Nuake/src/Core/FileSystem.h b/Nuake/src/Core/FileSystem.h index 9febe52c..18e96c80 100644 --- a/Nuake/src/Core/FileSystem.h +++ b/Nuake/src/Core/FileSystem.h @@ -1,10 +1,11 @@ #pragma once +#include "Core.h" +#include "String.h" + #include #include -#include "Core.h" #include #include -#include "String.h" namespace Nuake { diff --git a/Nuake/src/Core/Input.cpp b/Nuake/src/Core/Input.cpp index b59d35fd..b5cd1db5 100644 --- a/Nuake/src/Core/Input.cpp +++ b/Nuake/src/Core/Input.cpp @@ -1,5 +1,5 @@ #include "Input.h" -#include "../Window.h" +#include "src/Window.h" #include #include diff --git a/Nuake/src/Core/Input.h b/Nuake/src/Core/Input.h index ffbfc5cf..f925b574 100644 --- a/Nuake/src/Core/Input.h +++ b/Nuake/src/Core/Input.h @@ -1,7 +1,8 @@ #pragma once -#include -#include "../Core/Maths.h" +#include "src/Core/Maths.h" + #include +#include struct GLFWwindow; diff --git a/Nuake/src/Core/Logger.cpp b/Nuake/src/Core/Logger.cpp index ec5ba39c..7af7089c 100644 --- a/Nuake/src/Core/Logger.cpp +++ b/Nuake/src/Core/Logger.cpp @@ -1,4 +1,5 @@ #include "Logger.h" + #include #include #include @@ -6,7 +7,7 @@ namespace Nuake { - std::vector Logger::m_Logs = std::vector(); + std::vector Logger::m_Logs = std::vector(); void Logger::Log(const std::string& log, LOG_TYPE type) { diff --git a/Nuake/src/Core/Logger.h b/Nuake/src/Core/Logger.h index 74cb48c0..6c41a49c 100644 --- a/Nuake/src/Core/Logger.h +++ b/Nuake/src/Core/Logger.h @@ -20,11 +20,12 @@ namespace Nuake class Logger { - public: - static void Log(const std::string& log, LOG_TYPE type = VERBOSE); - static std::vector GetLogs(); private: static const int MAX_LOG = 64; static std::vector m_Logs; + + public: + static void Log(const std::string& log, LOG_TYPE type = VERBOSE); + static std::vector GetLogs(); }; } diff --git a/Nuake/src/Core/String.cpp b/Nuake/src/Core/String.cpp index b71007de..7c4ccc5a 100644 --- a/Nuake/src/Core/String.cpp +++ b/Nuake/src/Core/String.cpp @@ -2,11 +2,14 @@ #include #include -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) diff --git a/Nuake/src/Core/String.h b/Nuake/src/Core/String.h index 50e632b0..be3f6aa7 100644 --- a/Nuake/src/Core/String.h +++ b/Nuake/src/Core/String.h @@ -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); diff --git a/Nuake/src/Core/Timestep.h b/Nuake/src/Core/Timestep.h index fe73086a..d761eb5c 100644 --- a/Nuake/src/Core/Timestep.h +++ b/Nuake/src/Core/Timestep.h @@ -2,7 +2,8 @@ namespace Nuake { - class Timestep { + class Timestep + { private: float m_Time; diff --git a/Nuake/src/Resource/UUID.h b/Nuake/src/Resource/UUID.h index 67482900..7b51c22d 100644 --- a/Nuake/src/Resource/UUID.h +++ b/Nuake/src/Resource/UUID.h @@ -2,23 +2,24 @@ #include #include -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 { diff --git a/Nuake/src/Scene/Components/WrenScriptComponent.h b/Nuake/src/Scene/Components/WrenScriptComponent.h index 6ed39012..d5f069e2 100644 --- a/Nuake/src/Scene/Components/WrenScriptComponent.h +++ b/Nuake/src/Scene/Components/WrenScriptComponent.h @@ -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: diff --git a/Nuake/src/Scene/Scene.cpp b/Nuake/src/Scene/Scene.cpp index 4172cbcf..18f7f6c5 100644 --- a/Nuake/src/Scene/Scene.cpp +++ b/Nuake/src/Scene/Scene.cpp @@ -244,7 +244,7 @@ namespace Nuake { Ref Scene::GetCurrentCamera() { - if (Engine::IsPlayMode) + if (Engine::IsPlayMode()) { Ref cam = nullptr; { diff --git a/Nuake/src/Scene/Scene.h b/Nuake/src/Scene/Scene.h index b999a97a..63468d9f 100644 --- a/Nuake/src/Scene/Scene.h +++ b/Nuake/src/Scene/Scene.h @@ -1,5 +1,4 @@ #pragma once -#include #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; diff --git a/Nuake/src/Scene/Systems/PhysicsSystem.cpp b/Nuake/src/Scene/Systems/PhysicsSystem.cpp index 24fc52ec..a1eecbd5 100644 --- a/Nuake/src/Scene/Systems/PhysicsSystem.cpp +++ b/Nuake/src/Scene/Systems/PhysicsSystem.cpp @@ -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(); 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); diff --git a/Nuake/src/Scene/Systems/ScriptingSystem.cpp b/Nuake/src/Scene/Systems/ScriptingSystem.cpp index 5c9cfe2a..c41f1bff 100644 --- a/Nuake/src/Scene/Systems/ScriptingSystem.cpp +++ b/Nuake/src/Scene/Systems/ScriptingSystem.cpp @@ -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(); diff --git a/Nuake/src/Scripting/Modules/SceneModule.h b/Nuake/src/Scripting/Modules/SceneModule.h index b6f3b907..2e0087d7 100644 --- a/Nuake/src/Scripting/Modules/SceneModule.h +++ b/Nuake/src/Scripting/Modules/SceneModule.h @@ -115,7 +115,7 @@ namespace Nuake { if (ent.HasComponent()) { - wrenSetSlotHandle(vm, 0, ent.GetComponent().mWrenScript->m_Instance); + wrenSetSlotHandle(vm, 0, ent.GetComponent().mWrenScript->GetWrenInstanceHandle()); } } diff --git a/Nuake/src/Scripting/ScriptingEngine.cpp b/Nuake/src/Scripting/ScriptingEngine.cpp index 4755d6a8..1c286233 100644 --- a/Nuake/src/Scripting/ScriptingEngine.cpp +++ b/Nuake/src/Scripting/ScriptingEngine.cpp @@ -1,12 +1,13 @@ #include "ScriptingEngine.h" #include "WrenScript.h" -#include "../Core/FileSystem.h" -#include -#include -#include -#include -#include -#include +#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"); diff --git a/Nuake/src/Scripting/ScriptingEngine.h b/Nuake/src/Scripting/ScriptingEngine.h index 5e7fbf92..a1b42659 100644 --- a/Nuake/src/Scripting/ScriptingEngine.h +++ b/Nuake/src/Scripting/ScriptingEngine.h @@ -1,15 +1,18 @@ #pragma once +#include "src/Core/Core.h" +#include "src/Core/Timestep.h" + #include #include #include -#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 m_LoadedScripts; static std::map> m_Scripts; static std::map> Modules; + public: + static void Init(); + static void RunCode(const std::string& code); + static void Close(); + static Ref 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 script); static void UpdateScript(Ref script, Timestep timestep); static void ExitScript(Ref script); - static void Init(); - static void RunCode(const std::string& code); - static void Close(); - - static WrenForeignMethodFn bindForeignMethod( WrenVM* vm, diff --git a/Nuake/src/Scripting/VM.cpp b/Nuake/src/Scripting/VM.cpp deleted file mode 100644 index c4f12df2..00000000 --- a/Nuake/src/Scripting/VM.cpp +++ /dev/null @@ -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); - } -} \ No newline at end of file diff --git a/Nuake/src/Scripting/VM.h b/Nuake/src/Scripting/VM.h deleted file mode 100644 index 9a8a5cb2..00000000 --- a/Nuake/src/Scripting/VM.h +++ /dev/null @@ -1,13 +0,0 @@ -#pragma once -#include - -namespace Nuake { - class VM - { - VM(); - - inline WrenVM* GetVM(); - private: - WrenVM* m_VM; - }; -} \ No newline at end of file diff --git a/Nuake/src/Scripting/WrenScript.cpp b/Nuake/src/Scripting/WrenScript.cpp index fc544ee6..aadb1d8a 100644 --- a/Nuake/src/Scripting/WrenScript.cpp +++ b/Nuake/src/Scripting/WrenScript.cpp @@ -2,14 +2,16 @@ #include "src/Core/Logger.h" #include "src/Core/String.h" +#include "src/Core/FileSystem.h" #include -namespace Nuake { - WrenScript::WrenScript(Ref file, bool isEntity) +namespace Nuake +{ + WrenScript::WrenScript(Ref 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 WrenScript::GetModules() + std::vector 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(); diff --git a/Nuake/src/Scripting/WrenScript.h b/Nuake/src/Scripting/WrenScript.h index e4abe168..7a5c5009 100644 --- a/Nuake/src/Scripting/WrenScript.h +++ b/Nuake/src/Scripting/WrenScript.h @@ -1,21 +1,21 @@ #pragma once #include "ScriptingEngine.h" -#include "src/Core/FileSystem.h" #include #include struct WrenHandle; -namespace Nuake { +namespace Nuake +{ + class File; class WrenScript { private: - bool CompiledSuccesfully; - bool IsEntity = false; - std::vector mModules; + bool m_HasCompiledSuccesfully; + bool m_IsEntityScript = false; + std::vector m_Modules; - public: Ref mFile; std::map methods; @@ -26,12 +26,11 @@ namespace Nuake { WrenHandle* m_OnExitHandle; WrenHandle* m_SetEntityIDHandle; - // Building - WrenScript(Ref file, bool isEntity); - + public: + WrenScript(Ref file, bool isEntityScript); void ParseModules(); - std::vector 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 GetModules() const; + + WrenHandle* GetWrenInstanceHandle() const { return m_Instance; } }; } diff --git a/Nuake/src/Window.cpp b/Nuake/src/Window.cpp index dfda0ab2..29b92506 100644 --- a/Nuake/src/Window.cpp +++ b/Nuake/src/Window.cpp @@ -1,49 +1,42 @@ -#include - #include "Window.h" -#include -#include -#include "Rendering/Shaders/Shader.h" -#include -#include "Rendering/Renderer.h" -#include "Scene/Entities/Entity.h" -#include -#include -#include "Scene/Entities/ImGuiHelper.h" -#include "Core/Physics/PhysicsManager.h" -#include "imgui/ImGuizmo.h" +#include +#include + +#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 #include -#include "Resource/FontAwesome5.h" -#include "Engine.h" -#include - -namespace Nuake { - Ref Window::s_Instance; +#include +#include +#include +namespace Nuake +{ Window::Window() { m_Title = DEFAULT_TITLE; + m_Width = DEFAULT_WIDTH; + m_Height = DEFAULT_HEIGHT; Init(); Renderer::Init(); } - Window::~Window() { } - Ref Window::Get() { - if (s_Instance == nullptr) - s_Instance = CreateRef(); + static Ref instance; + if (instance == nullptr) + { + instance = CreateRef(); + } - 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) + bool Window::ShouldClose() { - m_Scene = scene; - return true; + return glfwWindowShouldClose(m_Window); } - Ref 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(true, glm::vec2(1920, 1080)); + m_Framebuffer->SetTexture(CreateRef(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 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 Window::GetFrameBuffer() const @@ -105,206 +190,128 @@ namespace Nuake { } } - int Window::Init() + Ref 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(true, glm::vec2(1920, 1080)); - m_Framebuffer->SetTexture(CreateRef(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) { - 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 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"); } } diff --git a/Nuake/src/Window.h b/Nuake/src/Window.h index e05112a5..3c8c892e 100644 --- a/Nuake/src/Window.h +++ b/Nuake/src/Window.h @@ -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 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 m_Framebuffer; - Ref m_Scene; - Vector2 m_FramebufferOffset; - + public: Window(); - ~Window(); + ~Window() = default; static Ref 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 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(); }; } -