Fix 3-way replication for when an object migrates in rapid succession
Signed-off-by: kberg-amzn <karlberg@amazon.com>
This commit is contained in:
-1
@@ -57,7 +57,6 @@ namespace Multiplayer
|
||||
EntityReplicationManager(AzNetworking::IConnection& connection, AzNetworking::IConnectionListener& connectionListener, Mode mode);
|
||||
~EntityReplicationManager() = default;
|
||||
|
||||
void SetRemoteHostId(const HostId& hostId);
|
||||
const HostId& GetRemoteHostId() const;
|
||||
|
||||
void ActivatePendingEntities();
|
||||
|
||||
+1
-7
@@ -43,8 +43,7 @@ namespace Multiplayer
|
||||
//! Constructor for an entity delete message.
|
||||
//! @param entityId the networkId of the entity being deleted
|
||||
//! @param isMigrated whether or not the entity is being migrated or deleted
|
||||
//! @param takeOwnership true if the remote replicator should take ownership of the entity
|
||||
explicit NetworkEntityUpdateMessage(NetEntityId entityId, bool isMigrated, bool takeOwnership);
|
||||
explicit NetworkEntityUpdateMessage(NetEntityId entityId, bool isMigrated);
|
||||
|
||||
NetworkEntityUpdateMessage& operator =(NetworkEntityUpdateMessage&& rhs);
|
||||
NetworkEntityUpdateMessage& operator =(const NetworkEntityUpdateMessage& rhs);
|
||||
@@ -71,10 +70,6 @@ namespace Multiplayer
|
||||
//! @return whether or not the entity was migrated
|
||||
bool GetWasMigrated() const;
|
||||
|
||||
//! Gets the current value of TakeOwnership.
|
||||
//! @return the current value of TakeOwnership
|
||||
bool GetTakeOwnership() const;
|
||||
|
||||
//! Gets the current value of HasValidPrefabId.
|
||||
//! @return the current value of HasValidPrefabId
|
||||
bool GetHasValidPrefabId() const;
|
||||
@@ -110,7 +105,6 @@ namespace Multiplayer
|
||||
NetEntityId m_entityId = InvalidNetEntityId;
|
||||
bool m_isDelete = false;
|
||||
bool m_wasMigrated = false;
|
||||
bool m_takeOwnership = false;
|
||||
bool m_hasValidPrefabId = false;
|
||||
PrefabEntityId m_prefabEntityId;
|
||||
|
||||
|
||||
+3
-9
@@ -47,6 +47,9 @@ namespace Multiplayer
|
||||
, m_entityExitDomainEventHandler([this](const ConstNetworkEntityHandle& entityHandle) { OnEntityExitDomain(entityHandle); })
|
||||
, m_notifyEntityMigrationHandler([this](const ConstNetworkEntityHandle& entityHandle, const HostId& remoteHostId) { OnPostEntityMigration(entityHandle, remoteHostId); })
|
||||
{
|
||||
// Set up our remote host identifier, we use the IP address of the host
|
||||
m_remoteHostId = connection.GetRemoteAddress();
|
||||
|
||||
// Our max payload size is whatever is passed in, minus room for a udp packetheader
|
||||
m_maxPayloadSize = connection.GetConnectionMtu() - UdpPacketHeaderSerializeSize - ReplicationManagerPacketOverhead;
|
||||
|
||||
@@ -65,11 +68,6 @@ namespace Multiplayer
|
||||
GetMultiplayer()->AddNotifyEntityMigrationEventHandler(m_notifyEntityMigrationHandler);
|
||||
}
|
||||
|
||||
void EntityReplicationManager::SetRemoteHostId(const HostId& hostId)
|
||||
{
|
||||
m_remoteHostId = hostId;
|
||||
}
|
||||
|
||||
const HostId& EntityReplicationManager::GetRemoteHostId() const
|
||||
{
|
||||
return m_remoteHostId;
|
||||
@@ -516,10 +514,6 @@ namespace Multiplayer
|
||||
AZLOG(NET_RepDeletes, "Deleting replicater for entity id %u remote host %s", updateMessage.GetEntityId(), GetRemoteHostId().GetString().c_str());
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
shouldDeleteEntity = updateMessage.GetTakeOwnership();
|
||||
}
|
||||
|
||||
// Handle entity cleanup
|
||||
if (shouldDeleteEntity)
|
||||
|
||||
@@ -296,10 +296,10 @@ namespace Multiplayer
|
||||
bool EntityReplicator::OwnsReplicatorLifetime() const
|
||||
{
|
||||
bool ret(false);
|
||||
if (GetBoundLocalNetworkRole() == NetEntityRole::Authority
|
||||
|| (GetBoundLocalNetworkRole() == NetEntityRole::Server
|
||||
if (GetBoundLocalNetworkRole() == NetEntityRole::Authority // Authority always owns lifetime
|
||||
|| (GetBoundLocalNetworkRole() == NetEntityRole::Server // Server also owns lifetime if the remote endpoint is a client of some form
|
||||
&& (GetRemoteNetworkRole() == NetEntityRole::Client
|
||||
|| GetRemoteNetworkRole() == NetEntityRole::Autonomous)))
|
||||
|| GetRemoteNetworkRole() == NetEntityRole::Autonomous)))
|
||||
{
|
||||
ret = true;
|
||||
}
|
||||
@@ -309,10 +309,9 @@ namespace Multiplayer
|
||||
bool EntityReplicator::RemoteManagerOwnsEntityLifetime() const
|
||||
{
|
||||
bool isServer = (GetBoundLocalNetworkRole() == NetEntityRole::Server)
|
||||
&& (GetRemoteNetworkRole() == NetEntityRole::Authority);
|
||||
&& (GetRemoteNetworkRole() == NetEntityRole::Authority);
|
||||
bool isClient = (GetBoundLocalNetworkRole() == NetEntityRole::Client)
|
||||
|| (GetBoundLocalNetworkRole() == NetEntityRole::Autonomous);
|
||||
|
||||
|| (GetBoundLocalNetworkRole() == NetEntityRole::Autonomous);
|
||||
return isServer || isClient;
|
||||
}
|
||||
|
||||
@@ -477,14 +476,14 @@ namespace Multiplayer
|
||||
WasMigrated() ? 1 : 0,
|
||||
m_replicationManager.GetRemoteHostId().GetString().c_str()
|
||||
);
|
||||
return NetworkEntityUpdateMessage(GetEntityHandle().GetNetEntityId(), WasMigrated(), m_propertyPublisher->IsRemoteReplicatorEstablished());
|
||||
return NetworkEntityUpdateMessage(GetEntityHandle().GetNetEntityId(), WasMigrated());
|
||||
}
|
||||
|
||||
NetBindComponent* netBindComponent = GetNetBindComponent();
|
||||
//const bool sendSliceName = !m_propertyPublisher->IsRemoteReplicatorEstablished();
|
||||
const bool sendSliceName = !m_propertyPublisher->IsRemoteReplicatorEstablished();
|
||||
|
||||
NetworkEntityUpdateMessage updateMessage(GetRemoteNetworkRole(), GetEntityHandle().GetNetEntityId());
|
||||
//if (sendSliceName)
|
||||
if (sendSliceName)
|
||||
{
|
||||
updateMessage.SetPrefabEntityId(netBindComponent->GetPrefabEntityId());
|
||||
}
|
||||
|
||||
@@ -18,7 +18,6 @@ namespace Multiplayer
|
||||
, m_entityId(rhs.m_entityId)
|
||||
, m_isDelete(rhs.m_isDelete)
|
||||
, m_wasMigrated(rhs.m_wasMigrated)
|
||||
, m_takeOwnership(rhs.m_takeOwnership)
|
||||
, m_hasValidPrefabId(rhs.m_hasValidPrefabId)
|
||||
, m_prefabEntityId(rhs.m_prefabEntityId)
|
||||
, m_data(AZStd::move(rhs.m_data))
|
||||
@@ -31,7 +30,6 @@ namespace Multiplayer
|
||||
, m_entityId(rhs.m_entityId)
|
||||
, m_isDelete(rhs.m_isDelete)
|
||||
, m_wasMigrated(rhs.m_wasMigrated)
|
||||
, m_takeOwnership(rhs.m_takeOwnership)
|
||||
, m_hasValidPrefabId(rhs.m_hasValidPrefabId)
|
||||
, m_prefabEntityId(rhs.m_prefabEntityId)
|
||||
{
|
||||
@@ -58,11 +56,10 @@ namespace Multiplayer
|
||||
;
|
||||
}
|
||||
|
||||
NetworkEntityUpdateMessage::NetworkEntityUpdateMessage(NetEntityId entityId, bool wasMigrated, bool takeOwnership)
|
||||
NetworkEntityUpdateMessage::NetworkEntityUpdateMessage(NetEntityId entityId, bool wasMigrated)
|
||||
: m_entityId(entityId)
|
||||
, m_isDelete(true)
|
||||
, m_wasMigrated(wasMigrated)
|
||||
, m_takeOwnership(takeOwnership)
|
||||
{
|
||||
// this is a delete entity message c-tor
|
||||
}
|
||||
@@ -73,7 +70,6 @@ namespace Multiplayer
|
||||
m_entityId = rhs.m_entityId;
|
||||
m_isDelete = rhs.m_isDelete;
|
||||
m_wasMigrated = rhs.m_wasMigrated;
|
||||
m_takeOwnership = rhs.m_takeOwnership;
|
||||
m_hasValidPrefabId = rhs.m_hasValidPrefabId;
|
||||
m_prefabEntityId = rhs.m_prefabEntityId;
|
||||
m_data = AZStd::move(rhs.m_data);
|
||||
@@ -86,7 +82,6 @@ namespace Multiplayer
|
||||
m_entityId = rhs.m_entityId;
|
||||
m_isDelete = rhs.m_isDelete;
|
||||
m_wasMigrated = rhs.m_wasMigrated;
|
||||
m_takeOwnership = rhs.m_takeOwnership;
|
||||
m_hasValidPrefabId = rhs.m_hasValidPrefabId;
|
||||
m_prefabEntityId = rhs.m_prefabEntityId;
|
||||
if (rhs.m_data != nullptr)
|
||||
@@ -104,7 +99,6 @@ namespace Multiplayer
|
||||
&& (m_entityId == rhs.m_entityId)
|
||||
&& (m_isDelete == rhs.m_isDelete)
|
||||
&& (m_wasMigrated == rhs.m_wasMigrated)
|
||||
&& (m_takeOwnership == rhs.m_takeOwnership)
|
||||
&& (m_hasValidPrefabId == rhs.m_hasValidPrefabId)
|
||||
&& (m_prefabEntityId == rhs.m_prefabEntityId));
|
||||
}
|
||||
@@ -160,11 +154,6 @@ namespace Multiplayer
|
||||
return m_wasMigrated;
|
||||
}
|
||||
|
||||
bool NetworkEntityUpdateMessage::GetTakeOwnership() const
|
||||
{
|
||||
return m_takeOwnership;
|
||||
}
|
||||
|
||||
bool NetworkEntityUpdateMessage::GetHasValidPrefabId() const
|
||||
{
|
||||
return m_hasValidPrefabId;
|
||||
@@ -210,17 +199,15 @@ namespace Multiplayer
|
||||
serializer.Serialize(m_entityId, "EntityId");
|
||||
|
||||
// Use the upper 4 bits for boolean flags, and the lower 4 bits for the network role
|
||||
uint8_t networkTypeAndFlags = (m_isDelete ? 0x80 : 0x00)
|
||||
| (m_wasMigrated ? 0x40 : 0x00)
|
||||
| (m_takeOwnership ? 0x20 : 0x00)
|
||||
uint8_t networkTypeAndFlags = (m_isDelete ? 0x40 : 0x00)
|
||||
| (m_wasMigrated ? 0x20 : 0x00)
|
||||
| (m_hasValidPrefabId ? 0x10 : 0x00)
|
||||
| static_cast<uint8_t>(m_networkRole);
|
||||
|
||||
if (serializer.Serialize(networkTypeAndFlags, "TypeAndFlags"))
|
||||
{
|
||||
m_isDelete = (networkTypeAndFlags & 0x80) == 0x80;
|
||||
m_wasMigrated = (networkTypeAndFlags & 0x40) == 0x40;
|
||||
m_takeOwnership = (networkTypeAndFlags & 0x20) == 0x20;
|
||||
m_isDelete = (networkTypeAndFlags & 0x40) == 0x40;
|
||||
m_wasMigrated = (networkTypeAndFlags & 0x20) == 0x20;
|
||||
m_hasValidPrefabId = (networkTypeAndFlags & 0x10) == 0x10;
|
||||
m_networkRole = static_cast<NetEntityRole>(networkTypeAndFlags & 0x0F);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user