Removal and Replacement of the CryTimer (gEnv->pTimer) (#5409)
Replaced and removed the CryTimer (gEnv->pTimer). The new TimeSystem is a merger of the current time functionality found in the engine.
* Rename TimeSystemComponent.h/.cpp to TimeSystem.h/.cpp
* Adding New TimeSystem
* remove old timer cvars
* small improvements to the time system.
- updated parts to use the time conversion functions.
- in AdvanceTickDeltaTimes applying t_simulationTickScale is now uses doubles instead of floats.
* Replace gEnv->pTimer / ITimer usages with TimeSystem
* Updating usages of AZ::TimeMs{ 0 } and AZ::TimeUs{ 0 } to AZ::Time::ZeroTimeMs and AZ::Time::ZeroTimeUs
* red code the CryTimer
* using TimeUs instead of TimeMs is some cases + updating usages of old cvars to new
Signed-off-by: amzn-sean <75276488+amzn-sean@users.noreply.github.com>
This commit is contained in:
@@ -29,6 +29,7 @@
|
||||
#include <AzCore/Debug/IEventLogger.h>
|
||||
#include <AzCore/Interface/Interface.h>
|
||||
#include <AzCore/std/algorithm.h>
|
||||
#include <AzCore/Time/ITime.h>
|
||||
#include <AzFramework/Logging/MissingAssetLogger.h>
|
||||
#include <AzFramework/Entity/EntityDebugDisplayBus.h>
|
||||
#include <AzCore/Interface/Interface.h>
|
||||
@@ -156,6 +157,16 @@ SSystemCVars g_cvars;
|
||||
#include <AzCore/Component/ComponentApplication.h>
|
||||
#include "AZCoreLogSink.h"
|
||||
|
||||
namespace
|
||||
{
|
||||
float GetMovieFrameDeltaTime()
|
||||
{
|
||||
// Use GetRealTickDeltaTimeUs for CryMovie, because it should not be affected by pausing game time
|
||||
const AZ::TimeUs delta = AZ::GetRealTickDeltaTimeUs();
|
||||
return AZ::TimeUsToSeconds(delta);
|
||||
}
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
// System Implementation.
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
@@ -192,7 +203,6 @@ CSystem::CSystem(SharedEnvironmentInstance* pSharedEnvironment)
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
// Initialize global environment interface pointers.
|
||||
m_env.pSystem = this;
|
||||
m_env.pTimer = &m_Time;
|
||||
m_env.bIgnoreAllAsserts = false;
|
||||
m_env.bNoAssertDialog = false;
|
||||
|
||||
@@ -563,14 +573,15 @@ ISystem* CSystem::GetCrySystem()
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
void CSystem::SleepIfNeeded()
|
||||
{
|
||||
ITimer* const pTimer = gEnv->pTimer;
|
||||
static bool firstCall = true;
|
||||
|
||||
typedef MiniQueue<CTimeValue, 32> PrevNow;
|
||||
static PrevNow prevNow;
|
||||
if (firstCall)
|
||||
{
|
||||
m_lastTickTime = pTimer->GetAsyncTime();
|
||||
const AZ::TimeMs timeMs = AZ::GetRealElapsedTimeMs();
|
||||
const double timeSec = AZ::TimeMsToSecondsDouble(timeMs);
|
||||
m_lastTickTime = CTimeValue(timeSec);
|
||||
prevNow.Push(m_lastTickTime);
|
||||
firstCall = false;
|
||||
return;
|
||||
@@ -578,8 +589,10 @@ void CSystem::SleepIfNeeded()
|
||||
|
||||
const float maxRate = m_svDedicatedMaxRate->GetFVal();
|
||||
const float minTime = 1.0f / maxRate;
|
||||
CTimeValue now = pTimer->GetAsyncTime();
|
||||
float elapsed = (now - m_lastTickTime).GetSeconds();
|
||||
const AZ::TimeMs nowTimeMs = AZ::GetRealElapsedTimeMs();
|
||||
const double nowTimeSec = AZ::TimeMsToSecondsDouble(nowTimeMs);
|
||||
const CTimeValue now = CTimeValue(nowTimeSec);
|
||||
const float elapsed = (now - m_lastTickTime).GetSeconds();
|
||||
|
||||
if (prevNow.Full())
|
||||
{
|
||||
@@ -591,7 +604,9 @@ void CSystem::SleepIfNeeded()
|
||||
if (elapsed > minTime && allowStallCatchup)
|
||||
{
|
||||
allowStallCatchup = false;
|
||||
m_lastTickTime = pTimer->GetAsyncTime();
|
||||
const AZ::TimeMs lastTimeMs = AZ::GetRealElapsedTimeMs();
|
||||
const double lastTimeSec = AZ::TimeMsToSecondsDouble(lastTimeMs);
|
||||
m_lastTickTime = CTimeValue(lastTimeSec);
|
||||
return;
|
||||
}
|
||||
allowStallCatchup = true;
|
||||
@@ -607,7 +622,9 @@ void CSystem::SleepIfNeeded()
|
||||
Sleep(sleepMS);
|
||||
}
|
||||
|
||||
m_lastTickTime = pTimer->GetAsyncTime();
|
||||
const AZ::TimeMs lastTimeMs = AZ::GetRealElapsedTimeMs();
|
||||
const double lastTimeSec = AZ::TimeMsToSecondsDouble(lastTimeMs);
|
||||
m_lastTickTime = CTimeValue(lastTimeSec);
|
||||
}
|
||||
|
||||
extern DWORD g_idDebugThreads[];
|
||||
@@ -734,24 +751,21 @@ bool CSystem::UpdatePreTickBus(int updateFlags, int nPauseMode)
|
||||
|
||||
if (maxFPS > 0 && vSync == 0)
|
||||
{
|
||||
CTimeValue timeFrameMax;
|
||||
const float safeMarginFPS = 0.5f;//save margin to not drop below 30 fps
|
||||
static CTimeValue sTimeLast = gEnv->pTimer->GetAsyncTime();
|
||||
timeFrameMax.SetMilliSeconds((int64)(1000.f / ((float)maxFPS + safeMarginFPS)));
|
||||
const CTimeValue timeLast = timeFrameMax + sTimeLast;
|
||||
while (timeLast.GetValue() > gEnv->pTimer->GetAsyncTime().GetValue())
|
||||
static AZ::TimeMs sTimeLast = AZ::GetRealElapsedTimeMs();
|
||||
const AZ::TimeMs timeFrameMax(static_cast<AZ::TimeMs>(
|
||||
(int64)(1000.f / ((float)maxFPS + safeMarginFPS))
|
||||
));
|
||||
const AZ::TimeMs timeLast = timeFrameMax + sTimeLast;
|
||||
while (timeLast > AZ::GetRealElapsedTimeMs())
|
||||
{
|
||||
CrySleep(0);
|
||||
}
|
||||
sTimeLast = gEnv->pTimer->GetAsyncTime();
|
||||
sTimeLast = AZ::GetRealElapsedTimeMs();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
//update time subsystem
|
||||
m_Time.UpdateOnFrameStart();
|
||||
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
//update console system
|
||||
if (m_env.pConsole)
|
||||
@@ -765,13 +779,10 @@ bool CSystem::UpdatePreTickBus(int updateFlags, int nPauseMode)
|
||||
return false;
|
||||
}
|
||||
|
||||
// Use UI timer for CryMovie, because it should not be affected by pausing game time
|
||||
const float fMovieFrameTime = m_Time.GetFrameTime(ITimer::ETIMER_UI);
|
||||
|
||||
// Run movie system pre-update
|
||||
if (!bNoUpdate)
|
||||
{
|
||||
UpdateMovieSystem(updateFlags, fMovieFrameTime, true);
|
||||
UpdateMovieSystem(updateFlags, GetMovieFrameDeltaTime(), true);
|
||||
}
|
||||
|
||||
return !IsQuitting();
|
||||
@@ -780,13 +791,14 @@ bool CSystem::UpdatePreTickBus(int updateFlags, int nPauseMode)
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
bool CSystem::UpdatePostTickBus(int updateFlags, int /*nPauseMode*/)
|
||||
{
|
||||
CTimeValue updateStart = gEnv->pTimer->GetAsyncTime();
|
||||
const AZ::TimeMs updateStartTimeMs = AZ::GetRealElapsedTimeMs();
|
||||
const double updateStartTimeSec = AZ::TimeMsToSecondsDouble(updateStartTimeMs);
|
||||
const CTimeValue updateStart(updateStartTimeSec);
|
||||
|
||||
// Run movie system post-update
|
||||
if (!m_bNoUpdate)
|
||||
{
|
||||
const float fMovieFrameTime = m_Time.GetFrameTime(ITimer::ETIMER_UI);
|
||||
UpdateMovieSystem(updateFlags, fMovieFrameTime, false);
|
||||
UpdateMovieSystem(updateFlags, GetMovieFrameDeltaTime(), false);
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
@@ -797,7 +809,9 @@ bool CSystem::UpdatePostTickBus(int updateFlags, int /*nPauseMode*/)
|
||||
}
|
||||
|
||||
//Now update frame statistics
|
||||
CTimeValue cur_time = gEnv->pTimer->GetAsyncTime();
|
||||
const AZ::TimeMs curTimeMs = AZ::GetRealElapsedTimeMs();
|
||||
const double curTimeSec = AZ::TimeMsToSecondsDouble(curTimeMs);
|
||||
const CTimeValue cur_time(curTimeSec);
|
||||
|
||||
CTimeValue a_second(g_cvars.sys_update_profile_time);
|
||||
std::vector< std::pair<CTimeValue, float> >::iterator it = m_updateTimes.begin();
|
||||
@@ -1366,19 +1380,16 @@ const char* CSystem::GetSystemGlobalStateName(const ESystemGlobalState systemGlo
|
||||
|
||||
void CSystem::SetSystemGlobalState(const ESystemGlobalState systemGlobalState)
|
||||
{
|
||||
static CTimeValue s_startTime = CTimeValue();
|
||||
static AZ::TimeMs s_startTime = AZ::Time::ZeroTimeMs;
|
||||
if (systemGlobalState != m_systemGlobalState)
|
||||
{
|
||||
if (gEnv && gEnv->pTimer)
|
||||
{
|
||||
const CTimeValue endTime = gEnv->pTimer->GetAsyncTime();
|
||||
[[maybe_unused]] const float numSeconds = endTime.GetDifferenceInSeconds(s_startTime);
|
||||
CryLog("SetGlobalState %d->%d '%s'->'%s' %3.1f seconds",
|
||||
m_systemGlobalState, systemGlobalState,
|
||||
CSystem::GetSystemGlobalStateName(m_systemGlobalState), CSystem::GetSystemGlobalStateName(systemGlobalState),
|
||||
numSeconds);
|
||||
s_startTime = gEnv->pTimer->GetAsyncTime();
|
||||
}
|
||||
const AZ::TimeMs endTime = AZ::GetRealElapsedTimeMs();
|
||||
[[maybe_unused]] const double numSeconds = AZ::TimeMsToSecondsDouble(endTime - s_startTime);
|
||||
CryLog("SetGlobalState %d->%d '%s'->'%s' %3.1f seconds",
|
||||
m_systemGlobalState, systemGlobalState,
|
||||
CSystem::GetSystemGlobalStateName(m_systemGlobalState), CSystem::GetSystemGlobalStateName(systemGlobalState),
|
||||
numSeconds);
|
||||
s_startTime = AZ::GetRealElapsedTimeMs();
|
||||
}
|
||||
m_systemGlobalState = systemGlobalState;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user