From 1813ad138ce3d4858bfd4fa1603981d03c4a21e3 Mon Sep 17 00:00:00 2001 From: mushgunAX Date: Tue, 27 Sep 2022 22:05:59 +0800 Subject: [PATCH] FRC changed --- .../src/Application/SBApplication.cpp | 3 ++ .../src/FRC/SHFramerateController.cpp | 22 +++++++++- SHADE_Engine/src/FRC/SHFramerateController.h | 44 +++++++++++++++++++ 3 files changed, 68 insertions(+), 1 deletion(-) diff --git a/SHADE_Application/src/Application/SBApplication.cpp b/SHADE_Application/src/Application/SBApplication.cpp index 20aa3b5a..97c78ad6 100644 --- a/SHADE_Application/src/Application/SBApplication.cpp +++ b/SHADE_Application/src/Application/SBApplication.cpp @@ -24,6 +24,7 @@ #include "Scene/SHSceneManager.h" #include "Math/Transform/SHTransformSystem.h" #include "Input/SHInputManagerSystem.h" +#include "FRC/SHFramerateController.h" #include "Scenes/SBTestScene.h" #include "Math/Transform/SHTransformComponent.h" @@ -95,6 +96,7 @@ namespace Sandbox #endif SHSceneManager::InitSceneManager("TestScene"); + SHFrameRateController::UpdateFRC(); } void SBApplication::Update(void) @@ -103,6 +105,7 @@ namespace Sandbox //TODO: Change true to window is open while (!window.WindowShouldClose()) { + SHFrameRateController::UpdateFRC(); SHSceneManager::UpdateSceneManager(); SHSceneManager::SceneUpdate(1/60.0f); //#ifdef SHEDITOR diff --git a/SHADE_Engine/src/FRC/SHFramerateController.cpp b/SHADE_Engine/src/FRC/SHFramerateController.cpp index d64c6336..0791d628 100644 --- a/SHADE_Engine/src/FRC/SHFramerateController.cpp +++ b/SHADE_Engine/src/FRC/SHFramerateController.cpp @@ -9,12 +9,31 @@ consent of DigiPen Institute of Technology is prohibited. *********************************************************************/ + +//TODO Legacy code. Delete soon + #include #include #include #include "SHFramerateController.h" #include "../Tools/SHLogger.h" +namespace SHADE +{ + double SHFrameRateController::rawDeltaTime = 0.0; + std::chrono::steady_clock::time_point SHFrameRateController::prevFrameTime = std::chrono::high_resolution_clock::now(); + + void SHFrameRateController::UpdateFRC() noexcept + { + std::chrono::duration deltaTime; + deltaTime = std::chrono::high_resolution_clock::now() - prevFrameTime; + prevFrameTime = std::chrono::high_resolution_clock::now(); + rawDeltaTime = deltaTime.count(); + } +} + +//TODO Legacy code. Delete soon +#if 0 namespace SHADE { //Init statics @@ -131,4 +150,5 @@ namespace SHADE currentScene = nextScene; } } -} \ No newline at end of file +} +#endif \ No newline at end of file diff --git a/SHADE_Engine/src/FRC/SHFramerateController.h b/SHADE_Engine/src/FRC/SHFramerateController.h index 26f276d8..b9637cf2 100644 --- a/SHADE_Engine/src/FRC/SHFramerateController.h +++ b/SHADE_Engine/src/FRC/SHFramerateController.h @@ -13,6 +13,38 @@ #define SH_FRAMERATECONTROLLER_H #pragma once +#include +#include "Tools/SHLogger.h" +#include "SH_API.h" + +namespace SHADE +{ + class SH_API SHFrameRateController + { + private: + //Varying delta time. The actual time it took for every frame + static double rawDeltaTime; + static std::chrono::steady_clock::time_point prevFrameTime; + + + public: + //Gets the raw delta time + static inline double GetRawDeltaTime() noexcept + { + return rawDeltaTime; + } + + //Updates the raw delta time accordingly + static void UpdateFRC() noexcept; + + }; + +} + + + +//TODO Legacy code. Delete soon +#if 0 #include "../Scene/SHScene.h" namespace SHADE @@ -56,7 +88,19 @@ namespace SHADE //halt execution of the current scene and prepare //execution of the next static inline void SetNextScene(SHScene* const next) { nextScene = next; } + + + }; + + + } +#endif + + + + + #endif \ No newline at end of file -- 2.40.1