Several updates to complete rewind support and remove unneeded functionality
This commit is contained in:
+29
-28
@@ -656,7 +656,7 @@ namespace Multiplayer
|
||||
{
|
||||
case Mode::LocalServerToRemoteClient:
|
||||
{
|
||||
// don't trust the client by default
|
||||
// Don't trust the client by default
|
||||
result = UpdateValidationResult::DropMessageAndDisconnect;
|
||||
// Clients sending data must have a replicator and be sending in the correct mode, further, they must have a replicator and can never delete a replicator
|
||||
if (updateMessage.GetNetworkRole() == NetEntityRole::Authority && entityReplicator && !updateMessage.GetIsDelete())
|
||||
@@ -671,7 +671,7 @@ namespace Multiplayer
|
||||
}
|
||||
else
|
||||
{
|
||||
// we can process this
|
||||
// We can process this
|
||||
result = UpdateValidationResult::HandleMessage;
|
||||
}
|
||||
} // If we've migrated the entity away from the server, but we get this late, just drop it
|
||||
@@ -699,7 +699,7 @@ namespace Multiplayer
|
||||
case Mode::LocalServerToRemoteServer:
|
||||
{
|
||||
AZ_Assert(updateMessage.GetNetworkRole() == NetEntityRole::Server || updateMessage.GetIsDelete(), "Unexpected update type coming from peer server");
|
||||
// trust messages from a peer server by default
|
||||
// Trust messages from a peer server by default
|
||||
result = UpdateValidationResult::HandleMessage;
|
||||
// If we have a replicator, make sure we're in the correct state
|
||||
if (entityReplicator)
|
||||
@@ -782,7 +782,7 @@ namespace Multiplayer
|
||||
PrefabEntityId prefabEntityId;
|
||||
if (updateMessage.GetHasValidPrefabId())
|
||||
{
|
||||
// If the update packet contained a sliceEntryId, use that directly
|
||||
// If the update packet contained a PrefabEntityId, use that directly
|
||||
prefabEntityId = updateMessage.GetPrefabEntityId();
|
||||
}
|
||||
else
|
||||
@@ -940,7 +940,7 @@ namespace Multiplayer
|
||||
{
|
||||
const ReplicationSet& newWindow = m_replicationWindow->GetReplicationSet();
|
||||
|
||||
// walk both for adds and removals
|
||||
// Walk both for adds and removals
|
||||
auto newWindowIter = newWindow.begin();
|
||||
auto currWindowIter = m_entityReplicatorMap.begin();
|
||||
while (newWindowIter != newWindow.end() && currWindowIter != m_entityReplicatorMap.end())
|
||||
@@ -959,9 +959,9 @@ namespace Multiplayer
|
||||
}
|
||||
++currWindowIter;
|
||||
}
|
||||
else // same entity
|
||||
else // Same entity
|
||||
{
|
||||
// check if we changed modes
|
||||
// Check if we changed modes
|
||||
EntityReplicator* currReplicator = currWindowIter->second.get();
|
||||
if (currReplicator->GetRemoteNetworkRole() != newWindowIter->second.m_netEntityRole)
|
||||
{
|
||||
@@ -973,14 +973,14 @@ namespace Multiplayer
|
||||
}
|
||||
}
|
||||
|
||||
// do remaining adds
|
||||
// Do remaining adds
|
||||
while (newWindowIter != newWindow.end())
|
||||
{
|
||||
AddEntityReplicator(newWindowIter->first, newWindowIter->second.m_netEntityRole);
|
||||
++newWindowIter;
|
||||
}
|
||||
|
||||
// do remaining removes
|
||||
// Do remaining removes
|
||||
while (currWindowIter != m_entityReplicatorMap.end())
|
||||
{
|
||||
EntityReplicator* currReplicator = currWindowIter->second.get();
|
||||
@@ -1028,13 +1028,13 @@ namespace Multiplayer
|
||||
|
||||
const EntityReplicator* entityReplicator = GetEntityReplicator(entityHandle.GetNetEntityId());
|
||||
hasAuthority = (netBindComponent->GetNetEntityRole() == NetEntityRole::Authority); // Make sure someone hasn't migrated this already
|
||||
isInDomain = (m_remoteEntityDomain && m_remoteEntityDomain->IsInDomain(entityHandle)); // Make sure the remote side would want it
|
||||
isInDomain = (m_remoteEntityDomain && m_remoteEntityDomain->IsInDomain(entityHandle)); // Make sure the remote side would want it
|
||||
if (entityReplicator && entityReplicator->GetBoundLocalNetworkRole() == NetEntityRole::Authority)
|
||||
{
|
||||
isMarkedForRemoval = entityReplicator->IsMarkedForRemoval(); // Make sure we aren't telling the other side to remove the replicator
|
||||
isMarkedForRemoval = entityReplicator->IsMarkedForRemoval(); // Make sure we aren't telling the other side to remove the replicator
|
||||
const PropertyPublisher* propertyPublisher = entityReplicator->GetPropertyPublisher();
|
||||
AZ_Assert(propertyPublisher, "Expected to have a property publisher");
|
||||
isRemoteReplicatorEstablished = propertyPublisher->IsRemoteReplicatorEstablished(); // Make sure they are setup to receive the replicator
|
||||
isRemoteReplicatorEstablished = propertyPublisher->IsRemoteReplicatorEstablished(); // Make sure they are setup to receive the replicator
|
||||
}
|
||||
|
||||
return hasAuthority && isInDomain && !isMarkedForRemoval && isRemoteReplicatorEstablished;
|
||||
@@ -1094,9 +1094,9 @@ namespace Multiplayer
|
||||
}
|
||||
|
||||
bool didSucceed = true;
|
||||
MultiplayerPackets::EntityMigration message;
|
||||
message.SetEntityId(replicator->GetEntityHandle().GetNetEntityId());
|
||||
message.SetPrefabEntityId(netBindComponent->GetPrefabEntityId());
|
||||
EntityMigrationMessage message;
|
||||
message.m_entityId = replicator->GetEntityHandle().GetNetEntityId();
|
||||
message.m_prefabEntityId = netBindComponent->GetPrefabEntityId();
|
||||
|
||||
if (localEnt->GetState() == AZ::Entity::State::Active)
|
||||
{
|
||||
@@ -1110,17 +1110,18 @@ namespace Multiplayer
|
||||
// Send an update packet if it needs one
|
||||
propPublisher->GenerateRecord();
|
||||
bool needsNetworkPropertyUpdate = propPublisher->PrepareSerialization();
|
||||
AzNetworking::NetworkInputSerializer inputSerializer(message.ModifyPropertyUpdateData().GetBuffer(), message.ModifyPropertyUpdateData().GetCapacity());
|
||||
AzNetworking::NetworkInputSerializer inputSerializer(message.m_propertyUpdateData.GetBuffer(), message.m_propertyUpdateData.GetCapacity());
|
||||
if (needsNetworkPropertyUpdate)
|
||||
{
|
||||
// write out entity state into the buffer
|
||||
// Write out entity state into the buffer
|
||||
propPublisher->UpdateSerialization(inputSerializer);
|
||||
}
|
||||
didSucceed &= inputSerializer.IsValid();
|
||||
message.ModifyPropertyUpdateData().Resize(inputSerializer.GetSize());
|
||||
message.m_propertyUpdateData.Resize(inputSerializer.GetSize());
|
||||
}
|
||||
AZ_Assert(didSucceed, "Failed to migrate entity from server");
|
||||
m_connection.SendReliablePacket(message);
|
||||
// TODO: Move this to an event
|
||||
//m_connection.SendReliablePacket(message);
|
||||
AZLOG(NET_RepDeletes, "Migration packet sent %u to remote manager id %d", netEntityId, aznumeric_cast<int32_t>(GetRemoteHostId()));
|
||||
|
||||
// Immediately add a new replicator so that we catch RPC invocations, the remote side will make us a new one, and then remove us if needs be
|
||||
@@ -1128,21 +1129,21 @@ namespace Multiplayer
|
||||
}
|
||||
}
|
||||
|
||||
bool EntityReplicationManager::HandleMessage([[maybe_unused]] AzNetworking::IConnection* invokingConnection, MultiplayerPackets::EntityMigration& message)
|
||||
bool EntityReplicationManager::HandleEntityMigration([[maybe_unused]] AzNetworking::IConnection* invokingConnection, EntityMigrationMessage& message)
|
||||
{
|
||||
EntityReplicator* replicator = GetEntityReplicator(message.GetEntityId());
|
||||
EntityReplicator* replicator = GetEntityReplicator(message.m_entityId);
|
||||
{
|
||||
if (message.GetPropertyUpdateData().GetSize() > 0)
|
||||
if (message.m_propertyUpdateData.GetSize() > 0)
|
||||
{
|
||||
AzNetworking::TrackChangedSerializer<AzNetworking::NetworkOutputSerializer> outputSerializer(message.ModifyPropertyUpdateData().GetBuffer(), message.ModifyPropertyUpdateData().GetSize());
|
||||
AzNetworking::TrackChangedSerializer<AzNetworking::NetworkOutputSerializer> outputSerializer(message.m_propertyUpdateData.GetBuffer(), message.m_propertyUpdateData.GetSize());
|
||||
if (!HandlePropertyChangeMessage
|
||||
(
|
||||
replicator,
|
||||
AzNetworking::InvalidPacketId,
|
||||
message.GetEntityId(),
|
||||
message.m_entityId,
|
||||
NetEntityRole::Server,
|
||||
outputSerializer,
|
||||
message.GetPrefabEntityId()
|
||||
message.m_prefabEntityId
|
||||
))
|
||||
{
|
||||
AZ_Assert(false, "Unable to process network properties during server entity migration");
|
||||
@@ -1150,10 +1151,10 @@ namespace Multiplayer
|
||||
}
|
||||
}
|
||||
}
|
||||
// the HandlePropertyChangeMessage will have made a replicator if we didn't have one already
|
||||
// The HandlePropertyChangeMessage will have made a replicator if we didn't have one already
|
||||
if (!replicator)
|
||||
{
|
||||
replicator = GetEntityReplicator(message.GetEntityId());
|
||||
replicator = GetEntityReplicator(message.m_entityId);
|
||||
}
|
||||
AZ_Assert(replicator, "Do not have replicator after handling migration message");
|
||||
|
||||
@@ -1170,7 +1171,7 @@ namespace Multiplayer
|
||||
netBindComponent->ActivateControllers(EntityIsMigrating::True);
|
||||
}
|
||||
|
||||
// change the role on the replicator
|
||||
// Change the role on the replicator
|
||||
AddEntityReplicator(entityHandle, NetEntityRole::Server);
|
||||
|
||||
AZLOG(NET_RepDeletes, "Handle Migration %u new authority from remote manager id %d", entityHandle.GetNetEntityId(), aznumeric_cast<int32_t>(GetRemoteHostId()));
|
||||
|
||||
+3
-2
@@ -17,6 +17,8 @@
|
||||
#include <Multiplayer/EntityDomains/IEntityDomain.h>
|
||||
#include <Multiplayer/NetworkEntity/INetworkEntityManager.h>
|
||||
#include <Multiplayer/NetworkEntity/NetworkEntityHandle.h>
|
||||
#include <Multiplayer/NetworkEntity/NetworkEntityUpdateMessage.h>
|
||||
#include <Multiplayer/NetworkEntity/NetworkEntityRpcMessage.h>
|
||||
#include <Multiplayer/ReplicationWindows/IReplicationWindow.h>
|
||||
#include <AzNetworking/DataStructures/TimeoutQueue.h>
|
||||
#include <AzNetworking/PacketLayer/IPacketHeader.h>
|
||||
@@ -26,7 +28,6 @@
|
||||
#include <AzCore/std/limits.h>
|
||||
#include <AzCore/EBus/Event.h>
|
||||
#include <AzCore/EBus/ScheduledEvent.h>
|
||||
#include <Source/AutoGen/Multiplayer.AutoPackets.h>
|
||||
|
||||
namespace AzNetworking
|
||||
{
|
||||
@@ -82,7 +83,7 @@ namespace Multiplayer
|
||||
|
||||
void AddAutonomousEntityReplicatorCreatedHandle(AZ::Event<NetEntityId>::Handler& handler);
|
||||
|
||||
bool HandleMessage(AzNetworking::IConnection* invokingConnection, MultiplayerPackets::EntityMigration& message);
|
||||
bool HandleEntityMigration(AzNetworking::IConnection* invokingConnection, EntityMigrationMessage& message);
|
||||
bool HandleEntityDeleteMessage(EntityReplicator* entityReplicator, const AzNetworking::IPacketHeader& packetHeader, const NetworkEntityUpdateMessage& updateMessage);
|
||||
bool HandleEntityUpdateMessage(AzNetworking::IConnection* invokingConnection, const AzNetworking::IPacketHeader& packetHeader, const NetworkEntityUpdateMessage& updateMessage);
|
||||
bool HandleEntityRpcMessage(AzNetworking::IConnection* invokingConnection, NetworkEntityRpcMessage& message);
|
||||
|
||||
@@ -16,14 +16,12 @@ namespace Multiplayer
|
||||
{
|
||||
ReplicationRecordStats::ReplicationRecordStats
|
||||
(
|
||||
uint32_t authorityToAuthorityCount,
|
||||
uint32_t authorityToClientCount,
|
||||
uint32_t authorityToServerCount,
|
||||
uint32_t authorityToAutonomousCount,
|
||||
uint32_t autonomousToAuthorityCount
|
||||
)
|
||||
: m_authorityToAuthorityCount(authorityToAuthorityCount)
|
||||
, m_authorityToClientCount(authorityToClientCount)
|
||||
: m_authorityToClientCount(authorityToClientCount)
|
||||
, m_authorityToServerCount(authorityToServerCount)
|
||||
, m_authorityToAutonomousCount(authorityToAutonomousCount)
|
||||
, m_autonomousToAuthorityCount(autonomousToAuthorityCount)
|
||||
@@ -33,8 +31,7 @@ namespace Multiplayer
|
||||
|
||||
bool ReplicationRecordStats::operator ==(const ReplicationRecordStats& rhs) const
|
||||
{
|
||||
return (m_authorityToAuthorityCount == rhs.m_authorityToAuthorityCount)
|
||||
&& (m_authorityToClientCount == rhs.m_authorityToClientCount)
|
||||
return (m_authorityToClientCount == rhs.m_authorityToClientCount)
|
||||
&& (m_authorityToServerCount == rhs.m_authorityToServerCount)
|
||||
&& (m_authorityToAutonomousCount == rhs.m_authorityToAutonomousCount)
|
||||
&& (m_autonomousToAuthorityCount == rhs.m_autonomousToAuthorityCount);
|
||||
@@ -44,7 +41,6 @@ namespace Multiplayer
|
||||
{
|
||||
return ReplicationRecordStats
|
||||
{
|
||||
(m_authorityToAuthorityCount - rhs.m_authorityToAuthorityCount),
|
||||
(m_authorityToClientCount - rhs.m_authorityToClientCount),
|
||||
(m_authorityToServerCount - rhs.m_authorityToServerCount),
|
||||
(m_authorityToAutonomousCount - rhs.m_authorityToAutonomousCount),
|
||||
@@ -71,7 +67,6 @@ namespace Multiplayer
|
||||
bool ReplicationRecord::AreAllBitsConsumed() const
|
||||
{
|
||||
bool ret = true;
|
||||
ret &= m_authorityToAuthorityConsumedBits == m_authorityToAuthority.GetSize();
|
||||
ret &= m_authorityToClientConsumedBits == m_authorityToClient.GetSize();
|
||||
ret &= m_authorityToServerConsumedBits == m_authorityToServer.GetSize();
|
||||
ret &= m_authorityToAutonomousConsumedBits == m_authorityToAutonomous.GetSize();
|
||||
@@ -81,7 +76,6 @@ namespace Multiplayer
|
||||
|
||||
void ReplicationRecord::ResetConsumedBits()
|
||||
{
|
||||
m_authorityToAuthorityConsumedBits = 0;
|
||||
m_authorityToClientConsumedBits = 0;
|
||||
m_authorityToServerConsumedBits = 0;
|
||||
m_authorityToAutonomousConsumedBits = 0;
|
||||
@@ -92,11 +86,7 @@ namespace Multiplayer
|
||||
{
|
||||
ResetConsumedBits();
|
||||
|
||||
uint32_t recordSize = m_authorityToAuthority.GetSize();
|
||||
m_authorityToAuthority.Clear();
|
||||
m_authorityToAuthority.Resize(recordSize);
|
||||
|
||||
recordSize = m_authorityToClient.GetSize();
|
||||
uint32_t recordSize = m_authorityToClient.GetSize();
|
||||
m_authorityToClient.Clear();
|
||||
m_authorityToClient.Resize(recordSize);
|
||||
|
||||
@@ -115,7 +105,6 @@ namespace Multiplayer
|
||||
|
||||
void ReplicationRecord::Append(const ReplicationRecord &rhs)
|
||||
{
|
||||
m_authorityToAuthority |= rhs.m_authorityToAuthority;
|
||||
m_authorityToClient |= rhs.m_authorityToClient;
|
||||
m_authorityToServer |= rhs.m_authorityToServer;
|
||||
m_authorityToAutonomous |= rhs.m_authorityToAutonomous;
|
||||
@@ -124,7 +113,6 @@ namespace Multiplayer
|
||||
|
||||
void ReplicationRecord::Subtract(const ReplicationRecord &rhs)
|
||||
{
|
||||
m_authorityToAuthority.Subtract(rhs.m_authorityToAuthority);
|
||||
m_authorityToClient.Subtract(rhs.m_authorityToClient);
|
||||
m_authorityToServer.Subtract(rhs.m_authorityToServer);
|
||||
m_authorityToAutonomous.Subtract(rhs.m_authorityToAutonomous);
|
||||
@@ -134,10 +122,6 @@ namespace Multiplayer
|
||||
bool ReplicationRecord::HasChanges() const
|
||||
{
|
||||
bool hasChanges(false);
|
||||
if (ContainsAuthorityToAuthorityBits())
|
||||
{
|
||||
hasChanges = hasChanges ? hasChanges : m_authorityToAuthority.AnySet();
|
||||
}
|
||||
if (ContainsAuthorityToClientBits())
|
||||
{
|
||||
hasChanges = hasChanges ? hasChanges : m_authorityToClient.AnySet();
|
||||
@@ -159,10 +143,6 @@ namespace Multiplayer
|
||||
|
||||
bool ReplicationRecord::Serialize(AzNetworking::ISerializer& serializer)
|
||||
{
|
||||
if (ContainsAuthorityToAuthorityBits())
|
||||
{
|
||||
serializer.Serialize(m_authorityToAuthority, "AuthorityToAuthorityRecord");
|
||||
}
|
||||
if (ContainsAuthorityToClientBits())
|
||||
{
|
||||
serializer.Serialize(m_authorityToClient, "AuthorityToClientRecord");
|
||||
@@ -182,14 +162,6 @@ namespace Multiplayer
|
||||
return serializer.IsValid();
|
||||
}
|
||||
|
||||
void ReplicationRecord::ConsumeAuthorityToAuthorityBits(uint32_t consumedBits)
|
||||
{
|
||||
if (ContainsAuthorityToAuthorityBits())
|
||||
{
|
||||
m_authorityToAuthorityConsumedBits += consumedBits;
|
||||
}
|
||||
}
|
||||
|
||||
void ReplicationRecord::ConsumeAuthorityToClientBits(uint32_t consumedBits)
|
||||
{
|
||||
if (ContainsAuthorityToClientBits())
|
||||
@@ -222,12 +194,6 @@ namespace Multiplayer
|
||||
}
|
||||
}
|
||||
|
||||
bool ReplicationRecord::ContainsAuthorityToAuthorityBits() const
|
||||
{
|
||||
return (m_netEntityRole == NetEntityRole::Authority)
|
||||
|| (m_netEntityRole == NetEntityRole::InvalidRole);
|
||||
}
|
||||
|
||||
bool ReplicationRecord::ContainsAuthorityToClientBits() const
|
||||
{
|
||||
return (m_netEntityRole != NetEntityRole::Authority)
|
||||
@@ -252,11 +218,6 @@ namespace Multiplayer
|
||||
|| (m_netEntityRole == NetEntityRole::InvalidRole);
|
||||
}
|
||||
|
||||
uint32_t ReplicationRecord::GetRemainingAuthorityToAuthorityBits() const
|
||||
{
|
||||
return m_authorityToAuthorityConsumedBits < m_authorityToAuthority.GetValidBitCount() ? m_authorityToAuthority.GetValidBitCount() - m_authorityToAuthorityConsumedBits : 0;
|
||||
}
|
||||
|
||||
uint32_t ReplicationRecord::GetRemainingAuthorityToClientBits() const
|
||||
{
|
||||
return m_authorityToClientConsumedBits < m_authorityToClient.GetValidBitCount() ? m_authorityToClient.GetValidBitCount() - m_authorityToClientConsumedBits : 0;
|
||||
@@ -281,7 +242,6 @@ namespace Multiplayer
|
||||
{
|
||||
return ReplicationRecordStats
|
||||
{
|
||||
m_authorityToAuthorityConsumedBits,
|
||||
m_authorityToClientConsumedBits,
|
||||
m_authorityToServerConsumedBits,
|
||||
m_authorityToAutonomousConsumedBits,
|
||||
|
||||
Reference in New Issue
Block a user