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:
@@ -8,7 +8,8 @@
|
||||
|
||||
#include "LyShineTest.h"
|
||||
#include <Mocks/ISystemMock.h>
|
||||
#include <Mocks/ITimerMock.h>
|
||||
#include <AzCore/UnitTest/Mocks/MockITime.h>
|
||||
#include <AzFramework/Application/Application.h>
|
||||
|
||||
#include <UiCanvasComponent.h>
|
||||
#include <Animation/AnimSequence.h>
|
||||
@@ -17,21 +18,26 @@
|
||||
|
||||
namespace UnitTest
|
||||
{
|
||||
class FrameTimerMock
|
||||
: public TimerMock
|
||||
struct AnimationTestStubTimer : public AZ::StubTimeSystem
|
||||
{
|
||||
public:
|
||||
const CTimeValue& GetFrameStartTime([[maybe_unused]] ITimer::ETimer which = ITimer::ETIMER_GAME) const override
|
||||
AZ_RTTI(UnitTest::AnimationTestStubTimer, "{541EBC6C-E793-4433-9402-4CAD2F6770E3}", AZ::StubTimeSystem);
|
||||
|
||||
AZ::TimeMs GetElapsedTimeMs() const override
|
||||
{
|
||||
return m_frameStartTime;
|
||||
}
|
||||
void AddFrameStartTime(float seconds)
|
||||
{
|
||||
m_frameStartTime += CTimeValue(seconds);
|
||||
return AZ::TimeUsToMs(m_timeUs);
|
||||
}
|
||||
|
||||
private:
|
||||
CTimeValue m_frameStartTime = CTimeValue();
|
||||
AZ::TimeUs GetElapsedTimeUs() const override
|
||||
{
|
||||
return m_timeUs;
|
||||
}
|
||||
|
||||
void AddFrameTime(float sec)
|
||||
{
|
||||
m_timeUs += AZ::SecondsToTimeUs(sec);
|
||||
}
|
||||
|
||||
AZ::TimeUs m_timeUs = AZ::Time::ZeroTimeUs;
|
||||
};
|
||||
|
||||
class TrackEventHandler
|
||||
@@ -65,6 +71,22 @@ namespace UnitTest
|
||||
AZStd::vector<EventInfo> m_recievedEvents;
|
||||
};
|
||||
|
||||
class LyShineAnimationTestApplication : public AzFramework::Application
|
||||
{
|
||||
public:
|
||||
LyShineAnimationTestApplication()
|
||||
: AzFramework::Application()
|
||||
{
|
||||
m_timeSystem.reset();
|
||||
m_timeSystem = AZStd::make_unique<UnitTest::AnimationTestStubTimer>();
|
||||
}
|
||||
|
||||
UnitTest::AnimationTestStubTimer* GetTimer()
|
||||
{
|
||||
return azdynamic_cast<UnitTest::AnimationTestStubTimer*>(m_timeSystem.get());
|
||||
}
|
||||
};
|
||||
|
||||
class LyShineAnimationTest
|
||||
: public LyShineTest
|
||||
{
|
||||
@@ -74,31 +96,38 @@ namespace UnitTest
|
||||
{
|
||||
}
|
||||
|
||||
void SetupApplication() override
|
||||
{
|
||||
AZ::ComponentApplication::Descriptor appDesc;
|
||||
appDesc.m_memoryBlocksByteSize = 10 * 1024 * 1024;
|
||||
appDesc.m_recordingMode = AZ::Debug::AllocationRecords::RECORD_FULL;
|
||||
appDesc.m_stackRecordLevels = 20;
|
||||
|
||||
m_application = aznew LyShineAnimationTestApplication();
|
||||
m_systemEntity = m_application->Create(appDesc);
|
||||
m_systemEntity->Init();
|
||||
m_systemEntity->Activate();
|
||||
}
|
||||
|
||||
void SetupEnvironment() override
|
||||
{
|
||||
LyShineTest::SetupEnvironment();
|
||||
|
||||
m_data = AZStd::make_unique<Data>();
|
||||
m_env->m_stubEnv.pTimer = &m_data->m_timer;
|
||||
|
||||
m_canvasComponent = aznew UiCanvasComponent;
|
||||
}
|
||||
|
||||
void TearDown() override
|
||||
{
|
||||
delete m_canvasComponent;
|
||||
m_data.reset();
|
||||
|
||||
UiAnimationNotificationBus::ClearQueuedEvents();
|
||||
LyShineTest::TearDown();
|
||||
}
|
||||
|
||||
struct Data
|
||||
UnitTest::AnimationTestStubTimer* GetTimer()
|
||||
{
|
||||
testing::NiceMock<FrameTimerMock> m_timer;
|
||||
};
|
||||
|
||||
AZStd::unique_ptr<Data> m_data;
|
||||
return static_cast<LyShineAnimationTestApplication*>(m_application)->GetTimer();
|
||||
}
|
||||
UiCanvasComponent* m_canvasComponent;
|
||||
};
|
||||
|
||||
@@ -126,13 +155,14 @@ namespace UnitTest
|
||||
eventHandler.Connect(m_canvasComponent->GetEntityId());
|
||||
animSys->PlaySequence(sequence, nullptr, true, true);
|
||||
|
||||
UnitTest::AnimationTestStubTimer* timer = GetTimer();
|
||||
for (int frame = 0; frame < 2; ++frame)
|
||||
{
|
||||
static float deltaTime = 1.0f / 60.0f;
|
||||
|
||||
animSys->PreUpdate(deltaTime);
|
||||
animSys->PostUpdate(deltaTime);
|
||||
m_data->m_timer.AddFrameStartTime(deltaTime);
|
||||
timer->AddFrameTime(deltaTime);
|
||||
}
|
||||
|
||||
UiAnimationNotificationBus::ExecuteQueuedEvents();
|
||||
|
||||
Reference in New Issue
Block a user