diff --git a/Nuake/Engine.cpp b/Nuake/Engine.cpp index 2422009f..36aee3bf 100644 --- a/Nuake/Engine.cpp +++ b/Nuake/Engine.cpp @@ -19,18 +19,17 @@ namespace Nuake { + Ref Engine::currentProject; + Ref Engine::currentWindow; - Ref Engine::s_CurrentProject; - Ref Engine::s_CurrentWindow; + GameState Engine::gameState = GameState::Stopped; - GameState Engine::s_GameState = GameState::Stopped; - - 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; - float Engine::s_TimeScale = 1.0f; + float Engine::lastFrameTime = 0.0f; + float Engine::fixedUpdateRate = 1.0f / 90.0f; + float Engine::fixedUpdateDifference = 0.f; + float Engine::time = 0.f; + Timestep Engine::timeStep = 0.f; + float Engine::timeScale = 1.0f; void Engine::Init() { @@ -39,7 +38,7 @@ namespace Nuake NavManager::Get().Initialize(); // Creates the window - s_CurrentWindow = Window::Get(); + currentWindow = Window::Get(); Input::Init(); Renderer2D::Init(); @@ -54,15 +53,15 @@ namespace Nuake JobSystem::Get().Update(); - s_Time = static_cast(glfwGetTime()); - s_TimeStep = s_Time - s_LastFrameTime; - s_LastFrameTime = s_Time; + time = static_cast(glfwGetTime()); + timeStep = time - lastFrameTime; + lastFrameTime = time; // Dont update if no scene is loaded. - if (s_CurrentWindow->GetScene()) + if (currentWindow->GetScene()) { - float scaledTimeStep = s_TimeStep * s_TimeScale; - s_CurrentWindow->Update(scaledTimeStep); + float scaledTimeStep = timeStep * timeScale; + currentWindow->Update(scaledTimeStep); // Play mode update all the entities, Editor does not. if (!Engine::IsPlayMode()) @@ -70,14 +69,14 @@ namespace Nuake GetCurrentScene()->EditorUpdate(scaledTimeStep); } - s_FixedUpdateDifference += s_TimeStep; + fixedUpdateDifference += timeStep; // Fixed update - while (s_FixedUpdateDifference >= s_FixedUpdateRate) + while (fixedUpdateDifference >= fixedUpdateRate) { - s_CurrentWindow->FixedUpdate(s_FixedUpdateRate * s_TimeScale); + currentWindow->FixedUpdate(fixedUpdateRate * timeScale); - s_FixedUpdateDifference -= s_FixedUpdateRate; + fixedUpdateDifference -= fixedUpdateRate; } Input::Update(); @@ -87,7 +86,7 @@ namespace Nuake void Engine::EnterPlayMode() { - s_LastFrameTime = (float)glfwGetTime(); // Reset timestep timer. + lastFrameTime = (float)glfwGetTime(); // Reset timestep timer. // Dont trigger init if already in player mode. if (GetGameState() == GameState::Playing) @@ -112,11 +111,11 @@ namespace Nuake void Engine::ExitPlayMode() { // Dont trigger exit if already not in play mode. - if (s_GameState != GameState::Stopped) + if (gameState != GameState::Stopped) { GetCurrentScene()->OnExit(); Input::ShowMouse(); - s_GameState = GameState::Stopped; + gameState = GameState::Stopped; } } @@ -152,9 +151,9 @@ namespace Nuake Ref Engine::GetCurrentScene() { - if (s_CurrentWindow) + if (currentWindow) { - return s_CurrentWindow->GetScene(); + return currentWindow->GetScene(); } return nullptr; @@ -162,19 +161,19 @@ namespace Nuake bool Engine::LoadScene(Ref scene) { - return s_CurrentWindow->SetScene(scene); + return currentWindow->SetScene(scene); } Ref Engine::GetProject() { - return s_CurrentProject; + return currentProject; } bool Engine::LoadProject(Ref project) { - s_CurrentProject = project; + currentProject = project; - if (!Engine::LoadScene(s_CurrentProject->DefaultScene)) + if (!Engine::LoadScene(currentProject->DefaultScene)) { return false; } @@ -188,6 +187,6 @@ namespace Nuake Ref Engine::GetCurrentWindow() { - return s_CurrentWindow; + return currentWindow; } } diff --git a/Nuake/Engine.h b/Nuake/Engine.h index e7941e7b..d84c618a 100644 --- a/Nuake/Engine.h +++ b/Nuake/Engine.h @@ -1,13 +1,10 @@ #pragma once +#include "NuakePCH.h" #include "src/Core/Core.h" +#include "src/Core/Logger.h" #include "src/Window.h" #include "src/Scene/Scene.h" #include "src/Resource/Project.h" -#include "src/Core/Logger.h" - -/* TODOS: - -*/ // Welcome to the Nuake source code. namespace Nuake @@ -21,19 +18,7 @@ namespace Nuake class Engine { - private: - static Ref s_CurrentWindow; - static Ref s_CurrentProject; - static Ref s_CurrentScene; - static GameState s_GameState; - - static float s_LastFrameTime; - static float s_FixedUpdateRate; - static float s_FixedUpdateDifference; - static float s_Time; - static Timestep s_TimeStep; - static float s_TimeScale; public: static void Init(); // Initialize the engine. static void Tick(); // Updates everything, called every frame. @@ -46,16 +31,16 @@ namespace Nuake static void Draw(); // Start new frame static void EndDraw(); // Swap buffer - static void SetGameState(GameState gameState) { s_GameState = gameState; } - static GameState GetGameState() { return s_GameState; } - static bool IsPlayMode() { return s_GameState == GameState::Playing; } + static void SetGameState(GameState gameState) { gameState = gameState; } + static GameState GetGameState() { return gameState; } + static bool IsPlayMode() { return gameState == GameState::Playing; } - static inline float GetTime() { return s_Time; } - static inline Timestep GetTimestep() { return s_TimeStep; } - static inline void SetPhysicsStep(int amount) { s_FixedUpdateRate = 1.0f / static_cast(amount); } - static inline float GetFixedTimeStep() { return s_FixedUpdateRate; } - static inline void SetTimeScale(float timeScale) { s_TimeScale = timeScale; } - static inline float GetTimeScale() { return s_TimeScale; } + static inline float GetTime() { return time; } + static inline Timestep GetTimestep() { return timeStep; } + static inline void SetPhysicsStep(int amount) { fixedUpdateRate = 1.0f / static_cast(amount); } + static inline float GetFixedTimeStep() { return fixedUpdateRate; } + static inline void SetTimeScale(float timeScale) { timeScale = timeScale; } + static inline float GetTimeScale() { return timeScale; } static Ref GetCurrentWindow(); @@ -65,6 +50,20 @@ namespace Nuake static bool LoadProject(Ref project); static Ref GetProject(); + private: + static Ref currentWindow; + static Ref currentProject; + static Ref currentScene; + + static GameState gameState; + + static float lastFrameTime; + static float fixedUpdateRate; + static float fixedUpdateDifference; + static float time; + static Timestep timeStep; + static float timeScale; + }; } diff --git a/Nuake/src/Scene/Components.h b/Nuake/src/Scene/Components.h index fd9f3195..32115d4f 100644 --- a/Nuake/src/Scene/Components.h +++ b/Nuake/src/Scene/Components.h @@ -1,4 +1,5 @@ #pragma once + #include "Components/AudioEmitterComponent.h" #include "Components/BaseComponent.h" #include "Components/BoneComponent.h" @@ -20,6 +21,8 @@ #include "Components/QuakeMap.h" #include "Components/RigidbodyComponent.h" #include "Components/SkinnedModelComponent.h" +#include "Components/SphereCollider.h" #include "Components/SpriteComponent.h" #include "Components/TransformComponent.h" +#include "Components/WrenScriptComponent.h" diff --git a/Nuake/src/Scene/Entities/Entity.cpp b/Nuake/src/Scene/Entities/Entity.cpp index b221ac63..3dc7ea53 100644 --- a/Nuake/src/Scene/Entities/Entity.cpp +++ b/Nuake/src/Scene/Entities/Entity.cpp @@ -1,24 +1,7 @@ #include "Entity.h" -#include "src/Scene/Components/ParentComponent.h" -#include "src/Scene/Components/NameComponent.h" -#include "src/Scene/Components/TransformComponent.h" -#include "src/Scene/Components/CameraComponent.h" -#include "src/Scene/Components/QuakeMap.h" -#include "src/Scene/Components/LightComponent.h" -#include "src/Scene/Components/QuakeMap.h" -#include "src/Scene/Components/WrenScriptComponent.h" -#include "src/Scene/Components/CharacterControllerComponent.h" -#include "src/Scene/Components/RigidbodyComponent.h" -#include "src/Scene/Components/BSPBrushComponent.h" -#include "src/Scene/Components/Components.h" -#include "src/Scene/Components/BoxCollider.h" -#include "src/Scene/Components/CapsuleColliderComponent.h" -#include "src/Scene/Components/SpriteComponent.h" -#include "src/Scene/Components/ParticleEmitterComponent.h" -#include "src/Scene/Components/BoneComponent.h" -#include "src/Scene/Components/SkinnedModelComponent.h" -#include +#include "src/Scene/Components.h" + namespace Nuake {