diff --git a/Editor/Editor.cpp b/Editor/Editor.cpp index b15649f2..f530c6df 100644 --- a/Editor/Editor.cpp +++ b/Editor/Editor.cpp @@ -183,7 +183,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/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/Systems/PhysicsSystem.cpp b/Nuake/src/Scene/Systems/PhysicsSystem.cpp index b7b94ef5..4a256ab4 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();