Bug fixes for stats and for sending rpc and property updates from the client

This commit is contained in:
karlberg
2021-05-06 19:39:31 -07:00
parent 4b1fe9b10b
commit b2b632aede
4 changed files with 35 additions and 2 deletions
@@ -14,6 +14,12 @@
namespace Multiplayer
{
MultiplayerStats::Metric::Metric()
{
AZStd::uninitialized_fill_n(m_callHistory.data(), RingbufferSamples, 0);
AZStd::uninitialized_fill_n(m_byteHistory.data(), RingbufferSamples, 0);
}
void MultiplayerStats::ReserveComponentStats(NetComponentId netComponentId, uint16_t propertyCount, uint16_t rpcCount)
{
const uint16_t netComponentIndex = aznumeric_cast<uint16_t>(netComponentId);
@@ -71,6 +77,29 @@ namespace Multiplayer
{
m_totalHistoryTimeMs = metricFrameTimeMs * static_cast<AZ::TimeMs>(RingbufferSamples);
m_recordMetricIndex = ++m_recordMetricIndex % RingbufferSamples;
for (ComponentStats& componentStats : m_componentStats)
{
for (Metric& metric : componentStats.m_propertyUpdatesSent)
{
metric.m_callHistory[m_recordMetricIndex] = 0;
metric.m_byteHistory[m_recordMetricIndex] = 0;
}
for (Metric& metric : componentStats.m_propertyUpdatesRecv)
{
metric.m_callHistory[m_recordMetricIndex] = 0;
metric.m_byteHistory[m_recordMetricIndex] = 0;
}
for (Metric& metric : componentStats.m_rpcsSent)
{
metric.m_callHistory[m_recordMetricIndex] = 0;
metric.m_byteHistory[m_recordMetricIndex] = 0;
}
for (Metric& metric : componentStats.m_rpcsRecv)
{
metric.m_callHistory[m_recordMetricIndex] = 0;
metric.m_byteHistory[m_recordMetricIndex] = 0;
}
}
}
static void CombineMetrics(MultiplayerStats::Metric& outArg1, const MultiplayerStats::Metric& arg2)
@@ -37,6 +37,7 @@ namespace Multiplayer
using MetricRingbuffer = AZStd::array<uint64_t, RingbufferSamples>;
struct Metric
{
Metric();
uint64_t m_totalCalls = 0;
uint64_t m_totalBytes = 0;
MetricRingbuffer m_callHistory;
@@ -50,8 +50,9 @@ namespace Multiplayer
return m_entityReplicationManager;
}
void ClientToServerConnectionData::Update([[maybe_unused]] AZ::TimeMs hostTimeMs)
void ClientToServerConnectionData::Update(AZ::TimeMs hostTimeMs)
{
m_entityReplicationManager.ActivatePendingEntities();
m_entityReplicationManager.SendUpdates(hostTimeMs);
}
}
@@ -9,7 +9,7 @@
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*
*/
#pragma optimize("", off)
#include <Source/MultiplayerSystemComponent.h>
#include <Source/Components/MultiplayerComponent.h>
#include <Source/AutoGen/AutoComponentTypes.h>
@@ -127,6 +127,7 @@ namespace Multiplayer
void MultiplayerSystemComponent::OnTick([[maybe_unused]] float deltaTime, [[maybe_unused]] AZ::ScriptTimePoint time)
{
AZ::TimeMs deltaTimeMs = aznumeric_cast<AZ::TimeMs>(static_cast<int32_t>(deltaTime * 1000.0f));
AZ::TimeMs hostTimeMs = AZ::GetElapsedTimeMs();
// Handle deferred local rpc messages that were generated during the updates
@@ -137,6 +138,7 @@ namespace Multiplayer
m_networkEntityManager.NotifyEntitiesDirtied();
MultiplayerStats& stats = GetStats();
stats.TickStats(deltaTimeMs);
stats.m_entityCount = GetNetworkEntityManager()->GetEntityCount();
stats.m_serverConnectionCount = 0;
stats.m_clientConnectionCount = 0;