Addressing PR feedback

This commit is contained in:
karlberg
2021-04-27 16:03:39 -07:00
parent 138b10c902
commit 2fc710d73b
32 changed files with 307 additions and 197 deletions
+10 -10
View File
@@ -75,26 +75,26 @@ namespace Multiplayer
virtual void AddSessionShutdownHandler(SessionShutdownEvent::Handler& handler) = 0;
//! Returns the gem name associated with the provided component index.
//! @param netComponentIndex the component index to return the gem name of
//! @param netComponentId the componentId to return the gem name of
//! @return the name of the gem that contains the requested component
virtual const char* GetComponentGemName(uint16_t netComponentIndex) const = 0;
virtual const char* GetComponentGemName(NetComponentId netComponentId) const = 0;
//! Returns the component name associated with the provided component index.
//! @param netComponentIndex the component index to return the component name of
//! @param netComponentId the componentId to return the component name of
//! @return the name of the component
virtual const char* GetComponentName(uint16_t netComponentIndex) const = 0;
virtual const char* GetComponentName(NetComponentId netComponentId) const = 0;
//! Returns the property name associated with the provided component index and property index.
//! @param netComponentIndex the component index to return the property name of
//! @param propertyIndex the index off the network property to return the property name of
//! @param netComponentId the component index to return the property name of
//! @param propertyIndex the index of the network property to return the property name of
//! @return the name of the network property
virtual const char* GetComponentPropertyName(uint16_t netComponentIndex, uint16_t propertyIndex) const = 0;
virtual const char* GetComponentPropertyName(NetComponentId netComponentId, PropertyIndex propertyIndex) const = 0;
//! Returns the Rpc name associated with the provided component index and rpc index.
//! @param netComponentIndex the component index to return the property name of
//! @param rpcIndex the index off the rpc to return the rpc name of
//! @param netComponentId the componentId to return the property name of
//! @param rpcIndex the index of the rpc to return the rpc name of
//! @return the name of the requested rpc
virtual const char* GetComponentRpcName(uint16_t netComponentIndex, uint16_t rpcIndex) const = 0;
virtual const char* GetComponentRpcName(NetComponentId netComponentId, RpcIndex rpcIndex) const = 0;
//! Retrieve the stats object bound to this multiplayer instance.
//! @return the stats object bound to this multiplayer instance
@@ -14,48 +14,57 @@
namespace Multiplayer
{
void MultiplayerStats::ReserveComponentStats(uint16_t netComponentId, uint16_t propertyCount, uint16_t rpcCount)
void MultiplayerStats::ReserveComponentStats(NetComponentId netComponentId, uint16_t propertyCount, uint16_t rpcCount)
{
if (m_componentStats.size() <= netComponentId)
const uint16_t netComponentIndex = aznumeric_cast<uint16_t>(netComponentId);
if (m_componentStats.size() <= netComponentIndex)
{
m_componentStats.resize(netComponentId + 1);
m_componentStats.resize(netComponentIndex + 1);
}
m_componentStats[netComponentId].m_propertyUpdatesSent.resize(propertyCount);
m_componentStats[netComponentId].m_propertyUpdatesRecv.resize(propertyCount);
m_componentStats[netComponentId].m_rpcsSent.resize(rpcCount);
m_componentStats[netComponentId].m_rpcsRecv.resize(rpcCount);
m_componentStats[netComponentIndex].m_propertyUpdatesSent.resize(propertyCount);
m_componentStats[netComponentIndex].m_propertyUpdatesRecv.resize(propertyCount);
m_componentStats[netComponentIndex].m_rpcsSent.resize(rpcCount);
m_componentStats[netComponentIndex].m_rpcsRecv.resize(rpcCount);
}
void MultiplayerStats::RecordPropertySent(uint16_t netComponentId, uint16_t propertyId, uint32_t totalBytes)
void MultiplayerStats::RecordPropertySent(NetComponentId netComponentId, PropertyIndex propertyId, uint32_t totalBytes)
{
m_componentStats[netComponentId].m_propertyUpdatesSent[propertyId].m_totalCalls++;
m_componentStats[netComponentId].m_propertyUpdatesSent[propertyId].m_totalBytes += totalBytes;
m_componentStats[netComponentId].m_propertyUpdatesSent[propertyId].m_callHistory[m_recordMetricIndex]++;
m_componentStats[netComponentId].m_propertyUpdatesSent[propertyId].m_byteHistory[m_recordMetricIndex] += totalBytes;
const uint16_t netComponentIndex = aznumeric_cast<uint16_t>(netComponentId);
const uint16_t propertyIndex = aznumeric_cast<uint16_t>(propertyId);
m_componentStats[netComponentIndex].m_propertyUpdatesSent[propertyIndex].m_totalCalls++;
m_componentStats[netComponentIndex].m_propertyUpdatesSent[propertyIndex].m_totalBytes += totalBytes;
m_componentStats[netComponentIndex].m_propertyUpdatesSent[propertyIndex].m_callHistory[m_recordMetricIndex]++;
m_componentStats[netComponentIndex].m_propertyUpdatesSent[propertyIndex].m_byteHistory[m_recordMetricIndex] += totalBytes;
}
void MultiplayerStats::RecordPropertyReceived(uint16_t netComponentId, uint16_t propertyId, uint32_t totalBytes)
void MultiplayerStats::RecordPropertyReceived(NetComponentId netComponentId, PropertyIndex propertyId, uint32_t totalBytes)
{
m_componentStats[netComponentId].m_propertyUpdatesRecv[propertyId].m_totalCalls++;
m_componentStats[netComponentId].m_propertyUpdatesRecv[propertyId].m_totalBytes += totalBytes;
m_componentStats[netComponentId].m_propertyUpdatesRecv[propertyId].m_callHistory[m_recordMetricIndex]++;
m_componentStats[netComponentId].m_propertyUpdatesRecv[propertyId].m_byteHistory[m_recordMetricIndex] += totalBytes;
const uint16_t netComponentIndex = aznumeric_cast<uint16_t>(netComponentId);
const uint16_t propertyIndex = aznumeric_cast<uint16_t>(propertyId);
m_componentStats[netComponentIndex].m_propertyUpdatesRecv[propertyIndex].m_totalCalls++;
m_componentStats[netComponentIndex].m_propertyUpdatesRecv[propertyIndex].m_totalBytes += totalBytes;
m_componentStats[netComponentIndex].m_propertyUpdatesRecv[propertyIndex].m_callHistory[m_recordMetricIndex]++;
m_componentStats[netComponentIndex].m_propertyUpdatesRecv[propertyIndex].m_byteHistory[m_recordMetricIndex] += totalBytes;
}
void MultiplayerStats::RecordRpcSent(uint16_t netComponentId, uint16_t rpcId, uint32_t totalBytes)
void MultiplayerStats::RecordRpcSent(NetComponentId netComponentId, RpcIndex rpcId, uint32_t totalBytes)
{
m_componentStats[netComponentId].m_rpcsSent[rpcId].m_totalCalls++;
m_componentStats[netComponentId].m_rpcsSent[rpcId].m_totalBytes += totalBytes;
m_componentStats[netComponentId].m_rpcsSent[rpcId].m_callHistory[m_recordMetricIndex]++;
m_componentStats[netComponentId].m_rpcsSent[rpcId].m_byteHistory[m_recordMetricIndex] += totalBytes;
const uint16_t netComponentIndex = aznumeric_cast<uint16_t>(netComponentId);
const uint16_t rpcIndex = aznumeric_cast<uint16_t>(rpcId);
m_componentStats[netComponentIndex].m_rpcsSent[rpcIndex].m_totalCalls++;
m_componentStats[netComponentIndex].m_rpcsSent[rpcIndex].m_totalBytes += totalBytes;
m_componentStats[netComponentIndex].m_rpcsSent[rpcIndex].m_callHistory[m_recordMetricIndex]++;
m_componentStats[netComponentIndex].m_rpcsSent[rpcIndex].m_byteHistory[m_recordMetricIndex] += totalBytes;
}
void MultiplayerStats::RecordRpcReceived(uint16_t netComponentId, uint16_t rpcId, uint32_t totalBytes)
void MultiplayerStats::RecordRpcReceived(NetComponentId netComponentId, RpcIndex rpcId, uint32_t totalBytes)
{
m_componentStats[netComponentId].m_rpcsRecv[rpcId].m_totalCalls++;
m_componentStats[netComponentId].m_rpcsRecv[rpcId].m_totalBytes += totalBytes;
m_componentStats[netComponentId].m_rpcsRecv[rpcId].m_callHistory[m_recordMetricIndex]++;
m_componentStats[netComponentId].m_rpcsRecv[rpcId].m_byteHistory[m_recordMetricIndex] += totalBytes;
const uint16_t netComponentIndex = aznumeric_cast<uint16_t>(netComponentId);
const uint16_t rpcIndex = aznumeric_cast<uint16_t>(rpcId);
m_componentStats[netComponentIndex].m_rpcsRecv[rpcIndex].m_totalCalls++;
m_componentStats[netComponentIndex].m_rpcsRecv[rpcIndex].m_totalBytes += totalBytes;
m_componentStats[netComponentIndex].m_rpcsRecv[rpcIndex].m_callHistory[m_recordMetricIndex]++;
m_componentStats[netComponentIndex].m_rpcsRecv[rpcIndex].m_byteHistory[m_recordMetricIndex] += totalBytes;
}
void MultiplayerStats::TickStats(AZ::TimeMs metricFrameTimeMs)
@@ -85,24 +94,28 @@ namespace Multiplayer
return result;
}
MultiplayerStats::Metric MultiplayerStats::CalculateComponentPropertyUpdateSentMetrics(uint16_t netComponentId) const
MultiplayerStats::Metric MultiplayerStats::CalculateComponentPropertyUpdateSentMetrics(NetComponentId netComponentId) const
{
return SumMetricVector(m_componentStats[netComponentId].m_propertyUpdatesSent);
const uint16_t netComponentIndex = aznumeric_cast<uint16_t>(netComponentId);
return SumMetricVector(m_componentStats[netComponentIndex].m_propertyUpdatesSent);
}
MultiplayerStats::Metric MultiplayerStats::CalculateComponentPropertyUpdateRecvMetrics(uint16_t netComponentId) const
MultiplayerStats::Metric MultiplayerStats::CalculateComponentPropertyUpdateRecvMetrics(NetComponentId netComponentId) const
{
return SumMetricVector(m_componentStats[netComponentId].m_propertyUpdatesRecv);
const uint16_t netComponentIndex = aznumeric_cast<uint16_t>(netComponentId);
return SumMetricVector(m_componentStats[netComponentIndex].m_propertyUpdatesRecv);
}
MultiplayerStats::Metric MultiplayerStats::CalculateComponentRpcsSentMetrics(uint16_t netComponentId) const
MultiplayerStats::Metric MultiplayerStats::CalculateComponentRpcsSentMetrics(NetComponentId netComponentId) const
{
return SumMetricVector(m_componentStats[netComponentId].m_rpcsSent);
const uint16_t netComponentIndex = aznumeric_cast<uint16_t>(netComponentId);
return SumMetricVector(m_componentStats[netComponentIndex].m_rpcsSent);
}
MultiplayerStats::Metric MultiplayerStats::CalculateComponentRpcsRecvMetrics(uint16_t netComponentId) const
MultiplayerStats::Metric MultiplayerStats::CalculateComponentRpcsRecvMetrics(NetComponentId netComponentId) const
{
return SumMetricVector(m_componentStats[netComponentId].m_rpcsRecv);
const uint16_t netComponentIndex = aznumeric_cast<uint16_t>(netComponentId);
return SumMetricVector(m_componentStats[netComponentIndex].m_rpcsRecv);
}
MultiplayerStats::Metric MultiplayerStats::CalculateTotalPropertyUpdateSentMetrics() const
@@ -110,7 +123,8 @@ namespace Multiplayer
Metric result;
for (AZStd::size_t index = 0; index < m_componentStats.size(); ++index)
{
CombineMetrics(result, CalculateComponentPropertyUpdateSentMetrics(index));
const NetComponentId netComponentId = aznumeric_cast<NetComponentId>(index);
CombineMetrics(result, CalculateComponentPropertyUpdateSentMetrics(netComponentId));
}
return result;
}
@@ -120,7 +134,8 @@ namespace Multiplayer
Metric result;
for (AZStd::size_t index = 0; index < m_componentStats.size(); ++index)
{
CombineMetrics(result, CalculateComponentPropertyUpdateRecvMetrics(index));
const NetComponentId netComponentId = aznumeric_cast<NetComponentId>(index);
CombineMetrics(result, CalculateComponentPropertyUpdateRecvMetrics(netComponentId));
}
return result;
}
@@ -130,7 +145,8 @@ namespace Multiplayer
Metric result;
for (AZStd::size_t index = 0; index < m_componentStats.size(); ++index)
{
CombineMetrics(result, CalculateComponentRpcsSentMetrics(index));
const NetComponentId netComponentId = aznumeric_cast<NetComponentId>(index);
CombineMetrics(result, CalculateComponentRpcsSentMetrics(netComponentId));
}
return result;
}
@@ -140,7 +156,8 @@ namespace Multiplayer
Metric result;
for (AZStd::size_t index = 0; index < m_componentStats.size(); ++index)
{
CombineMetrics(result, CalculateComponentRpcsRecvMetrics(index));
const NetComponentId netComponentId = aznumeric_cast<NetComponentId>(index);
CombineMetrics(result, CalculateComponentRpcsRecvMetrics(netComponentId));
}
return result;
}
@@ -15,6 +15,7 @@
#include <AzCore/Time/ITime.h>
#include <AzCore/std/containers/vector.h>
#include <AzCore/std/containers/array.h>
#include <Include/MultiplayerTypes.h>
namespace AzNetworking
{
@@ -51,17 +52,17 @@ namespace Multiplayer
};
AZStd::vector<ComponentStats> m_componentStats;
void ReserveComponentStats(uint16_t netComponentId, uint16_t propertyCount, uint16_t rpcCount);
void RecordPropertySent(uint16_t netComponentId, uint16_t propertyId, uint32_t totalBytes);
void RecordPropertyReceived(uint16_t netComponentId, uint16_t propertyId, uint32_t totalBytes);
void RecordRpcSent(uint16_t netComponentId, uint16_t rpcId, uint32_t totalBytes);
void RecordRpcReceived(uint16_t netComponentId, uint16_t rpcId, uint32_t totalBytes);
void ReserveComponentStats(NetComponentId netComponentId, uint16_t propertyCount, uint16_t rpcCount);
void RecordPropertySent(NetComponentId netComponentId, PropertyIndex propertyId, uint32_t totalBytes);
void RecordPropertyReceived(NetComponentId netComponentId, PropertyIndex propertyId, uint32_t totalBytes);
void RecordRpcSent(NetComponentId netComponentId, RpcIndex rpcId, uint32_t totalBytes);
void RecordRpcReceived(NetComponentId netComponentId, RpcIndex rpcId, uint32_t totalBytes);
void TickStats(AZ::TimeMs metricFrameTimeMs);
Metric CalculateComponentPropertyUpdateSentMetrics(uint16_t netComponentId) const;
Metric CalculateComponentPropertyUpdateRecvMetrics(uint16_t netComponentId) const;
Metric CalculateComponentRpcsSentMetrics(uint16_t netComponentId) const;
Metric CalculateComponentRpcsRecvMetrics(uint16_t netComponentId) const;
Metric CalculateComponentPropertyUpdateSentMetrics(NetComponentId netComponentId) const;
Metric CalculateComponentPropertyUpdateRecvMetrics(NetComponentId netComponentId) const;
Metric CalculateComponentRpcsSentMetrics(NetComponentId netComponentId) const;
Metric CalculateComponentRpcsRecvMetrics(NetComponentId netComponentId) const;
Metric CalculateTotalPropertyUpdateSentMetrics() const;
Metric CalculateTotalPropertyUpdateRecvMetrics() const;
Metric CalculateTotalRpcsSentMetrics() const;
@@ -0,0 +1,118 @@
/*
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
* its licensors.
*
* For complete copyright and license terms please see the LICENSE at the root of this
* distribution (the "License"). All use of this software is governed by the License,
* or, if provided, by the license below or the license accompanying this file. Do not
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*
*/
#pragma once
#include <AzCore/EBus/Event.h>
#include <AzCore/Name/Name.h>
#include <AzCore/RTTI/TypeSafeIntegral.h>
#include <AzCore/std/string/fixed_string.h>
#include <AzNetworking/Serialization/ISerializer.h>
#include <AzNetworking/ConnectionLayer/ConnectionEnums.h>
namespace Multiplayer
{
//! The default number of rewindable samples for us to store.
static constexpr uint32_t RewindHistorySize = 128;
AZ_TYPE_SAFE_INTEGRAL(HostId, uint32_t);
static constexpr HostId InvalidHostId = static_cast<HostId>(-1);
AZ_TYPE_SAFE_INTEGRAL(NetEntityId, uint32_t);
static constexpr NetEntityId InvalidNetEntityId = static_cast<NetEntityId>(-1);
AZ_TYPE_SAFE_INTEGRAL(NetComponentId, uint16_t);
static constexpr NetComponentId InvalidNetComponentId = static_cast<NetComponentId>(-1);
AZ_TYPE_SAFE_INTEGRAL(PropertyIndex, uint16_t);
AZ_TYPE_SAFE_INTEGRAL(RpcIndex, uint16_t);
using LongNetworkString = AZ::CVarFixedString;
using ReliabilityType = AzNetworking::ReliabilityType;
class NetworkEntityRpcMessage;
using RpcSendEvent = AZ::Event<NetworkEntityRpcMessage&>;
// Note that we explicitly set storage classes so that sizeof() is accurate for serialized size
enum class RpcDeliveryType : uint8_t
{
None,
AuthorityToClient, // Invoked from Authority, handled on Client
AuthorityToAutonomous, // Invoked from Authority, handled on Autonomous
AutonomousToAuthority, // Invoked from Autonomous, handled on Authority
ServerToAuthority // Invoked from Server, handled on Authority
};
enum class NetEntityRole : uint8_t
{
InvalidRole, // No role
Client, // A simulated proxy on a client
Autonomous, // An autonomous proxy on a client (can execute local prediction)
Server, // A simulated proxy on a server
Authority // An authoritative proxy on a server (full authority)
};
enum class ComponentSerializationType : uint8_t
{
Properties,
Correction
};
enum class EntityIsMigrating : uint8_t
{
False,
True
};
// This is just a placeholder
// The level/prefab cooking will devise the actual solution for identifying a dynamically spawnable entity within a prefab
struct PrefabEntityId
{
AZ_TYPE_INFO(PrefabEntityId, "{EFD37465-CCAC-4E87-A825-41B4010A2C75}");
static constexpr uint32_t AllIndices = AZStd::numeric_limits<uint32_t>::max();
AZ::Name m_prefabName;
uint32_t m_entityOffset = AllIndices;
PrefabEntityId() = default;
explicit PrefabEntityId(AZ::Name name, uint32_t entityOffset = AllIndices)
: m_prefabName(name)
, m_entityOffset(entityOffset)
{
}
bool operator==(const PrefabEntityId& rhs) const
{
return m_prefabName == rhs.m_prefabName && m_entityOffset == rhs.m_entityOffset;
}
bool operator!=(const PrefabEntityId& rhs) const
{
return !(*this == rhs);
}
bool Serialize(AzNetworking::ISerializer& serializer)
{
serializer.Serialize(m_prefabName, "prefabName");
serializer.Serialize(m_entityOffset, "entityOffset");
return serializer.IsValid();
}
};
}
AZ_TYPE_SAFE_INTEGRAL_SERIALIZEBINDING(Multiplayer::HostId);
AZ_TYPE_SAFE_INTEGRAL_SERIALIZEBINDING(Multiplayer::NetEntityId);
AZ_TYPE_SAFE_INTEGRAL_SERIALIZEBINDING(Multiplayer::NetComponentId);
AZ_TYPE_SAFE_INTEGRAL_SERIALIZEBINDING(Multiplayer::PropertyIndex);
AZ_TYPE_SAFE_INTEGRAL_SERIALIZEBINDING(Multiplayer::RpcIndex);