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:
@@ -47,7 +47,6 @@ struct IConsole;
|
||||
struct IRemoteConsole;
|
||||
struct IRenderer;
|
||||
struct IProcess;
|
||||
struct ITimer;
|
||||
struct ICryFont;
|
||||
struct IMovieSystem;
|
||||
namespace Audio
|
||||
@@ -610,7 +609,6 @@ struct SSystemGlobalEnvironment
|
||||
{
|
||||
AZ::IO::IArchive* pCryPak;
|
||||
AZ::IO::FileIOBase* pFileIO;
|
||||
ITimer* pTimer;
|
||||
ICryFont* pCryFont;
|
||||
::IConsole* pConsole;
|
||||
ISystem* pSystem = nullptr;
|
||||
@@ -831,8 +829,6 @@ struct ISystem
|
||||
virtual IRemoteConsole* GetIRemoteConsole() = 0;
|
||||
virtual ISystemEventDispatcher* GetISystemEventDispatcher() = 0;
|
||||
|
||||
virtual ITimer* GetITimer() = 0;
|
||||
|
||||
// Arguments:
|
||||
// bValue - Set to true when running on a cheat protected server or a client that is connected to it (not used in singleplayer).
|
||||
virtual void SetForceNonDevMode(bool bValue) = 0;
|
||||
|
||||
@@ -1,211 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) Contributors to the Open 3D Engine Project.
|
||||
* For complete copyright and license terms please see the LICENSE at the root of this distribution.
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0 OR MIT
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
#ifndef CRYINCLUDE_CRYCOMMON_ITIMER_H
|
||||
#define CRYINCLUDE_CRYCOMMON_ITIMER_H
|
||||
#pragma once
|
||||
|
||||
|
||||
#include "TimeValue.h" // CTimeValue
|
||||
#include "SerializeFwd.h"
|
||||
|
||||
struct tm;
|
||||
|
||||
// Summary:
|
||||
// Interface to the Timer System.
|
||||
struct ITimer
|
||||
{
|
||||
enum ETimer
|
||||
{
|
||||
ETIMER_GAME = 0, // Pausable, serialized, frametime is smoothed/scaled/clamped.
|
||||
ETIMER_UI, // Non-pausable, non-serialized, frametime unprocessed.
|
||||
ETIMER_LAST
|
||||
};
|
||||
|
||||
enum ETimeScaleChannels
|
||||
{
|
||||
eTSC_Trackview = 0,
|
||||
eTSC_GameStart
|
||||
};
|
||||
|
||||
// <interfuscator:shuffle>
|
||||
virtual ~ITimer() {};
|
||||
|
||||
// Summary:
|
||||
// Resets the timer
|
||||
// Notes:
|
||||
// Only needed because float precision wasn't last that long - can be removed if 64bit is used everywhere.
|
||||
virtual void ResetTimer() = 0;
|
||||
|
||||
// Summary:
|
||||
// Updates the timer every frame, needs to be called by the system.
|
||||
virtual void UpdateOnFrameStart() = 0;
|
||||
|
||||
// Summary:
|
||||
// Returns the absolute time at the last UpdateOnFrameStart() call.
|
||||
// Todo:
|
||||
// Remove, use GetFrameStartTime() instead.
|
||||
// See also:
|
||||
// UpdateOnFrameStart(),GetFrameStartTime()
|
||||
virtual float GetCurrTime(ETimer which = ETIMER_GAME) const = 0;
|
||||
|
||||
// Summary:
|
||||
// Returns the absolute time at the last UpdateOnFrameStart() call.
|
||||
// See also:
|
||||
// UpdateOnFrameStart()
|
||||
//virtual const CTimeValue& GetFrameStartTime(ETimer which = ETIMER_GAME) const = 0;
|
||||
virtual const CTimeValue& GetFrameStartTime(ETimer which = ETIMER_GAME) const = 0;
|
||||
|
||||
// Summary:
|
||||
// Returns the absolute current time.
|
||||
// Notes:
|
||||
// The value continuously changes, slower than GetFrameStartTime().
|
||||
// See also:
|
||||
// GetFrameStartTime()
|
||||
virtual CTimeValue GetAsyncTime() const = 0;
|
||||
|
||||
// Summary:
|
||||
// Returns the absolute current time at the moment of the call.
|
||||
virtual float GetAsyncCurTime() = 0;
|
||||
|
||||
// Summary:
|
||||
// Returns the relative time passed from the last UpdateOnFrameStart() in seconds.
|
||||
// See also:
|
||||
// UpdateOnFrameStart()
|
||||
virtual float GetFrameTime(ETimer which = ETIMER_GAME) const = 0;
|
||||
|
||||
// Description:
|
||||
// Returns the relative time passed from the last UpdateOnFrameStart() in seconds without any dilation, smoothing, clamping, etc...
|
||||
// See also:
|
||||
// UpdateOnFrameStart()
|
||||
virtual float GetRealFrameTime() const = 0;
|
||||
|
||||
// Summary:
|
||||
// Returns the time scale applied to time values.
|
||||
virtual float GetTimeScale() const = 0;
|
||||
|
||||
// Summary:
|
||||
// Returns the time scale factor for the given channel
|
||||
virtual float GetTimeScale(uint32 channel) const = 0;
|
||||
|
||||
// Summary:
|
||||
// Clears all current time scale requests
|
||||
virtual void ClearTimeScales() = 0;
|
||||
|
||||
// Summary:
|
||||
// Sets the time scale applied to time values.
|
||||
virtual void SetTimeScale(float s, uint32 channel = 0) = 0;
|
||||
|
||||
// Summary:
|
||||
// Enables/disables timer.
|
||||
virtual void EnableTimer(bool bEnable) = 0;
|
||||
|
||||
// Return Value:
|
||||
// True if timer is enabled
|
||||
virtual bool IsTimerEnabled() const = 0;
|
||||
|
||||
// Summary:
|
||||
// Returns the current framerate in frames/second.
|
||||
virtual float GetFrameRate() = 0;
|
||||
|
||||
// Summary:
|
||||
// Returns the fraction to blend current frame in profiling stats.
|
||||
virtual float GetProfileFrameBlending(float* pfBlendTime = 0, int* piBlendMode = 0) = 0;
|
||||
|
||||
// Summary:
|
||||
// Serialization.
|
||||
virtual void Serialize(TSerialize ser) = 0;
|
||||
|
||||
// Summary:
|
||||
// Tries to pause/unpause a timer.
|
||||
// Return Value:
|
||||
// True if successfully paused/unpaused, false otherwise.
|
||||
virtual bool PauseTimer(ETimer which, bool bPause) = 0;
|
||||
|
||||
// Summary:
|
||||
// Determines if a timer is paused.
|
||||
// Returns:
|
||||
// True if paused, false otherwise.
|
||||
virtual bool IsTimerPaused(ETimer which) = 0;
|
||||
|
||||
// Summary:
|
||||
// Tries to set a timer.
|
||||
// Returns:
|
||||
// True if successful, false otherwise.
|
||||
virtual bool SetTimer(ETimer which, float timeInSeconds) = 0;
|
||||
|
||||
// Summary:
|
||||
// Makes a tm struct from a time_t in UTC
|
||||
// Example:
|
||||
// Like gmtime.
|
||||
virtual void SecondsToDateUTC(time_t time, struct tm& outDateUTC) = 0;
|
||||
|
||||
// Summary:
|
||||
// Makes a UTC time from a tm.
|
||||
// Example:
|
||||
// Like timegm, but not available on all platforms.
|
||||
virtual time_t DateToSecondsUTC(struct tm& timePtr) = 0;
|
||||
|
||||
|
||||
// Summary
|
||||
// Convert from ticks (CryGetTicks()) to seconds
|
||||
//
|
||||
virtual float TicksToSeconds(int64 ticks) = 0;
|
||||
|
||||
// Summary
|
||||
// Get number of ticks per second
|
||||
//
|
||||
virtual int64 GetTicksPerSecond() = 0;
|
||||
|
||||
// Summary
|
||||
// Create a new timer of the same type
|
||||
//
|
||||
virtual ITimer* CreateNewTimer() = 0;
|
||||
|
||||
/*!
|
||||
This is similar to the cvar t_FixedStep. However it is stronger, and will cause even GetRealFrameTime to follow the fixed time stamp.
|
||||
GetRealFrameTime will always return the same value as GetFrameTime. This mode is mostly intended for Feature tests that have strict requirements
|
||||
for determinism. It will cause even fps counters to return a fixed value that does not match the actual fps. I could see this also being useful
|
||||
if rendering a video.
|
||||
*/
|
||||
virtual void EnableFixedTimeMode(bool enable, float timeStep) = 0;
|
||||
// </interfuscator:shuffle>
|
||||
};
|
||||
|
||||
// Description:
|
||||
// This class is used for automatic profiling of a section of the code.
|
||||
// Creates an instance of this class, and upon exiting from the code section.
|
||||
template <typename time>
|
||||
class CITimerAutoProfiler
|
||||
{
|
||||
public:
|
||||
CITimerAutoProfiler (ITimer* pTimer, time& rTime)
|
||||
: m_pTimer (pTimer)
|
||||
, m_rTime (rTime)
|
||||
{
|
||||
rTime -= pTimer->GetAsyncCurTime();
|
||||
}
|
||||
|
||||
~CITimerAutoProfiler ()
|
||||
{
|
||||
m_rTime += m_pTimer->GetAsyncCurTime();
|
||||
}
|
||||
|
||||
protected:
|
||||
ITimer* m_pTimer;
|
||||
time& m_rTime;
|
||||
};
|
||||
|
||||
// Description:
|
||||
// Include this string AUTO_PROFILE_SECTION(pITimer, g_fTimer) for the section of code where the profiler timer must be turned on and off.
|
||||
// The profiler timer is just some global or static float or double value that accumulates the time (in seconds) spent in the given block of code.
|
||||
// pITimer is a pointer to the ITimer interface, g_fTimer is the global accumulator.
|
||||
#define AUTO_PROFILE_SECTION(pITimer, g_fTimer) CITimerAutoProfiler<double> __section_auto_profiler(pITimer, g_fTimer)
|
||||
|
||||
#endif // CRYINCLUDE_CRYCOMMON_ITIMER_H
|
||||
@@ -9,7 +9,6 @@
|
||||
|
||||
#include <Range.h>
|
||||
#include <AnimKey.h>
|
||||
#include <ITimer.h>
|
||||
#include <LyShine/ILyShine.h>
|
||||
#include <AzCore/Math/Vector2.h>
|
||||
#include <AzCore/Math/Vector3.h>
|
||||
|
||||
@@ -13,7 +13,7 @@
|
||||
#include <AzCore/IO/Path/Path.h>
|
||||
#include <AzFramework/Archive/INestedArchive.h>
|
||||
#include <AzFramework/Archive/IArchive.h>
|
||||
|
||||
#include <CryCommon/platform.h>
|
||||
|
||||
struct CryPakMock
|
||||
: AZ::IO::IArchive
|
||||
|
||||
@@ -75,8 +75,6 @@ public:
|
||||
IRemoteConsole * ());
|
||||
MOCK_METHOD0(GetISystemEventDispatcher,
|
||||
ISystemEventDispatcher * ());
|
||||
MOCK_METHOD0(GetITimer,
|
||||
ITimer * ());
|
||||
MOCK_METHOD1(SetForceNonDevMode,
|
||||
void(bool bValue));
|
||||
MOCK_CONST_METHOD0(GetForceNonDevMode,
|
||||
|
||||
@@ -1,51 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) Contributors to the Open 3D Engine Project.
|
||||
* For complete copyright and license terms please see the LICENSE at the root of this distribution.
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0 OR MIT
|
||||
*
|
||||
*/
|
||||
#ifndef CRYINCLUDE_CRYSYSTEM_ITIMERMOCK_H
|
||||
#define CRYINCLUDE_CRYSYSTEM_ITIMERMOCK_H
|
||||
#pragma once
|
||||
|
||||
#include <ISerialize.h>
|
||||
#include <ITimer.h>
|
||||
#include <AzTest/AzTest.h>
|
||||
|
||||
// Implements all common timing routines
|
||||
class TimerMock
|
||||
: public ITimer
|
||||
{
|
||||
public:
|
||||
MOCK_METHOD0(ResetTimer, void());
|
||||
MOCK_METHOD0(UpdateOnFrameStart, void());
|
||||
MOCK_CONST_METHOD1(GetCurrTime, float(ETimer which));
|
||||
MOCK_CONST_METHOD0(GetAsyncTime, CTimeValue());
|
||||
MOCK_METHOD0(GetAsyncCurTime, float());
|
||||
MOCK_CONST_METHOD1(GetFrameTime, float(ETimer which));
|
||||
MOCK_CONST_METHOD0(GetRealFrameTime, float());
|
||||
MOCK_CONST_METHOD0(GetTimeScale, float());
|
||||
MOCK_CONST_METHOD1(GetTimeScale, float(uint32 channel));
|
||||
MOCK_METHOD2(SetTimeScale, void(float scale, uint32 channel));
|
||||
MOCK_METHOD0(ClearTimeScales, void());
|
||||
MOCK_METHOD1(EnableTimer, void(bool bEnable));
|
||||
MOCK_METHOD0(GetFrameRate, float());
|
||||
MOCK_METHOD2(GetProfileFrameBlending, float(float* pfBlendTime, int* piBlendMode));
|
||||
MOCK_METHOD1(Serialize, void(TSerialize ser));
|
||||
MOCK_CONST_METHOD0(IsTimerEnabled, bool());
|
||||
MOCK_METHOD2(PauseTimer, bool(ETimer which, bool bPause));
|
||||
MOCK_METHOD1(IsTimerPaused, bool(ETimer which));
|
||||
MOCK_METHOD2(SetTimer, bool(ETimer which, float timeInSeconds));
|
||||
MOCK_METHOD2(SecondsToDateUTC, void(time_t time, struct tm& outDateUTC));
|
||||
MOCK_METHOD1(DateToSecondsUTC, time_t(struct tm& timePtr));
|
||||
MOCK_METHOD1(TicksToSeconds, float(int64 ticks));
|
||||
MOCK_METHOD0(GetTicksPerSecond, int64());
|
||||
|
||||
MOCK_CONST_METHOD1(GetFrameStartTime, const CTimeValue&(ETimer which));
|
||||
MOCK_METHOD0(CreateNewTimer, ITimer * ());
|
||||
|
||||
MOCK_METHOD2(EnableFixedTimeMode, void(bool enable, float timeStep));
|
||||
};
|
||||
|
||||
#endif // CRYINCLUDE_CRYSYSTEM_ITIMERMOCK_H
|
||||
@@ -1,112 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) Contributors to the Open 3D Engine Project.
|
||||
* For complete copyright and license terms please see the LICENSE at the root of this distribution.
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0 OR MIT
|
||||
*
|
||||
*/
|
||||
#pragma once
|
||||
|
||||
#include <CryCommon/ITimer.h>
|
||||
#include <CryCommon/ISerialize.h>
|
||||
|
||||
//! Simple stub timer that exposes a single simple interface for setting the current time.
|
||||
class StubTimer
|
||||
: public ITimer
|
||||
{
|
||||
public:
|
||||
// Stub methods
|
||||
void SetTime(float seconds)
|
||||
{
|
||||
m_frameStartTime.SetSeconds(seconds);
|
||||
}
|
||||
//~Stub methods
|
||||
|
||||
StubTimer(float frameTime)
|
||||
: m_frameTime(frameTime)
|
||||
, m_frameRate(1.0f / frameTime)
|
||||
, m_frameStartTime(0.0f)
|
||||
{
|
||||
}
|
||||
virtual ~StubTimer() {};
|
||||
|
||||
// ITimer
|
||||
void ResetTimer() override {}
|
||||
void UpdateOnFrameStart() override {}
|
||||
float GetCurrTime([[maybe_unused]] ETimer which = ETIMER_GAME) const override
|
||||
{
|
||||
// return the same as the frame start time
|
||||
return m_frameStartTime.GetSeconds();
|
||||
}
|
||||
const CTimeValue& GetFrameStartTime([[maybe_unused]] ETimer which = ETIMER_GAME) const override
|
||||
{
|
||||
return m_frameStartTime;
|
||||
}
|
||||
CTimeValue GetAsyncTime() const override
|
||||
{
|
||||
return m_frameStartTime;
|
||||
}
|
||||
float GetAsyncCurTime() override
|
||||
{
|
||||
return m_frameStartTime.GetSeconds();
|
||||
}
|
||||
float GetFrameTime([[maybe_unused]] ETimer which = ETIMER_GAME) const override
|
||||
{
|
||||
return m_frameTime;
|
||||
}
|
||||
float GetRealFrameTime() const override
|
||||
{
|
||||
return m_frameTime;
|
||||
}
|
||||
float GetTimeScale() const override
|
||||
{
|
||||
return 1.0f;
|
||||
}
|
||||
float GetTimeScale([[maybe_unused]] uint32 channel) const override
|
||||
{
|
||||
return 1.0f;
|
||||
}
|
||||
void ClearTimeScales() override {}
|
||||
void SetTimeScale([[maybe_unused]] float s, [[maybe_unused]] uint32 channel = 0) override {}
|
||||
void EnableTimer([[maybe_unused]] bool bEnable) override {}
|
||||
bool IsTimerEnabled() const override
|
||||
{
|
||||
return true;
|
||||
}
|
||||
float GetFrameRate() override
|
||||
{
|
||||
return m_frameRate;
|
||||
}
|
||||
float GetProfileFrameBlending([[maybe_unused]] float* pfBlendTime = 0, [[maybe_unused]] int* piBlendMode = 0) override
|
||||
{
|
||||
return 0.0f;
|
||||
}
|
||||
void Serialize([[maybe_unused]] TSerialize ser) override {}
|
||||
bool PauseTimer([[maybe_unused]] ETimer which, [[maybe_unused]] bool bPause) override { return false; }
|
||||
bool IsTimerPaused([[maybe_unused]] ETimer which) override { return false; }
|
||||
bool SetTimer([[maybe_unused]] ETimer which, [[maybe_unused]] float timeInSeconds) override { return false; }
|
||||
void SecondsToDateUTC([[maybe_unused]] time_t time, [[maybe_unused]] struct tm& outDateUTC) override {}
|
||||
time_t DateToSecondsUTC([[maybe_unused]] struct tm& timePtr) override
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
float TicksToSeconds([[maybe_unused]] int64 ticks) override
|
||||
{
|
||||
return 0.0f;
|
||||
}
|
||||
int64 GetTicksPerSecond() override
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
ITimer* CreateNewTimer() override
|
||||
{
|
||||
return nullptr;
|
||||
}
|
||||
void EnableFixedTimeMode([[maybe_unused]] bool enable, [[maybe_unused]] float timeStep) override {}
|
||||
// ~ITimer
|
||||
|
||||
private:
|
||||
CTimeValue m_frameStartTime;
|
||||
float m_frameTime;
|
||||
float m_frameRate;
|
||||
};
|
||||
@@ -1,38 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) Contributors to the Open 3D Engine Project.
|
||||
* For complete copyright and license terms please see the LICENSE at the root of this distribution.
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0 OR MIT
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
#pragma once
|
||||
#ifndef CRYINCLUDE_CRYCOMMON_TIMER_H
|
||||
#define CRYINCLUDE_CRYCOMMON_TIMER_H
|
||||
|
||||
struct Timer
|
||||
{
|
||||
Timer()
|
||||
: endTime(-1.0f)
|
||||
{
|
||||
}
|
||||
|
||||
void Reset(float duration, float variation = 0.0f)
|
||||
{
|
||||
endTime = gEnv->pSystem->GetITimer()->GetFrameStartTime() + CTimeValue(duration) + CTimeValue(cry_random(0.0f, variation));
|
||||
}
|
||||
|
||||
bool Elapsed() const
|
||||
{
|
||||
return endTime >= 0.0f && gEnv->pSystem->GetITimer()->GetFrameStartTime() >= endTime;
|
||||
}
|
||||
|
||||
float GetSecondsLeft() const
|
||||
{
|
||||
return (endTime - gEnv->pSystem->GetITimer()->GetFrameStartTime()).GetSeconds();
|
||||
}
|
||||
|
||||
CTimeValue endTime;
|
||||
};
|
||||
#endif // CRYINCLUDE_CRYCOMMON_TIMER_H
|
||||
@@ -34,7 +34,6 @@ set(FILES
|
||||
StatObjBus.h
|
||||
ISystem.h
|
||||
ITexture.h
|
||||
ITimer.h
|
||||
IValidator.h
|
||||
IWindowMessageHandler.h
|
||||
IXml.h
|
||||
@@ -68,7 +67,6 @@ set(FILES
|
||||
SimpleSerialize.h
|
||||
smartptr.h
|
||||
StlUtils.h
|
||||
Timer.h
|
||||
TimeValue.h
|
||||
VectorMap.h
|
||||
VertexFormats.h
|
||||
|
||||
@@ -12,6 +12,5 @@ set(FILES
|
||||
Mocks/ICryPakMock.h
|
||||
Mocks/ILogMock.h
|
||||
Mocks/ISystemMock.h
|
||||
Mocks/ITimerMock.h
|
||||
Mocks/ICVarMock.h
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user