IFilterEntityManager work

Signed-off-by: AMZN-Olex <5432499+AMZN-Olex@users.noreply.github.com>
This commit is contained in:
AMZN-Olex
2021-06-30 17:28:55 -04:00
parent bafcdfe037
commit d7bfd34a67
7 changed files with 91 additions and 26 deletions
@@ -10,6 +10,7 @@
#include <AzCore/RTTI/RTTI.h>
#include <AzNetworking/ConnectionLayer/IConnection.h>
#include <AzNetworking/DataStructures/ByteBuffer.h>
#include <Multiplayer/NetworkEntity/IFilterEntityManager.h>
#include <Multiplayer/Components/MultiplayerComponentRegistry.h>
#include <Multiplayer/NetworkEntity/INetworkEntityManager.h>
#include <Multiplayer/NetworkTime/INetworkTime.h>
@@ -128,6 +129,15 @@ namespace Multiplayer
//! @return pointer to the network entity manager instance bound to this multiplayer instance
virtual INetworkEntityManager* GetNetworkEntityManager() = 0;
//! Sets user-defined filtering manager for entities.
//! This allows selectively choosing which entities to replicate on a per client connection.
//! See IFilterEntityManager for details.
//! @param entityFilter non-owning pointer, the caller is responsible for memory management.
virtual void SetFilterEntityManager(IFilterEntityManager* entityFilter) = 0;
//! @return pointer to the user-defined filtering manager of entities. By default, this isn't set and returns nullptr.
virtual IFilterEntityManager* GetFilterEntityManager() = 0;
//! Retrieve the stats object bound to this multiplayer instance.
//! @return the stats object bound to this multiplayer instance
MultiplayerStats& GetStats() { return m_stats; }
@@ -0,0 +1,48 @@
/*
* Copyright (c) Contributors to the Open 3D Engine Project
*
* SPDX-License-Identifier: Apache-2.0 OR MIT
*
*/
#pragma once
#include <AzNetworking/ConnectionLayer/IConnection.h>
#include <Multiplayer/NetworkEntity/NetworkEntityHandle.h>
namespace Multiplayer
{
//! @class IFilterEntityManager
//! @brief IFilterEntityManager provides an interface for filtering entities out from replication down to clients.
//!
//! By default, all entities with NetBindComponent on them are replicated to all clients.
//! (There is a built-in distance filtering, where only entities within vicinity of a player are sent to that player.
//! This is controlled by sv_ClientAwarenessRadius AZ_CVAR variable.)
//!
//! There are use cases where you want to limit the entities sent to a client, for example "fog of war" or
//! "out of line of sight" anti-cheating mechanic by omitting information clients should not have access to.
//!
//! By implementing IFilterEntityManager interface and setting it on GetMultiplayer()->SetFilterEntityManager()
//! entities can be filtered by IsEntityFiltered(...) returning true.
//!
//! Note: one cannot filter out entities in Level prefab (spawned by LoadLevel console command). Level prefabs are fully
//! spawned on each client. Filtering of entities is applied to dynamically spawned prefabs, and specifically
//! entities must have NetBindComponent on them.
class IFilterEntityManager
{
public:
AZ_RTTI(IFilterEntityManager, "{91F879F2-3DAF-43B8-B474-B312D26C0F48}");
virtual ~IFilterEntityManager() = default;
//! Return true if a given entity should be filtered out, false otherwise.
//! Important: this method is a hot code path, it will be called over all entities around each player frequently.
//! Ideally, this method should be implemented as a quick look up.
//!
//! @param entity the entity to be considered for filtering
//! @param controllerEntity player's entity for the associated connection
//! @param connectionId the affected connection should the entity be filtered out.
//! @return if false the given entity will be not be replicated to the connection
virtual bool IsEntityFiltered(AZ::Entity* entity, ConstNetworkEntityHandle controllerEntity, AzNetworking::ConnectionId connectionId) = 0;
};
}