diff --git a/Gems/Multiplayer/Code/Include/IMultiplayer.h b/Gems/Multiplayer/Code/Include/IMultiplayer.h index 9b50a966e6..67776e15be 100644 --- a/Gems/Multiplayer/Code/Include/IMultiplayer.h +++ b/Gems/Multiplayer/Code/Include/IMultiplayer.h @@ -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 diff --git a/Gems/Multiplayer/Code/Include/MultiplayerStats.cpp b/Gems/Multiplayer/Code/Include/MultiplayerStats.cpp index 27dba01c84..b9f47814b4 100644 --- a/Gems/Multiplayer/Code/Include/MultiplayerStats.cpp +++ b/Gems/Multiplayer/Code/Include/MultiplayerStats.cpp @@ -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(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(netComponentId); + const uint16_t propertyIndex = aznumeric_cast(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(netComponentId); + const uint16_t propertyIndex = aznumeric_cast(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(netComponentId); + const uint16_t rpcIndex = aznumeric_cast(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(netComponentId); + const uint16_t rpcIndex = aznumeric_cast(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(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(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(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(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(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(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(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(index); + CombineMetrics(result, CalculateComponentRpcsRecvMetrics(netComponentId)); } return result; } diff --git a/Gems/Multiplayer/Code/Include/MultiplayerStats.h b/Gems/Multiplayer/Code/Include/MultiplayerStats.h index e3081b8149..fcbd741bb9 100644 --- a/Gems/Multiplayer/Code/Include/MultiplayerStats.h +++ b/Gems/Multiplayer/Code/Include/MultiplayerStats.h @@ -15,6 +15,7 @@ #include #include #include +#include namespace AzNetworking { @@ -51,17 +52,17 @@ namespace Multiplayer }; AZStd::vector 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; diff --git a/Gems/Multiplayer/Code/Include/MultiplayerTypes.h b/Gems/Multiplayer/Code/Include/MultiplayerTypes.h new file mode 100644 index 0000000000..ca3734e4f0 --- /dev/null +++ b/Gems/Multiplayer/Code/Include/MultiplayerTypes.h @@ -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 +#include +#include +#include +#include +#include + +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(-1); + + AZ_TYPE_SAFE_INTEGRAL(NetEntityId, uint32_t); + static constexpr NetEntityId InvalidNetEntityId = static_cast(-1); + + AZ_TYPE_SAFE_INTEGRAL(NetComponentId, uint16_t); + static constexpr NetComponentId InvalidNetComponentId = static_cast(-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; + + // 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::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); diff --git a/Gems/Multiplayer/Code/Source/AutoGen/AutoComponentTypes_Header.jinja b/Gems/Multiplayer/Code/Source/AutoGen/AutoComponentTypes_Header.jinja index 1490d91f19..fc2860ebe7 100644 --- a/Gems/Multiplayer/Code/Source/AutoGen/AutoComponentTypes_Header.jinja +++ b/Gems/Multiplayer/Code/Source/AutoGen/AutoComponentTypes_Header.jinja @@ -1,7 +1,7 @@ #pragma once #include -#include +#include namespace AZ { diff --git a/Gems/Multiplayer/Code/Source/AutoGen/AutoComponentTypes_Source.jinja b/Gems/Multiplayer/Code/Source/AutoGen/AutoComponentTypes_Source.jinja index 584dde06e0..57375b39f2 100644 --- a/Gems/Multiplayer/Code/Source/AutoGen/AutoComponentTypes_Source.jinja +++ b/Gems/Multiplayer/Code/Source/AutoGen/AutoComponentTypes_Source.jinja @@ -39,7 +39,7 @@ namespace {{ Namespace }} componentData.m_componentPropertyNameLookupFunction = {{ ComponentBaseName }}::GetNetworkPropertyName; componentData.m_componentRpcNameLookupFunction = {{ ComponentBaseName }}::GetRpcName; {{ ComponentBaseName }}::s_netComponentId = multiplayerComponentRegistry->RegisterMultiplayerComponent(componentData); - stats.ReserveComponentStats(static_cast({{ ComponentBaseName }}::s_netComponentId), static_cast({{ NetworkPropertyCount }}), static_cast({{ RpcCount }})); + stats.ReserveComponentStats({{ ComponentBaseName }}::s_netComponentId, static_cast({{ NetworkPropertyCount }}), static_cast({{ RpcCount }})); } {% endfor %} } diff --git a/Gems/Multiplayer/Code/Source/AutoGen/AutoComponent_Header.jinja b/Gems/Multiplayer/Code/Source/AutoGen/AutoComponent_Header.jinja index a91792bae6..14a68cddf1 100644 --- a/Gems/Multiplayer/Code/Source/AutoGen/AutoComponent_Header.jinja +++ b/Gems/Multiplayer/Code/Source/AutoGen/AutoComponent_Header.jinja @@ -227,7 +227,7 @@ AZStd::fixed_vector<{{ Property.attrib['Type'] }}, {{ Property.attrib['Count'] } #include #include #include -#include +#include {% call(Include) AutoComponentMacros.ParseIncludes(Component) %} #include <{{ Include.attrib['File'] }}> {% endcall %} @@ -251,9 +251,6 @@ namespace {{ Component.attrib['Namespace'] }} class {{ ComponentName }}; class {{ ControllerName }}; - //! Returns a human readable name for the provided remoteProcedureId. - const char* GetRemoteProcedureName(uint16_t remoteProcedureId); - {% set RecordName = ComponentName + "Record" %} //! @class {{RecordName }} //! @brief A record of the changed bits in the NetworkProperties for component {{ ComponentName }}. @@ -487,8 +484,8 @@ namespace {{ Component.attrib['Namespace'] }} void NotifyChangesAutonomousToAuthorityProperties(const {{ RecordName }}& replicationRecord) const; //! Debug name helpers - static const char* GetNetworkPropertyName(uint16_t propertyIndex); - static const char* GetRpcName(uint16_t rpcIndex); + static const char* GetNetworkPropertyName(PropertyIndex propertyIndex); + static const char* GetRpcName(RpcIndex rpcIndex); AZStd::unique_ptr<{{ RecordName }}> m_currentRecord; AZStd::unique_ptr<{{ ControllerName }}> m_controller; diff --git a/Gems/Multiplayer/Code/Source/AutoGen/AutoComponent_Source.jinja b/Gems/Multiplayer/Code/Source/AutoGen/AutoComponent_Source.jinja index a423bad71e..fb802541ce 100644 --- a/Gems/Multiplayer/Code/Source/AutoGen/AutoComponent_Source.jinja +++ b/Gems/Multiplayer/Code/Source/AutoGen/AutoComponent_Source.jinja @@ -285,7 +285,7 @@ void {{ ClassName }}::Set{{ UpperFirst(Property.attrib['Name']) }}(const {{ Prop {{ AutoComponentMacros.ParseRpcParams(Property, paramNames, paramTypes, paramDefines) }} void {{ ClassName }}::{{ UpperFirst(Property.attrib['Name']) }}({{ ', '.join(paramDefines) }}) { - constexpr uint16_t rpcId = static_cast({{ UpperFirst(Component.attrib['Name']) }}Internal::RemoteProcedure::{{ UpperFirst(Property.attrib['Name']) }}); + constexpr RpcIndex rpcId = static_cast({{ UpperFirst(Component.attrib['Name']) }}Internal::RemoteProcedure::{{ UpperFirst(Property.attrib['Name']) }}); {% if Property.attrib['IsReliable']|booleanTrue %} constexpr AzNetworking::ReliabilityType isReliable = Multiplayer::ReliabilityType::Reliable; {% else %} @@ -508,8 +508,8 @@ bool {{ ClassName }}::Serialize{{ AutoComponentMacros.GetNetPropertiesSetName(Re static_cast({{ AutoComponentMacros.GetNetPropertiesQualifiedPropertyDirtyEnum(Component.attrib['Name'], ReplicateFrom, ReplicateTo, Property) }}), m_{{ LowerFirst(Property.attrib['Name']) }}, "{{ Property.attrib['Name'] }}", - static_cast(GetNetComponentId()), - static_cast({{ UpperFirst(Component.attrib['Name']) }}Internal::NetworkProperties::{{ UpperFirst(Property.attrib['Name']) }}), + GetNetComponentId(), + static_cast({{ UpperFirst(Component.attrib['Name']) }}Internal::NetworkProperties::{{ UpperFirst(Property.attrib['Name']) }}), stats ); {% endif %} @@ -1253,7 +1253,7 @@ namespace {{ Component.attrib['Namespace'] }} #pragma warning(disable: 4065) // switch statement contains 'default' but no 'case' labels bool {{ ComponentBaseName }}::HandleRpcMessage([[maybe_unused]] Multiplayer::NetEntityRole remoteRole, Multiplayer::NetworkEntityRpcMessage& message) { - const {{ UpperFirst(Component.attrib['Name']) }}Internal::RemoteProcedure rpcType = static_cast<{{ UpperFirst(Component.attrib['Name']) }}Internal::RemoteProcedure>(message.GetRpcMessageType()); + const {{ UpperFirst(Component.attrib['Name']) }}Internal::RemoteProcedure rpcType = static_cast<{{ UpperFirst(Component.attrib['Name']) }}Internal::RemoteProcedure>(message.GetRpcIndex()); switch (rpcType) { {{ DeclareRpcHandleCases(Component, ComponentDerived, 'Server', 'Authority', "(remoteRole == Multiplayer::NetEntityRole::Authority || remoteRole == Multiplayer::NetEntityRole::Server)" )|indent(8) }} @@ -1396,7 +1396,7 @@ namespace {{ Component.attrib['Namespace'] }} } {% endif %} - const char* {{ ComponentBaseName }}::GetNetworkPropertyName([[maybe_unused]] uint16_t propertyIndex) + const char* {{ ComponentBaseName }}::GetNetworkPropertyName([[maybe_unused]] PropertyIndex propertyIndex) { {% if NetworkPropertyCount > 0 %} const {{ UpperFirst(Component.attrib['Name']) }}Internal::NetworkProperties propertyId = static_cast<{{ UpperFirst(Component.attrib['Name']) }}Internal::NetworkProperties>(propertyIndex); @@ -1411,7 +1411,7 @@ namespace {{ Component.attrib['Namespace'] }} return "Unknown network property"; } - const char* {{ ComponentBaseName }}::GetRpcName([[maybe_unused]] uint16_t rpcIndex) + const char* {{ ComponentBaseName }}::GetRpcName([[maybe_unused]] RpcIndex rpcIndex) { {% if RpcCount > 0 %} const {{ UpperFirst(Component.attrib['Name']) }}Internal::RemoteProcedure rpcId = static_cast<{{ UpperFirst(Component.attrib['Name']) }}Internal::RemoteProcedure>(rpcIndex); diff --git a/Gems/Multiplayer/Code/Source/AutoGen/LocalPredictionPlayerInputComponent.AutoComponent.xml b/Gems/Multiplayer/Code/Source/AutoGen/LocalPredictionPlayerInputComponent.AutoComponent.xml index d38ebbb1b8..4eaf7ff0fb 100644 --- a/Gems/Multiplayer/Code/Source/AutoGen/LocalPredictionPlayerInputComponent.AutoComponent.xml +++ b/Gems/Multiplayer/Code/Source/AutoGen/LocalPredictionPlayerInputComponent.AutoComponent.xml @@ -10,7 +10,7 @@ - + diff --git a/Gems/Multiplayer/Code/Source/AutoGen/Multiplayer.AutoPackets.xml b/Gems/Multiplayer/Code/Source/AutoGen/Multiplayer.AutoPackets.xml index e5549e90d6..95204a3c3f 100644 --- a/Gems/Multiplayer/Code/Source/AutoGen/Multiplayer.AutoPackets.xml +++ b/Gems/Multiplayer/Code/Source/AutoGen/Multiplayer.AutoPackets.xml @@ -2,7 +2,7 @@ - + diff --git a/Gems/Multiplayer/Code/Source/AutoGen/NetworkTransformComponent.AutoComponent.xml b/Gems/Multiplayer/Code/Source/AutoGen/NetworkTransformComponent.AutoComponent.xml index e6323ba5fd..46065b386f 100644 --- a/Gems/Multiplayer/Code/Source/AutoGen/NetworkTransformComponent.AutoComponent.xml +++ b/Gems/Multiplayer/Code/Source/AutoGen/NetworkTransformComponent.AutoComponent.xml @@ -10,7 +10,7 @@ - + diff --git a/Gems/Multiplayer/Code/Source/Components/MultiplayerComponent.h b/Gems/Multiplayer/Code/Source/Components/MultiplayerComponent.h index 42f995f764..3642a55476 100644 --- a/Gems/Multiplayer/Code/Source/Components/MultiplayerComponent.h +++ b/Gems/Multiplayer/Code/Source/Components/MultiplayerComponent.h @@ -16,7 +16,7 @@ #include #include #include -#include +#include #include //! Macro to declare bindings for a multiplayer component inheriting from MultiplayerComponent @@ -110,8 +110,8 @@ namespace Multiplayer int32_t bitIndex, TYPE& value, const char* name, - uint16_t componentId, - uint16_t propertyId, + NetComponentId componentId, + PropertyIndex propertyIndex, MultiplayerStats& stats ) { @@ -132,11 +132,11 @@ namespace Multiplayer { if (modifyRecord) { - stats.RecordPropertyReceived(componentId, propertyId, updateSize); + stats.RecordPropertyReceived(componentId, propertyIndex, updateSize); } else { - stats.RecordPropertySent(componentId, propertyId, updateSize); + stats.RecordPropertySent(componentId, propertyIndex, updateSize); } } } diff --git a/Gems/Multiplayer/Code/Source/Components/MultiplayerComponentRegistry.cpp b/Gems/Multiplayer/Code/Source/Components/MultiplayerComponentRegistry.cpp index ab701c754d..de1782cc59 100644 --- a/Gems/Multiplayer/Code/Source/Components/MultiplayerComponentRegistry.cpp +++ b/Gems/Multiplayer/Code/Source/Components/MultiplayerComponentRegistry.cpp @@ -33,13 +33,13 @@ namespace Multiplayer return componentData.m_componentName.GetCStr(); } - const char* MultiplayerComponentRegistry::GetComponentPropertyName(NetComponentId netComponentId, uint16_t propertyIndex) const + const char* MultiplayerComponentRegistry::GetComponentPropertyName(NetComponentId netComponentId, PropertyIndex propertyIndex) const { const ComponentData& componentData = GetMultiplayerComponentData(netComponentId); return componentData.m_componentPropertyNameLookupFunction(propertyIndex); } - const char* MultiplayerComponentRegistry::GetComponentRpcName(NetComponentId netComponentId, uint16_t rpcIndex) const + const char* MultiplayerComponentRegistry::GetComponentRpcName(NetComponentId netComponentId, RpcIndex rpcIndex) const { const ComponentData& componentData = GetMultiplayerComponentData(netComponentId); return componentData.m_componentRpcNameLookupFunction(rpcIndex); diff --git a/Gems/Multiplayer/Code/Source/Components/MultiplayerComponentRegistry.h b/Gems/Multiplayer/Code/Source/Components/MultiplayerComponentRegistry.h index 372de9320a..e16f942100 100644 --- a/Gems/Multiplayer/Code/Source/Components/MultiplayerComponentRegistry.h +++ b/Gems/Multiplayer/Code/Source/Components/MultiplayerComponentRegistry.h @@ -21,13 +21,14 @@ namespace Multiplayer class MultiplayerComponentRegistry { public: - using NameLookupFunction = AZStd::function; + using PropertyNameLookupFunction = AZStd::function; + using RpcNameLookupFunction = AZStd::function; struct ComponentData { AZ::Name m_gemName; AZ::Name m_componentName; - NameLookupFunction m_componentPropertyNameLookupFunction; - NameLookupFunction m_componentRpcNameLookupFunction; + PropertyNameLookupFunction m_componentPropertyNameLookupFunction; + RpcNameLookupFunction m_componentRpcNameLookupFunction; }; //! Registers a multiplayer component with the multiplayer system. @@ -49,13 +50,13 @@ namespace Multiplayer //! @param netComponentId the NetComponentId to return the property name of //! @param propertyIndex the index off the network property to return the property name of //! @return the name of the network property - const char* GetComponentPropertyName(NetComponentId netComponentId, uint16_t propertyIndex) const; + const char* GetComponentPropertyName(NetComponentId netComponentId, PropertyIndex propertyIndex) const; //! Returns the Rpc name associated with the provided NetComponentId and rpcId. //! @param netComponentId the NetComponentId 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 - const char* GetComponentRpcName(NetComponentId netComponentId, uint16_t rpcIndex) const; + const char* GetComponentRpcName(NetComponentId netComponentId, RpcIndex rpcIndex) const; //! Retrieves the stored component data for a given NetComponentId. //! @param netComponentId the NetComponentId to return component data for diff --git a/Gems/Multiplayer/Code/Source/Components/NetBindComponent.h b/Gems/Multiplayer/Code/Source/Components/NetBindComponent.h index 8860c16fc1..e992dbfd72 100644 --- a/Gems/Multiplayer/Code/Source/Components/NetBindComponent.h +++ b/Gems/Multiplayer/Code/Source/Components/NetBindComponent.h @@ -23,7 +23,7 @@ #include #include #include -#include +#include #include namespace Multiplayer diff --git a/Gems/Multiplayer/Code/Source/Debug/MultiplayerDebugSystemComponent.cpp b/Gems/Multiplayer/Code/Source/Debug/MultiplayerDebugSystemComponent.cpp index 2eac15928d..506581b5e4 100644 --- a/Gems/Multiplayer/Code/Source/Debug/MultiplayerDebugSystemComponent.cpp +++ b/Gems/Multiplayer/Code/Source/Debug/MultiplayerDebugSystemComponent.cpp @@ -60,36 +60,6 @@ namespace Multiplayer { if (ImGui::BeginMenu("Multiplayer")) { - //{ - // static int lossPercent{ 0 }; - // lossPercent = static_cast(net_UdpDebugLossPercent); - // if (ImGui::SliderInt("UDP Loss Percent", &lossPercent, 0, 100)) - // { - // net_UdpDebugLossPercent = lossPercent; - // m_ClientAgent.UpdateConnectionCvars(net_UdpDebugLossPercent); - // } - //} - // - //{ - // static int latency{ 0 }; - // latency = static_cast(net_UdpDebugLatencyMs); - // if (ImGui::SliderInt("UDP Latency Ms", &latency, 0, 3000)) - // { - // net_UdpDebugLatencyMs = latency; - // m_ClientAgent.UpdateConnectionCvars(net_UdpDebugLatencyMs); - // } - //} - // - //{ - // static int variance{ 0 }; - // variance = static_cast(net_UdpDebugVarianceMs); - // if (ImGui::SliderInt("UDP Variance Ms", &variance, 0, 1000)) - // { - // net_UdpDebugVarianceMs = variance; - // m_ClientAgent.UpdateConnectionCvars(net_UdpDebugVarianceMs); - // } - //} - ImGui::Checkbox("Networking Stats", &m_displayNetworkingStats); ImGui::Checkbox("Multiplayer Stats", &m_displayMultiplayerStats); ImGui::EndMenu(); @@ -147,12 +117,12 @@ namespace Multiplayer return DrawMetricsRow(name, true, totalCalls, totalBytes, callsPerSecond, bytesPerSecond); } - bool DrawComponentRow(const char* name, const MultiplayerStats& stats, uint16_t componentIndex) + bool DrawComponentRow(const char* name, const MultiplayerStats& stats, NetComponentId netComponentId) { - const MultiplayerStats::Metric propertyUpdatesSent = stats.CalculateComponentPropertyUpdateSentMetrics(componentIndex); - const MultiplayerStats::Metric propertyUpdatesRecv = stats.CalculateComponentPropertyUpdateRecvMetrics(componentIndex); - const MultiplayerStats::Metric rpcsSent = stats.CalculateComponentRpcsSentMetrics(componentIndex); - const MultiplayerStats::Metric rpcsRecv = stats.CalculateComponentRpcsRecvMetrics(componentIndex); + const MultiplayerStats::Metric propertyUpdatesSent = stats.CalculateComponentPropertyUpdateSentMetrics(netComponentId); + const MultiplayerStats::Metric propertyUpdatesRecv = stats.CalculateComponentPropertyUpdateRecvMetrics(netComponentId); + const MultiplayerStats::Metric rpcsSent = stats.CalculateComponentRpcsSentMetrics(netComponentId); + const MultiplayerStats::Metric rpcsRecv = stats.CalculateComponentRpcsRecvMetrics(netComponentId); const uint64_t totalCalls = propertyUpdatesSent.m_totalCalls + propertyUpdatesRecv.m_totalCalls + rpcsSent.m_totalCalls + rpcsRecv.m_totalCalls; const uint64_t totalBytes = propertyUpdatesSent.m_totalBytes + propertyUpdatesRecv.m_totalBytes + rpcsSent.m_totalBytes + rpcsRecv.m_totalBytes; @@ -166,20 +136,21 @@ namespace Multiplayer return DrawMetricsRow(name, true, totalCalls, totalBytes, callsPerSecond, bytesPerSecond); } - void DrawComponentDetails(const MultiplayerStats& stats, uint16_t componentIndex) + void DrawComponentDetails(const MultiplayerStats& stats, NetComponentId netComponentId) { IMultiplayer* multiplayer = AZ::Interface::Get(); { - const MultiplayerStats::Metric metric = stats.CalculateComponentPropertyUpdateSentMetrics(componentIndex); + const MultiplayerStats::Metric metric = stats.CalculateComponentPropertyUpdateSentMetrics(netComponentId); float callsPerSecond = 0.0f; float bytesPerSecond = 0.0f; AccumulatePerSecondValues(stats, metric, callsPerSecond, bytesPerSecond); if (DrawMetricsRow("PropertyUpdates Sent", true, metric.m_totalCalls, metric.m_totalBytes, callsPerSecond, bytesPerSecond)) { - const MultiplayerStats::ComponentStats& componentStats = stats.m_componentStats[componentIndex]; + const MultiplayerStats::ComponentStats& componentStats = stats.m_componentStats[aznumeric_cast(netComponentId)]; for (AZStd::size_t index = 0; index < componentStats.m_propertyUpdatesSent.size(); ++index) { - const char* propertyName = multiplayer->GetComponentPropertyName(componentIndex, aznumeric_cast(index)); + const PropertyIndex propertyIndex = aznumeric_cast(index); + const char* propertyName = multiplayer->GetComponentPropertyName(netComponentId, propertyIndex); const MultiplayerStats::Metric& subMetric = componentStats.m_propertyUpdatesSent[index]; callsPerSecond = 0.0f; bytesPerSecond = 0.0f; @@ -191,16 +162,17 @@ namespace Multiplayer } { - const MultiplayerStats::Metric metric = stats.CalculateComponentPropertyUpdateRecvMetrics(componentIndex); + const MultiplayerStats::Metric metric = stats.CalculateComponentPropertyUpdateRecvMetrics(netComponentId); float callsPerSecond = 0.0f; float bytesPerSecond = 0.0f; AccumulatePerSecondValues(stats, metric, callsPerSecond, bytesPerSecond); if (DrawMetricsRow("PropertyUpdates Recv", true, metric.m_totalCalls, metric.m_totalBytes, callsPerSecond, bytesPerSecond)) { - const MultiplayerStats::ComponentStats& componentStats = stats.m_componentStats[componentIndex]; + const MultiplayerStats::ComponentStats& componentStats = stats.m_componentStats[aznumeric_cast(netComponentId)]; for (AZStd::size_t index = 0; index < componentStats.m_propertyUpdatesRecv.size(); ++index) { - const char* propertyName = multiplayer->GetComponentPropertyName(componentIndex, aznumeric_cast(index)); + const PropertyIndex propertyIndex = aznumeric_cast(index); + const char* propertyName = multiplayer->GetComponentPropertyName(netComponentId, propertyIndex); const MultiplayerStats::Metric& subMetric = componentStats.m_propertyUpdatesRecv[index]; callsPerSecond = 0.0f; bytesPerSecond = 0.0f; @@ -212,16 +184,17 @@ namespace Multiplayer } { - const MultiplayerStats::Metric metric = stats.CalculateComponentRpcsSentMetrics(componentIndex); + const MultiplayerStats::Metric metric = stats.CalculateComponentRpcsSentMetrics(netComponentId); float callsPerSecond = 0.0f; float bytesPerSecond = 0.0f; AccumulatePerSecondValues(stats, metric, callsPerSecond, bytesPerSecond); if (DrawMetricsRow("RemoteProcedures Sent", true, metric.m_totalCalls, metric.m_totalBytes, callsPerSecond, bytesPerSecond)) { - const MultiplayerStats::ComponentStats& componentStats = stats.m_componentStats[componentIndex]; + const MultiplayerStats::ComponentStats& componentStats = stats.m_componentStats[aznumeric_cast(netComponentId)]; for (AZStd::size_t index = 0; index < componentStats.m_rpcsSent.size(); ++index) { - const char* rpcName = multiplayer->GetComponentRpcName(componentIndex, aznumeric_cast(index)); + const RpcIndex rpcIndex = aznumeric_cast(index); + const char* rpcName = multiplayer->GetComponentRpcName(netComponentId, rpcIndex); const MultiplayerStats::Metric& subMetric = componentStats.m_rpcsSent[index]; callsPerSecond = 0.0f; bytesPerSecond = 0.0f; @@ -233,16 +206,17 @@ namespace Multiplayer } { - const MultiplayerStats::Metric metric = stats.CalculateComponentRpcsRecvMetrics(componentIndex); + const MultiplayerStats::Metric metric = stats.CalculateComponentRpcsRecvMetrics(netComponentId); float callsPerSecond = 0.0f; float bytesPerSecond = 0.0f; AccumulatePerSecondValues(stats, metric, callsPerSecond, bytesPerSecond); if (DrawMetricsRow("RemoteProcedures Recv", true, metric.m_totalCalls, metric.m_totalBytes, callsPerSecond, bytesPerSecond)) { - const MultiplayerStats::ComponentStats& componentStats = stats.m_componentStats[componentIndex]; + const MultiplayerStats::ComponentStats& componentStats = stats.m_componentStats[aznumeric_cast(netComponentId)]; for (AZStd::size_t index = 0; index < componentStats.m_rpcsRecv.size(); ++index) { - const char* rpcName = multiplayer->GetComponentRpcName(componentIndex, aznumeric_cast(index)); + const RpcIndex rpcIndex = aznumeric_cast(index); + const char* rpcName = multiplayer->GetComponentRpcName(netComponentId, rpcIndex); const MultiplayerStats::Metric& subMetric = componentStats.m_rpcsRecv[index]; callsPerSecond = 0.0f; bytesPerSecond = 0.0f; @@ -259,11 +233,6 @@ namespace Multiplayer const float TEXT_BASE_WIDTH = ImGui::CalcTextSize("A").x; const float TEXT_BASE_HEIGHT = ImGui::GetTextLineHeightWithSpacing(); - if (m_displayNetworkingStats) - { - - } - if (m_displayMultiplayerStats) { if (ImGui::Begin("Multiplayer Stats", &m_displayMultiplayerStats, ImGuiWindowFlags_HorizontalScrollbar)) @@ -296,14 +265,14 @@ namespace Multiplayer { for (AZStd::size_t index = 0; index < stats.m_componentStats.size(); ++index) { - const uint16_t componentIndex = aznumeric_cast(index); + const NetComponentId netComponentId = aznumeric_cast(index); using StringLabel = AZStd::fixed_string<128>; - const StringLabel gemName = multiplayer->GetComponentGemName(componentIndex); - const StringLabel componentName = multiplayer->GetComponentName(componentIndex); + const StringLabel gemName = multiplayer->GetComponentGemName(netComponentId); + const StringLabel componentName = multiplayer->GetComponentName(netComponentId); const StringLabel label = gemName + "::" + componentName; - if (DrawComponentRow(label.c_str(), stats, componentIndex)) + if (DrawComponentRow(label.c_str(), stats, netComponentId)) { - DrawComponentDetails(stats, componentIndex); + DrawComponentDetails(stats, netComponentId); ImGui::TreePop(); } } diff --git a/Gems/Multiplayer/Code/Source/MultiplayerSystemComponent.cpp b/Gems/Multiplayer/Code/Source/MultiplayerSystemComponent.cpp index 8976cb46b4..2756bb649a 100644 --- a/Gems/Multiplayer/Code/Source/MultiplayerSystemComponent.cpp +++ b/Gems/Multiplayer/Code/Source/MultiplayerSystemComponent.cpp @@ -506,24 +506,24 @@ namespace Multiplayer handler.Connect(m_shutdownEvent); } - const char* MultiplayerSystemComponent::GetComponentGemName(uint16_t netComponentIndex) const + const char* MultiplayerSystemComponent::GetComponentGemName(NetComponentId netComponentId) const { - return GetMultiplayerComponentRegistry()->GetComponentGemName(static_cast(netComponentIndex)); + return GetMultiplayerComponentRegistry()->GetComponentGemName(netComponentId); } - const char* MultiplayerSystemComponent::GetComponentName(uint16_t netComponentIndex) const + const char* MultiplayerSystemComponent::GetComponentName(NetComponentId netComponentId) const { - return GetMultiplayerComponentRegistry()->GetComponentName(static_cast(netComponentIndex)); + return GetMultiplayerComponentRegistry()->GetComponentName(netComponentId); } - const char* MultiplayerSystemComponent::GetComponentPropertyName(uint16_t netComponentIndex, uint16_t propertyIndex) const + const char* MultiplayerSystemComponent::GetComponentPropertyName(NetComponentId netComponentId, PropertyIndex propertyIndex) const { - return GetMultiplayerComponentRegistry()->GetComponentPropertyName(static_cast(netComponentIndex), propertyIndex); + return GetMultiplayerComponentRegistry()->GetComponentPropertyName(netComponentId, propertyIndex); } - const char* MultiplayerSystemComponent::GetComponentRpcName(uint16_t netComponentIndex, uint16_t rpcIndex) const + const char* MultiplayerSystemComponent::GetComponentRpcName(NetComponentId netComponentId, RpcIndex rpcIndex) const { - return GetMultiplayerComponentRegistry()->GetComponentRpcName(static_cast(netComponentIndex), rpcIndex); + return GetMultiplayerComponentRegistry()->GetComponentRpcName(netComponentId, rpcIndex); } void MultiplayerSystemComponent::DumpStats([[maybe_unused]] const AZ::ConsoleCommandContainer& arguments) diff --git a/Gems/Multiplayer/Code/Source/MultiplayerSystemComponent.h b/Gems/Multiplayer/Code/Source/MultiplayerSystemComponent.h index 6010a132ea..f8d56e0408 100644 --- a/Gems/Multiplayer/Code/Source/MultiplayerSystemComponent.h +++ b/Gems/Multiplayer/Code/Source/MultiplayerSystemComponent.h @@ -88,10 +88,10 @@ namespace Multiplayer void AddConnectionAcquiredHandler(ConnectionAcquiredEvent::Handler& handler) override; void AddSessionInitHandler(SessionInitEvent::Handler& handler) override; void AddSessionShutdownHandler(SessionShutdownEvent::Handler& handler) override; - const char* GetComponentGemName(uint16_t netComponentIndex) const override; - const char* GetComponentName(uint16_t netComponentIndex) const override; - const char* GetComponentPropertyName(uint16_t netComponentIndex, uint16_t propertyIndex) const override; - const char* GetComponentRpcName(uint16_t netComponentIndex, uint16_t rpcIndex) const override; + const char* GetComponentGemName(NetComponentId netComponentId) const override; + const char* GetComponentName(NetComponentId netComponentId) const override; + const char* GetComponentPropertyName(NetComponentId netComponentId, PropertyIndex propertyIndex) const override; + const char* GetComponentRpcName(NetComponentId netComponentId, RpcIndex rpcIndex) const override; //! @} //! Console commands. diff --git a/Gems/Multiplayer/Code/Source/MultiplayerTypes.h b/Gems/Multiplayer/Code/Source/MultiplayerTypes.h index 7ffaa8a56e..ca3734e4f0 100644 --- a/Gems/Multiplayer/Code/Source/MultiplayerTypes.h +++ b/Gems/Multiplayer/Code/Source/MultiplayerTypes.h @@ -33,6 +33,9 @@ namespace Multiplayer AZ_TYPE_SAFE_INTEGRAL(NetComponentId, uint16_t); static constexpr NetComponentId InvalidNetComponentId = static_cast(-1); + AZ_TYPE_SAFE_INTEGRAL(PropertyIndex, uint16_t); + AZ_TYPE_SAFE_INTEGRAL(RpcIndex, uint16_t); + using LongNetworkString = AZ::CVarFixedString; using ReliabilityType = AzNetworking::ReliabilityType; @@ -111,3 +114,5 @@ namespace Multiplayer 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); diff --git a/Gems/Multiplayer/Code/Source/NetworkEntity/EntityReplication/EntityReplicationManager.cpp b/Gems/Multiplayer/Code/Source/NetworkEntity/EntityReplication/EntityReplicationManager.cpp index 8db582f6e5..938e3b2c23 100644 --- a/Gems/Multiplayer/Code/Source/NetworkEntity/EntityReplication/EntityReplicationManager.cpp +++ b/Gems/Multiplayer/Code/Source/NetworkEntity/EntityReplication/EntityReplicationManager.cpp @@ -21,6 +21,7 @@ #include #include #include +#include #include #include #include @@ -825,11 +826,12 @@ namespace Multiplayer { if (entityReplicator == nullptr) { + IMultiplayer* multiplayer = AZ::Interface::Get(); AZLOG_INFO ( - "EntityReplicationManager: Dropping remote RPC message for component %u of rpc type %d, entityId %u has already been deleted", - aznumeric_cast(message.GetComponentId()), - message.GetRpcMessageType(), + "EntityReplicationManager: Dropping remote RPC message for component %s of rpc index %s, entityId %u has already been deleted", + multiplayer->GetComponentName(message.GetComponentId()), + multiplayer->GetComponentRpcName(message.GetComponentId(), message.GetRpcIndex()), message.GetEntityId() ); return false; diff --git a/Gems/Multiplayer/Code/Source/NetworkEntity/EntityReplication/EntityReplicator.cpp b/Gems/Multiplayer/Code/Source/NetworkEntity/EntityReplication/EntityReplicator.cpp index 42bc9d99d8..b645101677 100644 --- a/Gems/Multiplayer/Code/Source/NetworkEntity/EntityReplication/EntityReplicator.cpp +++ b/Gems/Multiplayer/Code/Source/NetworkEntity/EntityReplication/EntityReplicator.cpp @@ -449,7 +449,7 @@ namespace Multiplayer { // Received rpc metrics, log rpc sent, number of bytes, and the componentId/rpcId for bandwidth metrics MultiplayerStats& stats = AZ::Interface::Get()->GetStats(); - stats.RecordRpcSent(static_cast(entityRpcMessage.GetComponentId()), entityRpcMessage.GetRpcMessageType(), entityRpcMessage.GetEstimatedSerializeSize()); + stats.RecordRpcSent(entityRpcMessage.GetComponentId(), entityRpcMessage.GetRpcIndex(), entityRpcMessage.GetEstimatedSerializeSize()); m_replicationManager.AddDeferredRpcMessage(entityRpcMessage); } @@ -603,7 +603,7 @@ namespace Multiplayer aznumeric_cast(GetRemoteNetworkRole()), aznumeric_cast(entityRpcMessage.GetRpcDeliveryType()), aznumeric_cast(entityRpcMessage.GetComponentId()), - aznumeric_cast(entityRpcMessage.GetRpcMessageType()), + aznumeric_cast(entityRpcMessage.GetRpcIndex()), entityRpcMessage.GetReliability() == ReliabilityType::Reliable ? "true" : "false", IsMarkedForRemoval() ? "true" : "false" ); @@ -620,7 +620,7 @@ namespace Multiplayer aznumeric_cast(GetRemoteNetworkRole()), aznumeric_cast(entityRpcMessage.GetRpcDeliveryType()), aznumeric_cast(entityRpcMessage.GetComponentId()), - aznumeric_cast(entityRpcMessage.GetRpcMessageType()), + aznumeric_cast(entityRpcMessage.GetRpcIndex()), entityRpcMessage.GetReliability() == ReliabilityType::Reliable ? "true" : "false", IsMarkedForRemoval() ? "true" : "false" ); @@ -632,7 +632,7 @@ namespace Multiplayer { // Received rpc metrics, log rpc received, time spent, number of bytes, and the componentId/rpcId for bandwidth metrics MultiplayerStats& stats = AZ::Interface::Get()->GetStats(); - stats.RecordRpcReceived(static_cast(entityRpcMessage.GetComponentId()), entityRpcMessage.GetRpcMessageType(), entityRpcMessage.GetEstimatedSerializeSize()); + stats.RecordRpcReceived(entityRpcMessage.GetComponentId(), entityRpcMessage.GetRpcIndex(), entityRpcMessage.GetEstimatedSerializeSize()); if (!m_netBindComponent) { @@ -644,7 +644,7 @@ namespace Multiplayer aznumeric_cast(GetRemoteNetworkRole()), aznumeric_cast(entityRpcMessage.GetRpcDeliveryType()), aznumeric_cast(entityRpcMessage.GetComponentId()), - aznumeric_cast(entityRpcMessage.GetRpcMessageType()), + aznumeric_cast(entityRpcMessage.GetRpcIndex()), entityRpcMessage.GetReliability() == ReliabilityType::Reliable ? "true" : "false", IsMarkedForRemoval() ? "true" : "false" ); diff --git a/Gems/Multiplayer/Code/Source/NetworkEntity/EntityReplication/ReplicationRecord.h b/Gems/Multiplayer/Code/Source/NetworkEntity/EntityReplication/ReplicationRecord.h index 7c2f4668ed..83721a5539 100644 --- a/Gems/Multiplayer/Code/Source/NetworkEntity/EntityReplication/ReplicationRecord.h +++ b/Gems/Multiplayer/Code/Source/NetworkEntity/EntityReplication/ReplicationRecord.h @@ -15,7 +15,7 @@ #include #include #include -#include +#include namespace Multiplayer { diff --git a/Gems/Multiplayer/Code/Source/NetworkEntity/INetworkEntityManager.h b/Gems/Multiplayer/Code/Source/NetworkEntity/INetworkEntityManager.h index 82b13841c8..da6d9a4cbe 100644 --- a/Gems/Multiplayer/Code/Source/NetworkEntity/INetworkEntityManager.h +++ b/Gems/Multiplayer/Code/Source/NetworkEntity/INetworkEntityManager.h @@ -12,7 +12,7 @@ #pragma once -#include +#include #include #include #include diff --git a/Gems/Multiplayer/Code/Source/NetworkEntity/NetworkEntityHandle.h b/Gems/Multiplayer/Code/Source/NetworkEntity/NetworkEntityHandle.h index 7e1f3f15fa..0f84ed4477 100644 --- a/Gems/Multiplayer/Code/Source/NetworkEntity/NetworkEntityHandle.h +++ b/Gems/Multiplayer/Code/Source/NetworkEntity/NetworkEntityHandle.h @@ -13,7 +13,7 @@ #pragma once #include -#include +#include namespace Multiplayer { diff --git a/Gems/Multiplayer/Code/Source/NetworkEntity/NetworkEntityRpcMessage.cpp b/Gems/Multiplayer/Code/Source/NetworkEntity/NetworkEntityRpcMessage.cpp index e4cffc14fa..8be93ece73 100644 --- a/Gems/Multiplayer/Code/Source/NetworkEntity/NetworkEntityRpcMessage.cpp +++ b/Gems/Multiplayer/Code/Source/NetworkEntity/NetworkEntityRpcMessage.cpp @@ -21,7 +21,7 @@ namespace Multiplayer : m_rpcDeliveryType(rhs.m_rpcDeliveryType) , m_entityId(rhs.m_entityId) , m_componentId(rhs.m_componentId) - , m_rpcMessageType(rhs.m_rpcMessageType) + , m_rpcIndex(rhs.m_rpcIndex) , m_data(AZStd::move(rhs.m_data)) , m_isReliable(rhs.m_isReliable) { @@ -32,7 +32,7 @@ namespace Multiplayer : m_rpcDeliveryType(rhs.m_rpcDeliveryType) , m_entityId(rhs.m_entityId) , m_componentId(rhs.m_componentId) - , m_rpcMessageType(rhs.m_rpcMessageType) + , m_rpcIndex(rhs.m_rpcIndex) , m_isReliable(rhs.m_isReliable) { if (rhs.m_data != nullptr) @@ -42,11 +42,11 @@ namespace Multiplayer } } - NetworkEntityRpcMessage::NetworkEntityRpcMessage(RpcDeliveryType rpcDeliveryType, NetEntityId entityId, NetComponentId componentId, uint16_t rpcMessageType, ReliabilityType isReliable) + NetworkEntityRpcMessage::NetworkEntityRpcMessage(RpcDeliveryType rpcDeliveryType, NetEntityId entityId, NetComponentId componentId, RpcIndex rpcIndex, ReliabilityType isReliable) : m_rpcDeliveryType(rpcDeliveryType) , m_entityId(entityId) , m_componentId(componentId) - , m_rpcMessageType(rpcMessageType) + , m_rpcIndex(rpcIndex) , m_isReliable(isReliable) { ; @@ -57,7 +57,7 @@ namespace Multiplayer m_rpcDeliveryType = rhs.m_rpcDeliveryType; m_entityId = rhs.m_entityId; m_componentId = rhs.m_componentId; - m_rpcMessageType = rhs.m_rpcMessageType; + m_rpcIndex = rhs.m_rpcIndex; m_isReliable = rhs.m_isReliable; m_data = AZStd::move(rhs.m_data); return *this; @@ -68,7 +68,7 @@ namespace Multiplayer m_rpcDeliveryType = rhs.m_rpcDeliveryType; m_entityId = rhs.m_entityId; m_componentId = rhs.m_componentId; - m_rpcMessageType = rhs.m_rpcMessageType; + m_rpcIndex = rhs.m_rpcIndex; m_isReliable = rhs.m_isReliable; if (rhs.m_data != nullptr) { @@ -85,7 +85,7 @@ namespace Multiplayer return ((m_rpcDeliveryType == rhs.m_rpcDeliveryType) && (m_entityId == rhs.m_entityId) && (m_componentId == rhs.m_componentId) - && (m_rpcMessageType == rhs.m_rpcMessageType)); + && (m_rpcIndex == rhs.m_rpcIndex)); } bool NetworkEntityRpcMessage::operator !=(const NetworkEntityRpcMessage& rhs) const @@ -101,7 +101,7 @@ namespace Multiplayer + sizeof(uint16_t); // 2-byte size header + the actual blob payload itself - const uint32_t sizeOfBlob = (m_data != nullptr) ? sizeof(uint16_t) + m_data->GetSize() : 0; + const uint32_t sizeOfBlob = (m_data != nullptr) ? sizeof(RpcIndex) + m_data->GetSize() : 0; // No sliceId, remote replicator already exists so we don't need to know what type of entity this is return sizeOfFields + sizeOfBlob; @@ -127,9 +127,9 @@ namespace Multiplayer return m_componentId; } - uint16_t NetworkEntityRpcMessage::GetRpcMessageType() const + RpcIndex NetworkEntityRpcMessage::GetRpcIndex() const { - return m_rpcMessageType; + return m_rpcIndex; } bool NetworkEntityRpcMessage::SetRpcParams(IRpcParamStruct& params) @@ -167,7 +167,7 @@ namespace Multiplayer serializer.Serialize(m_rpcDeliveryType, "RpcDeliveryType"); serializer.Serialize(m_entityId, "EntityId"); serializer.Serialize(m_componentId, "ComponentId"); - serializer.Serialize(m_rpcMessageType, "RpcMessageType"); + serializer.Serialize(m_rpcIndex, "RpcIndex"); // m_data should never be nullptr, it contains serialized data for our Rpc params struct if (m_data == nullptr) diff --git a/Gems/Multiplayer/Code/Source/NetworkEntity/NetworkEntityRpcMessage.h b/Gems/Multiplayer/Code/Source/NetworkEntity/NetworkEntityRpcMessage.h index 87a4a5d6af..08b1960172 100644 --- a/Gems/Multiplayer/Code/Source/NetworkEntity/NetworkEntityRpcMessage.h +++ b/Gems/Multiplayer/Code/Source/NetworkEntity/NetworkEntityRpcMessage.h @@ -14,7 +14,7 @@ #include #include -#include +#include namespace Multiplayer { @@ -35,12 +35,12 @@ namespace Multiplayer NetworkEntityRpcMessage(const NetworkEntityRpcMessage& rhs); //! Fill explicit constructor. - //! @param rpcDeliveryType the delivery type (origin and target) for this RPC - //! @param entityId the networked entityId of the entity handling this RPC - //! @param componentType the networked componentId of the component handling this RPC - //! @param rpcMessageType the component defined RPC type, so the component knows which RPC this message corresponds to - //! @param isReliable whether or not this RPC should be sent reliably - explicit NetworkEntityRpcMessage(RpcDeliveryType rpcDeliveryType, NetEntityId entityId, NetComponentId componentId, uint16_t rpcMessageType, ReliabilityType isReliable); + //! @param rpcDeliveryType the delivery type (origin and target) for this rpc + //! @param entityId the networked entityId of the entity handling this rpc + //! @param componentType the networked componentId of the component handling this rpc + //! @param rpcIndex the component defined rpc index, so the component knows which rpc this message corresponds to + //! @param isReliable whether or not this rpc should be sent reliably + explicit NetworkEntityRpcMessage(RpcDeliveryType rpcDeliveryType, NetEntityId entityId, NetComponentId componentId, RpcIndex rpcIndex, ReliabilityType isReliable); NetworkEntityRpcMessage& operator =(NetworkEntityRpcMessage&& rhs); NetworkEntityRpcMessage& operator =(const NetworkEntityRpcMessage& rhs); @@ -67,9 +67,9 @@ namespace Multiplayer //! @return the current value of EntityComponentType NetComponentId GetComponentId() const; - //! Gets the current value of RpcMessageType. - //! @return the current value of RpcMessageType - uint16_t GetRpcMessageType() const; + //! Gets the current value of RpcIndex. + //! @return the current value of RpcIndex + RpcIndex GetRpcIndex() const; //! Writes the data contained inside a_Params to this NetworkEntityRpcMessage's blob buffer. //! @param params the parameters to save inside this NetworkEntityRpcMessage instance @@ -98,7 +98,7 @@ namespace Multiplayer RpcDeliveryType m_rpcDeliveryType = RpcDeliveryType::None; NetEntityId m_entityId = InvalidNetEntityId; NetComponentId m_componentId = InvalidNetComponentId; - uint16_t m_rpcMessageType = 0; + RpcIndex m_rpcIndex = RpcIndex{ 0 }; // Only allocated if we actually have data // This is to prevent blowing out stack memory if we declare an array of these EntityUpdateMessages diff --git a/Gems/Multiplayer/Code/Source/NetworkEntity/NetworkEntityTracker.h b/Gems/Multiplayer/Code/Source/NetworkEntity/NetworkEntityTracker.h index 5c9d8485dd..ffc150e5cc 100644 --- a/Gems/Multiplayer/Code/Source/NetworkEntity/NetworkEntityTracker.h +++ b/Gems/Multiplayer/Code/Source/NetworkEntity/NetworkEntityTracker.h @@ -12,7 +12,7 @@ #pragma once -#include +#include #include #include #include diff --git a/Gems/Multiplayer/Code/Source/NetworkEntity/NetworkEntityUpdateMessage.cpp b/Gems/Multiplayer/Code/Source/NetworkEntity/NetworkEntityUpdateMessage.cpp index 63345e79a0..27c39ea135 100644 --- a/Gems/Multiplayer/Code/Source/NetworkEntity/NetworkEntityUpdateMessage.cpp +++ b/Gems/Multiplayer/Code/Source/NetworkEntity/NetworkEntityUpdateMessage.cpp @@ -131,7 +131,7 @@ namespace Multiplayer } // 2-byte size header + the actual blob payload itself - const uint32_t sizeOfBlob = (m_data != nullptr) ? sizeof(uint16_t) + m_data->GetSize() : 0; + const uint32_t sizeOfBlob = (m_data != nullptr) ? sizeof(PropertyIndex) + m_data->GetSize() : 0; if (m_hasValidPrefabId) { diff --git a/Gems/Multiplayer/Code/Source/NetworkEntity/NetworkEntityUpdateMessage.h b/Gems/Multiplayer/Code/Source/NetworkEntity/NetworkEntityUpdateMessage.h index 481181e0b4..9ca539d75d 100644 --- a/Gems/Multiplayer/Code/Source/NetworkEntity/NetworkEntityUpdateMessage.h +++ b/Gems/Multiplayer/Code/Source/NetworkEntity/NetworkEntityUpdateMessage.h @@ -15,7 +15,7 @@ #include #include #include -#include +#include namespace Multiplayer { diff --git a/Gems/Multiplayer/Code/Source/NetworkInput/IMultiplayerComponentInput.h b/Gems/Multiplayer/Code/Source/NetworkInput/IMultiplayerComponentInput.h index a87f8e0b47..b5df01a1a8 100644 --- a/Gems/Multiplayer/Code/Source/NetworkInput/IMultiplayerComponentInput.h +++ b/Gems/Multiplayer/Code/Source/NetworkInput/IMultiplayerComponentInput.h @@ -12,7 +12,7 @@ #pragma once -#include +#include #include #include #include diff --git a/Gems/Multiplayer/Code/Source/ReplicationWindows/IReplicationWindow.h b/Gems/Multiplayer/Code/Source/ReplicationWindows/IReplicationWindow.h index bc0e909dcd..27c14f8049 100644 --- a/Gems/Multiplayer/Code/Source/ReplicationWindows/IReplicationWindow.h +++ b/Gems/Multiplayer/Code/Source/ReplicationWindows/IReplicationWindow.h @@ -12,7 +12,7 @@ #pragma once -#include +#include #include #include diff --git a/Gems/Multiplayer/Code/multiplayer_files.cmake b/Gems/Multiplayer/Code/multiplayer_files.cmake index 58601423da..f26e40355e 100644 --- a/Gems/Multiplayer/Code/multiplayer_files.cmake +++ b/Gems/Multiplayer/Code/multiplayer_files.cmake @@ -13,11 +13,11 @@ set(FILES Include/IMultiplayer.h Include/MultiplayerStats.cpp Include/MultiplayerStats.h + Include/MultiplayerTypes.h Source/Multiplayer_precompiled.cpp Source/Multiplayer_precompiled.h Source/MultiplayerSystemComponent.cpp Source/MultiplayerSystemComponent.h - Source/MultiplayerTypes.h Source/AutoGen/AutoComponent_Header.jinja Source/AutoGen/AutoComponent_Source.jinja Source/AutoGen/AutoComponent_Common.jinja