Files
o3de/Gems/Gestures/Code/Tests/BaseGestureTest.h
T
amzn-sean 38a03817bb 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>
2021-11-15 12:11:58 +00:00

107 lines
2.5 KiB
C++

/*
* 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 <AzCore/Memory/OSAllocator.h>
#include <AzCore/UnitTest/Mocks/MockITime.h>
#include <AzTest/AzTest.h>
#include <Gestures/IGestureRecognizer.h>
namespace GesturesTests
{
struct StubTimer : public AZ::StubTimeSystem
{
AZ::TimeMs GetRealElapsedTimeMs() const override
{
return m_realElapsedTime;
}
AZ::TimeMs m_realElapsedTime = AZ::Time::ZeroTimeMs;
};
} // namespace GesturesTests
class BaseGestureTest : public ::testing::Test
{
public:
BaseGestureTest()
: m_pos(0.0f, 0.0f)
{
}
void SetUp() override
{
// global environment stubs
m_env = new(AZ_OS_MALLOC(sizeof(SSystemGlobalEnvironment), alignof(SSystemGlobalEnvironment))) SSystemGlobalEnvironment();
gEnv = m_env;
m_stubTimer = new GesturesTests::StubTimer();
// simulated position
m_pos = AZ::Vector2(0.0f, 0.0f);
}
void TearDown() override
{
gEnv = nullptr;
if (m_env)
{
m_env->~SSystemGlobalEnvironment();
AZ_OS_FREE(m_env);
m_env = nullptr;
}
delete m_stubTimer;
}
protected:
// time manipulation
void SetTime(float sec)
{
m_stubTimer->m_realElapsedTime = AZ::SecondsToTimeMs(sec);
}
// simple position caching interface
void MoveTo(float x, float y)
{
m_pos = AZ::Vector2(x, y);
}
void MouseDownAt(Gestures::IRecognizer& recognizer, float sec)
{
Press(recognizer, 0, m_pos, sec);
}
void MouseUpAt(Gestures::IRecognizer& recognizer, float sec)
{
Release(recognizer, 0, m_pos, sec);
}
// more direct interface
void Press(Gestures::IRecognizer& recognizer, uint index, AZ::Vector2 pos, float sec)
{
SetTime(sec);
recognizer.OnPressedEvent(pos, index);
}
void Move(Gestures::IRecognizer& recognizer, uint index, AZ::Vector2 pos, float sec)
{
SetTime(sec);
recognizer.OnDownEvent(pos, index);
}
void Release(Gestures::IRecognizer& recognizer, uint index, AZ::Vector2 pos, float sec)
{
SetTime(sec);
recognizer.OnReleasedEvent(pos, index);
}
private:
SSystemGlobalEnvironment* m_env = nullptr;
GesturesTests::StubTimer* m_stubTimer = nullptr;
AZ::Vector2 m_pos;
};