Some cleanup around handling of migrations to simplify interfaces and add additional hooks for functionality

Signed-off-by: kberg-amzn <karlberg@amazon.com>
This commit is contained in:
kberg-amzn
2021-11-03 19:34:10 -07:00
parent 70a1eb65d8
commit 8a3d055f8b
13 changed files with 194 additions and 116 deletions
@@ -17,8 +17,6 @@ namespace Multiplayer
class IEntityDomain
{
public:
using EntitiesNotInDomain = AZStd::unordered_set<NetEntityId>;
virtual ~IEntityDomain() = default;
//! For domains that operate on a region of space, this sets the area the domain is responsible for.
@@ -34,12 +32,10 @@ namespace Multiplayer
//! @return false if this entity should not belong to the entity manger, true if it could be owned by the entity manager
virtual bool IsInDomain(const ConstNetworkEntityHandle& entityHandle) const = 0;
//! Enable Entity Domain Exit Tracking for entities on the host.
//! @param ownedEntitySet the set of entities to activate tracking for
virtual void ActivateTracking(const INetworkEntityManager::OwnedEntitySet& ownedEntitySet) = 0;
//! Return the set of netbound entities not included in this domain.
virtual const EntitiesNotInDomain& RetrieveEntitiesNotInDomain() const = 0;
//! This method will be invoked whenever we unexpectedly lose the authoritative entity replicator for an entity.
//! This gives our entity domain a chance to determine whether or not it should assume authority in this instance.
//! @param entityHandle the network entity handle of the entity that has lost it's authoritative replicator
virtual void HandleLossOfAuthoritativeReplicator(const ConstNetworkEntityHandle& entityHandle) = 0;
//! Debug draw to visualize host entity domains.
virtual void DebugDraw() const = 0;
@@ -26,6 +26,7 @@ namespace Multiplayer
using EntityExitDomainEvent = AZ::Event<const ConstNetworkEntityHandle&>;
using ControllersActivatedEvent = AZ::Event<const ConstNetworkEntityHandle&, EntityIsMigrating>;
using ControllersDeactivatedEvent = AZ::Event<const ConstNetworkEntityHandle&, EntityIsMigrating>;
using NetEntityIdSet = AZStd::unordered_set<NetEntityId>;
//! @class INetworkEntityManager
//! @brief The interface for managing all networked entities.
@@ -34,18 +35,17 @@ namespace Multiplayer
public:
AZ_RTTI(INetworkEntityManager, "{109759DE-9492-439C-A0B1-AE46E6FD029C}");
using OwnedEntitySet = AZStd::unordered_set<ConstNetworkEntityHandle>;
using EntityList = AZStd::vector<NetworkEntityHandle>;
virtual ~INetworkEntityManager() = default;
//! Configures the NetworkEntityManager to operate as an authoritative host.
//! @param hostId the hostId of this NetworkEntityManager
//! Configures the NetworkEntityManager.
//! @param hostId the hostId of this NetworkEntityManager (invalid for clients)
//! @param entityDomain the entity domain used to determine which entities this manager has authority over
virtual void Initialize(const HostId& hostId, AZStd::unique_ptr<IEntityDomain> entityDomain) = 0;
//! Returns whether or not the network entity manager has been initialized to host.
//! @return boolean true if this network entity manager has been intialized to host
//! Returns whether or not the network entity manager has been initialized.
//! @return boolean true if this network entity manager has been intialized
virtual bool IsInitialized() const = 0;
//! Returns the entity domain associated with this network entity manager, this will be nullptr on clients.
@@ -181,6 +181,19 @@ namespace Multiplayer
//! @param entityRpcMessage the local rpc message to handle
virtual void HandleLocalRpcMessage(NetworkEntityRpcMessage& message) = 0;
//! Handles a set of entities transitioning between entity domains.
//! @param entitiesNotInDomain the set of entities that are no longer contained within our entity domain
virtual void HandleEntitiesExitDomain(const NetEntityIdSet& entitiesNotInDomain) = 0;
//! Forcibly assumes authoritative control over the given entity.
//! This should only be used in the event of the unexpected loss of the previous authority, any other usage could corrupt the simulation.
//! @param entityHandle the entity to forcibly assume authoritative control over
virtual void ForceAssumeAuthority(const ConstNetworkEntityHandle& entityHandle) = 0;
//! Overrides the default timeout time used during entity migrations.
//! @param timeoutTimeMs the timeout time to use in milliseconds
virtual void SetMigrateTimeoutTimeMs(AZ::TimeMs timeoutTimeMs) = 0;
//! Visualization of network entity manager state.
virtual void DebugDraw() const = 0;
};