Merge pull request #59 from SHADE-DP/SP3-19-frame-rate-controller
FRC changed FRC code changed to adapt better with current state of the engine. Sole purpose to retrieve the varying raw delta time Only two functions: Get the varying raw delta time of the current frame Update the FRC to update the raw delta time
This commit is contained in:
commit
a9932d5494
|
@ -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<SBTestScene>("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
|
||||
|
|
|
@ -9,12 +9,31 @@
|
|||
consent of DigiPen Institute of Technology is prohibited.
|
||||
*********************************************************************/
|
||||
|
||||
|
||||
//TODO Legacy code. Delete soon
|
||||
|
||||
#include <chrono>
|
||||
#include <cassert>
|
||||
#include <SHpch.h>
|
||||
#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<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
|
||||
{
|
||||
//Init statics
|
||||
|
@ -131,4 +150,5 @@ namespace SHADE
|
|||
currentScene = nextScene;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
|
@ -13,6 +13,38 @@
|
|||
#define SH_FRAMERATECONTROLLER_H
|
||||
#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"
|
||||
|
||||
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
|
Loading…
Reference in New Issue