Integrating up through commit 90f050496
This commit is contained in:
@@ -58,4 +58,13 @@ namespace Multiplayer
|
||||
NetBindComponent* netBindComponent = GetNetBindComponent();
|
||||
return netBindComponent ? netBindComponent->GetEntityHandle() : NetworkEntityHandle();
|
||||
}
|
||||
|
||||
void MultiplayerComponent::MarkDirty()
|
||||
{
|
||||
NetBindComponent* netBindComponent = GetNetBindComponent();
|
||||
if (netBindComponent != nullptr)
|
||||
{
|
||||
netBindComponent->MarkDirty();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,14 +14,15 @@
|
||||
|
||||
#include <AzCore/Component/Component.h>
|
||||
#include <AzNetworking/Serialization/ISerializer.h>
|
||||
#include <AzNetworking/DataStructures/FixedSizeBitsetView.h>
|
||||
#include <Source/NetworkEntity/NetworkEntityHandle.h>
|
||||
#include <Source/MultiplayerTypes.h>
|
||||
|
||||
//! Macro to declare bindings for a multiplayer component inheriting from MultiplayerComponent
|
||||
#define AZ_MULTIPLAYER_COMPONENT(ComponentClass, Guid) \
|
||||
AZ_RTTI(ComponentClass, Guid, AZ::Component) \
|
||||
AZ_COMPONENT_INTRUSIVE_DESCRIPTOR_TYPE(ComponentClass) \
|
||||
AZ_COMPONENT_BASE(ComponentClass, Guid, Multiplayer::MultiplayerComponent)
|
||||
#define AZ_MULTIPLAYER_COMPONENT(ComponentClass, Guid, Base) \
|
||||
AZ_RTTI(ComponentClass, Guid, AZ::Component) \
|
||||
AZ_COMPONENT_INTRUSIVE_DESCRIPTOR_TYPE(ComponentClass) \
|
||||
AZ_COMPONENT_BASE(ComponentClass, Guid, Base)
|
||||
|
||||
namespace Multiplayer
|
||||
{
|
||||
@@ -50,7 +51,7 @@ namespace Multiplayer
|
||||
NetBindComponent* GetNetBindComponent();
|
||||
//! @}
|
||||
|
||||
//! Linearly searches the components attached to the entity and returns the requested component. .
|
||||
//! Linearly searches the components attached to the entity and returns the requested component.
|
||||
//! @return the requested component, or nullptr if the component does not exist on the entity
|
||||
//! @{
|
||||
template <typename ComponentType>
|
||||
@@ -62,25 +63,22 @@ namespace Multiplayer
|
||||
NetEntityId GetNetEntityId() const;
|
||||
ConstNetworkEntityHandle GetEntityHandle() const;
|
||||
NetworkEntityHandle GetEntityHandle();
|
||||
void MarkDirty();
|
||||
|
||||
virtual NetComponentId GetNetComponentId() const = 0;
|
||||
|
||||
virtual bool HandleRpcMessage(NetEntityRole netEntityRole, NetworkEntityRpcMessage& rpcMessage) = 0;
|
||||
virtual bool SerializeStateDeltaMessage(ReplicationRecord& replicationRecord, AzNetworking::ISerializer& serializer, ComponentSerializationType componentSerializationType) = 0;
|
||||
virtual void NotifyStateDeltaChanges(ReplicationRecord& replicationRecord, ComponentSerializationType componentSerializationType) = 0;
|
||||
virtual bool SerializeStateDeltaMessage(ReplicationRecord& replicationRecord, AzNetworking::ISerializer& serializer) = 0;
|
||||
virtual void NotifyStateDeltaChanges(ReplicationRecord& replicationRecord) = 0;
|
||||
|
||||
protected:
|
||||
|
||||
virtual bool HasController() const = 0;
|
||||
virtual MultiplayerController* GetController() = 0;
|
||||
|
||||
virtual bool Migrate(AzNetworking::ISerializer& serializer) = 0;
|
||||
virtual void ConstructController() = 0;
|
||||
virtual void DestructController() = 0;
|
||||
virtual void ActivateController(EntityIsMigrating entityIsMigrating) = 0;
|
||||
virtual void DeactivateController(EntityIsMigrating entityIsMigrating) = 0;
|
||||
virtual void NetworkAttach(NetBindComponent& netBindComponent, ReplicationRecord& currentEntityRecord, ReplicationRecord& predictableEntityRecord) = 0;
|
||||
virtual void NetworkDetach() = 0;
|
||||
virtual void NetworkAttach(NetBindComponent* netBindComponent, ReplicationRecord& currentEntityRecord, ReplicationRecord& predictableEntityRecord) = 0;
|
||||
|
||||
mutable NetBindComponent* m_netBindComponent = nullptr;
|
||||
|
||||
@@ -100,4 +98,42 @@ namespace Multiplayer
|
||||
{
|
||||
return GetEntity()->FindComponent<ComponentType>();
|
||||
}
|
||||
|
||||
template <typename TYPE>
|
||||
inline void SerializeNetworkPropertyHelper
|
||||
(
|
||||
AzNetworking::ISerializer& serializer,
|
||||
bool modifyRecord,
|
||||
AzNetworking::FixedSizeBitsetView& bitset,
|
||||
int32_t bitIndex,
|
||||
TYPE& value,
|
||||
const char* name,
|
||||
[[maybe_unused]] NetComponentId componentId
|
||||
)
|
||||
{
|
||||
if (bitset.GetBit(bitIndex))
|
||||
{
|
||||
//uint32_t prevUpdateSize = serializer.GetSize();
|
||||
serializer.ClearTrackedChangesFlag();
|
||||
serializer.Serialize(value, name);
|
||||
if (modifyRecord && !serializer.GetTrackedChangesFlag())
|
||||
{
|
||||
bitset.SetBit(bitIndex, false);
|
||||
}
|
||||
//uint32_t postUpdateSize = serializer.GetSize();
|
||||
// Network Property metrics
|
||||
// uint32_t updateSize = (postUpdateSize - prevUpdateSize);
|
||||
// if (updateSize > 0)
|
||||
// {
|
||||
// if (serializer.GetSerializerMode() == AzNetworking::SerializerMode::WriteToObject)
|
||||
// {
|
||||
// GetPacketHandlerMetricsInstance().LogRecvNetworkPropertyUpdates(componentType, name, updateSize);
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// GetPacketHandlerMetricsInstance().LogSentNetworkPropertyUpdates(componentType, name, updateSize);
|
||||
// }
|
||||
// }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -52,10 +52,19 @@ namespace Multiplayer
|
||||
return m_owner.GetNetBindComponent();
|
||||
}
|
||||
|
||||
const MultiplayerComponent& MultiplayerController::GetOwner() const
|
||||
{
|
||||
return m_owner;
|
||||
}
|
||||
|
||||
MultiplayerComponent& MultiplayerController::GetOwner()
|
||||
{
|
||||
return m_owner;
|
||||
}
|
||||
|
||||
bool MultiplayerController::IsProcessingInput() const
|
||||
{
|
||||
//return m_owner.GetNetBindComponent()->IsProcessingInput();
|
||||
return false;
|
||||
return GetNetBindComponent()->IsProcessingInput();
|
||||
}
|
||||
|
||||
MultiplayerController* MultiplayerController::FindController(const AZ::Uuid& typeId, const NetworkEntityHandle& entityHandle) const
|
||||
|
||||
@@ -13,6 +13,7 @@
|
||||
#pragma once
|
||||
|
||||
#include <Source/NetworkEntity/NetworkEntityHandle.h>
|
||||
#include <AzCore/Math/Aabb.h>
|
||||
|
||||
namespace Multiplayer
|
||||
{
|
||||
@@ -36,6 +37,12 @@ namespace Multiplayer
|
||||
MultiplayerController(MultiplayerComponent& owner);
|
||||
virtual ~MultiplayerController() = default;
|
||||
|
||||
//! Activates the controller.
|
||||
virtual void Activate(EntityIsMigrating entityIsMigrating) = 0;
|
||||
|
||||
//! Deactivates the controller.
|
||||
virtual void Deactivate(EntityIsMigrating entityIsMigrating) = 0;
|
||||
|
||||
//! Returns the networkId for the entity that owns this controller.
|
||||
//! @return the networkId for the entity that owns this controller
|
||||
NetEntityId GetNetEntityId() const;
|
||||
@@ -54,8 +61,18 @@ namespace Multiplayer
|
||||
|
||||
protected:
|
||||
|
||||
//! Returns the NetBindComponent responsible for net binding for this controller
|
||||
//! @{
|
||||
const NetBindComponent* GetNetBindComponent() const;
|
||||
NetBindComponent* GetNetBindComponent();
|
||||
//! @}
|
||||
|
||||
//! Returns the MultiplayerComponent that owns this controller instance.
|
||||
//! @return the MultiplayerComponent that owns this controller instance
|
||||
//! @{
|
||||
const MultiplayerComponent& GetOwner() const;
|
||||
MultiplayerComponent& GetOwner();
|
||||
//! @}
|
||||
|
||||
//! Returns true if the owning entity is currently inside ProcessInput scope.
|
||||
bool IsProcessingInput() const;
|
||||
@@ -63,11 +80,11 @@ namespace Multiplayer
|
||||
//! Returns the input priority ordering for determining the order of ProcessInput or CreateInput functions.
|
||||
virtual InputPriorityOrder GetInputOrder() const = 0;
|
||||
|
||||
//! Hints the rewind system how close an entity should be in order to rewind, this can be very important for performance at scale.
|
||||
//! 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 the maximum distance an entity should be for this component to interact with it given the provided input
|
||||
virtual float GetRewindDistanceForInput(const NetworkInput& networkInput, float deltaTime) const = 0;
|
||||
//! @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
|
||||
|
||||
@@ -75,9 +75,9 @@ namespace Multiplayer
|
||||
void NetBindComponent::Activate()
|
||||
{
|
||||
m_needsToBeStopped = true;
|
||||
if (m_netEntityRole == NetEntityRole::ServerAuthority)
|
||||
if (m_netEntityRole == NetEntityRole::Authority)
|
||||
{
|
||||
m_handleLocalServerRpcMessageEventHandle.Connect(m_sendServerSimulationtoServerAuthorityRpcEvent);
|
||||
m_handleLocalServerRpcMessageEventHandle.Connect(m_sendServertoAuthorityRpcEvent);
|
||||
}
|
||||
if (NetworkRoleHasController(m_netEntityRole))
|
||||
{
|
||||
@@ -98,7 +98,6 @@ namespace Multiplayer
|
||||
{
|
||||
GetNetworkEntityManager()->NotifyControllersDeactivated(m_netEntityHandle, EntityIsMigrating::False);
|
||||
}
|
||||
NetworkDetach();
|
||||
}
|
||||
|
||||
NetEntityRole NetBindComponent::GetNetEntityRole() const
|
||||
@@ -108,13 +107,13 @@ namespace Multiplayer
|
||||
|
||||
bool NetBindComponent::IsAuthority() const
|
||||
{
|
||||
return (m_netEntityRole == NetEntityRole::ServerAuthority);
|
||||
return (m_netEntityRole == NetEntityRole::Authority);
|
||||
}
|
||||
|
||||
bool NetBindComponent::HasController() const
|
||||
{
|
||||
return (m_netEntityRole == NetEntityRole::ServerAuthority)
|
||||
|| (m_netEntityRole == NetEntityRole::ClientAutonomous);
|
||||
return (m_netEntityRole == NetEntityRole::Authority)
|
||||
|| (m_netEntityRole == NetEntityRole::Autonomous);
|
||||
}
|
||||
|
||||
NetEntityId NetBindComponent::GetNetEntityId() const
|
||||
@@ -160,7 +159,7 @@ namespace Multiplayer
|
||||
void NetBindComponent::CreateInput(NetworkInput& networkInput, float deltaTime)
|
||||
{
|
||||
// Only autonomous or authority runs this logic
|
||||
AZ_Assert(m_netEntityRole == NetEntityRole::ClientAutonomous || m_netEntityRole == NetEntityRole::ServerAuthority, "Incorrect network role for input creation");
|
||||
AZ_Assert(m_netEntityRole == NetEntityRole::Autonomous || m_netEntityRole == NetEntityRole::Authority, "Incorrect network role for input creation");
|
||||
for (MultiplayerComponent* multiplayerComponent : m_multiplayerInputComponentVector)
|
||||
{
|
||||
multiplayerComponent->GetController()->CreateInput(networkInput, deltaTime);
|
||||
@@ -177,15 +176,19 @@ namespace Multiplayer
|
||||
}
|
||||
}
|
||||
|
||||
float NetBindComponent::GetRewindDistanceForInput(const NetworkInput& networkInput, float deltaTime) const
|
||||
AZ::Aabb NetBindComponent::GetRewindBoundsForInput(const NetworkInput& networkInput, float deltaTime) const
|
||||
{
|
||||
AZ_Assert(m_netEntityRole == NetEntityRole::ServerAuthority, "Incorrect network role for computing rewind distance");
|
||||
float rewindDistance = 0.0f;
|
||||
AZ_Assert(m_netEntityRole == NetEntityRole::Authority, "Incorrect network role for computing rewind bounds");
|
||||
AZ::Aabb bounds = AZ::Aabb::CreateNull();
|
||||
for (MultiplayerComponent* multiplayerComponent : m_multiplayerInputComponentVector)
|
||||
{
|
||||
rewindDistance = AZStd::max(rewindDistance, multiplayerComponent->GetController()->GetRewindDistanceForInput(networkInput, deltaTime));
|
||||
const AZ::Aabb componentBounds = multiplayerComponent->GetController()->GetRewindBoundsForInput(networkInput, deltaTime);
|
||||
if (componentBounds.IsValid())
|
||||
{
|
||||
bounds.AddAabb(componentBounds);
|
||||
}
|
||||
}
|
||||
return rewindDistance;
|
||||
return bounds;
|
||||
}
|
||||
|
||||
bool NetBindComponent::HandleRpcMessage(NetEntityRole remoteRole, NetworkEntityRpcMessage& message)
|
||||
@@ -203,25 +206,25 @@ namespace Multiplayer
|
||||
const NetEntityRole netEntityRole = m_netEntityRole;
|
||||
ReplicationRecord replicationRecord(netEntityRole);
|
||||
replicationRecord.Serialize(serializer);
|
||||
if ((serializer.GetSerializerMode() == AzNetworking::SerializerMode::WriteToObject) && (netEntityRole == NetEntityRole::ServerSimulation))
|
||||
if ((serializer.GetSerializerMode() == AzNetworking::SerializerMode::WriteToObject) && (netEntityRole == NetEntityRole::Server))
|
||||
{
|
||||
// Make sure to capture the entirety of the TotalRecord, before we clear out bits that haven't changed from our local state
|
||||
// If this entity migrates, we need to send all bits that might have changed from original baseline
|
||||
m_totalRecord.Append(replicationRecord);
|
||||
}
|
||||
// This will modify the replicationRecord and clear out bits that have not changed from the local state, this prevents us from notifying that something has changed multiple times
|
||||
SerializeStateDeltaMessage(replicationRecord, serializer, ComponentSerializationType::Properties);
|
||||
SerializeStateDeltaMessage(replicationRecord, serializer);
|
||||
|
||||
if (serializer.IsValid())
|
||||
{
|
||||
replicationRecord.ResetConsumedBits();
|
||||
if (notifyChanges)
|
||||
{
|
||||
NotifyStateDeltaChanges(replicationRecord, ComponentSerializationType::Properties);
|
||||
NotifyStateDeltaChanges(replicationRecord);
|
||||
}
|
||||
|
||||
// If we are deserializing on an entity, and this is a server simulation, then we need to remark our bits as dirty to replicate to the client
|
||||
if ((serializer.GetSerializerMode() == AzNetworking::SerializerMode::WriteToObject) && (netEntityRole == NetEntityRole::ServerSimulation))
|
||||
if ((serializer.GetSerializerMode() == AzNetworking::SerializerMode::WriteToObject) && (netEntityRole == NetEntityRole::Server))
|
||||
{
|
||||
m_currentRecord.Append(replicationRecord);
|
||||
MarkDirty();
|
||||
@@ -230,24 +233,24 @@ namespace Multiplayer
|
||||
return serializer.IsValid();
|
||||
}
|
||||
|
||||
RpcSendEvent& NetBindComponent::GetSendServerAuthorityToClientSimulationRpcEvent()
|
||||
RpcSendEvent& NetBindComponent::GetSendAuthorityToClientRpcEvent()
|
||||
{
|
||||
return m_sendServerAuthorityToClientSimulationRpcEvent;
|
||||
return m_sendAuthorityToClientRpcEvent;
|
||||
}
|
||||
|
||||
RpcSendEvent& NetBindComponent::GetSendServerAuthorityToClientAutonomousRpcEvent()
|
||||
RpcSendEvent& NetBindComponent::GetSendAuthorityToAutonomousRpcEvent()
|
||||
{
|
||||
return m_sendServerAuthorityToClientAutonomousRpcEvent;
|
||||
return m_sendAuthorityToAutonomousRpcEvent;
|
||||
}
|
||||
|
||||
RpcSendEvent& NetBindComponent::GetSendServerSimulationToServerAuthorityRpcEvent()
|
||||
RpcSendEvent& NetBindComponent::GetSendServerToAuthorityRpcEvent()
|
||||
{
|
||||
return m_sendServerSimulationtoServerAuthorityRpcEvent;
|
||||
return m_sendServertoAuthorityRpcEvent;
|
||||
}
|
||||
|
||||
RpcSendEvent& NetBindComponent::GetSendClientAutonomousToServerAuthorityRpcEvent()
|
||||
RpcSendEvent& NetBindComponent::GetSendAutonomousToAuthorityRpcEvent()
|
||||
{
|
||||
return m_sendClientAutonomousToServerAuthorityRpcEvent;
|
||||
return m_sendAutonomousToAuthorityRpcEvent;
|
||||
}
|
||||
|
||||
const ReplicationRecord& NetBindComponent::GetPredictableRecord() const
|
||||
@@ -266,7 +269,7 @@ namespace Multiplayer
|
||||
void NetBindComponent::NotifyLocalChanges()
|
||||
{
|
||||
m_localNotificationRecord.ResetConsumedBits(); // Make sure our consumed bits are reset so that we can run through the notifications
|
||||
NotifyStateDeltaChanges(m_localNotificationRecord, ComponentSerializationType::Properties);
|
||||
NotifyStateDeltaChanges(m_localNotificationRecord);
|
||||
m_localNotificationRecord.Clear();
|
||||
}
|
||||
|
||||
@@ -297,40 +300,31 @@ namespace Multiplayer
|
||||
// The m_predictableRecord is a record that that marks every NetworkProperty that has been set as Predictable
|
||||
// We copy this record and use a temporary so that SerializeStateDeltaMessage will not modify the m_predictableRecord
|
||||
// since SerializeStateDeltaMessage will clear the dirty bit for the NetworkProperty if it did not actually change
|
||||
const bool success = SerializeStateDeltaMessage(tmpRecord, serializer, ComponentSerializationType::Correction);
|
||||
const bool success = SerializeStateDeltaMessage(tmpRecord, serializer);
|
||||
if (serializer.GetSerializerMode() == AzNetworking::SerializerMode::WriteToObject)
|
||||
{
|
||||
tmpRecord.ResetConsumedBits();
|
||||
NotifyStateDeltaChanges(tmpRecord, ComponentSerializationType::Correction);
|
||||
NotifyStateDeltaChanges(tmpRecord);
|
||||
}
|
||||
return success;
|
||||
}
|
||||
|
||||
bool NetBindComponent::SerializeStateDeltaMessage
|
||||
(
|
||||
ReplicationRecord& replicationRecord,
|
||||
AzNetworking::ISerializer& serializer,
|
||||
ComponentSerializationType componentSerializationType
|
||||
)
|
||||
bool NetBindComponent::SerializeStateDeltaMessage(ReplicationRecord& replicationRecord, AzNetworking::ISerializer& serializer)
|
||||
{
|
||||
bool success = true;
|
||||
for (auto iter = m_multiplayerSerializationComponentVector.begin(); iter != m_multiplayerSerializationComponentVector.end(); ++iter)
|
||||
{
|
||||
success &= (*iter)->SerializeStateDeltaMessage(replicationRecord, serializer, componentSerializationType);
|
||||
success &= (*iter)->SerializeStateDeltaMessage(replicationRecord, serializer);
|
||||
}
|
||||
|
||||
return success;
|
||||
}
|
||||
|
||||
void NetBindComponent::NotifyStateDeltaChanges
|
||||
(
|
||||
ReplicationRecord& replicationRecord,
|
||||
ComponentSerializationType componentSerializationType
|
||||
)
|
||||
void NetBindComponent::NotifyStateDeltaChanges(ReplicationRecord& replicationRecord)
|
||||
{
|
||||
for (auto iter = m_multiplayerSerializationComponentVector.begin(); iter != m_multiplayerSerializationComponentVector.end(); ++iter)
|
||||
{
|
||||
(*iter)->NotifyStateDeltaChanges(replicationRecord, componentSerializationType);
|
||||
(*iter)->NotifyStateDeltaChanges(replicationRecord);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -352,27 +346,6 @@ namespace Multiplayer
|
||||
}
|
||||
}
|
||||
|
||||
bool NetBindComponent::IsMigrationDataValid() const
|
||||
{
|
||||
return m_isMigrationDataValid;
|
||||
}
|
||||
|
||||
void NetBindComponent::SetMigrationDataValid(bool migrationDataValid)
|
||||
{
|
||||
m_isMigrationDataValid = migrationDataValid;
|
||||
}
|
||||
|
||||
bool NetBindComponent::SerializeMigrationData(AzNetworking::ISerializer& serializer)
|
||||
{
|
||||
bool ret = true;
|
||||
// Purposefully not listed in reverse order, must match the order during construction
|
||||
for (auto iter = m_multiplayerSerializationComponentVector.begin(); iter != m_multiplayerSerializationComponentVector.end(); ++iter)
|
||||
{
|
||||
ret &= (*iter)->Migrate(serializer);
|
||||
}
|
||||
return ret && serializer.IsValid();
|
||||
}
|
||||
|
||||
void NetBindComponent::PreInit(AZ::Entity* entity, const PrefabEntityId& prefabEntityId, NetEntityId netEntityId, NetEntityRole netEntityRole)
|
||||
{
|
||||
AZ_Assert(entity != nullptr, "AZ::Entity is null");
|
||||
@@ -404,11 +377,11 @@ namespace Multiplayer
|
||||
{
|
||||
switch (m_netEntityRole)
|
||||
{
|
||||
case NetEntityRole::ClientSimulation:
|
||||
m_netEntityRole = NetEntityRole::ClientAutonomous;
|
||||
case NetEntityRole::Client:
|
||||
m_netEntityRole = NetEntityRole::Autonomous;
|
||||
break;
|
||||
case NetEntityRole::ServerSimulation:
|
||||
m_netEntityRole = NetEntityRole::ServerAuthority;
|
||||
case NetEntityRole::Server:
|
||||
m_netEntityRole = NetEntityRole::Authority;
|
||||
break;
|
||||
default:
|
||||
AZ_Assert(false, "Controller already constructed");
|
||||
@@ -441,11 +414,11 @@ namespace Multiplayer
|
||||
|
||||
switch (m_netEntityRole)
|
||||
{
|
||||
case NetEntityRole::ClientAutonomous:
|
||||
m_netEntityRole = NetEntityRole::ClientSimulation;
|
||||
case NetEntityRole::Autonomous:
|
||||
m_netEntityRole = NetEntityRole::Client;
|
||||
break;
|
||||
case NetEntityRole::ServerAuthority:
|
||||
m_netEntityRole = NetEntityRole::ServerSimulation;
|
||||
case NetEntityRole::Authority:
|
||||
m_netEntityRole = NetEntityRole::Server;
|
||||
break;
|
||||
default:
|
||||
AZ_Assert(false, "Controllers already destructed");
|
||||
@@ -465,9 +438,9 @@ namespace Multiplayer
|
||||
}
|
||||
}
|
||||
DetermineInputOrdering();
|
||||
if (GetNetEntityRole() == NetEntityRole::ServerAuthority)
|
||||
if (GetNetEntityRole() == NetEntityRole::Authority)
|
||||
{
|
||||
m_handleLocalServerRpcMessageEventHandle.Connect(m_sendServerSimulationtoServerAuthorityRpcEvent);
|
||||
m_handleLocalServerRpcMessageEventHandle.Connect(m_sendServertoAuthorityRpcEvent);
|
||||
}
|
||||
GetNetworkEntityManager()->NotifyControllersActivated(m_netEntityHandle, entityIsMigrating);
|
||||
}
|
||||
@@ -502,19 +475,11 @@ namespace Multiplayer
|
||||
{
|
||||
for (auto* component : m_multiplayerSerializationComponentVector)
|
||||
{
|
||||
component->NetworkAttach(*this, m_currentRecord, m_predictableRecord);
|
||||
component->NetworkAttach(this, m_currentRecord, m_predictableRecord);
|
||||
}
|
||||
m_totalRecord = m_currentRecord;
|
||||
}
|
||||
|
||||
void NetBindComponent::NetworkDetach()
|
||||
{
|
||||
for (auto* component : m_multiplayerSerializationComponentVector)
|
||||
{
|
||||
component->NetworkDetach();
|
||||
}
|
||||
}
|
||||
|
||||
void NetBindComponent::HandleMarkedDirty()
|
||||
{
|
||||
m_dirtiedEvent.Signal();
|
||||
@@ -532,7 +497,7 @@ namespace Multiplayer
|
||||
|
||||
void NetBindComponent::HandleLocalServerRpcMessage(NetworkEntityRpcMessage& message)
|
||||
{
|
||||
message.SetRpcDeliveryType(RpcDeliveryType::ServerSimulationToServerAuthority);
|
||||
message.SetRpcDeliveryType(RpcDeliveryType::ServerToAuthority);
|
||||
GetNetworkEntityManager()->HandleLocalRpcMessage(message);
|
||||
}
|
||||
|
||||
@@ -574,8 +539,8 @@ namespace Multiplayer
|
||||
{
|
||||
switch (networkRole)
|
||||
{
|
||||
case NetEntityRole::ClientAutonomous: // Fall through
|
||||
case NetEntityRole::ServerAuthority:
|
||||
case NetEntityRole::Autonomous: // Fall through
|
||||
case NetEntityRole::Authority:
|
||||
return true;
|
||||
default:
|
||||
return false;
|
||||
|
||||
@@ -14,6 +14,7 @@
|
||||
|
||||
#include <AzCore/Component/Component.h>
|
||||
#include <AzCore/Component/Entity.h>
|
||||
#include <AzCore/Math/Aabb.h>
|
||||
#include <AzCore/std/containers/map.h>
|
||||
#include <AzCore/std/containers/vector.h>
|
||||
#include <AzCore/std/smart_ptr/unique_ptr.h>
|
||||
@@ -23,6 +24,7 @@
|
||||
#include <Source/NetworkEntity/NetworkEntityHandle.h>
|
||||
#include <Source/NetworkInput/IMultiplayerComponentInput.h>
|
||||
#include <Source/MultiplayerTypes.h>
|
||||
#include <AzCore/EBus/Event.h>
|
||||
|
||||
namespace Multiplayer
|
||||
{
|
||||
@@ -68,15 +70,15 @@ namespace Multiplayer
|
||||
bool IsProcessingInput() const;
|
||||
void CreateInput(NetworkInput& networkInput, float deltaTime);
|
||||
void ProcessInput(NetworkInput& networkInput, float deltaTime);
|
||||
float GetRewindDistanceForInput(const NetworkInput& networkInput, float deltaTime) const;
|
||||
AZ::Aabb GetRewindBoundsForInput(const NetworkInput& networkInput, float deltaTime) const;
|
||||
|
||||
bool HandleRpcMessage(NetEntityRole remoteRole, NetworkEntityRpcMessage& message);
|
||||
bool HandlePropertyChangeMessage(AzNetworking::ISerializer& serializer, bool notifyChanges = true);
|
||||
|
||||
RpcSendEvent& GetSendServerAuthorityToClientSimulationRpcEvent();
|
||||
RpcSendEvent& GetSendServerAuthorityToClientAutonomousRpcEvent();
|
||||
RpcSendEvent& GetSendServerSimulationToServerAuthorityRpcEvent();
|
||||
RpcSendEvent& GetSendClientAutonomousToServerAuthorityRpcEvent();
|
||||
RpcSendEvent& GetSendAuthorityToClientRpcEvent();
|
||||
RpcSendEvent& GetSendAuthorityToAutonomousRpcEvent();
|
||||
RpcSendEvent& GetSendServerToAuthorityRpcEvent();
|
||||
RpcSendEvent& GetSendAutonomousToAuthorityRpcEvent();
|
||||
|
||||
const ReplicationRecord& GetPredictableRecord() const;
|
||||
|
||||
@@ -88,20 +90,15 @@ namespace Multiplayer
|
||||
void AddEntityDirtiedEventHandler(EntityDirtiedEvent::Handler& eventHandler);
|
||||
void AddEntityMigrationEventHandler(EntityMigrationEvent::Handler& eventHandler);
|
||||
|
||||
bool SerializeEntityCorrection(AzNetworking::ISerializer& a_Serializer);
|
||||
bool SerializeEntityCorrection(AzNetworking::ISerializer& serializer);
|
||||
|
||||
bool SerializeStateDeltaMessage(ReplicationRecord& replicationRecord, AzNetworking::ISerializer& serializer, ComponentSerializationType componentSerializationType);
|
||||
void NotifyStateDeltaChanges(ReplicationRecord& replicationRecord, ComponentSerializationType componentSerializationType);
|
||||
bool SerializeStateDeltaMessage(ReplicationRecord& replicationRecord, AzNetworking::ISerializer& serializer);
|
||||
void NotifyStateDeltaChanges(ReplicationRecord& replicationRecord);
|
||||
|
||||
void FillReplicationRecord(ReplicationRecord& replicationRecord) const;
|
||||
void FillTotalReplicationRecord(ReplicationRecord& replicationRecord) const;
|
||||
|
||||
bool IsMigrationDataValid() const;
|
||||
|
||||
private:
|
||||
void SetMigrationDataValid(bool migrationDataValid);
|
||||
bool SerializeMigrationData(AzNetworking::ISerializer& serializer);
|
||||
|
||||
void PreInit(AZ::Entity* entity, const PrefabEntityId& prefabEntityId, NetEntityId netEntityId, NetEntityRole netEntityRole);
|
||||
|
||||
void ConstructControllers();
|
||||
@@ -112,7 +109,6 @@ namespace Multiplayer
|
||||
void OnEntityStateEvent(AZ::Entity::State oldState, AZ::Entity::State newState);
|
||||
|
||||
void NetworkAttach();
|
||||
void NetworkDetach();
|
||||
|
||||
void HandleMarkedDirty();
|
||||
void HandleLocalServerRpcMessage(NetworkEntityRpcMessage& message);
|
||||
@@ -130,10 +126,10 @@ namespace Multiplayer
|
||||
AZStd::vector<MultiplayerComponent*> m_multiplayerSerializationComponentVector;
|
||||
AZStd::vector<MultiplayerComponent*> m_multiplayerInputComponentVector;
|
||||
|
||||
RpcSendEvent m_sendServerAuthorityToClientSimulationRpcEvent;
|
||||
RpcSendEvent m_sendServerAuthorityToClientAutonomousRpcEvent;
|
||||
RpcSendEvent m_sendServerSimulationtoServerAuthorityRpcEvent;
|
||||
RpcSendEvent m_sendClientAutonomousToServerAuthorityRpcEvent;
|
||||
RpcSendEvent m_sendAuthorityToClientRpcEvent;
|
||||
RpcSendEvent m_sendAuthorityToAutonomousRpcEvent;
|
||||
RpcSendEvent m_sendServertoAuthorityRpcEvent;
|
||||
RpcSendEvent m_sendAutonomousToAuthorityRpcEvent;
|
||||
|
||||
EntityStopEvent m_entityStopEvent;
|
||||
EntityDirtiedEvent m_dirtiedEvent;
|
||||
|
||||
@@ -0,0 +1,26 @@
|
||||
/*
|
||||
* 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.
|
||||
*
|
||||
*/
|
||||
|
||||
#include <Source/Components/NetworkTransformComponent.h>
|
||||
|
||||
namespace Multiplayer
|
||||
{
|
||||
void NetworkTransformComponent::NetworkTransformComponent::Reflect(AZ::ReflectContext* context)
|
||||
{
|
||||
AZ::SerializeContext* serializeContext = azrtti_cast<AZ::SerializeContext*>(context);
|
||||
if (serializeContext)
|
||||
{
|
||||
serializeContext->Class<NetworkTransformComponent, NetworkTransformComponentBase>()
|
||||
->Version(1);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
/*
|
||||
* 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 <Source/AutoGen/NetworkTransformComponent.AutoComponent.h>
|
||||
|
||||
namespace Multiplayer
|
||||
{
|
||||
class NetworkTransformComponent
|
||||
: public NetworkTransformComponentBase
|
||||
{
|
||||
public:
|
||||
AZ_MULTIPLAYER_COMPONENT(Multiplayer::NetworkTransformComponent, s_networkTransformComponentConcreteUuid, Multiplayer::NetworkTransformComponentBase);
|
||||
|
||||
static void Reflect([[maybe_unused]] AZ::ReflectContext* context);
|
||||
|
||||
void OnInit() override {}
|
||||
void OnActivate([[maybe_unused]] Multiplayer::EntityIsMigrating entityIsMigrating) override {}
|
||||
void OnDeactivate([[maybe_unused]] Multiplayer::EntityIsMigrating entityIsMigrating) override {}
|
||||
};
|
||||
|
||||
class NetworkTransformComponentController
|
||||
: public NetworkTransformComponentControllerBase
|
||||
{
|
||||
public:
|
||||
NetworkTransformComponentController(NetworkTransformComponent& parent) : NetworkTransformComponentControllerBase(parent) {}
|
||||
|
||||
void OnActivate([[maybe_unused]] Multiplayer::EntityIsMigrating entityIsMigrating) override {}
|
||||
void OnDeactivate([[maybe_unused]] Multiplayer::EntityIsMigrating entityIsMigrating) override {}
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user