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:
amzn-sean
2021-11-15 12:11:58 +00:00
committed by GitHub
parent 0ada8b335b
commit 38a03817bb
142 changed files with 1215 additions and 2090 deletions
-1
View File
@@ -6,7 +6,6 @@
*
*/
#include <AzCore/Debug/Timer.h>
#include <AzCore/Debug/StackTracer.h>
#include <AzCore/Debug/TraceMessagesDrillerBus.h>
#include <AzCore/Debug/Profiler.h>
@@ -11,7 +11,7 @@
#include <AzCore/EBus/ScheduledEvent.h>
#include <AzCore/Interface/Interface.h>
#include <AzCore/Console/LoggerSystemComponent.h>
#include <AzCore/Time/TimeSystemComponent.h>
#include <AzCore/Time/TimeSystem.h>
#include <AzCore/Name/NameDictionary.h>
#include <AzCore/UnitTest/TestTypes.h>
@@ -26,22 +26,22 @@ namespace UnitTest
SetupAllocator();
AZ::NameDictionary::Create();
m_loggerComponent = new AZ::LoggerSystemComponent;
m_timeComponent = new AZ::TimeSystemComponent;
m_eventSchedulerComponent = new AZ::EventSchedulerSystemComponent;
m_loggerComponent = AZStd::make_unique<AZ::LoggerSystemComponent>();
m_timeSystem = AZStd::make_unique<AZ::TimeSystem>();
m_eventSchedulerComponent = AZStd::make_unique<AZ::EventSchedulerSystemComponent>();
m_testEvent = new AZ::ScheduledEvent([this] { TestBasicEvent(); }, AZ::Name("UnitTestEvent fire once event"));
m_testRequeue = new AZ::ScheduledEvent([this] { TestAutoRequeuedEvent(); }, AZ::Name("UnitTestEvent auto Requeue"));
m_testEvent = AZStd::make_unique<AZ::ScheduledEvent>([this] { TestBasicEvent(); }, AZ::Name("UnitTestEvent fire once event"));
m_testRequeue = AZStd::make_unique<AZ::ScheduledEvent>([this] { TestAutoRequeuedEvent(); }, AZ::Name("UnitTestEvent auto Requeue"));
}
void TearDown() override
{
delete m_testEvent;
delete m_testRequeue;
m_testEvent.reset();
m_testRequeue.reset();
delete m_eventSchedulerComponent;
delete m_timeComponent;
delete m_loggerComponent;
m_eventSchedulerComponent.reset();
m_timeSystem.reset();
m_loggerComponent.reset();
AZ::NameDictionary::Destroy();
TeardownAllocator();
@@ -60,12 +60,12 @@ namespace UnitTest
uint32_t m_basicEventTriggerCount = 0;
uint32_t m_requeuedEventTriggerCount = 0;
AZ::ScheduledEvent* m_testEvent = nullptr;
AZ::ScheduledEvent* m_testRequeue = nullptr;
AZStd::unique_ptr<AZ::ScheduledEvent> m_testEvent;
AZStd::unique_ptr<AZ::ScheduledEvent> m_testRequeue;
AZ::LoggerSystemComponent* m_loggerComponent = nullptr;
AZ::TimeSystemComponent* m_timeComponent = nullptr;
AZ::EventSchedulerSystemComponent* m_eventSchedulerComponent = nullptr;
AZStd::unique_ptr<AZ::LoggerSystemComponent> m_loggerComponent;
AZStd::unique_ptr<AZ::TimeSystem> m_timeSystem;
AZStd::unique_ptr<AZ::EventSchedulerSystemComponent> m_eventSchedulerComponent;
};
TEST_F(ScheduledEventTests, TestFireOnce)
+28 -4
View File
@@ -6,7 +6,7 @@
*
*/
#include <AzCore/Time/TimeSystemComponent.h>
#include <AzCore/Time/TimeSystem.h>
#include <AzCore/UnitTest/TestTypes.h>
namespace UnitTest
@@ -18,16 +18,16 @@ namespace UnitTest
void SetUp() override
{
SetupAllocator();
m_timeComponent = new AZ::TimeSystemComponent;
m_timeSystem = AZStd::make_unique<AZ::TimeSystem>();
}
void TearDown() override
{
delete m_timeComponent;
m_timeSystem.reset();
TeardownAllocator();
}
AZ::TimeSystemComponent* m_timeComponent = nullptr;
AZStd::unique_ptr<AZ::TimeSystem> m_timeSystem;
};
TEST_F(TimeTests, TestConversionUsToMs)
@@ -44,6 +44,30 @@ namespace UnitTest
EXPECT_EQ(timeUs, AZ::TimeUs{ 1000000 });
}
TEST_F(TimeTests, TestConversionTimeMsToSeconds)
{
AZ::TimeMs timeMs = AZ::TimeMs{ 1000 };
float timeSecondsFloat = AZ::TimeMsToSeconds(timeMs);
EXPECT_TRUE(AZ::IsClose(timeSecondsFloat, 1.0f));
double timeSecondsDouble = AZ::TimeMsToSecondsDouble(timeMs);
EXPECT_TRUE(AZ::IsClose(timeSecondsDouble, 1.0));
}
TEST_F(TimeTests, TestConversionSecondsToTimeUs)
{
double seconds = 1.0;
AZ::TimeUs timeUs = AZ::SecondsToTimeUs(seconds);
EXPECT_EQ(timeUs, AZ::TimeUs{ 1000000 });
}
TEST_F(TimeTests, TestConversionSecondsToTimeMs)
{
double seconds = 1.0;
AZ::TimeMs timeMs = AZ::SecondsToTimeMs(seconds);
EXPECT_EQ(timeMs, AZ::TimeMs{ 1000 });
}
TEST_F(TimeTests, TestClocks)
{
AZ::TimeUs timeUs = AZ::GetElapsedTimeUs();