diff --git a/Code/CryEngine/CrySystem/SystemInit.cpp b/Code/CryEngine/CrySystem/SystemInit.cpp index 48cb5e0d9e..7d3a13d1a2 100644 --- a/Code/CryEngine/CrySystem/SystemInit.cpp +++ b/Code/CryEngine/CrySystem/SystemInit.cpp @@ -1216,7 +1216,7 @@ bool CSystem::InitShine([[maybe_unused]] const SSystemInitParams& initParams) if (!m_env.pLyShine) { - AZ_Error(AZ_TRACE_SYSTEM_WINDOW, false, "LYShine System did not initialize correctly. Please check that the LyShine gem is enabled for this project in ProjectConfigurator."); + AZ_Error(AZ_TRACE_SYSTEM_WINDOW, false, "LYShine System did not initialize correctly. Please check that the LyShine gem is enabled for this project in *_dependencies.cmake."); return false; } return true; diff --git a/Gems/Multiplayer/Code/Include/IConnectionData.h b/Gems/Multiplayer/Code/Include/Multiplayer/IConnectionData.h similarity index 97% rename from Gems/Multiplayer/Code/Include/IConnectionData.h rename to Gems/Multiplayer/Code/Include/Multiplayer/IConnectionData.h index dcc2c940ef..39fdb61435 100644 --- a/Gems/Multiplayer/Code/Include/IConnectionData.h +++ b/Gems/Multiplayer/Code/Include/Multiplayer/IConnectionData.h @@ -12,7 +12,7 @@ #pragma once -#include +#include #include namespace Multiplayer diff --git a/Gems/Multiplayer/Code/Include/IEntityDomain.h b/Gems/Multiplayer/Code/Include/Multiplayer/IEntityDomain.h similarity index 97% rename from Gems/Multiplayer/Code/Include/IEntityDomain.h rename to Gems/Multiplayer/Code/Include/Multiplayer/IEntityDomain.h index 6571797d05..70215612b0 100644 --- a/Gems/Multiplayer/Code/Include/IEntityDomain.h +++ b/Gems/Multiplayer/Code/Include/Multiplayer/IEntityDomain.h @@ -12,7 +12,7 @@ #pragma once -#include +#include namespace Multiplayer { diff --git a/Gems/Multiplayer/Code/Include/IMultiplayer.h b/Gems/Multiplayer/Code/Include/Multiplayer/IMultiplayer.h similarity index 63% rename from Gems/Multiplayer/Code/Include/IMultiplayer.h rename to Gems/Multiplayer/Code/Include/Multiplayer/IMultiplayer.h index 039b86b2a6..4931fb167f 100644 --- a/Gems/Multiplayer/Code/Include/IMultiplayer.h +++ b/Gems/Multiplayer/Code/Include/Multiplayer/IMultiplayer.h @@ -15,8 +15,9 @@ #include #include #include -#include -#include +#include +#include +#include namespace AzNetworking { @@ -46,6 +47,7 @@ namespace Multiplayer using ConnectionAcquiredEvent = AZ::Event; using SessionInitEvent = AZ::Event; using SessionShutdownEvent = AZ::Event; + using OnConnectFunctor = AZStd::function; //! IMultiplayer provides insight into the Multiplayer session and its Agents class IMultiplayer @@ -55,26 +57,30 @@ namespace Multiplayer virtual ~IMultiplayer() = default; - //! Gets the type of Agent this IMultiplayer impl represents + //! Gets the type of Agent this IMultiplayer impl represents. //! @return The type of agents represented virtual MultiplayerAgentType GetAgentType() const = 0; - //! Sets the type of this Multiplayer connection and calls any related callback + //! Sets the type of this Multiplayer connection and calls any related callback. //! @param state The state of this connection virtual void InitializeMultiplayer(MultiplayerAgentType state) = 0; - //! Adds a ConnectionAcquiredEvent Handler which is invoked when a new endpoint connects to the session + //! Adds a ConnectionAcquiredEvent Handler which is invoked when a new endpoint connects to the session. //! @param handler The SessionInitEvent Handler to add virtual void AddConnectionAcquiredHandler(ConnectionAcquiredEvent::Handler& handler) = 0; - //! Adds a SessionInitEvent Handler which is invoked when a new network session starts + //! Adds a SessionInitEvent Handler which is invoked when a new network session starts. //! @param handler The SessionInitEvent Handler to add virtual void AddSessionInitHandler(SessionInitEvent::Handler& handler) = 0; - //! Adds a SessionShutdownEvent Handler which is invoked when the current network session ends + //! Adds a SessionShutdownEvent Handler which is invoked when the current network session ends. //! @param handler The SessionShutdownEvent handler to add virtual void AddSessionShutdownHandler(SessionShutdownEvent::Handler& handler) = 0; + //! Overrides the default connect behaviour with the provided functor. + //! @param functor the function to invoke during a new connection event + virtual void SetOnConnectFunctor(const OnConnectFunctor& functor) = 0; + //! Sends a packet telling if entity update messages can be sent //! @param readyForEntityUpdates Ready for entity updates or not virtual void SendReadyForEntityUpdates(bool readyForEntityUpdates) = 0; @@ -87,6 +93,14 @@ namespace Multiplayer //! @return the current server time in milliseconds virtual AZ::TimeMs GetCurrentHostTimeMs() const = 0; + //! Returns the network time instance bound to this multiplayer instance. + //! @return pointer to the network time instance bound to this multiplayer instance + virtual INetworkTime* GetNetworkTime() = 0; + + //! Returns the network entity manager instance bound to this multiplayer instance. + //! @return pointer to the network entity manager instance bound to this multiplayer instance + virtual INetworkEntityManager* GetNetworkEntityManager() = 0; + //! Returns the gem name associated with the provided component index. //! @param netComponentId the componentId to return the gem name of //! @return the name of the gem that contains the requested component @@ -117,6 +131,60 @@ namespace Multiplayer MultiplayerStats m_stats; }; + // Convenience helpers + inline IMultiplayer* GetMultiplayer() + { + return AZ::Interface::Get(); + } + + inline INetworkEntityManager* GetNetworkEntityManager() + { + IMultiplayer* multiplayer = GetMultiplayer(); + return (multiplayer != nullptr) ? multiplayer->GetNetworkEntityManager() : nullptr; + } + + inline NetworkEntityTracker* GetNetworkEntityTracker() + { + INetworkEntityManager* networkEntityManager = GetNetworkEntityManager(); + return (networkEntityManager != nullptr) ? networkEntityManager->GetNetworkEntityTracker() : nullptr; + } + + inline NetworkEntityAuthorityTracker* GetNetworkEntityAuthorityTracker() + { + INetworkEntityManager* networkEntityManager = GetNetworkEntityManager(); + return (networkEntityManager != nullptr) ? networkEntityManager->GetNetworkEntityAuthorityTracker() : nullptr; + } + + inline MultiplayerComponentRegistry* GetMultiplayerComponentRegistry() + { + INetworkEntityManager* networkEntityManager = GetNetworkEntityManager(); + return (networkEntityManager != nullptr) ? networkEntityManager->GetMultiplayerComponentRegistry() : nullptr; + } + + //! @class ScopedAlterTime + //! @brief This is a wrapper that temporarily adjusts global program time for backward reconciliation purposes. + class ScopedAlterTime final + { + public: + inline ScopedAlterTime(HostFrameId frameId, AZ::TimeMs timeMs, AzNetworking::ConnectionId connectionId) + { + INetworkTime* time = GetNetworkTime(); + m_previousHostFrameId = time->GetHostFrameId(); + m_previousHostTimeMs = time->GetHostTimeMs(); + m_previousRewindConnectionId = time->GetRewindingConnectionId(); + time->AlterTime(frameId, timeMs, connectionId); + } + inline ~ScopedAlterTime() + { + INetworkTime* time = GetNetworkTime(); + time->AlterTime(m_previousHostFrameId, m_previousHostTimeMs, m_previousRewindConnectionId); + } + private: + HostFrameId m_previousHostFrameId = InvalidHostFrameId; + AZ::TimeMs m_previousHostTimeMs = AZ::TimeMs{ 0 }; + AzNetworking::ConnectionId m_previousRewindConnectionId = AzNetworking::InvalidConnectionId; + }; + inline const char* GetEnumString(MultiplayerAgentType value) { switch (value) diff --git a/Gems/Multiplayer/Code/Include/IMultiplayerComponentInput.h b/Gems/Multiplayer/Code/Include/Multiplayer/IMultiplayerComponentInput.h similarity index 96% rename from Gems/Multiplayer/Code/Include/IMultiplayerComponentInput.h rename to Gems/Multiplayer/Code/Include/Multiplayer/IMultiplayerComponentInput.h index b5df01a1a8..b26feadc4f 100644 --- a/Gems/Multiplayer/Code/Include/IMultiplayerComponentInput.h +++ b/Gems/Multiplayer/Code/Include/Multiplayer/IMultiplayerComponentInput.h @@ -12,7 +12,7 @@ #pragma once -#include +#include #include #include #include diff --git a/Gems/Multiplayer/Code/Include/INetworkEntityManager.h b/Gems/Multiplayer/Code/Include/Multiplayer/INetworkEntityManager.h similarity index 88% rename from Gems/Multiplayer/Code/Include/INetworkEntityManager.h rename to Gems/Multiplayer/Code/Include/Multiplayer/INetworkEntityManager.h index d9b611ece0..17224e64cb 100644 --- a/Gems/Multiplayer/Code/Include/INetworkEntityManager.h +++ b/Gems/Multiplayer/Code/Include/Multiplayer/INetworkEntityManager.h @@ -12,8 +12,8 @@ #pragma once -#include -#include +#include +#include #include #include #include @@ -59,9 +59,24 @@ namespace Multiplayer //! Creates new entities of the given archetype //! @param prefabEntryId the name of the spawnable to spawn - virtual EntityList CreateEntitiesImmediate( - const PrefabEntityId& prefabEntryId, NetEntityId netEntityId, NetEntityRole netEntityRole, AutoActivate autoActivate, - const AZ::Transform& transform) = 0; + virtual EntityList CreateEntitiesImmediate + ( + const PrefabEntityId& prefabEntryId, + NetEntityRole netEntityRole, + const AZ::Transform& transform + ) = 0; + + //! Creates new entities of the given archetype + //! This interface is internally used to spawn replicated entities + //! @param prefabEntryId the name of the spawnable to spawn + virtual EntityList CreateEntitiesImmediate + ( + const PrefabEntityId& prefabEntryId, + NetEntityId netEntityId, + NetEntityRole netEntityRole, + AutoActivate autoActivate, + const AZ::Transform& transform + ) = 0; //! Returns an ConstEntityPtr for the provided entityId. //! @param netEntityId the netEntityId to get an ConstEntityPtr for @@ -134,25 +149,4 @@ namespace Multiplayer //! @param entityRpcMessage the local rpc message to handle virtual void HandleLocalRpcMessage(NetworkEntityRpcMessage& message) = 0; }; - - // Convenience helpers - inline INetworkEntityManager* GetNetworkEntityManager() - { - return AZ::Interface::Get(); - } - - inline NetworkEntityTracker* GetNetworkEntityTracker() - { - return GetNetworkEntityManager()->GetNetworkEntityTracker(); - } - - inline NetworkEntityAuthorityTracker* GetNetworkEntityAuthorityTracker() - { - return GetNetworkEntityManager()->GetNetworkEntityAuthorityTracker(); - } - - inline MultiplayerComponentRegistry* GetMultiplayerComponentRegistry() - { - return GetNetworkEntityManager()->GetMultiplayerComponentRegistry(); - } } diff --git a/Gems/Multiplayer/Code/Include/Multiplayer/INetworkPlayerSpawner.h b/Gems/Multiplayer/Code/Include/Multiplayer/INetworkPlayerSpawner.h new file mode 100644 index 0000000000..f50d60e82d --- /dev/null +++ b/Gems/Multiplayer/Code/Include/Multiplayer/INetworkPlayerSpawner.h @@ -0,0 +1,18 @@ +/* +* 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 + +namespace Multiplayer +{ + +} diff --git a/Gems/Multiplayer/Code/Include/INetworkTime.h b/Gems/Multiplayer/Code/Include/Multiplayer/INetworkTime.h similarity index 74% rename from Gems/Multiplayer/Code/Include/INetworkTime.h rename to Gems/Multiplayer/Code/Include/Multiplayer/INetworkTime.h index 5346a0e0d0..240eed270a 100644 --- a/Gems/Multiplayer/Code/Include/INetworkTime.h +++ b/Gems/Multiplayer/Code/Include/Multiplayer/INetworkTime.h @@ -14,7 +14,7 @@ #include #include -#include +#include namespace Multiplayer { @@ -47,9 +47,6 @@ namespace Multiplayer //! @return the hosts current timeMs virtual AZ::TimeMs GetHostTimeMs() const = 0; - //! Synchronizes rewindable entity state for the current application time. - virtual void SyncRewindableEntityState() = 0; - //! Get the controlling connection that may be currently altering global game time. //! Note this abstraction is required at a relatively high level to allow for 'don't rewind the shooter' semantics //! @return the ConnectionId of the connection requesting the rewind operation @@ -67,6 +64,13 @@ namespace Multiplayer //! @param rewindConnectionId the rewinding ConnectionId virtual void AlterTime(HostFrameId frameId, AZ::TimeMs timeMs, AzNetworking::ConnectionId rewindConnectionId) = 0; + //! Syncs all entities contained within a volume to the current rewind state. + //! @param rewindVolume the volume to rewind entities within (needed for physics entities) + virtual void SyncEntitiesToRewindState(const AZ::Aabb& rewindVolume) = 0; + + //! Restores all rewound entities to the current application time. + virtual void ClearRewoundEntities() = 0; + AZ_DISABLE_COPY_MOVE(INetworkTime); }; @@ -80,27 +84,9 @@ namespace Multiplayer }; using INetworkTimeRequestBus = AZ::EBus; - //! @class ScopedAlterTime - //! @brief This is a wrapper that temporarily adjusts global program time for backward reconciliation purposes. - class ScopedAlterTime final + // Convenience helpers + inline INetworkTime* GetNetworkTime() { - public: - inline ScopedAlterTime(HostFrameId frameId, AZ::TimeMs timeMs, AzNetworking::ConnectionId connectionId) - { - INetworkTime* time = AZ::Interface::Get(); - m_previousHostFrameId = time->GetHostFrameId(); - m_previousHostTimeMs = time->GetHostTimeMs(); - m_previousRewindConnectionId = time->GetRewindingConnectionId(); - time->AlterTime(frameId, timeMs, connectionId); - } - inline ~ScopedAlterTime() - { - INetworkTime* time = AZ::Interface::Get(); - time->AlterTime(m_previousHostFrameId, m_previousHostTimeMs, m_previousRewindConnectionId); - } - private: - HostFrameId m_previousHostFrameId = InvalidHostFrameId; - AZ::TimeMs m_previousHostTimeMs = AZ::TimeMs{ 0 }; - AzNetworking::ConnectionId m_previousRewindConnectionId = AzNetworking::InvalidConnectionId; - }; + return AZ::Interface::Get(); + } } diff --git a/Gems/Multiplayer/Code/Include/IReplicationWindow.h b/Gems/Multiplayer/Code/Include/Multiplayer/IReplicationWindow.h similarity index 94% rename from Gems/Multiplayer/Code/Include/IReplicationWindow.h rename to Gems/Multiplayer/Code/Include/Multiplayer/IReplicationWindow.h index eb34a2f87d..d0192e8aa4 100644 --- a/Gems/Multiplayer/Code/Include/IReplicationWindow.h +++ b/Gems/Multiplayer/Code/Include/Multiplayer/IReplicationWindow.h @@ -12,8 +12,8 @@ #pragma once -#include -#include +#include +#include #include namespace Multiplayer diff --git a/Gems/Multiplayer/Code/Source/Components/MultiplayerComponent.h b/Gems/Multiplayer/Code/Include/Multiplayer/MultiplayerComponent.h similarity index 97% rename from Gems/Multiplayer/Code/Source/Components/MultiplayerComponent.h rename to Gems/Multiplayer/Code/Include/Multiplayer/MultiplayerComponent.h index 0f64221dde..29348a698a 100644 --- a/Gems/Multiplayer/Code/Source/Components/MultiplayerComponent.h +++ b/Gems/Multiplayer/Code/Include/Multiplayer/MultiplayerComponent.h @@ -15,9 +15,9 @@ #include #include #include -#include -#include -#include +#include +#include +#include //! Macro to declare bindings for a multiplayer component inheriting from MultiplayerComponent #define AZ_MULTIPLAYER_COMPONENT(ComponentClass, Guid, Base) \ diff --git a/Gems/Multiplayer/Code/Source/Components/MultiplayerComponentRegistry.h b/Gems/Multiplayer/Code/Include/Multiplayer/MultiplayerComponentRegistry.h similarity index 98% rename from Gems/Multiplayer/Code/Source/Components/MultiplayerComponentRegistry.h rename to Gems/Multiplayer/Code/Include/Multiplayer/MultiplayerComponentRegistry.h index e16f942100..d06362ed4b 100644 --- a/Gems/Multiplayer/Code/Source/Components/MultiplayerComponentRegistry.h +++ b/Gems/Multiplayer/Code/Include/Multiplayer/MultiplayerComponentRegistry.h @@ -14,7 +14,7 @@ #include #include -#include +#include namespace Multiplayer { diff --git a/Gems/Multiplayer/Code/Source/Components/MultiplayerController.h b/Gems/Multiplayer/Code/Include/Multiplayer/MultiplayerController.h similarity index 90% rename from Gems/Multiplayer/Code/Source/Components/MultiplayerController.h rename to Gems/Multiplayer/Code/Include/Multiplayer/MultiplayerController.h index de07e39e66..89c47c40d4 100644 --- a/Gems/Multiplayer/Code/Source/Components/MultiplayerController.h +++ b/Gems/Multiplayer/Code/Include/Multiplayer/MultiplayerController.h @@ -12,7 +12,7 @@ #pragma once -#include +#include #include namespace Multiplayer @@ -84,12 +84,6 @@ namespace Multiplayer //! Returns the input priority ordering for determining the order of ProcessInput or CreateInput functions. virtual InputPriorityOrder GetInputOrder() const = 0; - //! Queries the rewind system to determine what volume is relevent for a given input, this is very important for performance at scale. - //! @param networkInput input structure to process - //! @param deltaTime amount of time the provided input would be integrated over - //! @return a world-space aabb representing the volume relevent to the provided input - virtual AZ::Aabb GetRewindBoundsForInput(const NetworkInput& networkInput, float deltaTime) const = 0; - //! Base execution for ProcessInput packet, do not call directly. //! @param networkInput input structure to process //! @param deltaTime amount of time to integrate the provided inputs over diff --git a/Gems/Multiplayer/Code/Include/MultiplayerStats.cpp b/Gems/Multiplayer/Code/Include/Multiplayer/MultiplayerStats.cpp similarity index 99% rename from Gems/Multiplayer/Code/Include/MultiplayerStats.cpp rename to Gems/Multiplayer/Code/Include/Multiplayer/MultiplayerStats.cpp index 7672997ad5..1f063b749d 100644 --- a/Gems/Multiplayer/Code/Include/MultiplayerStats.cpp +++ b/Gems/Multiplayer/Code/Include/Multiplayer/MultiplayerStats.cpp @@ -10,7 +10,7 @@ * */ -#include +#include namespace Multiplayer { diff --git a/Gems/Multiplayer/Code/Include/MultiplayerStats.h b/Gems/Multiplayer/Code/Include/Multiplayer/MultiplayerStats.h similarity index 98% rename from Gems/Multiplayer/Code/Include/MultiplayerStats.h rename to Gems/Multiplayer/Code/Include/Multiplayer/MultiplayerStats.h index dc266a14bf..5d00c4d205 100644 --- a/Gems/Multiplayer/Code/Include/MultiplayerStats.h +++ b/Gems/Multiplayer/Code/Include/Multiplayer/MultiplayerStats.h @@ -15,7 +15,7 @@ #include #include #include -#include +#include namespace AzNetworking { diff --git a/Gems/Multiplayer/Code/Include/MultiplayerTypes.h b/Gems/Multiplayer/Code/Include/Multiplayer/MultiplayerTypes.h similarity index 100% rename from Gems/Multiplayer/Code/Include/MultiplayerTypes.h rename to Gems/Multiplayer/Code/Include/Multiplayer/MultiplayerTypes.h diff --git a/Gems/Multiplayer/Code/Source/Components/NetBindComponent.h b/Gems/Multiplayer/Code/Include/Multiplayer/NetBindComponent.h similarity index 95% rename from Gems/Multiplayer/Code/Source/Components/NetBindComponent.h rename to Gems/Multiplayer/Code/Include/Multiplayer/NetBindComponent.h index 0885e44aa4..464333e3b2 100644 --- a/Gems/Multiplayer/Code/Source/Components/NetBindComponent.h +++ b/Gems/Multiplayer/Code/Include/Multiplayer/NetBindComponent.h @@ -20,11 +20,11 @@ #include #include #include -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include #include namespace Multiplayer @@ -73,7 +73,6 @@ namespace Multiplayer bool IsProcessingInput() const; void CreateInput(NetworkInput& networkInput, float deltaTime); void ProcessInput(NetworkInput& networkInput, float deltaTime); - AZ::Aabb GetRewindBoundsForInput(const NetworkInput& networkInput, float deltaTime) const; bool HandleRpcMessage(AzNetworking::IConnection* invokingConnection, NetEntityRole remoteRole, NetworkEntityRpcMessage& message); bool HandlePropertyChangeMessage(AzNetworking::ISerializer& serializer, bool notifyChanges = true); diff --git a/Gems/Multiplayer/Code/Include/NetworkEntityHandle.h b/Gems/Multiplayer/Code/Include/Multiplayer/NetworkEntityHandle.h similarity index 98% rename from Gems/Multiplayer/Code/Include/NetworkEntityHandle.h rename to Gems/Multiplayer/Code/Include/Multiplayer/NetworkEntityHandle.h index 9b8546ef2c..813589fac6 100644 --- a/Gems/Multiplayer/Code/Include/NetworkEntityHandle.h +++ b/Gems/Multiplayer/Code/Include/Multiplayer/NetworkEntityHandle.h @@ -13,7 +13,7 @@ #pragma once #include -#include +#include namespace Multiplayer { @@ -138,4 +138,4 @@ namespace Multiplayer }; } -#include +#include diff --git a/Gems/Multiplayer/Code/Include/NetworkEntityHandle.inl b/Gems/Multiplayer/Code/Include/Multiplayer/NetworkEntityHandle.inl similarity index 100% rename from Gems/Multiplayer/Code/Include/NetworkEntityHandle.inl rename to Gems/Multiplayer/Code/Include/Multiplayer/NetworkEntityHandle.inl diff --git a/Gems/Multiplayer/Code/Source/NetworkEntity/NetworkEntityRpcMessage.h b/Gems/Multiplayer/Code/Include/Multiplayer/NetworkEntityRpcMessage.h similarity index 99% rename from Gems/Multiplayer/Code/Source/NetworkEntity/NetworkEntityRpcMessage.h rename to Gems/Multiplayer/Code/Include/Multiplayer/NetworkEntityRpcMessage.h index 08b1960172..f6a7ff2c65 100644 --- a/Gems/Multiplayer/Code/Source/NetworkEntity/NetworkEntityRpcMessage.h +++ b/Gems/Multiplayer/Code/Include/Multiplayer/NetworkEntityRpcMessage.h @@ -14,7 +14,7 @@ #include #include -#include +#include namespace Multiplayer { diff --git a/Gems/Multiplayer/Code/Source/NetworkEntity/NetworkEntityUpdateMessage.h b/Gems/Multiplayer/Code/Include/Multiplayer/NetworkEntityUpdateMessage.h similarity index 99% rename from Gems/Multiplayer/Code/Source/NetworkEntity/NetworkEntityUpdateMessage.h rename to Gems/Multiplayer/Code/Include/Multiplayer/NetworkEntityUpdateMessage.h index 9ca539d75d..e96191262a 100644 --- a/Gems/Multiplayer/Code/Source/NetworkEntity/NetworkEntityUpdateMessage.h +++ b/Gems/Multiplayer/Code/Include/Multiplayer/NetworkEntityUpdateMessage.h @@ -15,7 +15,7 @@ #include #include #include -#include +#include namespace Multiplayer { diff --git a/Gems/Multiplayer/Code/Source/NetworkInput/NetworkInput.h b/Gems/Multiplayer/Code/Include/Multiplayer/NetworkInput.h similarity index 95% rename from Gems/Multiplayer/Code/Source/NetworkInput/NetworkInput.h rename to Gems/Multiplayer/Code/Include/Multiplayer/NetworkInput.h index b2b0fa12c6..9c6d2ce66a 100644 --- a/Gems/Multiplayer/Code/Source/NetworkInput/NetworkInput.h +++ b/Gems/Multiplayer/Code/Include/Multiplayer/NetworkInput.h @@ -12,9 +12,9 @@ #pragma once -#include -#include -#include +#include +#include +#include #include namespace Multiplayer diff --git a/Gems/Multiplayer/Code/Source/NetworkEntity/EntityReplication/ReplicationRecord.h b/Gems/Multiplayer/Code/Include/Multiplayer/ReplicationRecord.h similarity index 98% rename from Gems/Multiplayer/Code/Source/NetworkEntity/EntityReplication/ReplicationRecord.h rename to Gems/Multiplayer/Code/Include/Multiplayer/ReplicationRecord.h index 83721a5539..f6eb93c4ba 100644 --- a/Gems/Multiplayer/Code/Source/NetworkEntity/EntityReplication/ReplicationRecord.h +++ b/Gems/Multiplayer/Code/Include/Multiplayer/ReplicationRecord.h @@ -15,7 +15,7 @@ #include #include #include -#include +#include namespace Multiplayer { diff --git a/Gems/Multiplayer/Code/Source/NetworkTime/RewindableObject.h b/Gems/Multiplayer/Code/Include/Multiplayer/RewindableObject.h similarity index 98% rename from Gems/Multiplayer/Code/Source/NetworkTime/RewindableObject.h rename to Gems/Multiplayer/Code/Include/Multiplayer/RewindableObject.h index 4e830d4480..9e1655aec7 100644 --- a/Gems/Multiplayer/Code/Source/NetworkTime/RewindableObject.h +++ b/Gems/Multiplayer/Code/Include/Multiplayer/RewindableObject.h @@ -12,7 +12,7 @@ #pragma once -#include +#include #include #include #include @@ -115,4 +115,4 @@ namespace AZ AZ_TYPE_INFO_TEMPLATE(Multiplayer::RewindableObject, "{B2937B44-FEE1-4277-B1E0-863DE76D363F}", AZ_TYPE_INFO_TYPENAME, AZ_TYPE_INFO_AUTO); } -#include +#include diff --git a/Gems/Multiplayer/Code/Source/NetworkTime/RewindableObject.inl b/Gems/Multiplayer/Code/Include/Multiplayer/RewindableObject.inl similarity index 97% rename from Gems/Multiplayer/Code/Source/NetworkTime/RewindableObject.inl rename to Gems/Multiplayer/Code/Include/Multiplayer/RewindableObject.inl index 0835421ebd..20f52ffcb0 100644 --- a/Gems/Multiplayer/Code/Source/NetworkTime/RewindableObject.inl +++ b/Gems/Multiplayer/Code/Include/Multiplayer/RewindableObject.inl @@ -47,7 +47,7 @@ namespace Multiplayer template inline RewindableObject &RewindableObject::operator =(const RewindableObject& rhs) { - INetworkTime* networkTime = AZ::Interface::Get(); + INetworkTime* networkTime = Multiplayer::GetNetworkTime(); SetValueForTime(rhs.GetValueForTime(networkTime->GetHostFrameId()), GetCurrentTimeForProperty()); return *this; } @@ -115,7 +115,7 @@ namespace Multiplayer template inline HostFrameId RewindableObject::GetCurrentTimeForProperty() const { - INetworkTime* networkTime = AZ::Interface::Get(); + INetworkTime* networkTime = Multiplayer::GetNetworkTime(); return networkTime->GetHostFrameIdForRewindingConnection(m_owningConnectionId); } diff --git a/Gems/Multiplayer/Code/Source/AutoGen/AutoComponentTypes_Header.jinja b/Gems/Multiplayer/Code/Source/AutoGen/AutoComponentTypes_Header.jinja index fc2860ebe7..849b4245e2 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 2bae618d94..453d74c907 100644 --- a/Gems/Multiplayer/Code/Source/AutoGen/AutoComponentTypes_Source.jinja +++ b/Gems/Multiplayer/Code/Source/AutoGen/AutoComponentTypes_Source.jinja @@ -1,6 +1,6 @@ #include -#include -#include +#include +#include {% for Component in dataFiles %} {% set ComponentDerived = Component.attrib['OverrideComponent']|booleanTrue %} {% set ControllerDerived = Component.attrib['OverrideController']|booleanTrue %} @@ -21,8 +21,8 @@ namespace {{ Namespace }} { void RegisterMultiplayerComponents() { - Multiplayer::MultiplayerComponentRegistry* multiplayerComponentRegistry = GetMultiplayerComponentRegistry(); - Multiplayer::MultiplayerStats& stats = AZ::Interface::Get()->GetStats(); + Multiplayer::MultiplayerComponentRegistry* multiplayerComponentRegistry = Multiplayer::GetMultiplayerComponentRegistry(); + Multiplayer::MultiplayerStats& stats = Multiplayer::GetMultiplayer()->GetStats(); {% for Component in dataFiles %} {% set ComponentName = Component.attrib['Name'] %} {% set ComponentBaseName = ComponentName %} diff --git a/Gems/Multiplayer/Code/Source/AutoGen/AutoComponent_Header.jinja b/Gems/Multiplayer/Code/Source/AutoGen/AutoComponent_Header.jinja index faaa009e34..c22945c983 100644 --- a/Gems/Multiplayer/Code/Source/AutoGen/AutoComponent_Header.jinja +++ b/Gems/Multiplayer/Code/Source/AutoGen/AutoComponent_Header.jinja @@ -221,13 +221,14 @@ AZStd::fixed_vector<{{ Property.attrib['Type'] }}, {{ Property.attrib['Count'] } #include #include #include -#include -#include -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include +#include +#include +#include {% call(Include) AutoComponentMacros.ParseIncludes(Component) %} #include <{{ Include.attrib['File'] }}> {% endcall %} @@ -359,7 +360,6 @@ namespace {{ Component.attrib['Namespace'] }} //! MultiplayerController interface //! @{ Multiplayer::MultiplayerController::InputPriorityOrder GetInputOrder() const override { return Multiplayer::MultiplayerController::InputPriorityOrder::Default; } - AZ::Aabb GetRewindBoundsForInput([[maybe_unused]] const NetworkInput& networkInput, [[maybe_unused]] float deltaTime) const override { return AZ::Aabb::CreateNull(); } void CreateInput([[maybe_unused]] Multiplayer::NetworkInput& input, [[maybe_unused]] float deltaTime) override {} void ProcessInput([[maybe_unused]] Multiplayer::NetworkInput& input, [[maybe_unused]] float deltaTime) override {} //! @} @@ -434,12 +434,12 @@ namespace {{ Component.attrib['Namespace'] }} //! MultiplayerComponent interface //! @{ - NetComponentId GetNetComponentId() const override; + Multiplayer::NetComponentId GetNetComponentId() const override; bool HandleRpcMessage(AzNetworking::IConnection* invokingConnection, Multiplayer::NetEntityRole remoteRole, Multiplayer::NetworkEntityRpcMessage& rpcMessage) override; bool SerializeStateDeltaMessage(Multiplayer::ReplicationRecord& replicationRecord, AzNetworking::ISerializer& serializer) override; void NotifyStateDeltaChanges(Multiplayer::ReplicationRecord& replicationRecord) override; bool HasController() const override; - MultiplayerController* GetController() override; + Multiplayer::MultiplayerController* GetController() override; protected: void ConstructController() override; @@ -484,8 +484,8 @@ namespace {{ Component.attrib['Namespace'] }} void NotifyChangesAutonomousToAuthorityProperties(const {{ RecordName }}& replicationRecord) const; //! Debug name helpers - static const char* GetNetworkPropertyName(PropertyIndex propertyIndex); - static const char* GetRpcName(RpcIndex rpcIndex); + static const char* GetNetworkPropertyName(Multiplayer::PropertyIndex propertyIndex); + static const char* GetRpcName(Multiplayer::RpcIndex rpcIndex); AZStd::unique_ptr<{{ RecordName }}> m_currentRecord; AZStd::unique_ptr<{{ ControllerName }}> m_controller; @@ -517,7 +517,7 @@ namespace {{ Component.attrib['Namespace'] }} {{ Type }}* {{ Name }} = nullptr; {% endcall %} - static NetComponentId s_netComponentId; + static Multiplayer::NetComponentId s_netComponentId; friend void RegisterMultiplayerComponents(); }; } diff --git a/Gems/Multiplayer/Code/Source/AutoGen/AutoComponent_Source.jinja b/Gems/Multiplayer/Code/Source/AutoGen/AutoComponent_Source.jinja index 6e54ec3d58..200d38910b 100644 --- a/Gems/Multiplayer/Code/Source/AutoGen/AutoComponent_Source.jinja +++ b/Gems/Multiplayer/Code/Source/AutoGen/AutoComponent_Source.jinja @@ -476,7 +476,7 @@ bool {{ ClassName }}::Serialize{{ AutoComponentMacros.GetNetPropertiesSetName(Re {%- if networkPropertyCount.update({'value': networkPropertyCount.value + 1}) %}{% endif -%} {% endcall %} {% if networkPropertyCount.value > 0 %} - MultiplayerStats& stats = AZ::Interface::Get()->GetStats(); + MultiplayerStats& stats = GetMultiplayer()->GetStats(); // We modify the record if we are writing an update so that we don't notify for a change that really didn't change the value (just a duplicated send from the server) [[maybe_unused]] bool modifyRecord = serializer.GetSerializerMode() == AzNetworking::SerializerMode::WriteToObject; {% call(Property) AutoComponentMacros.ParseNetworkProperties(Component, ReplicateFrom, ReplicateTo) %} @@ -902,8 +902,8 @@ m_{{ LowerFirst(Property.attrib['Name']) }} = m_{{ LowerFirst(Property.attrib['N #include #include #include -#include -#include +#include +#include {% if ComponentDerived or ControllerDerived %} #include <{{ Component.attrib['OverrideInclude'] }}> {% endif %} @@ -915,7 +915,7 @@ m_{{ LowerFirst(Property.attrib['Name']) }} = m_{{ LowerFirst(Property.attrib['N namespace {{ Component.attrib['Namespace'] }} { - NetComponentId {{ UpperFirst(ComponentBaseName) }}::s_netComponentId = InvalidNetComponentId; + Multiplayer::NetComponentId {{ UpperFirst(ComponentBaseName) }}::s_netComponentId = Multiplayer::InvalidNetComponentId; namespace {{ UpperFirst(Component.attrib['Name']) }}Internal { @@ -1141,16 +1141,23 @@ namespace {{ Component.attrib['Namespace'] }} AZ::EditContext* editContext = serializeContext->GetEditContext(); if (editContext) { + editContext->Class<{{ ComponentBaseName }}>("{{ ComponentBaseName }}", "{{ Component.attrib['Description'] }}") + ->ClassElement(AZ::Edit::ClassElements::EditorData, "") + ->Attribute(AZ::Edit::Attributes::Category, "{{ Component.attrib['Namespace'] }}") + ->Attribute(AZ::Edit::Attributes::AppearsInAddComponentMenu, AZ_CRC_CE("Game")) + {{ DefineNetworkPropertyEditReflection(Component, 'Authority', 'Authority', ComponentBaseName)|indent(20) -}} +{{ DefineNetworkPropertyEditReflection(Component, 'Authority', 'Server', ComponentBaseName)|indent(20) -}} +{{ DefineNetworkPropertyEditReflection(Component, 'Authority', 'Client', ComponentBaseName)|indent(20) -}} +{{ DefineNetworkPropertyEditReflection(Component, 'Authority', 'Autonomous', ComponentBaseName)|indent(20) -}} +{{ DefineNetworkPropertyEditReflection(Component, 'Autonomous', 'Authority', ComponentBaseName)|indent(20) }} + {{ DefineArchetypePropertyEditReflection(Component, ComponentBaseName)|indent(20) }}; +{% if ComponentDerived %} + editContext->Class<{{ ComponentName }}>("{{ ComponentName }}", "{{ Component.attrib['Description'] }}") ->ClassElement(AZ::Edit::ClassElements::EditorData, "") - ->Attribute(AZ::Edit::Attributes::Category, "Multiplayer") - ->Attribute(AZ::Edit::Attributes::AppearsInAddComponentMenu, AZ_CRC_CE("Game")) - {{ DefineNetworkPropertyEditReflection(Component, 'Authority', 'Authority', ComponentName)|indent(20) -}} -{{ DefineNetworkPropertyEditReflection(Component, 'Authority', 'Server', ComponentName)|indent(20) -}} -{{ DefineNetworkPropertyEditReflection(Component, 'Authority', 'Client', ComponentName)|indent(20) -}} -{{ DefineNetworkPropertyEditReflection(Component, 'Authority', 'Autonomous', ComponentName)|indent(20) -}} -{{ DefineNetworkPropertyEditReflection(Component, 'Autonomous', 'Authority', ComponentName)|indent(20) }} - {{ DefineArchetypePropertyEditReflection(Component, ComponentName)|indent(20) }}; + ->Attribute(AZ::Edit::Attributes::Category, "{{ Component.attrib['Namespace'] }}") + ->Attribute(AZ::Edit::Attributes::AppearsInAddComponentMenu, AZ_CRC_CE("Game")); +{% endif %} } } } @@ -1401,7 +1408,7 @@ namespace {{ Component.attrib['Namespace'] }} } {% endif %} - const char* {{ ComponentBaseName }}::GetNetworkPropertyName([[maybe_unused]] PropertyIndex propertyIndex) + const char* {{ ComponentBaseName }}::GetNetworkPropertyName([[maybe_unused]] Multiplayer::PropertyIndex propertyIndex) { {% if NetworkPropertyCount > 0 %} const {{ UpperFirst(Component.attrib['Name']) }}Internal::NetworkProperties propertyId = static_cast<{{ UpperFirst(Component.attrib['Name']) }}Internal::NetworkProperties>(propertyIndex); @@ -1416,7 +1423,7 @@ namespace {{ Component.attrib['Namespace'] }} return "Unknown network property"; } - const char* {{ ComponentBaseName }}::GetRpcName([[maybe_unused]] RpcIndex rpcIndex) + const char* {{ ComponentBaseName }}::GetRpcName([[maybe_unused]] Multiplayer::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 44edcaf505..a5a7e8decd 100644 --- a/Gems/Multiplayer/Code/Source/AutoGen/LocalPredictionPlayerInputComponent.AutoComponent.xml +++ b/Gems/Multiplayer/Code/Source/AutoGen/LocalPredictionPlayerInputComponent.AutoComponent.xml @@ -10,8 +10,8 @@ - - + + diff --git a/Gems/Multiplayer/Code/Source/AutoGen/Multiplayer.AutoPackets.xml b/Gems/Multiplayer/Code/Source/AutoGen/Multiplayer.AutoPackets.xml index daf55c3d92..1260075cba 100644 --- a/Gems/Multiplayer/Code/Source/AutoGen/Multiplayer.AutoPackets.xml +++ b/Gems/Multiplayer/Code/Source/AutoGen/Multiplayer.AutoPackets.xml @@ -2,10 +2,10 @@ - - - - + + + + diff --git a/Gems/Multiplayer/Code/Source/AutoGen/NetworkTransformComponent.AutoComponent.xml b/Gems/Multiplayer/Code/Source/AutoGen/NetworkTransformComponent.AutoComponent.xml index 46065b386f..e76ac75edc 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/LocalPredictionPlayerInputComponent.cpp b/Gems/Multiplayer/Code/Source/Components/LocalPredictionPlayerInputComponent.cpp index 90b590d99d..b57c465df2 100644 --- a/Gems/Multiplayer/Code/Source/Components/LocalPredictionPlayerInputComponent.cpp +++ b/Gems/Multiplayer/Code/Source/Components/LocalPredictionPlayerInputComponent.cpp @@ -94,7 +94,7 @@ namespace Multiplayer if (entityIsMigrating == EntityIsMigrating::True) { m_allowMigrateClientInput = true; - m_serverMigrateFrameId = AZ::Interface::Get()->GetHostFrameId(); + m_serverMigrateFrameId = GetNetworkTime()->GetHostFrameId(); } } @@ -492,8 +492,8 @@ namespace Multiplayer const uint32_t maxClientInputs = inputRate > 0.0 ? static_cast(maxRewindHistory / inputRate) : 0; - INetworkTime* networkTime = AZ::Interface::Get(); - IMultiplayer* multiplayer = AZ::Interface::Get(); + IMultiplayer* multiplayer = GetMultiplayer(); + INetworkTime* networkTime = GetNetworkTime(); while (m_moveAccumulator >= inputRate) { m_moveAccumulator -= inputRate; diff --git a/Gems/Multiplayer/Code/Source/Components/LocalPredictionPlayerInputComponent.h b/Gems/Multiplayer/Code/Source/Components/LocalPredictionPlayerInputComponent.h index 15a4f3a048..924fd78391 100644 --- a/Gems/Multiplayer/Code/Source/Components/LocalPredictionPlayerInputComponent.h +++ b/Gems/Multiplayer/Code/Source/Components/LocalPredictionPlayerInputComponent.h @@ -13,7 +13,7 @@ #pragma once #include -#include +#include namespace Multiplayer { diff --git a/Gems/Multiplayer/Code/Source/Components/MultiplayerComponent.cpp b/Gems/Multiplayer/Code/Source/Components/MultiplayerComponent.cpp index fcdad87416..ae6fc50f5a 100644 --- a/Gems/Multiplayer/Code/Source/Components/MultiplayerComponent.cpp +++ b/Gems/Multiplayer/Code/Source/Components/MultiplayerComponent.cpp @@ -10,8 +10,8 @@ * */ -#include -#include +#include +#include #include namespace Multiplayer diff --git a/Gems/Multiplayer/Code/Source/Components/MultiplayerComponentRegistry.cpp b/Gems/Multiplayer/Code/Source/Components/MultiplayerComponentRegistry.cpp index de1782cc59..648b28633e 100644 --- a/Gems/Multiplayer/Code/Source/Components/MultiplayerComponentRegistry.cpp +++ b/Gems/Multiplayer/Code/Source/Components/MultiplayerComponentRegistry.cpp @@ -10,7 +10,7 @@ * */ -#include +#include namespace Multiplayer { diff --git a/Gems/Multiplayer/Code/Source/Components/MultiplayerController.cpp b/Gems/Multiplayer/Code/Source/Components/MultiplayerController.cpp index 737ecc10cc..9b8f41d5bc 100644 --- a/Gems/Multiplayer/Code/Source/Components/MultiplayerController.cpp +++ b/Gems/Multiplayer/Code/Source/Components/MultiplayerController.cpp @@ -10,9 +10,9 @@ * */ -#include -#include -#include +#include +#include +#include namespace Multiplayer { diff --git a/Gems/Multiplayer/Code/Source/Components/NetBindComponent.cpp b/Gems/Multiplayer/Code/Source/Components/NetBindComponent.cpp index eba09734a9..6dc661415e 100644 --- a/Gems/Multiplayer/Code/Source/Components/NetBindComponent.cpp +++ b/Gems/Multiplayer/Code/Source/Components/NetBindComponent.cpp @@ -10,13 +10,13 @@ * */ -#include -#include -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include +#include +#include #include #include #include @@ -177,21 +177,6 @@ namespace Multiplayer } } - AZ::Aabb NetBindComponent::GetRewindBoundsForInput(const NetworkInput& networkInput, float deltaTime) const - { - AZ_Assert(m_netEntityRole == NetEntityRole::Authority, "Incorrect network role for computing rewind bounds"); - AZ::Aabb bounds = AZ::Aabb::CreateNull(); - for (MultiplayerComponent* multiplayerComponent : m_multiplayerInputComponentVector) - { - const AZ::Aabb componentBounds = multiplayerComponent->GetController()->GetRewindBoundsForInput(networkInput, deltaTime); - if (componentBounds.IsValid()) - { - bounds.AddAabb(componentBounds); - } - } - return bounds; - } - bool NetBindComponent::HandleRpcMessage(AzNetworking::IConnection* invokingConnection, NetEntityRole remoteRole, NetworkEntityRpcMessage& message) { auto findIt = m_multiplayerComponentMap.find(message.GetComponentId()); diff --git a/Gems/Multiplayer/Code/Source/ConnectionData/ClientToServerConnectionData.h b/Gems/Multiplayer/Code/Source/ConnectionData/ClientToServerConnectionData.h index b72a6aad2b..449ffafe45 100644 --- a/Gems/Multiplayer/Code/Source/ConnectionData/ClientToServerConnectionData.h +++ b/Gems/Multiplayer/Code/Source/ConnectionData/ClientToServerConnectionData.h @@ -12,7 +12,7 @@ #pragma once -#include +#include #include namespace Multiplayer diff --git a/Gems/Multiplayer/Code/Source/ConnectionData/ServerToClientConnectionData.h b/Gems/Multiplayer/Code/Source/ConnectionData/ServerToClientConnectionData.h index b02e6de9aa..6274a6ba31 100644 --- a/Gems/Multiplayer/Code/Source/ConnectionData/ServerToClientConnectionData.h +++ b/Gems/Multiplayer/Code/Source/ConnectionData/ServerToClientConnectionData.h @@ -12,7 +12,7 @@ #pragma once -#include +#include #include namespace Multiplayer diff --git a/Gems/Multiplayer/Code/Source/Debug/MultiplayerDebugSystemComponent.cpp b/Gems/Multiplayer/Code/Source/Debug/MultiplayerDebugSystemComponent.cpp index aec8d8520e..1ae4bffd07 100644 --- a/Gems/Multiplayer/Code/Source/Debug/MultiplayerDebugSystemComponent.cpp +++ b/Gems/Multiplayer/Code/Source/Debug/MultiplayerDebugSystemComponent.cpp @@ -13,7 +13,7 @@ #include #include #include -#include +#include namespace Multiplayer { diff --git a/Gems/Multiplayer/Code/Source/EntityDomains/FullOwnershipEntityDomain.h b/Gems/Multiplayer/Code/Source/EntityDomains/FullOwnershipEntityDomain.h index c1abbe74cd..3bf6eb554f 100644 --- a/Gems/Multiplayer/Code/Source/EntityDomains/FullOwnershipEntityDomain.h +++ b/Gems/Multiplayer/Code/Source/EntityDomains/FullOwnershipEntityDomain.h @@ -12,7 +12,7 @@ #pragma once -#include +#include namespace Multiplayer { diff --git a/Gems/Multiplayer/Code/Source/MultiplayerGem.cpp b/Gems/Multiplayer/Code/Source/MultiplayerGem.cpp index cafdbf2a09..aef3e546ad 100644 --- a/Gems/Multiplayer/Code/Source/MultiplayerGem.cpp +++ b/Gems/Multiplayer/Code/Source/MultiplayerGem.cpp @@ -13,10 +13,10 @@ #include #include #include -#include #include #include #include +#include #include namespace Multiplayer diff --git a/Gems/Multiplayer/Code/Source/MultiplayerSystemComponent.cpp b/Gems/Multiplayer/Code/Source/MultiplayerSystemComponent.cpp index e6fb77eca7..80a09d7d48 100644 --- a/Gems/Multiplayer/Code/Source/MultiplayerSystemComponent.cpp +++ b/Gems/Multiplayer/Code/Source/MultiplayerSystemComponent.cpp @@ -11,18 +11,21 @@ */ #include -#include #include #include #include #include #include #include +#include #include #include #include #include #include +#include +#include +#include namespace AZ::ConsoleTypeHelpers { @@ -69,6 +72,7 @@ namespace Multiplayer AZ_CVAR(ProtocolType, sv_protocol, ProtocolType::Udp, nullptr, AZ::ConsoleFunctorFlags::DontReplicate, "This flag controls whether we use TCP or UDP for game networking"); AZ_CVAR(bool, sv_isDedicated, true, nullptr, AZ::ConsoleFunctorFlags::DontReplicate, "Whether the host command creates an independent or client hosted server"); AZ_CVAR(AZ::TimeMs, cl_defaultNetworkEntityActivationTimeSliceMs, AZ::TimeMs{ 0 }, nullptr, AZ::ConsoleFunctorFlags::DontReplicate, "Max Ms to use to activate entities coming from the network, 0 means instantiate everything"); + AZ_CVAR(AZ::CVarFixedString, sv_defaultPlayerSpawnAsset, "prefabs/player.network.spawnable", nullptr, AZ::ConsoleFunctorFlags::DontReplicate, "The default spawnable to use when a new player connects"); void MultiplayerSystemComponent::Reflect(AZ::ReflectContext* context) { @@ -411,6 +415,11 @@ namespace Multiplayer void MultiplayerSystemComponent::OnConnect(AzNetworking::IConnection* connection) { + MultiplayerAgentDatum datum; + datum.m_id = connection->GetConnectionId(); + datum.m_isInvited = false; + datum.m_agentType = MultiplayerAgentType::Client; + if (connection->GetConnectionRole() == ConnectionRole::Connector) { AZLOG_INFO("New outgoing connection to remote address: %s", connection->GetRemoteAddress().GetString().c_str()); @@ -419,36 +428,46 @@ namespace Multiplayer else { AZLOG_INFO("New incoming connection from remote address: %s", connection->GetRemoteAddress().GetString().c_str()); - MultiplayerAgentDatum datum; - datum.m_id = connection->GetConnectionId(); - datum.m_isInvited = false; - datum.m_agentType = MultiplayerAgentType::Client; m_connAcquiredEvent.Signal(datum); } - if (GetAgentType() == MultiplayerAgentType::ClientServer - || GetAgentType() == MultiplayerAgentType::DedicatedServer) + if (m_onConnectFunctor) { - // TODO: This needs to be set to the players autonomous proxy ------------v - NetworkEntityHandle controlledEntity = GetNetworkEntityTracker()->Get(NetEntityId{ 0 }); - - if (connection->GetUserData() == nullptr) // Only add user data if the connect event handler has not already done so - { - connection->SetUserData(new ServerToClientConnectionData(connection, *this, controlledEntity)); - } - - AZStd::unique_ptr window = AZStd::make_unique(controlledEntity, connection); - reinterpret_cast(connection->GetUserData())->GetReplicationManager().SetReplicationWindow(AZStd::move(window)); + // Default OnConnect behaviour has been overridden + m_onConnectFunctor(connection, datum); } else { - if (connection->GetUserData() == nullptr) // Only add user data if the connect event handler has not already done so + if (GetAgentType() == MultiplayerAgentType::ClientServer + || GetAgentType() == MultiplayerAgentType::DedicatedServer) { - connection->SetUserData(new ClientToServerConnectionData(connection, *this)); - } + PrefabEntityId playerPrefabEntityId(AZ::Name(static_cast(sv_defaultPlayerSpawnAsset).c_str()), 1); + INetworkEntityManager::EntityList entityList = m_networkEntityManager.CreateEntitiesImmediate(playerPrefabEntityId, NetEntityRole::Authority, AZ::Transform::CreateIdentity()); - AZStd::unique_ptr window = AZStd::make_unique(); - reinterpret_cast(connection->GetUserData())->GetReplicationManager().SetEntityActivationTimeSliceMs(cl_defaultNetworkEntityActivationTimeSliceMs); + NetworkEntityHandle controlledEntity; + if (entityList.size() > 0) + { + controlledEntity = entityList[0]; + } + + if (connection->GetUserData() == nullptr) // Only add user data if the connect event handler has not already done so + { + connection->SetUserData(new ServerToClientConnectionData(connection, *this, controlledEntity)); + } + + AZStd::unique_ptr window = AZStd::make_unique(controlledEntity, connection); + reinterpret_cast(connection->GetUserData())->GetReplicationManager().SetReplicationWindow(AZStd::move(window)); + } + else + { + if (connection->GetUserData() == nullptr) // Only add user data if the connect event handler has not already done so + { + connection->SetUserData(new ClientToServerConnectionData(connection, *this)); + } + + AZStd::unique_ptr window = AZStd::make_unique(); + reinterpret_cast(connection->GetUserData())->GetReplicationManager().SetEntityActivationTimeSliceMs(cl_defaultNetworkEntityActivationTimeSliceMs); + } } } @@ -521,6 +540,11 @@ namespace Multiplayer handler.Connect(m_shutdownEvent); } + void MultiplayerSystemComponent::SetOnConnectFunctor(const OnConnectFunctor& functor) + { + m_onConnectFunctor = functor; + } + void MultiplayerSystemComponent::SendReadyForEntityUpdates(bool readyForEntityUpdates) { IConnectionSet& connectionSet = m_networkInterface->GetConnectionSet(); @@ -542,6 +566,16 @@ namespace Multiplayer } } + INetworkTime* MultiplayerSystemComponent::GetNetworkTime() + { + return &m_networkTime; + } + + INetworkEntityManager* MultiplayerSystemComponent::GetNetworkEntityManager() + { + return &m_networkEntityManager; + } + const char* MultiplayerSystemComponent::GetComponentGemName(NetComponentId netComponentId) const { return GetMultiplayerComponentRegistry()->GetComponentGemName(netComponentId); diff --git a/Gems/Multiplayer/Code/Source/MultiplayerSystemComponent.h b/Gems/Multiplayer/Code/Source/MultiplayerSystemComponent.h index 477745e6b5..ba59a82eae 100644 --- a/Gems/Multiplayer/Code/Source/MultiplayerSystemComponent.h +++ b/Gems/Multiplayer/Code/Source/MultiplayerSystemComponent.h @@ -19,7 +19,7 @@ #include #include #include -#include +#include #include #include #include @@ -89,8 +89,11 @@ namespace Multiplayer void AddConnectionAcquiredHandler(ConnectionAcquiredEvent::Handler& handler) override; void AddSessionInitHandler(SessionInitEvent::Handler& handler) override; void AddSessionShutdownHandler(SessionShutdownEvent::Handler& handler) override; + void SetOnConnectFunctor(const OnConnectFunctor& functor) override; void SendReadyForEntityUpdates(bool readyForEntityUpdates) override; AZ::TimeMs GetCurrentHostTimeMs() const override; + INetworkTime* GetNetworkTime() override; + INetworkEntityManager* GetNetworkEntityManager() override; const char* GetComponentGemName(NetComponentId netComponentId) const override; const char* GetComponentName(NetComponentId netComponentId) const override; const char* GetComponentPropertyName(NetComponentId netComponentId, PropertyIndex propertyIndex) const override; @@ -121,6 +124,8 @@ namespace Multiplayer SessionShutdownEvent m_shutdownEvent; ConnectionAcquiredEvent m_connAcquiredEvent; + OnConnectFunctor m_onConnectFunctor = nullptr; + AZ::TimeMs m_lastReplicatedHostTimeMs = AZ::TimeMs{ 0 }; HostFrameId m_lastReplicatedHostFrameId = InvalidHostFrameId; }; diff --git a/Gems/Multiplayer/Code/Source/NetworkEntity/EntityReplication/EntityReplicationManager.cpp b/Gems/Multiplayer/Code/Source/NetworkEntity/EntityReplication/EntityReplicationManager.cpp index 1e7649f561..286090ca74 100644 --- a/Gems/Multiplayer/Code/Source/NetworkEntity/EntityReplication/EntityReplicationManager.cpp +++ b/Gems/Multiplayer/Code/Source/NetworkEntity/EntityReplication/EntityReplicationManager.cpp @@ -14,14 +14,14 @@ #include #include #include -#include -#include -#include #include -#include -#include -#include -#include +#include +#include +#include +#include +#include +#include +#include #include #include #include @@ -60,7 +60,11 @@ namespace Multiplayer // Start window update events m_updateWindow.Enqueue(AZ::TimeMs{ 0 }, true); - GetNetworkEntityManager()->AddEntityExitDomainHandler(m_entityExitDomainEventHandler); + INetworkEntityManager* networkEntityManager = GetNetworkEntityManager(); + if (networkEntityManager != nullptr) + { + networkEntityManager->AddEntityExitDomainHandler(m_entityExitDomainEventHandler); + } } void EntityReplicationManager::SetRemoteHostId(HostId hostId) @@ -824,7 +828,7 @@ namespace Multiplayer { if (entityReplicator == nullptr) { - IMultiplayer* multiplayer = AZ::Interface::Get(); + IMultiplayer* multiplayer = GetMultiplayer(); AZLOG_INFO ( "EntityReplicationManager: Dropping remote RPC message for component %s of rpc index %s, entityId %u has already been deleted", diff --git a/Gems/Multiplayer/Code/Source/NetworkEntity/EntityReplication/EntityReplicationManager.h b/Gems/Multiplayer/Code/Source/NetworkEntity/EntityReplication/EntityReplicationManager.h index 4fc14e210f..50a4ad43d4 100644 --- a/Gems/Multiplayer/Code/Source/NetworkEntity/EntityReplication/EntityReplicationManager.h +++ b/Gems/Multiplayer/Code/Source/NetworkEntity/EntityReplication/EntityReplicationManager.h @@ -13,11 +13,11 @@ #pragma once #include -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include #include #include #include diff --git a/Gems/Multiplayer/Code/Source/NetworkEntity/EntityReplication/EntityReplicator.cpp b/Gems/Multiplayer/Code/Source/NetworkEntity/EntityReplication/EntityReplicator.cpp index 7431b95a22..15293d518d 100644 --- a/Gems/Multiplayer/Code/Source/NetworkEntity/EntityReplication/EntityReplicator.cpp +++ b/Gems/Multiplayer/Code/Source/NetworkEntity/EntityReplication/EntityReplicator.cpp @@ -16,11 +16,11 @@ #include #include #include -#include -#include #include #include -#include +#include +#include +#include #include #include @@ -448,7 +448,7 @@ namespace Multiplayer void EntityReplicator::DeferRpcMessage(NetworkEntityRpcMessage& entityRpcMessage) { // Received rpc metrics, log rpc sent, number of bytes, and the componentId/rpcId for bandwidth metrics - MultiplayerStats& stats = AZ::Interface::Get()->GetStats(); + MultiplayerStats& stats = GetMultiplayer()->GetStats(); stats.RecordRpcSent(entityRpcMessage.GetComponentId(), entityRpcMessage.GetRpcIndex(), entityRpcMessage.GetEstimatedSerializeSize()); m_replicationManager.AddDeferredRpcMessage(entityRpcMessage); @@ -631,7 +631,7 @@ namespace Multiplayer bool EntityReplicator::HandleRpcMessage(AzNetworking::IConnection* invokingConnection, NetworkEntityRpcMessage& entityRpcMessage) { // Received rpc metrics, log rpc received, time spent, number of bytes, and the componentId/rpcId for bandwidth metrics - MultiplayerStats& stats = AZ::Interface::Get()->GetStats(); + MultiplayerStats& stats = GetMultiplayer()->GetStats(); stats.RecordRpcReceived(entityRpcMessage.GetComponentId(), entityRpcMessage.GetRpcIndex(), entityRpcMessage.GetEstimatedSerializeSize()); if (!m_netBindComponent) diff --git a/Gems/Multiplayer/Code/Source/NetworkEntity/EntityReplication/EntityReplicator.h b/Gems/Multiplayer/Code/Source/NetworkEntity/EntityReplication/EntityReplicator.h index 93494ab07c..3587c28975 100644 --- a/Gems/Multiplayer/Code/Source/NetworkEntity/EntityReplication/EntityReplicator.h +++ b/Gems/Multiplayer/Code/Source/NetworkEntity/EntityReplication/EntityReplicator.h @@ -18,8 +18,8 @@ #include #include #include -#include -#include +#include +#include namespace AzNetworking { diff --git a/Gems/Multiplayer/Code/Source/NetworkEntity/EntityReplication/PropertyPublisher.h b/Gems/Multiplayer/Code/Source/NetworkEntity/EntityReplication/PropertyPublisher.h index 238e665a00..be8ac1b65b 100644 --- a/Gems/Multiplayer/Code/Source/NetworkEntity/EntityReplication/PropertyPublisher.h +++ b/Gems/Multiplayer/Code/Source/NetworkEntity/EntityReplication/PropertyPublisher.h @@ -12,7 +12,7 @@ #pragma once -#include +#include #include namespace AzNetworking diff --git a/Gems/Multiplayer/Code/Source/NetworkEntity/EntityReplication/PropertySubscriber.cpp b/Gems/Multiplayer/Code/Source/NetworkEntity/EntityReplication/PropertySubscriber.cpp index 7b8c3e6094..4994884364 100644 --- a/Gems/Multiplayer/Code/Source/NetworkEntity/EntityReplication/PropertySubscriber.cpp +++ b/Gems/Multiplayer/Code/Source/NetworkEntity/EntityReplication/PropertySubscriber.cpp @@ -12,7 +12,7 @@ #include #include -#include +#include namespace Multiplayer { diff --git a/Gems/Multiplayer/Code/Source/NetworkEntity/EntityReplication/ReplicationRecord.cpp b/Gems/Multiplayer/Code/Source/NetworkEntity/EntityReplication/ReplicationRecord.cpp index 5f8dae8ff4..6aa6c10b11 100644 --- a/Gems/Multiplayer/Code/Source/NetworkEntity/EntityReplication/ReplicationRecord.cpp +++ b/Gems/Multiplayer/Code/Source/NetworkEntity/EntityReplication/ReplicationRecord.cpp @@ -10,7 +10,7 @@ * */ -#include +#include namespace Multiplayer { diff --git a/Gems/Multiplayer/Code/Source/NetworkEntity/NetworkEntityAuthorityTracker.cpp b/Gems/Multiplayer/Code/Source/NetworkEntity/NetworkEntityAuthorityTracker.cpp index 797d67e3ef..ecfd416380 100644 --- a/Gems/Multiplayer/Code/Source/NetworkEntity/NetworkEntityAuthorityTracker.cpp +++ b/Gems/Multiplayer/Code/Source/NetworkEntity/NetworkEntityAuthorityTracker.cpp @@ -11,8 +11,8 @@ */ #include -#include -#include +#include +#include #include #include #include diff --git a/Gems/Multiplayer/Code/Source/NetworkEntity/NetworkEntityHandle.cpp b/Gems/Multiplayer/Code/Source/NetworkEntity/NetworkEntityHandle.cpp index ca0275d20b..0dd7292d25 100644 --- a/Gems/Multiplayer/Code/Source/NetworkEntity/NetworkEntityHandle.cpp +++ b/Gems/Multiplayer/Code/Source/NetworkEntity/NetworkEntityHandle.cpp @@ -10,11 +10,11 @@ * */ -#include +#include +#include +#include +#include #include -#include -#include -#include #include #include diff --git a/Gems/Multiplayer/Code/Source/NetworkEntity/NetworkEntityManager.cpp b/Gems/Multiplayer/Code/Source/NetworkEntity/NetworkEntityManager.cpp index 1c7fb5f7af..28b72abf25 100644 --- a/Gems/Multiplayer/Code/Source/NetworkEntity/NetworkEntityManager.cpp +++ b/Gems/Multiplayer/Code/Source/NetworkEntity/NetworkEntityManager.cpp @@ -11,7 +11,6 @@ */ #include - #include #include #include @@ -22,9 +21,9 @@ #include #include #include -#include +#include +#include #include -#include namespace Multiplayer { @@ -38,7 +37,6 @@ namespace Multiplayer , m_onSpawnedHandler([this](AZ::Data::Asset spawnable) { this->OnSpawned(spawnable); }) , m_onDespawnedHandler([this](AZ::Data::Asset spawnable) { this->OnDespawned(spawnable); }) { - AZ::Interface::Register(this); AzFramework::RootSpawnableNotificationBus::Handler::BusConnect(); AzFramework::SpawnableEntitiesInterface::Get()->AddOnSpawnedHandler(m_onSpawnedHandler); @@ -48,7 +46,6 @@ namespace Multiplayer NetworkEntityManager::~NetworkEntityManager() { AzFramework::RootSpawnableNotificationBus::Handler::BusDisconnect(); - AZ::Interface::Unregister(this); } void NetworkEntityManager::Initialize(HostId hostId, AZStd::unique_ptr entityDomain) @@ -365,9 +362,24 @@ namespace Multiplayer return returnList; } - INetworkEntityManager::EntityList NetworkEntityManager::CreateEntitiesImmediate( - const PrefabEntityId& prefabEntryId, NetEntityId netEntityId, NetEntityRole netEntityRole, - AutoActivate autoActivate, const AZ::Transform& transform) + INetworkEntityManager::EntityList NetworkEntityManager::CreateEntitiesImmediate + ( + const PrefabEntityId& prefabEntryId, + NetEntityRole netEntityRole, + const AZ::Transform& transform + ) + { + return CreateEntitiesImmediate(prefabEntryId, NextId(), netEntityRole, AutoActivate::Activate, transform); + } + + INetworkEntityManager::EntityList NetworkEntityManager::CreateEntitiesImmediate + ( + const PrefabEntityId& prefabEntryId, + NetEntityId netEntityId, + NetEntityRole netEntityRole, + AutoActivate autoActivate, + const AZ::Transform& transform + ) { INetworkEntityManager::EntityList returnList; @@ -436,7 +448,7 @@ namespace Multiplayer void NetworkEntityManager::OnRootSpawnableAssigned( [[maybe_unused]] AZ::Data::Asset rootSpawnable, [[maybe_unused]] uint32_t generation) { - auto* multiplayer = AZ::Interface::Get(); + auto* multiplayer = GetMultiplayer(); const auto agentType = multiplayer->GetAgentType(); if (agentType == MultiplayerAgentType::Client) @@ -448,7 +460,7 @@ namespace Multiplayer void NetworkEntityManager::OnRootSpawnableReleased([[maybe_unused]] uint32_t generation) { // TODO: Do we need to clear all entities here? - auto* multiplayer = AZ::Interface::Get(); + auto* multiplayer = GetMultiplayer(); const auto agentType = multiplayer->GetAgentType(); if (agentType == MultiplayerAgentType::Client) @@ -494,7 +506,7 @@ namespace Multiplayer return; } - auto* multiplayer = AZ::Interface::Get(); + auto* multiplayer = GetMultiplayer(); const auto agentType = multiplayer->GetAgentType(); const bool spawnImmediately = diff --git a/Gems/Multiplayer/Code/Source/NetworkEntity/NetworkEntityManager.h b/Gems/Multiplayer/Code/Source/NetworkEntity/NetworkEntityManager.h index ae2cb0dd9e..e763e7ebca 100644 --- a/Gems/Multiplayer/Code/Source/NetworkEntity/NetworkEntityManager.h +++ b/Gems/Multiplayer/Code/Source/NetworkEntity/NetworkEntityManager.h @@ -17,11 +17,11 @@ #include #include #include -#include -#include -#include #include -#include +#include +#include +#include +#include namespace Multiplayer { @@ -47,10 +47,20 @@ namespace Multiplayer ConstNetworkEntityHandle GetEntity(NetEntityId netEntityId) const override; EntityList CreateEntitiesImmediate(const AzFramework::Spawnable& spawnable, NetEntityRole netEntityRole); - - EntityList CreateEntitiesImmediate( - const PrefabEntityId& prefabEntryId, NetEntityId netEntityId, NetEntityRole netEntityRole, - AutoActivate autoActivate, const AZ::Transform& transform) override; + EntityList CreateEntitiesImmediate + ( + const PrefabEntityId& prefabEntryId, + NetEntityRole netEntityRole, + const AZ::Transform& transform + ) override; + EntityList CreateEntitiesImmediate + ( + const PrefabEntityId& prefabEntryId, + NetEntityId netEntityId, + NetEntityRole netEntityRole, + AutoActivate autoActivate, + const AZ::Transform& transform + ) override; uint32_t GetEntityCount() const override; NetworkEntityHandle AddEntityToEntityMap(NetEntityId netEntityId, AZ::Entity* entity) override; @@ -81,7 +91,6 @@ namespace Multiplayer private: void RemoveEntities(); - NetEntityId NextId(); void OnSpawned(AZ::Data::Asset spawnable); diff --git a/Gems/Multiplayer/Code/Source/NetworkEntity/NetworkEntityRpcMessage.cpp b/Gems/Multiplayer/Code/Source/NetworkEntity/NetworkEntityRpcMessage.cpp index 4bfc753f75..d58c192162 100644 --- a/Gems/Multiplayer/Code/Source/NetworkEntity/NetworkEntityRpcMessage.cpp +++ b/Gems/Multiplayer/Code/Source/NetworkEntity/NetworkEntityRpcMessage.cpp @@ -10,7 +10,7 @@ * */ -#include +#include #include #include #include diff --git a/Gems/Multiplayer/Code/Source/NetworkEntity/NetworkEntityTracker.cpp b/Gems/Multiplayer/Code/Source/NetworkEntity/NetworkEntityTracker.cpp index 69f715317a..42104e79fd 100644 --- a/Gems/Multiplayer/Code/Source/NetworkEntity/NetworkEntityTracker.cpp +++ b/Gems/Multiplayer/Code/Source/NetworkEntity/NetworkEntityTracker.cpp @@ -11,7 +11,7 @@ */ #include -#include +#include #include #include diff --git a/Gems/Multiplayer/Code/Source/NetworkEntity/NetworkEntityTracker.h b/Gems/Multiplayer/Code/Source/NetworkEntity/NetworkEntityTracker.h index 4cfb242154..34f5d03f2f 100644 --- a/Gems/Multiplayer/Code/Source/NetworkEntity/NetworkEntityTracker.h +++ b/Gems/Multiplayer/Code/Source/NetworkEntity/NetworkEntityTracker.h @@ -12,8 +12,8 @@ #pragma once -#include -#include +#include +#include #include #include diff --git a/Gems/Multiplayer/Code/Source/NetworkEntity/NetworkEntityUpdateMessage.cpp b/Gems/Multiplayer/Code/Source/NetworkEntity/NetworkEntityUpdateMessage.cpp index 27c39ea135..5ece0c7157 100644 --- a/Gems/Multiplayer/Code/Source/NetworkEntity/NetworkEntityUpdateMessage.cpp +++ b/Gems/Multiplayer/Code/Source/NetworkEntity/NetworkEntityUpdateMessage.cpp @@ -10,7 +10,7 @@ * */ -#include +#include #include #include #include diff --git a/Gems/Multiplayer/Code/Source/NetworkInput/NetworkInput.cpp b/Gems/Multiplayer/Code/Source/NetworkInput/NetworkInput.cpp index 0ab1d5ffcc..eafd4375e7 100644 --- a/Gems/Multiplayer/Code/Source/NetworkInput/NetworkInput.cpp +++ b/Gems/Multiplayer/Code/Source/NetworkInput/NetworkInput.cpp @@ -10,8 +10,8 @@ * */ -#include -#include +#include +#include #include #include diff --git a/Gems/Multiplayer/Code/Source/NetworkInput/NetworkInputArray.cpp b/Gems/Multiplayer/Code/Source/NetworkInput/NetworkInputArray.cpp index 0f5a0d7c0c..82e5cea0c4 100644 --- a/Gems/Multiplayer/Code/Source/NetworkInput/NetworkInputArray.cpp +++ b/Gems/Multiplayer/Code/Source/NetworkInput/NetworkInputArray.cpp @@ -11,7 +11,7 @@ */ #include -#include +#include #include #include diff --git a/Gems/Multiplayer/Code/Source/NetworkInput/NetworkInputArray.h b/Gems/Multiplayer/Code/Source/NetworkInput/NetworkInputArray.h index 504992fecb..d5cbcbbed3 100644 --- a/Gems/Multiplayer/Code/Source/NetworkInput/NetworkInputArray.h +++ b/Gems/Multiplayer/Code/Source/NetworkInput/NetworkInputArray.h @@ -12,8 +12,8 @@ #pragma once -#include -#include +#include +#include #include #include diff --git a/Gems/Multiplayer/Code/Source/NetworkInput/NetworkInputChild.cpp b/Gems/Multiplayer/Code/Source/NetworkInput/NetworkInputChild.cpp index 8f70f7e1fa..c6b8e8d7ef 100644 --- a/Gems/Multiplayer/Code/Source/NetworkInput/NetworkInputChild.cpp +++ b/Gems/Multiplayer/Code/Source/NetworkInput/NetworkInputChild.cpp @@ -11,7 +11,7 @@ */ #include -#include +#include #include namespace Multiplayer diff --git a/Gems/Multiplayer/Code/Source/NetworkInput/NetworkInputChild.h b/Gems/Multiplayer/Code/Source/NetworkInput/NetworkInputChild.h index 18b518f19f..fa4ab1e4e9 100644 --- a/Gems/Multiplayer/Code/Source/NetworkInput/NetworkInputChild.h +++ b/Gems/Multiplayer/Code/Source/NetworkInput/NetworkInputChild.h @@ -12,7 +12,7 @@ #pragma once -#include +#include namespace Multiplayer { diff --git a/Gems/Multiplayer/Code/Source/NetworkInput/NetworkInputHistory.h b/Gems/Multiplayer/Code/Source/NetworkInput/NetworkInputHistory.h index ad406ffd8b..c5f0a70fd3 100644 --- a/Gems/Multiplayer/Code/Source/NetworkInput/NetworkInputHistory.h +++ b/Gems/Multiplayer/Code/Source/NetworkInput/NetworkInputHistory.h @@ -12,7 +12,7 @@ #pragma once -#include +#include #include namespace Multiplayer diff --git a/Gems/Multiplayer/Code/Source/NetworkInput/NetworkInputMigrationVector.cpp b/Gems/Multiplayer/Code/Source/NetworkInput/NetworkInputMigrationVector.cpp index dee72156ed..4395ff5b7d 100644 --- a/Gems/Multiplayer/Code/Source/NetworkInput/NetworkInputMigrationVector.cpp +++ b/Gems/Multiplayer/Code/Source/NetworkInput/NetworkInputMigrationVector.cpp @@ -11,7 +11,7 @@ */ #include -#include +#include #include namespace Multiplayer diff --git a/Gems/Multiplayer/Code/Source/NetworkInput/NetworkInputMigrationVector.h b/Gems/Multiplayer/Code/Source/NetworkInput/NetworkInputMigrationVector.h index c6ea425fec..454cef4e0a 100644 --- a/Gems/Multiplayer/Code/Source/NetworkInput/NetworkInputMigrationVector.h +++ b/Gems/Multiplayer/Code/Source/NetworkInput/NetworkInputMigrationVector.h @@ -12,8 +12,8 @@ #pragma once -#include -#include +#include +#include #include #include diff --git a/Gems/Multiplayer/Code/Source/NetworkTime/NetworkTime.cpp b/Gems/Multiplayer/Code/Source/NetworkTime/NetworkTime.cpp index 9a0e784d36..d991e59d05 100644 --- a/Gems/Multiplayer/Code/Source/NetworkTime/NetworkTime.cpp +++ b/Gems/Multiplayer/Code/Source/NetworkTime/NetworkTime.cpp @@ -11,6 +11,9 @@ */ #include +#include +#include +#include namespace Multiplayer { @@ -51,11 +54,6 @@ namespace Multiplayer return m_hostTimeMs; } - void NetworkTime::SyncRewindableEntityState() - { - - } - AzNetworking::ConnectionId NetworkTime::GetRewindingConnectionId() const { return m_rewindingConnectionId; @@ -72,4 +70,38 @@ namespace Multiplayer m_hostTimeMs = timeMs; m_rewindingConnectionId = rewindConnectionId; } + + void NetworkTime::SyncEntitiesToRewindState(const AZ::Aabb& rewindVolume) + { + // TODO: extrude rewind volume for initial gather + AZStd::vector gatheredEntries; + AZ::Interface::Get()->GetDefaultVisibilityScene()->Enumerate(rewindVolume, [&gatheredEntries](const AzFramework::IVisibilityScene::NodeData& nodeData) + { + gatheredEntries.reserve(gatheredEntries.size() + nodeData.m_entries.size()); + for (AzFramework::VisibilityEntry* visEntry : nodeData.m_entries) + { + if (visEntry->m_typeFlags & AzFramework::VisibilityEntry::TypeFlags::TYPE_Entity) + { + // TODO: offset aabb for exact rewound position and check against the non-extruded rewind volume + gatheredEntries.push_back(visEntry); + } + } + }); + + for (AzFramework::VisibilityEntry* visEntry : gatheredEntries) + { + AZ::Entity* entity = static_cast(visEntry->m_userData); + [[maybe_unused]] NetBindComponent* entryNetBindComponent = entity->template FindComponent(); + if (entryNetBindComponent != nullptr) + { + // TODO: invoke the sync to rewind event on the netBindComponent and add the entity to the rewound entity set + } + } + } + + void NetworkTime::ClearRewoundEntities() + { + AZ_Assert(!IsTimeRewound(), "Cannot clear rewound entity state while still within scoped rewind"); + // TODO: iterate all rewound entities, signal them to sync rewind state, and clear the rewound entity set + } } diff --git a/Gems/Multiplayer/Code/Source/NetworkTime/NetworkTime.h b/Gems/Multiplayer/Code/Source/NetworkTime/NetworkTime.h index 06e758b349..ff2da0f759 100644 --- a/Gems/Multiplayer/Code/Source/NetworkTime/NetworkTime.h +++ b/Gems/Multiplayer/Code/Source/NetworkTime/NetworkTime.h @@ -12,7 +12,7 @@ #pragma once -#include +#include #include #include @@ -33,10 +33,11 @@ namespace Multiplayer HostFrameId GetUnalteredHostFrameId() const override; void IncrementHostFrameId() override; AZ::TimeMs GetHostTimeMs() const override; - void SyncRewindableEntityState() override; AzNetworking::ConnectionId GetRewindingConnectionId() const override; HostFrameId GetHostFrameIdForRewindingConnection(AzNetworking::ConnectionId rewindConnectionId) const override; void AlterTime(HostFrameId frameId, AZ::TimeMs timeMs, AzNetworking::ConnectionId rewindConnectionId) override; + void SyncEntitiesToRewindState(const AZ::Aabb& rewindVolume) override; + void ClearRewoundEntities() override; //! @} private: diff --git a/Gems/Multiplayer/Code/Source/Pipeline/NetworkPrefabProcessor.cpp b/Gems/Multiplayer/Code/Source/Pipeline/NetworkPrefabProcessor.cpp index 4962d16fb4..805a982506 100644 --- a/Gems/Multiplayer/Code/Source/Pipeline/NetworkPrefabProcessor.cpp +++ b/Gems/Multiplayer/Code/Source/Pipeline/NetworkPrefabProcessor.cpp @@ -18,7 +18,7 @@ #include #include #include -#include +#include #include #include diff --git a/Gems/Multiplayer/Code/Source/ReplicationWindows/NullReplicationWindow.h b/Gems/Multiplayer/Code/Source/ReplicationWindows/NullReplicationWindow.h index 1922e65941..5cb9c0de70 100644 --- a/Gems/Multiplayer/Code/Source/ReplicationWindows/NullReplicationWindow.h +++ b/Gems/Multiplayer/Code/Source/ReplicationWindows/NullReplicationWindow.h @@ -12,7 +12,7 @@ #pragma once -#include +#include namespace Multiplayer { diff --git a/Gems/Multiplayer/Code/Source/ReplicationWindows/ServerToClientReplicationWindow.cpp b/Gems/Multiplayer/Code/Source/ReplicationWindows/ServerToClientReplicationWindow.cpp index c54a610de2..bf370c1952 100644 --- a/Gems/Multiplayer/Code/Source/ReplicationWindows/ServerToClientReplicationWindow.cpp +++ b/Gems/Multiplayer/Code/Source/ReplicationWindows/ServerToClientReplicationWindow.cpp @@ -11,7 +11,7 @@ */ #include -#include +#include #include #include #include @@ -65,7 +65,7 @@ namespace Multiplayer { AZ::Entity* entity = m_controlledEntity.GetEntity(); AZ_Assert(entity, "Invalid controlled entity provided to replication window"); - m_controlledEntityTransform = entity->GetTransform(); + m_controlledEntityTransform = entity ? entity->GetTransform() : nullptr; AZ_Assert(m_controlledEntityTransform, "Controlled player entity must have a transform"); //// this one is optional diff --git a/Gems/Multiplayer/Code/Source/ReplicationWindows/ServerToClientReplicationWindow.h b/Gems/Multiplayer/Code/Source/ReplicationWindows/ServerToClientReplicationWindow.h index 55a6a4b56e..25fbfd481d 100644 --- a/Gems/Multiplayer/Code/Source/ReplicationWindows/ServerToClientReplicationWindow.h +++ b/Gems/Multiplayer/Code/Source/ReplicationWindows/ServerToClientReplicationWindow.h @@ -12,9 +12,9 @@ #pragma once -#include -#include -#include +#include +#include +#include #include #include #include diff --git a/Gems/Multiplayer/Code/Tests/RewindableObjectTests.cpp b/Gems/Multiplayer/Code/Tests/RewindableObjectTests.cpp index 367b7ee0de..f614dc2690 100644 --- a/Gems/Multiplayer/Code/Tests/RewindableObjectTests.cpp +++ b/Gems/Multiplayer/Code/Tests/RewindableObjectTests.cpp @@ -10,7 +10,8 @@ * */ -#include +#include +#include #include #include #include @@ -37,7 +38,7 @@ namespace UnitTest { test = i; EXPECT_EQ(i, test); - AZ::Interface::Get()->IncrementHostFrameId(); + Multiplayer::GetNetworkTime()->IncrementHostFrameId(); } for (uint32_t i = 0; i < 16; ++i) @@ -50,7 +51,7 @@ namespace UnitTest { test = i; EXPECT_EQ(i, test); - AZ::Interface::Get()->IncrementHostFrameId(); + Multiplayer::GetNetworkTime()->IncrementHostFrameId(); } for (uint32_t i = 16; i < 48; ++i) @@ -68,7 +69,7 @@ namespace UnitTest { test = i; EXPECT_EQ(i, test); - AZ::Interface::Get()->IncrementHostFrameId(); + Multiplayer::GetNetworkTime()->IncrementHostFrameId(); } { diff --git a/Gems/Multiplayer/Code/multiplayer_files.cmake b/Gems/Multiplayer/Code/multiplayer_files.cmake index 1f4e57ae43..26909cbfd3 100644 --- a/Gems/Multiplayer/Code/multiplayer_files.cmake +++ b/Gems/Multiplayer/Code/multiplayer_files.cmake @@ -10,18 +10,29 @@ # set(FILES - Include/IConnectionData.h - Include/IEntityDomain.h - Include/IMultiplayer.h - Include/IMultiplayerComponentInput.h - Include/INetworkEntityManager.h - Include/INetworkTime.h - Include/IReplicationWindow.h - Include/MultiplayerStats.cpp - Include/MultiplayerStats.h - Include/MultiplayerTypes.h - Include/NetworkEntityHandle.h - Include/NetworkEntityHandle.inl + Include/Multiplayer/IConnectionData.h + Include/Multiplayer/IEntityDomain.h + Include/Multiplayer/IMultiplayer.h + Include/Multiplayer/IMultiplayerComponentInput.h + Include/Multiplayer/INetworkEntityManager.h + Include/Multiplayer/INetworkPlayerSpawner.h + Include/Multiplayer/INetworkTime.h + Include/Multiplayer/IReplicationWindow.h + Include/Multiplayer/MultiplayerComponent.h + Include/Multiplayer/MultiplayerController.h + Include/Multiplayer/MultiplayerComponentRegistry.h + Include/Multiplayer/MultiplayerStats.cpp + Include/Multiplayer/MultiplayerStats.h + Include/Multiplayer/MultiplayerTypes.h + Include/Multiplayer/NetBindComponent.h + Include/Multiplayer/NetworkEntityRpcMessage.h + Include/Multiplayer/NetworkEntityUpdateMessage.h + Include/Multiplayer/NetworkEntityHandle.h + Include/Multiplayer/NetworkEntityHandle.inl + Include/Multiplayer/NetworkInput.h + Include/Multiplayer/ReplicationRecord.h + Include/Multiplayer/RewindableObject.h + Include/Multiplayer/RewindableObject.inl Source/Multiplayer_precompiled.cpp Source/Multiplayer_precompiled.h Source/MultiplayerSystemComponent.cpp @@ -36,14 +47,10 @@ set(FILES Source/AutoGen/NetworkTransformComponent.AutoComponent.xml Source/Components/LocalPredictionPlayerInputComponent.cpp Source/Components/LocalPredictionPlayerInputComponent.h - Source/Components/MultiplayerComponentRegistry.cpp - Source/Components/MultiplayerComponentRegistry.h Source/Components/MultiplayerComponent.cpp - Source/Components/MultiplayerComponent.h Source/Components/MultiplayerController.cpp - Source/Components/MultiplayerController.h + Source/Components/MultiplayerComponentRegistry.cpp Source/Components/NetBindComponent.cpp - Source/Components/NetBindComponent.h Source/Components/NetworkTransformComponent.cpp Source/Components/NetworkTransformComponent.h Source/ConnectionData/ClientToServerConnectionData.cpp @@ -64,7 +71,6 @@ set(FILES Source/NetworkEntity/EntityReplication/PropertySubscriber.cpp Source/NetworkEntity/EntityReplication/PropertySubscriber.h Source/NetworkEntity/EntityReplication/ReplicationRecord.cpp - Source/NetworkEntity/EntityReplication/ReplicationRecord.h Source/NetworkEntity/NetworkEntityAuthorityTracker.cpp Source/NetworkEntity/NetworkEntityAuthorityTracker.h Source/NetworkEntity/NetworkEntityHandle.cpp @@ -73,14 +79,11 @@ set(FILES Source/NetworkEntity/NetworkSpawnableLibrary.cpp Source/NetworkEntity/NetworkSpawnableLibrary.h Source/NetworkEntity/NetworkEntityRpcMessage.cpp - Source/NetworkEntity/NetworkEntityRpcMessage.h Source/NetworkEntity/NetworkEntityTracker.cpp Source/NetworkEntity/NetworkEntityTracker.h Source/NetworkEntity/NetworkEntityTracker.inl Source/NetworkEntity/NetworkEntityUpdateMessage.cpp - Source/NetworkEntity/NetworkEntityUpdateMessage.h Source/NetworkInput/NetworkInput.cpp - Source/NetworkInput/NetworkInput.h Source/NetworkInput/NetworkInputArray.cpp Source/NetworkInput/NetworkInputArray.h Source/NetworkInput/NetworkInputChild.cpp @@ -91,8 +94,6 @@ set(FILES Source/NetworkInput/NetworkInputMigrationVector.h Source/NetworkTime/NetworkTime.cpp Source/NetworkTime/NetworkTime.h - Source/NetworkTime/RewindableObject.h - Source/NetworkTime/RewindableObject.inl Source/Pipeline/NetBindMarkerComponent.cpp Source/Pipeline/NetBindMarkerComponent.h Source/Pipeline/NetworkSpawnableHolderComponent.cpp