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
@@ -13,10 +13,12 @@
#include <AzCore/Math/ShapeIntersection.h>
#include <AzFramework/Visibility/IVisibilitySystem.h>
#include <AzFramework/Visibility/EntityBoundsUnionBus.h>
#include <AzFramework/Entity/EntityDebugDisplayBus.h>
namespace Multiplayer
{
AZ_CVAR(float, sv_RewindVolumeExtrudeDistance, 50.0f, nullptr, AZ::ConsoleFunctorFlags::Null, "The amount to increase rewind volume checks to account for fast moving entities");
AZ_CVAR(bool, bg_RewindDebugDraw, false, nullptr, AZ::ConsoleFunctorFlags::Null, "If true enables debug draw of rewind operations");
NetworkTime::NetworkTime()
{
@@ -94,21 +96,46 @@ namespace Multiplayer
// Since the vis system doesn't support rewound queries, first query with an expanded volume to catch any fast moving entities
const AZ::Aabb expandedVolume = rewindVolume.GetExpanded(AZ::Vector3(sv_RewindVolumeExtrudeDistance));
AzFramework::IEntityBoundsUnion* entityBoundsUnion = AZ::Interface<AzFramework::IEntityBoundsUnion>::Get();
AZStd::vector<NetBindComponent*> gatheredEntities;
AZ::Interface<AzFramework::IVisibilitySystem>::Get()->GetDefaultVisibilityScene()->Enumerate(expandedVolume,
[entityBoundsUnion, rewindVolume, &gatheredEntities](const AzFramework::IVisibilityScene::NodeData& nodeData)
AzFramework::DebugDisplayRequests* debugDisplay = nullptr;
if (bg_RewindDebugDraw)
{
gatheredEntities.reserve(gatheredEntities.size() + nodeData.m_entries.size());
AzFramework::DebugDisplayRequestBus::BusPtr debugDisplayBus;
AzFramework::DebugDisplayRequestBus::Bind(debugDisplayBus, AzFramework::g_defaultSceneEntityDebugDisplayId);
debugDisplay = AzFramework::DebugDisplayRequestBus::FindFirstHandler(debugDisplayBus);
}
if (debugDisplay)
{
debugDisplay->SetColor(AZ::Colors::Red);
debugDisplay->DrawWireBox(expandedVolume.GetMin(), expandedVolume.GetMax());
}
NetworkEntityTracker* networkEntityTracker = GetNetworkEntityTracker();
AzFramework::IEntityBoundsUnion* entityBoundsUnion = AZ::Interface<AzFramework::IEntityBoundsUnion>::Get();
AZ::Interface<AzFramework::IVisibilitySystem>::Get()->GetDefaultVisibilityScene()->Enumerate(expandedVolume,
[this, debugDisplay, networkEntityTracker, entityBoundsUnion, rewindVolume](const AzFramework::IVisibilityScene::NodeData& nodeData)
{
m_rewoundEntities.reserve(m_rewoundEntities.size() + nodeData.m_entries.size());
for (AzFramework::VisibilityEntry* visEntry : nodeData.m_entries)
{
if (visEntry->m_typeFlags & AzFramework::VisibilityEntry::TypeFlags::TYPE_Entity)
{
AZ::Entity* entity = static_cast<AZ::Entity*>(visEntry->m_userData);
NetworkEntityHandle entityHandle(entity, networkEntityTracker);
if (entityHandle.GetNetBindComponent() == nullptr)
{
// Not a net-bound entity, terminate processing of this entity
return;
}
const AZ::Aabb currentBounds = entityBoundsUnion->GetEntityWorldBoundsUnion(entity->GetId());
const AZ::Vector3 currentCenter = currentBounds.GetCenter();
NetworkTransformComponent* networkTransform = entity->template FindComponent<NetworkTransformComponent>();
if (debugDisplay)
{
debugDisplay->SetColor(AZ::Colors::White);
debugDisplay->DrawWireBox(currentBounds.GetMin(), currentBounds.GetMax());
}
if (networkTransform != nullptr)
{
@@ -123,24 +150,20 @@ namespace Multiplayer
}
const AZ::Vector3 rewindOffset = rewindCenter - currentCenter; // Compute offset between rewound and current positions
const AZ::Aabb rewoundAabb = currentBounds.GetTranslated(rewindOffset); // Apply offset to the entity aabb
if (debugDisplay)
{
debugDisplay->SetColor(AZ::Colors::Grey);
debugDisplay->DrawWireBox(rewoundAabb.GetMin(), rewoundAabb.GetMax());
}
if (AZ::ShapeIntersection::Overlaps(rewoundAabb, rewindVolume)) // Validate the rewound aabb intersects our rewind volume
{
// Due to component constraints, netBindComponent must exist if networkTransform exists
NetBindComponent* netBindComponent = entity->template FindComponent<NetBindComponent>();
gatheredEntities.push_back(netBindComponent);
m_rewoundEntities.push_back(entityHandle);
}
}
}
}
});
NetworkEntityTracker* networkEntityTracker = GetNetworkEntityTracker();
for (NetBindComponent* netBindComponent : gatheredEntities)
{
netBindComponent->NotifySyncRewindState();
m_rewoundEntities.push_back(NetworkEntityHandle(netBindComponent, networkEntityTracker));
}
}
void NetworkTime::ClearRewoundEntities()