Entity migrations now totally functional again, plus some fixes to network rigid bodies to make them work properly as they migrate around

Signed-off-by: kberg-amzn <karlberg@amazon.com>
This commit is contained in:
kberg-amzn
2021-09-30 22:53:51 -07:00
parent 02bc89cd92
commit 8d993494f6
27 changed files with 277 additions and 155 deletions
@@ -107,7 +107,7 @@ namespace Multiplayer
void ServerToClientReplicationWindow::UpdateWindow()
{
// clear the candidate queue, we're going to rebuild it
// Clear the candidate queue, we're going to rebuild it
ReplicationCandidateQueue::container_type clearQueueContainer;
clearQueueContainer.reserve(sv_MaxEntitiesToTrackReplication);
// Move the clearQueueContainer into the ReplicationCandidateQueue to maintain the reserved memory
@@ -118,7 +118,7 @@ namespace Multiplayer
NetBindComponent* netBindComponent = m_controlledEntity.GetNetBindComponent();
if (!netBindComponent || !netBindComponent->HasController())
{
// if we don't have a controlled entity, or we no longer have control of the entity, don't run the update
// If we don't have a controlled entity, or we no longer have control of the entity, don't run the update
return;
}
@@ -149,24 +149,25 @@ namespace Multiplayer
for (AzFramework::VisibilityEntry* visEntry : gatheredEntries)
{
AZ::Entity* entity = static_cast<AZ::Entity*>(visEntry->m_userData);
NetworkEntityHandle entityHandle(entity, networkEntityTracker);
if (entityHandle.GetNetBindComponent() == nullptr)
{
// Entity does not have netbinding, skip this entity
continue;
}
if (filterEntityManager && filterEntityManager->IsEntityFiltered(entity, m_controlledEntity, m_connection->GetConnectionId()))
{
continue;
}
NetBindComponent* entryNetBindComponent = entity->template FindComponent<NetBindComponent>();
if (entryNetBindComponent != nullptr)
{
// We want to find the closest extent to the player and prioritize using that distance
const AZ::Vector3 supportNormal = controlledEntityPosition - visEntry->m_boundingVolume.GetCenter();
const AZ::Vector3 closestPosition = visEntry->m_boundingVolume.GetSupport(supportNormal);
const float gatherDistanceSquared = controlledEntityPosition.GetDistanceSq(closestPosition);
const float priority = (gatherDistanceSquared > 0.0f) ? 1.0f / gatherDistanceSquared : 0.0f;
NetworkEntityHandle entityHandle(entryNetBindComponent, networkEntityTracker);
AddEntityToReplicationSet(entityHandle, priority, gatherDistanceSquared);
}
// We want to find the closest extent to the player and prioritize using that distance
const AZ::Vector3 supportNormal = controlledEntityPosition - visEntry->m_boundingVolume.GetCenter();
const AZ::Vector3 closestPosition = visEntry->m_boundingVolume.GetSupport(supportNormal);
const float gatherDistanceSquared = controlledEntityPosition.GetDistanceSq(closestPosition);
const float priority = (gatherDistanceSquared > 0.0f) ? 1.0f / gatherDistanceSquared : 0.0f;
AddEntityToReplicationSet(entityHandle, priority, gatherDistanceSquared);
}
// Add in Autonomous Entities
@@ -228,11 +229,10 @@ namespace Multiplayer
void ServerToClientReplicationWindow::OnEntityActivated(AZ::Entity* entity)
{
NetBindComponent* netBindComponent = entity->FindComponent<NetBindComponent>();
ConstNetworkEntityHandle entityHandle(entity);
NetBindComponent* netBindComponent = entityHandle.GetNetBindComponent();
if (netBindComponent != nullptr)
{
ConstNetworkEntityHandle entityHandle(netBindComponent, GetNetworkEntityTracker());
if (netBindComponent->HasController())
{
if (IFilterEntityManager* filter = GetMultiplayer()->GetFilterEntityManager())
@@ -261,10 +261,9 @@ namespace Multiplayer
void ServerToClientReplicationWindow::OnEntityDeactivated(AZ::Entity* entity)
{
NetBindComponent* netBindComponent = entity->FindComponent<NetBindComponent>();
if (netBindComponent != nullptr)
ConstNetworkEntityHandle entityHandle(entity);
if (entityHandle.GetNetBindComponent() != nullptr)
{
ConstNetworkEntityHandle entityHandle(netBindComponent, GetNetworkEntityTracker());
m_replicationSet.erase(entityHandle);
}
}