Integrating github/staging through commit ab87ed9

This commit is contained in:
alexpete
2021-04-09 11:27:37 -07:00
parent ae62a97894
commit 1044dc3da1
1582 changed files with 29374 additions and 519051 deletions
@@ -138,7 +138,7 @@ namespace Multiplayer
gatheredEntries.reserve(gatheredEntries.size() + nodeData.m_entries.size());
for (AzFramework::VisibilityEntry* visEntry : nodeData.m_entries)
{
if (visEntry->m_typeFlags & AzFramework::VisibilityEntry::TypeFlags::TYPE_NetEntity)
if (visEntry->m_typeFlags & AzFramework::VisibilityEntry::TypeFlags::TYPE_Entity)
{
gatheredEntries.push_back(visEntry);
}
@@ -149,6 +149,8 @@ namespace Multiplayer
// Add all the neighbors
for (AzFramework::VisibilityEntry* visEntry : gatheredEntries)
{
// TODO: Discard entities that don't have a NetBindComponent
//if (mp_ControlledFilteredEntityComponent && mp_ControlledFilteredEntityComponent->IsEntityFiltered(iterator.Get()))
//{
// continue;
@@ -1,141 +0,0 @@
/*
* 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/ReplicationWindows/ServerToServerReplicationWindow.h>
#include <Source/Components/NetBindComponent.h>
#include <AzFramework/Visibility/IVisibilitySystem.h>
#include <AzCore/Component/TransformBus.h>
#include <AzCore/Console/ILogger.h>
namespace Multiplayer
{
AZ_CVAR(float, sv_ReplicationWindowWidth, 100.0f, nullptr, AZ::ConsoleFunctorFlags::Null, "This is the additional area around the non-overlapping map region over which the server should replicate entities");
AZ_CVAR(AZ::TimeMs, sv_ServerReplicationWindowUpdateMs, AZ::TimeMs{ 300 }, nullptr, AZ::ConsoleFunctorFlags::Null, "Rate for replication window updates.");
ServerToServerReplicationWindow::ServerToServerReplicationWindow(const AZ::Aabb& aabb)
: m_aabb(aabb)
, m_updateWindowEvent([this]() { UpdateWindow(); }, AZ::Name("Server to server replication window update event"))
, m_controllersActivatedHandler([this](const ConstNetworkEntityHandle& entityHandle, EntityIsMigrating entityIsMigrating) { OnControllersActivated(entityHandle, entityIsMigrating); })
, m_controllersDeactivatedHandler([this](const ConstNetworkEntityHandle& entityHandle, EntityIsMigrating entityIsMigrating) { OnControllersDeactivated(entityHandle, entityIsMigrating); })
{
m_aabb.Expand(AZ::Vector3(sv_ReplicationWindowWidth, sv_ReplicationWindowWidth, sv_ReplicationWindowWidth));
m_updateWindowEvent.Enqueue(sv_ServerReplicationWindowUpdateMs, true);
GetNetworkEntityManager()->AddControllersActivatedHandler(m_controllersActivatedHandler);
GetNetworkEntityManager()->AddControllersDeactivatedHandler(m_controllersDeactivatedHandler);
}
bool ServerToServerReplicationWindow::ReplicationSetUpdateReady()
{
return m_initialGatherComplete;
}
const ReplicationSet& ServerToServerReplicationWindow::GetReplicationSet() const
{
return m_replicationSet;
}
uint32_t ServerToServerReplicationWindow::GetMaxEntityReplicatorSendCount() const
{
return AZStd::numeric_limits<uint32_t>::max();
}
bool ServerToServerReplicationWindow::IsInWindow(const ConstNetworkEntityHandle& entityHandle, NetEntityRole& outNetworkRole) const
{
outNetworkRole = NetEntityRole::InvalidRole;
NetBindComponent* netBindComponent = entityHandle.GetNetBindComponent();
if (netBindComponent != nullptr)
{
NetEntityRole networkRole = netBindComponent->GetNetEntityRole();
if (networkRole == NetEntityRole::Authority)
{
const AZ::Entity* entity = entityHandle.GetEntity();
AZ::TransformInterface* transformInterface = entity->GetTransform();
AZ::Vector3 entityPosition = transformInterface->GetWorldTranslation();
if (m_aabb.Contains(entityPosition))
{
outNetworkRole = Multiplayer::NetEntityRole::Server;
return true;
}
}
}
return false;
}
void ServerToServerReplicationWindow::UpdateWindow()
{
m_initialGatherComplete = true; // Auto updates bootstrapped
m_replicationSet.clear();
AZ::Interface<AzFramework::IVisibilitySystem>::Get()->Enumerate(m_aabb, [this](const AzFramework::IVisibilitySystem::NodeData& nodeData)
{
for (AzFramework::VisibilityEntry* visEntry : nodeData.m_entries)
{
if (visEntry->m_typeFlags & AzFramework::VisibilityEntry::TypeFlags::TYPE_NetEntity)
{
ConstNetworkEntityHandle entityHandle = ConstNetworkEntityHandle(static_cast<AZ::Entity*>(visEntry->m_userData), GetNetworkEntityTracker());
NetBindComponent* netBindComponent = entityHandle.GetNetBindComponent();
if (netBindComponent != nullptr)
{
NetEntityRole networkRole = netBindComponent->GetNetEntityRole();
if (networkRole == NetEntityRole::Authority)
{
m_replicationSet[entityHandle] = { NetEntityRole::Server, 0.0f }; // Note, server replication does not use priority
}
}
}
}
}
);
}
void ServerToServerReplicationWindow::DebugDraw() const
{
static const float BoundaryStripeHeight = 1.0f;
static const float BoundaryStripeSpacing = 0.5f;
static const int32_t BoundaryStripeCount = 10;
//auto* loc = draw.GetOwnerConst()->FindComponent<LocationComponent::Server>();
//if (loc == nullptr)
//{
// return;
//}
//
//Vec3 dmnMin = m_ReplicationWindowParams.GetMin();
//Vec3 dmnMax = m_ReplicationWindowParams.GetMax();
//
//dmnMin.z = loc->GetPosition().z;
//dmnMax.z = dmnMin.z + k_BoundaryStripeHeight;
//
//for (int i = 0; i < k_BoundaryStripeCount; ++i)
//{
// draw.AABB(dmnMin, dmnMax, DebugColors::green);
// dmnMin.z += k_BoundaryStripeSpacing;
// dmnMax.z += k_BoundaryStripeSpacing;
//}
}
void ServerToServerReplicationWindow::OnControllersActivated(const ConstNetworkEntityHandle& entityHandle, [[maybe_unused]] EntityIsMigrating entityIsMigrating)
{
NetEntityRole networkRole = NetEntityRole::InvalidRole;
if (IsInWindow(entityHandle, networkRole))
{
m_replicationSet[entityHandle] = { NetEntityRole::Server, 0.0f };
}
}
void ServerToServerReplicationWindow::OnControllersDeactivated(const ConstNetworkEntityHandle& entityHandle, [[maybe_unused]] EntityIsMigrating entityIsMigrating)
{
m_replicationSet.erase(entityHandle);
}
}
@@ -1,57 +0,0 @@
/*
* 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/ReplicationWindows/IReplicationWindow.h>
#include <Source/NetworkEntity/NetworkEntityHandle.h>
#include <Source/NetworkEntity/INetworkEntityManager.h>
#include <AzNetworking/ConnectionLayer/IConnection.h>
#include <AzCore/Math/Aabb.h>
#include <AzCore/EBus/ScheduledEvent.h>
#include <AzCore/Console/IConsole.h>
#include <AzCore/std/smart_ptr/unique_ptr.h>
namespace Multiplayer
{
class ServerToServerReplicationWindow
: public IReplicationWindow
{
public:
ServerToServerReplicationWindow(const AZ::Aabb& aabb);
//! IReplicationWindow interface
//! @{
bool ReplicationSetUpdateReady() override;
const ReplicationSet& GetReplicationSet() const override;
uint32_t GetMaxEntityReplicatorSendCount() const override;
bool IsInWindow(const ConstNetworkEntityHandle& entityPtr, NetEntityRole& outNetworkRole) const override;
void UpdateWindow() override;
void DebugDraw() const override;
//! @}
private:
void OnControllersActivated(const ConstNetworkEntityHandle& entityHandle, EntityIsMigrating entityIsMigrating);
void OnControllersDeactivated(const ConstNetworkEntityHandle& entityHandle, EntityIsMigrating entityIsMigrating);
ServerToServerReplicationWindow& operator=(const ServerToServerReplicationWindow&) = delete;
ReplicationSet m_replicationSet;
AZ::ScheduledEvent m_updateWindowEvent;
ControllersActivatedEvent::Handler m_controllersActivatedHandler;
ControllersDeactivatedEvent::Handler m_controllersDeactivatedHandler;
AZ::Aabb m_aabb;
bool m_initialGatherComplete = false; // Replication window need to run an initial gather on connection
};
}