Merge pull request #4253 from aws-lumberyard-dev/MigrationFixup
Migration fixup
This commit is contained in:
@@ -1367,9 +1367,6 @@ namespace AZ
|
||||
#endif
|
||||
}
|
||||
|
||||
//=========================================================================
|
||||
// Tick
|
||||
//=========================================================================
|
||||
void ComponentApplication::Tick(float deltaOverride /*= -1.f*/)
|
||||
{
|
||||
{
|
||||
@@ -1397,9 +1394,6 @@ namespace AZ
|
||||
}
|
||||
}
|
||||
|
||||
//=========================================================================
|
||||
// Tick
|
||||
//=========================================================================
|
||||
void ComponentApplication::TickSystem()
|
||||
{
|
||||
AZ_PROFILE_SCOPE(System, "Component application tick");
|
||||
@@ -1547,5 +1541,4 @@ namespace AZ
|
||||
AZ::SettingsRegistryScriptUtils::ReflectSettingsRegistryToBehaviorContext(*behaviorContext);
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace AZ
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
* SPDX-License-Identifier: Apache-2.0 OR MIT
|
||||
*
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <AzCore/Component/ComponentApplicationBus.h>
|
||||
|
||||
@@ -5,7 +5,6 @@
|
||||
* SPDX-License-Identifier: Apache-2.0 OR MIT
|
||||
*
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <AzCore/base.h>
|
||||
|
||||
@@ -13,14 +13,26 @@
|
||||
#include <AzCore/RTTI/RTTI.h>
|
||||
#include <AzCore/RTTI/TypeSafeIntegral.h>
|
||||
#include <AzCore/std/time.h>
|
||||
#include <AzCore/std/chrono/chrono.h>
|
||||
|
||||
namespace AZ
|
||||
{
|
||||
//! This is a strong typedef for representing a millisecond value since application start.
|
||||
AZ_TYPE_SAFE_INTEGRAL(TimeMs, int64_t);
|
||||
|
||||
//! This is a strong typedef for representing a microsecond value since application start.
|
||||
//! Using int64_t as the underlying type, this is good to represent approximately 292,471 years
|
||||
AZ_TYPE_SAFE_INTEGRAL(TimeUs, int64_t);
|
||||
|
||||
//! @class ITime
|
||||
//! @brief This is an AZ::Interface<> for managing time related operations.
|
||||
//! AZ::ITime and associated types may not operate in realtime. These abstractions are to allow our application
|
||||
//! simulation to operate both slower and faster than realtime in a well defined and user controllable manner
|
||||
//! The rate at which time passes for AZ::ITime is controlled by the cvar t_scale
|
||||
//! t_scale == 0 means simulation time should halt
|
||||
//! 0 < t_scale < 1 will cause time to pass slower than realtime, with t_scale 0.1 being roughly 1/10th realtime
|
||||
//! t_scale == 1 will cause time to pass at roughly realtime
|
||||
//! t_scale > 1 will cause time to pass faster than normal, with t_scale 10 being roughly 10x realtime
|
||||
class ITime
|
||||
{
|
||||
public:
|
||||
@@ -33,6 +45,10 @@ namespace AZ
|
||||
//! @return the number of milliseconds that have elapsed since application start
|
||||
virtual TimeMs GetElapsedTimeMs() const = 0;
|
||||
|
||||
//! Returns the number of microseconds since application start.
|
||||
//! @return the number of microseconds that have elapsed since application start
|
||||
virtual TimeUs GetElapsedTimeUs() const = 0;
|
||||
|
||||
AZ_DISABLE_COPY_MOVE(ITime);
|
||||
};
|
||||
|
||||
@@ -51,6 +67,53 @@ namespace AZ
|
||||
{
|
||||
return AZ::Interface<ITime>::Get()->GetElapsedTimeMs();
|
||||
}
|
||||
}
|
||||
|
||||
//! This is a simple convenience wrapper
|
||||
inline TimeUs GetElapsedTimeUs()
|
||||
{
|
||||
return AZ::Interface<ITime>::Get()->GetElapsedTimeUs();
|
||||
}
|
||||
|
||||
//! Converts from milliseconds to microseconds
|
||||
inline TimeUs TimeMsToUs(TimeMs value)
|
||||
{
|
||||
return static_cast<TimeUs>(value * static_cast<TimeMs>(1000));
|
||||
}
|
||||
|
||||
//! Converts from microseconds to milliseconds
|
||||
inline TimeMs TimeUsToMs(TimeUs value)
|
||||
{
|
||||
return static_cast<TimeMs>(value / static_cast<TimeUs>(1000));
|
||||
}
|
||||
|
||||
//! Converts from milliseconds to seconds
|
||||
inline float TimeMsToSeconds(TimeMs value)
|
||||
{
|
||||
return static_cast<float>(value) / 1000.0f;
|
||||
}
|
||||
|
||||
//! Converts from microseconds to seconds
|
||||
inline float TimeUsToSeconds(TimeUs value)
|
||||
{
|
||||
return static_cast<float>(value) / 1000000.0f;
|
||||
}
|
||||
|
||||
//! Converts from milliseconds to AZStd::chrono::time_point
|
||||
inline auto TimeMsToChrono(TimeMs value)
|
||||
{
|
||||
auto epoch = AZStd::chrono::time_point<AZStd::chrono::high_resolution_clock>();
|
||||
auto chronoValue = AZStd::chrono::milliseconds(aznumeric_cast<int64_t>(value));
|
||||
return epoch + chronoValue;
|
||||
}
|
||||
|
||||
//! Converts from microseconds to AZStd::chrono::time_point
|
||||
inline auto TimeUsToChrono(TimeUs value)
|
||||
{
|
||||
auto epoch = AZStd::chrono::time_point<AZStd::chrono::high_resolution_clock>();
|
||||
auto chronoValue = AZStd::chrono::microseconds(aznumeric_cast<int64_t>(value));
|
||||
return epoch + chronoValue;
|
||||
}
|
||||
} // namespace AZ
|
||||
|
||||
AZ_TYPE_SAFE_INTEGRAL_SERIALIZEBINDING(AZ::TimeMs);
|
||||
AZ_TYPE_SAFE_INTEGRAL_SERIALIZEBINDING(AZ::TimeUs);
|
||||
|
||||
@@ -35,7 +35,7 @@ namespace AZ
|
||||
|
||||
TimeSystemComponent::TimeSystemComponent()
|
||||
{
|
||||
m_lastInvokedTimeMs = static_cast<TimeMs>(AZStd::GetTimeNowMicroSecond() / 1000);
|
||||
m_lastInvokedTimeUs = static_cast<TimeUs>(AZStd::GetTimeNowMicroSecond());
|
||||
AZ::Interface<ITime>::Register(this);
|
||||
ITimeRequestBus::Handler::BusConnect();
|
||||
}
|
||||
@@ -58,18 +58,23 @@ namespace AZ
|
||||
|
||||
TimeMs TimeSystemComponent::GetElapsedTimeMs() const
|
||||
{
|
||||
TimeMs currentTime = static_cast<TimeMs>(AZStd::GetTimeNowMicroSecond() / 1000);
|
||||
TimeMs deltaTime = currentTime - m_lastInvokedTimeMs;
|
||||
return TimeUsToMs(GetElapsedTimeUs());
|
||||
}
|
||||
|
||||
TimeUs TimeSystemComponent::GetElapsedTimeUs() const
|
||||
{
|
||||
TimeUs currentTime = static_cast<TimeUs>(AZStd::GetTimeNowMicroSecond());
|
||||
TimeUs deltaTime = currentTime - m_lastInvokedTimeUs;
|
||||
|
||||
if (t_scale != 1.0f)
|
||||
{
|
||||
float floatDelta = static_cast<float>(deltaTime) * t_scale;
|
||||
deltaTime = static_cast<TimeMs>(static_cast<int64_t>(floatDelta));
|
||||
deltaTime = static_cast<TimeUs>(static_cast<int64_t>(floatDelta));
|
||||
}
|
||||
|
||||
m_accumulatedTimeMs += deltaTime;
|
||||
m_lastInvokedTimeMs = currentTime;
|
||||
m_accumulatedTimeUs += deltaTime;
|
||||
m_lastInvokedTimeUs = currentTime;
|
||||
|
||||
return m_accumulatedTimeMs;
|
||||
return m_accumulatedTimeUs;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -39,11 +39,12 @@ namespace AZ
|
||||
//! ITime overrides.
|
||||
//! @{
|
||||
TimeMs GetElapsedTimeMs() const override;
|
||||
TimeUs GetElapsedTimeUs() const override;
|
||||
//! @}
|
||||
|
||||
private:
|
||||
|
||||
mutable TimeMs m_lastInvokedTimeMs = TimeMs{0};
|
||||
mutable TimeMs m_accumulatedTimeMs = TimeMs{0};
|
||||
mutable TimeUs m_lastInvokedTimeUs = TimeUs{0};
|
||||
mutable TimeUs m_accumulatedTimeUs = TimeUs{0};
|
||||
};
|
||||
}
|
||||
|
||||
@@ -0,0 +1,56 @@
|
||||
/*
|
||||
* 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
|
||||
*
|
||||
*/
|
||||
|
||||
#include <AzCore/Time/TimeSystemComponent.h>
|
||||
#include <AzCore/UnitTest/TestTypes.h>
|
||||
|
||||
namespace UnitTest
|
||||
{
|
||||
class TimeTests
|
||||
: public AllocatorsFixture
|
||||
{
|
||||
public:
|
||||
void SetUp() override
|
||||
{
|
||||
SetupAllocator();
|
||||
m_timeComponent = new AZ::TimeSystemComponent;
|
||||
}
|
||||
|
||||
void TearDown() override
|
||||
{
|
||||
delete m_timeComponent;
|
||||
TeardownAllocator();
|
||||
}
|
||||
|
||||
AZ::TimeSystemComponent* m_timeComponent = nullptr;
|
||||
};
|
||||
|
||||
TEST_F(TimeTests, TestConversionUsToMs)
|
||||
{
|
||||
AZ::TimeUs timeUs = AZ::TimeUs{ 1000 };
|
||||
AZ::TimeMs timeMs = AZ::TimeUsToMs(timeUs);
|
||||
EXPECT_EQ(timeMs, AZ::TimeMs{ 1 });
|
||||
}
|
||||
|
||||
TEST_F(TimeTests, TestConversionMsToUs)
|
||||
{
|
||||
AZ::TimeMs timeMs = AZ::TimeMs{ 1000 };
|
||||
AZ::TimeUs timeUs = AZ::TimeMsToUs(timeMs);
|
||||
EXPECT_EQ(timeUs, AZ::TimeUs{ 1000000 });
|
||||
}
|
||||
|
||||
TEST_F(TimeTests, TestClocks)
|
||||
{
|
||||
AZ::TimeUs timeUs = AZ::GetElapsedTimeUs();
|
||||
AZ::TimeMs timeMs = AZ::GetElapsedTimeMs();
|
||||
|
||||
AZ::TimeMs timeUsToMs = AZ::TimeUsToMs(timeUs);
|
||||
int64_t delta = static_cast<int64_t>(timeMs) - static_cast<int64_t>(timeUsToMs);
|
||||
EXPECT_LT(abs(delta), 1);
|
||||
}
|
||||
}
|
||||
@@ -127,6 +127,7 @@ set(FILES
|
||||
Serialization/Json/UnorderedSetSerializerTests.cpp
|
||||
Serialization/Json/UnsupportedTypesSerializerTests.cpp
|
||||
Serialization/Json/UuidSerializerTests.cpp
|
||||
Time/TimeTests.cpp
|
||||
Math/AabbTests.cpp
|
||||
Math/ColorTests.cpp
|
||||
Math/CrcTests.cpp
|
||||
|
||||
Reference in New Issue
Block a user