moved delta time computation to the HAL
This commit is contained in:
@@ -34,6 +34,9 @@ namespace Juliet
|
|||||||
namespace Time
|
namespace Time
|
||||||
{
|
{
|
||||||
uint64 Timestamp();
|
uint64 Timestamp();
|
||||||
|
void ComputeDeltaTime();
|
||||||
|
float GetDeltaTime();
|
||||||
|
uint64 GetFrameNumber();
|
||||||
} // namespace Time
|
} // namespace Time
|
||||||
|
|
||||||
namespace Debug
|
namespace Debug
|
||||||
|
|||||||
@@ -23,10 +23,32 @@ namespace Juliet
|
|||||||
|
|
||||||
namespace Time
|
namespace Time
|
||||||
{
|
{
|
||||||
|
namespace
|
||||||
|
{
|
||||||
|
float DeltaTime = 0.0f;
|
||||||
|
uint64 Frame = 0;
|
||||||
|
} // namespace
|
||||||
|
|
||||||
uint64 Timestamp()
|
uint64 Timestamp()
|
||||||
{
|
{
|
||||||
return Internal::OS_Timestamp();
|
return Internal::OS_Timestamp();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ComputeDeltaTime()
|
||||||
|
{
|
||||||
|
DeltaTime = Internal::OS_ComputeDeltaTime();
|
||||||
|
++Frame;
|
||||||
|
}
|
||||||
|
|
||||||
|
float GetDeltaTime()
|
||||||
|
{
|
||||||
|
return DeltaTime;
|
||||||
|
}
|
||||||
|
|
||||||
|
uint64 GetFrameNumber()
|
||||||
|
{
|
||||||
|
return Frame;
|
||||||
|
}
|
||||||
} // namespace Time
|
} // namespace Time
|
||||||
|
|
||||||
namespace Debug
|
namespace Debug
|
||||||
|
|||||||
@@ -17,7 +17,8 @@ namespace Juliet
|
|||||||
namespace Time::Internal
|
namespace Time::Internal
|
||||||
{
|
{
|
||||||
uint64 OS_Timestamp();
|
uint64 OS_Timestamp();
|
||||||
}
|
float OS_ComputeDeltaTime();
|
||||||
|
} // namespace Time::Internal
|
||||||
|
|
||||||
namespace Internal
|
namespace Internal
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -54,6 +54,26 @@ namespace Juliet
|
|||||||
|
|
||||||
return (static_cast<uint64>(ft.dwHighDateTime) << 32) + ft.dwLowDateTime;
|
return (static_cast<uint64>(ft.dwHighDateTime) << 32) + ft.dwLowDateTime;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
float OS_ComputeDeltaTime()
|
||||||
|
{
|
||||||
|
static LARGE_INTEGER frequency = {};
|
||||||
|
static LARGE_INTEGER lastTime = {};
|
||||||
|
if (frequency.QuadPart == 0)
|
||||||
|
{
|
||||||
|
QueryPerformanceFrequency(&frequency);
|
||||||
|
QueryPerformanceCounter(&lastTime);
|
||||||
|
}
|
||||||
|
|
||||||
|
LARGE_INTEGER currentTime;
|
||||||
|
QueryPerformanceCounter(¤tTime);
|
||||||
|
const float deltaTime =
|
||||||
|
static_cast<float>(currentTime.QuadPart - lastTime.QuadPart) / static_cast<float>(frequency.QuadPart);
|
||||||
|
lastTime = currentTime;
|
||||||
|
|
||||||
|
return deltaTime;
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace Time::Internal
|
} // namespace Time::Internal
|
||||||
|
|
||||||
namespace Debug::Internal
|
namespace Debug::Internal
|
||||||
|
|||||||
@@ -3,6 +3,7 @@
|
|||||||
#include <Core/Common/CoreUtils.h>
|
#include <Core/Common/CoreUtils.h>
|
||||||
#include <Core/HAL/Event/SystemEvent.h>
|
#include <Core/HAL/Event/SystemEvent.h>
|
||||||
#include <Core/HAL/Filesystem/Filesystem_Private.h>
|
#include <Core/HAL/Filesystem/Filesystem_Private.h>
|
||||||
|
#include <Core/HAL/OS/OS.h>
|
||||||
#include <Core/JulietInit.h>
|
#include <Core/JulietInit.h>
|
||||||
#include <Core/Logging/LogManager.h>
|
#include <Core/Logging/LogManager.h>
|
||||||
#include <Core/Memory/MemoryArena.h>
|
#include <Core/Memory/MemoryArena.h>
|
||||||
@@ -19,14 +20,6 @@
|
|||||||
#include <imgui.h>
|
#include <imgui.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// TODO Move to os hal for query perf
|
|
||||||
#ifdef _WIN32
|
|
||||||
#ifndef WIN32_LEAN_AND_MEAN
|
|
||||||
#define WIN32_LEAN_AND_MEAN
|
|
||||||
#endif
|
|
||||||
#include <Windows.h>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
namespace Juliet
|
namespace Juliet
|
||||||
{
|
{
|
||||||
#if JULIET_DEBUG
|
#if JULIET_DEBUG
|
||||||
@@ -219,20 +212,9 @@ namespace Juliet
|
|||||||
ImGuiRenderer_NewFrame();
|
ImGuiRenderer_NewFrame();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// TODO : Move to os side as it is win32 only
|
Time::ComputeDeltaTime();
|
||||||
static LARGE_INTEGER frequency = {};
|
|
||||||
static LARGE_INTEGER lastTime = {};
|
|
||||||
if (frequency.QuadPart == 0)
|
|
||||||
{
|
|
||||||
QueryPerformanceFrequency(&frequency);
|
|
||||||
QueryPerformanceCounter(&lastTime);
|
|
||||||
}
|
|
||||||
|
|
||||||
LARGE_INTEGER currentTime;
|
const float deltaTime = Time::GetDeltaTime();
|
||||||
QueryPerformanceCounter(¤tTime);
|
|
||||||
float deltaTime =
|
|
||||||
static_cast<float>(currentTime.QuadPart - lastTime.QuadPart) / static_cast<float>(frequency.QuadPart);
|
|
||||||
lastTime = currentTime;
|
|
||||||
|
|
||||||
Events_NewFrame(deltaTime);
|
Events_NewFrame(deltaTime);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user