FRC changed

This commit is contained in:
mushgunAX 2022-09-27 22:05:59 +08:00
parent e0ad6fbc71
commit 1813ad138c
3 changed files with 68 additions and 1 deletions

View File

@ -24,6 +24,7 @@
#include "Scene/SHSceneManager.h" #include "Scene/SHSceneManager.h"
#include "Math/Transform/SHTransformSystem.h" #include "Math/Transform/SHTransformSystem.h"
#include "Input/SHInputManagerSystem.h" #include "Input/SHInputManagerSystem.h"
#include "FRC/SHFramerateController.h"
#include "Scenes/SBTestScene.h" #include "Scenes/SBTestScene.h"
#include "Math/Transform/SHTransformComponent.h" #include "Math/Transform/SHTransformComponent.h"
@ -95,6 +96,7 @@ namespace Sandbox
#endif #endif
SHSceneManager::InitSceneManager<SBTestScene>("TestScene"); SHSceneManager::InitSceneManager<SBTestScene>("TestScene");
SHFrameRateController::UpdateFRC();
} }
void SBApplication::Update(void) void SBApplication::Update(void)
@ -103,6 +105,7 @@ namespace Sandbox
//TODO: Change true to window is open //TODO: Change true to window is open
while (!window.WindowShouldClose()) while (!window.WindowShouldClose())
{ {
SHFrameRateController::UpdateFRC();
SHSceneManager::UpdateSceneManager(); SHSceneManager::UpdateSceneManager();
SHSceneManager::SceneUpdate(1/60.0f); SHSceneManager::SceneUpdate(1/60.0f);
//#ifdef SHEDITOR //#ifdef SHEDITOR

View File

@ -9,12 +9,31 @@
consent of DigiPen Institute of Technology is prohibited. consent of DigiPen Institute of Technology is prohibited.
*********************************************************************/ *********************************************************************/
//TODO Legacy code. Delete soon
#include <chrono> #include <chrono>
#include <cassert> #include <cassert>
#include <SHpch.h> #include <SHpch.h>
#include "SHFramerateController.h" #include "SHFramerateController.h"
#include "../Tools/SHLogger.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<double> 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 namespace SHADE
{ {
//Init statics //Init statics
@ -132,3 +151,4 @@ namespace SHADE
} }
} }
} }
#endif

View File

@ -13,6 +13,38 @@
#define SH_FRAMERATECONTROLLER_H #define SH_FRAMERATECONTROLLER_H
#pragma once #pragma once
#include <chrono>
#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" #include "../Scene/SHScene.h"
namespace SHADE namespace SHADE
@ -56,7 +88,19 @@ namespace SHADE
//halt execution of the current scene and prepare //halt execution of the current scene and prepare
//execution of the next //execution of the next
static inline void SetNextScene(SHScene* const next) { nextScene = next; } static inline void SetNextScene(SHScene* const next) { nextScene = next; }
}; };
} }
#endif
#endif #endif