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
@@ -42,7 +42,7 @@ namespace AzNetworking
{
const uint32_t sampleAtom = 1 - m_activeAtom;
if (m_atoms[sampleAtom].m_timeAccumulatorMs == AZ::TimeMs{0})
if (m_atoms[sampleAtom].m_timeAccumulatorMs == AZ::Time::ZeroTimeMs)
{
return 0.0f;
}
@@ -19,7 +19,7 @@ namespace AzNetworking
{
DatarateAtom() = default;
AZ::TimeMs m_timeAccumulatorMs = AZ::TimeMs{ 0 };
AZ::TimeMs m_timeAccumulatorMs = AZ::Time::ZeroTimeMs;
uint32_t m_bytesTransmitted = 0;
uint32_t m_packetsSent = 0;
uint32_t m_packetsLost = 0;
@@ -78,7 +78,7 @@ namespace AzNetworking
ConnectionPacketEntry(PacketId packetId, AZ::TimeMs sendTimeMs);
PacketId m_packetId = InvalidPacketId;
AZ::TimeMs m_sendTimeMs = AZ::TimeMs{0};
AZ::TimeMs m_sendTimeMs = AZ::Time::ZeroTimeMs;
};
//! @class ConnectionComputeRtt
@@ -28,8 +28,8 @@ namespace AzNetworking
ConnectionQuality(int32_t lossPercentage, AZ::TimeMs latencyMs, AZ::TimeMs varianceMs);
int32_t m_lossPercentage = 0;
AZ::TimeMs m_latencyMs = AZ::TimeMs{ 0 };
AZ::TimeMs m_varianceMs = AZ::TimeMs{ 0 };
AZ::TimeMs m_latencyMs = AZ::Time::ZeroTimeMs;
AZ::TimeMs m_varianceMs = AZ::Time::ZeroTimeMs;
};
enum class TrustZone
@@ -37,8 +37,8 @@ namespace AzNetworking
void UpdateTimeoutTime(AZ::TimeMs currentTimeMs);
uint64_t m_userData = 0;
AZ::TimeMs m_timeoutMs = AZ::TimeMs{0};
AZ::TimeMs m_nextTimeoutTimeMs = AZ::TimeMs{0};
AZ::TimeMs m_timeoutMs = AZ::Time::ZeroTimeMs;
AZ::TimeMs m_nextTimeoutTimeMs = AZ::Time::ZeroTimeMs;
};
TimeoutQueue() = default;
@@ -15,11 +15,11 @@ namespace AzNetworking
struct NetworkInterfaceMetrics
{
//! Returns the total number of milliseconds spent updating this network interface.
AZ::TimeMs m_updateTimeMs = AZ::TimeMs{ 0 };
AZ::TimeMs m_updateTimeMs = AZ::Time::ZeroTimeMs;
//! Returns the total number of connections bound to this network interface.
uint64_t m_connectionCount = 0;
//! Returns the total number of milliseconds spent sending data on this network interface.
AZ::TimeMs m_sendTimeMs = AZ::TimeMs{ 0 };
AZ::TimeMs m_sendTimeMs = AZ::Time::ZeroTimeMs;
//! Returns the total number of packets sent on this socket.
uint64_t m_sendPackets = 0;
//! Returns the total number of encrypted packets sent on this socket.
@@ -37,7 +37,7 @@ namespace AzNetworking
//! Returns the total number of packets that had to be resent on this network interface due to packet loss.
uint64_t m_resentPackets = 0;
//! Returns the total number of milliseconds spent processing received data on this network interface.
AZ::TimeMs m_recvTimeMs = AZ::TimeMs{ 0 };
AZ::TimeMs m_recvTimeMs = AZ::Time::ZeroTimeMs;
//! Returns the total number of packets received on this socket.
uint64_t m_recvPackets = 0;
//! Returns the total number of bytes received on this socket after compression.
@@ -67,6 +67,6 @@ namespace AzNetworking
uint32_t m_listenPortCount = 0;
TcpSocketManager m_tcpSocketManager;
AZ::ThreadSafeDeque<ListenPort> m_listenPorts;
AZ::TimeMs m_updateTimeMs = AZ::TimeMs{ 0 };
AZ::TimeMs m_updateTimeMs = AZ::Time::ZeroTimeMs;
};
}
@@ -107,7 +107,7 @@ namespace AzNetworking
auto readCallback = [this, startTimeMs](SocketFd socketFd) { HandleConnectionRecv(socketFd, startTimeMs); };
auto writeCallback = [this](SocketFd socketFd) { HandleConnectionSend(socketFd); };
m_tcpSocketManager.ProcessEvents(AZ::TimeMs{ 0 }, readCallback, writeCallback);
m_tcpSocketManager.ProcessEvents(AZ::Time::ZeroTimeMs, readCallback, writeCallback);
FlushQueuedRemoves();
@@ -146,7 +146,7 @@ namespace AzNetworking
AZ::Name m_name;
TrustZone m_trustZone;
uint16_t m_port = 0;
AZ::TimeMs m_timeoutMs = AZ::TimeMs{ 0 };
AZ::TimeMs m_timeoutMs = AZ::Time::ZeroTimeMs;
IConnectionListener& m_connectionListener;
TcpConnectionSet m_connectionSet;
TcpSocketManager m_tcpSocketManager;
@@ -736,7 +736,7 @@ namespace AzNetworking
udpConnection->SendUnreliablePacket(CorePackets::HeartbeatPacket(true));
++udpConnection->m_timeoutCounter;
}
else if (net_UdpTimeoutConnections && (GetTimeoutMs() > AZ::TimeMs{ 0 }))
else if (net_UdpTimeoutConnections && (GetTimeoutMs() > AZ::Time::ZeroTimeMs))
{
udpConnection->Disconnect(DisconnectReason::Timeout, TerminationEndpoint::Local);
return TimeoutResult::Delete;
@@ -171,7 +171,7 @@ namespace AzNetworking
TrustZone m_trustZone;
uint16_t m_port = 0;
bool m_allowIncomingConnections = false;
AZ::TimeMs m_timeoutMs = AZ::TimeMs{ 0 };
AZ::TimeMs m_timeoutMs = AZ::Time::ZeroTimeMs;
IConnectionListener& m_connectionListener;
UdpConnectionSet m_connectionSet;
TimeoutQueue m_connectionTimeoutQueue;
@@ -94,6 +94,6 @@ namespace AzNetworking
int32_t m_backIndex = 0;
AZStd::array<ReaderBuffer, 2> m_readerBuffers;
AZStd::vector<UdpSocket*> m_pendingAdds;
AZ::TimeMs m_updateTimeMs = AZ::TimeMs{ 0 };
AZ::TimeMs m_updateTimeMs = AZ::Time::ZeroTimeMs;
};
}
@@ -135,7 +135,7 @@ namespace AzNetworking
int32_t sentBytes = size;
#ifdef ENABLE_LATENCY_DEBUG
if (connectionQuality.m_latencyMs <= AZ::TimeMs{ 0 })
if (connectionQuality.m_latencyMs <= AZ::Time::ZeroTimeMs)
#endif
{
sentBytes = SendInternal(address, data, size, encrypt, dtlsEndpoint);
@@ -153,9 +153,9 @@ namespace AzNetworking
}
}
#ifdef ENABLE_LATENCY_DEBUG
else if ((connectionQuality.m_latencyMs > AZ::TimeMs{ 0 }) || (connectionQuality.m_varianceMs > AZ::TimeMs{ 0 }))
else if ((connectionQuality.m_latencyMs > AZ::Time::ZeroTimeMs) || (connectionQuality.m_varianceMs > AZ::Time::ZeroTimeMs))
{
const AZ::TimeMs jitterMs = aznumeric_cast<AZ::TimeMs>(m_random.GetRandom()) % (connectionQuality.m_varianceMs > AZ::TimeMs{ 0 }
const AZ::TimeMs jitterMs = aznumeric_cast<AZ::TimeMs>(m_random.GetRandom()) % (connectionQuality.m_varianceMs > AZ::Time::ZeroTimeMs
? connectionQuality.m_varianceMs
: AZ::TimeMs{ 1 });
const AZ::TimeMs deferTimeMs = (connectionQuality.m_latencyMs) + jitterMs;
@@ -94,7 +94,7 @@ namespace AzNetworking
static const uint32_t MaxCookieHistory = 8;
static bool g_encryptionInitialized = false;
static int32_t g_azNetworkingTrustDataIndex = 0;
static AZ::TimeMs g_lastCookieTimestamp = AZ::TimeMs{0};
static AZ::TimeMs g_lastCookieTimestamp = AZ::Time::ZeroTimeMs;
static uint64_t g_validCookieArray[MaxCookieHistory];
static uint32_t g_cookieReplaceIndex = 0;
@@ -15,7 +15,7 @@ namespace UnitTest
{
AzNetworking::PacketId m_packetId = AzNetworking::InvalidPacketId;
uint32_t m_id = 0;
AZ::TimeMs m_timeMs = AZ::TimeMs{ 0 };
AZ::TimeMs m_timeMs = AZ::Time::ZeroTimeMs;
float m_blendFactor = 0.f;
AZStd::vector<int> m_growVector, m_shrinkVector;
@@ -11,7 +11,7 @@
#include <AzNetworking/AutoGen/CorePackets.AutoPackets.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>
@@ -102,24 +102,24 @@ namespace UnitTest
SetupAllocator();
AZ::NameDictionary::Create();
m_loggerComponent = new AZ::LoggerSystemComponent;
m_timeComponent = new AZ::TimeSystemComponent;
m_networkingSystemComponent = new AzNetworking::NetworkingSystemComponent;
m_loggerComponent = AZStd::make_unique<AZ::LoggerSystemComponent>();
m_timeSystem = AZStd::make_unique<AZ::TimeSystem>();
m_networkingSystemComponent = AZStd::make_unique<AzNetworking::NetworkingSystemComponent>();
}
void TearDown() override
{
delete m_networkingSystemComponent;
delete m_timeComponent;
delete m_loggerComponent;
m_networkingSystemComponent.reset();
m_timeSystem.reset();
m_loggerComponent.reset();
AZ::NameDictionary::Destroy();
TeardownAllocator();
}
AZ::LoggerSystemComponent* m_loggerComponent;
AZ::TimeSystemComponent* m_timeComponent;
AzNetworking::NetworkingSystemComponent* m_networkingSystemComponent;
AZStd::unique_ptr<AZ::LoggerSystemComponent> m_loggerComponent;
AZStd::unique_ptr<AZ::TimeSystem> m_timeSystem;
AZStd::unique_ptr<AzNetworking::NetworkingSystemComponent> m_networkingSystemComponent;
};
#if AZ_TRAIT_DISABLE_FAILED_NETWORKING_TESTS
@@ -14,7 +14,7 @@
#include <AzNetworking/AutoGen/CorePackets.AutoPackets.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>
@@ -105,24 +105,24 @@ namespace UnitTest
SetupAllocator();
AZ::NameDictionary::Create();
m_loggerComponent = new AZ::LoggerSystemComponent;
m_timeComponent = new AZ::TimeSystemComponent;
m_networkingSystemComponent = new AzNetworking::NetworkingSystemComponent;
m_loggerComponent = AZStd::make_unique<AZ::LoggerSystemComponent>();
m_timeSystem = AZStd::make_unique<AZ::TimeSystem>();
m_networkingSystemComponent = AZStd::make_unique<AzNetworking::NetworkingSystemComponent>();
}
void TearDown() override
{
delete m_networkingSystemComponent;
delete m_timeComponent;
delete m_loggerComponent;
m_networkingSystemComponent.reset();
m_timeSystem.reset();
m_loggerComponent.reset();
AZ::NameDictionary::Destroy();
TeardownAllocator();
}
AZ::LoggerSystemComponent* m_loggerComponent;
AZ::TimeSystemComponent* m_timeComponent;
AzNetworking::NetworkingSystemComponent* m_networkingSystemComponent;
AZStd::unique_ptr<AZ::LoggerSystemComponent> m_loggerComponent;
AZStd::unique_ptr<AZ::TimeSystem> m_timeSystem;
AZStd::unique_ptr<AzNetworking::NetworkingSystemComponent> m_networkingSystemComponent;
};
TEST_F(UdpTransportTests, PacketIdWrap)