Integrating github/staging through commit ab87ed9
This commit is contained in:
@@ -1,66 +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/EntityDomains/GlobalEntityDomain.h>
|
||||
|
||||
namespace Multiplayer
|
||||
{
|
||||
GlobalEntityDomain::GlobalEntityDomain()
|
||||
: m_controllersActivatedHandler([this](const ConstNetworkEntityHandle& entityHandle, EntityIsMigrating entityIsMigrating) { OnControllersActivated(entityHandle, entityIsMigrating); })
|
||||
, m_controllersDeactivatedHandler([this](const ConstNetworkEntityHandle& entityHandle, EntityIsMigrating entityIsMigrating) { OnControllersDeactivated(entityHandle, entityIsMigrating); })
|
||||
{
|
||||
;
|
||||
}
|
||||
|
||||
bool GlobalEntityDomain::IsInDomain([[maybe_unused]] const ConstNetworkEntityHandle& entityHandle) const
|
||||
{
|
||||
//if (const GlobalAccessComponent* globalAccessComp = entityHandle->FindComponent<GlobalAccessComponent>())
|
||||
//{
|
||||
// return globalAccessComp->GetPropagationMode() == PropagationMode::GlobalResidency;
|
||||
//}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
void GlobalEntityDomain::ActivateTracking(const INetworkEntityManager::OwnedEntitySet& ownedEntitySet)
|
||||
{
|
||||
for (auto& entityHandle : ownedEntitySet)
|
||||
{
|
||||
OnControllersActivated(entityHandle, EntityIsMigrating::False);
|
||||
}
|
||||
GetNetworkEntityManager()->AddControllersActivatedHandler(m_controllersActivatedHandler);
|
||||
GetNetworkEntityManager()->AddControllersDeactivatedHandler(m_controllersDeactivatedHandler);
|
||||
}
|
||||
|
||||
void GlobalEntityDomain::RetrieveEntitiesNotInDomain(EntitiesNotInDomain& outEntitiesNotInDomain) const
|
||||
{
|
||||
outEntitiesNotInDomain.insert(m_entitiesNotInDomain.begin(), m_entitiesNotInDomain.end());
|
||||
}
|
||||
|
||||
void GlobalEntityDomain::DebugDraw() const
|
||||
{
|
||||
// Nothing to draw
|
||||
}
|
||||
|
||||
void GlobalEntityDomain::OnControllersActivated(const ConstNetworkEntityHandle& entityHandle, [[maybe_unused]] EntityIsMigrating entityIsMigrating)
|
||||
{
|
||||
if (!IsInDomain(entityHandle))
|
||||
{
|
||||
m_entitiesNotInDomain.insert(entityHandle.GetNetEntityId());
|
||||
}
|
||||
}
|
||||
|
||||
void GlobalEntityDomain::OnControllersDeactivated(const ConstNetworkEntityHandle& entityHandle, [[maybe_unused]] EntityIsMigrating entityIsMigrating)
|
||||
{
|
||||
m_entitiesNotInDomain.erase(entityHandle.GetNetEntityId());
|
||||
}
|
||||
}
|
||||
@@ -1,41 +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/EntityDomains/IEntityDomain.h>
|
||||
|
||||
namespace Multiplayer
|
||||
{
|
||||
class GlobalEntityDomain
|
||||
: public IEntityDomain
|
||||
{
|
||||
public:
|
||||
GlobalEntityDomain();
|
||||
|
||||
//! IEntityDomain overrides.
|
||||
//! @{
|
||||
bool IsInDomain(const ConstNetworkEntityHandle& entityHandle) const override;
|
||||
void ActivateTracking(const INetworkEntityManager::OwnedEntitySet& ownedEntitySet) override;
|
||||
void RetrieveEntitiesNotInDomain(EntitiesNotInDomain& outEntitiesNotInDomain) const override;
|
||||
void DebugDraw() const override;
|
||||
//! @}
|
||||
|
||||
private:
|
||||
void OnControllersActivated(const ConstNetworkEntityHandle& entityHandle, EntityIsMigrating entityIsMigrating);
|
||||
void OnControllersDeactivated(const ConstNetworkEntityHandle& entityHandle, EntityIsMigrating entityIsMigrating);
|
||||
|
||||
EntitiesNotInDomain m_entitiesNotInDomain;
|
||||
ControllersActivatedEvent::Handler m_controllersActivatedHandler;
|
||||
ControllersDeactivatedEvent::Handler m_controllersDeactivatedHandler;
|
||||
};
|
||||
}
|
||||
@@ -1,80 +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/EntityDomains/RoundRobinEntityDomain.h>
|
||||
|
||||
namespace Multiplayer
|
||||
{
|
||||
RoundRobinEntityDomain::RoundRobinEntityDomain(const RoundRobinEntityDomain& rhs)
|
||||
: m_hostId(rhs.m_hostId)
|
||||
, m_multiserverCount(rhs.m_multiserverCount)
|
||||
, m_entitiesNotInDomain(rhs.m_entitiesNotInDomain)
|
||||
, m_controllersActivatedHandler([this](const ConstNetworkEntityHandle& entityHandle, EntityIsMigrating entityIsMigrating) { OnControllersActivated(entityHandle, entityIsMigrating); })
|
||||
, m_controllersDeactivatedHandler([this](const ConstNetworkEntityHandle& entityHandle, EntityIsMigrating entityIsMigrating) { OnControllersDeactivated(entityHandle, entityIsMigrating); })
|
||||
{
|
||||
;
|
||||
}
|
||||
|
||||
RoundRobinEntityDomain::RoundRobinEntityDomain(HostId hostId, uint32_t multiserverCount)
|
||||
: m_hostId(hostId)
|
||||
, m_multiserverCount(multiserverCount)
|
||||
, m_controllersActivatedHandler([this](const ConstNetworkEntityHandle& entityHandle, EntityIsMigrating entityIsMigrating) { OnControllersActivated(entityHandle, entityIsMigrating); })
|
||||
, m_controllersDeactivatedHandler([this](const ConstNetworkEntityHandle& entityHandle, EntityIsMigrating entityIsMigrating) { OnControllersDeactivated(entityHandle, entityIsMigrating); })
|
||||
{
|
||||
;
|
||||
}
|
||||
|
||||
bool RoundRobinEntityDomain::IsInDomain([[maybe_unused]] const ConstNetworkEntityHandle& entityHandle) const
|
||||
{
|
||||
//const int desiredDomain = (entityHandle.GetNetEntityId() % m_ServerShardCount) + k_FirstGameShardId;
|
||||
//const bool netIdInDomain = desiredDomain == m_ServerShardId;
|
||||
//const bool isPlayer = entityHandle->FindComponent<PlayerComponent>() != nullptr;
|
||||
//const bool isGlobalEnt = entityHandle->FindComponent<GlobalAccessComponent>() != nullptr;
|
||||
//auto entityHierarchyComponent = entityHandle->FindComponent<EntityHierarchyComponent>();
|
||||
//const bool isParented = entityHierarchyComponent ? entityHierarchyComponent->IsParented() : false;
|
||||
//return netIdInDomain || isPlayer || isGlobalEnt || isParented;
|
||||
return false;
|
||||
}
|
||||
|
||||
void RoundRobinEntityDomain::ActivateTracking(const INetworkEntityManager::OwnedEntitySet& ownedEntitySet)
|
||||
{
|
||||
for (auto& entityHandle : ownedEntitySet)
|
||||
{
|
||||
OnControllersActivated(entityHandle, EntityIsMigrating::False);
|
||||
}
|
||||
GetNetworkEntityManager()->AddControllersActivatedHandler(m_controllersActivatedHandler);
|
||||
GetNetworkEntityManager()->AddControllersDeactivatedHandler(m_controllersDeactivatedHandler);
|
||||
}
|
||||
|
||||
void RoundRobinEntityDomain::DebugDraw() const
|
||||
{
|
||||
// Nothing to draw
|
||||
}
|
||||
|
||||
void RoundRobinEntityDomain::RetrieveEntitiesNotInDomain(EntitiesNotInDomain& outEntitiesNotInDomain) const
|
||||
{
|
||||
outEntitiesNotInDomain.insert(m_entitiesNotInDomain.begin(), m_entitiesNotInDomain.end());
|
||||
}
|
||||
|
||||
void RoundRobinEntityDomain::OnControllersActivated(const ConstNetworkEntityHandle& entityHandle, [[maybe_unused]] EntityIsMigrating entityIsMigrating)
|
||||
{
|
||||
if (!IsInDomain(entityHandle))
|
||||
{
|
||||
m_entitiesNotInDomain.insert(entityHandle.GetNetEntityId());
|
||||
}
|
||||
}
|
||||
|
||||
void RoundRobinEntityDomain::OnControllersDeactivated(const ConstNetworkEntityHandle& entityHandle, [[maybe_unused]] EntityIsMigrating entityIsMigrating)
|
||||
{
|
||||
m_entitiesNotInDomain.erase(entityHandle.GetNetEntityId());
|
||||
}
|
||||
}
|
||||
@@ -1,48 +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/EntityDomains/IEntityDomain.h>
|
||||
#include <AzCore/std/containers/unordered_set.h>
|
||||
|
||||
namespace Multiplayer
|
||||
{
|
||||
class RoundRobinEntityDomain
|
||||
: public IEntityDomain
|
||||
{
|
||||
public:
|
||||
RoundRobinEntityDomain() = delete;
|
||||
RoundRobinEntityDomain(const RoundRobinEntityDomain& rhs);
|
||||
RoundRobinEntityDomain(HostId hostId, uint32_t multiserverCount);
|
||||
|
||||
//! IEntityDomain overrides.
|
||||
//! @{
|
||||
bool IsInDomain(const ConstNetworkEntityHandle& entityHandle) const override;
|
||||
void ActivateTracking(const INetworkEntityManager::OwnedEntitySet& ownedEntitySet) override;
|
||||
void RetrieveEntitiesNotInDomain(EntitiesNotInDomain& outEntitiesNotInDomain) const override;
|
||||
void DebugDraw() const override;
|
||||
//! @}
|
||||
|
||||
private:
|
||||
void UpdateEntityDomain();
|
||||
|
||||
void OnControllersActivated(const ConstNetworkEntityHandle& entityHandle, EntityIsMigrating entityIsMigrating);
|
||||
void OnControllersDeactivated(const ConstNetworkEntityHandle& entityHandle, EntityIsMigrating entityIsMigrating);
|
||||
|
||||
HostId m_hostId = InvalidHostId;
|
||||
uint32_t m_multiserverCount = 0;
|
||||
EntitiesNotInDomain m_entitiesNotInDomain;
|
||||
ControllersActivatedEvent::Handler m_controllersActivatedHandler;
|
||||
ControllersDeactivatedEvent::Handler m_controllersDeactivatedHandler;
|
||||
};
|
||||
}
|
||||
@@ -1,150 +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/EntityDomains/SpatialEntityDomain.h>
|
||||
#include <AzCore/Component/TransformBus.h>
|
||||
#include <AzCore/Console/IConsole.h>
|
||||
#include <AzCore/Console/ILogger.h>
|
||||
|
||||
namespace Multiplayer
|
||||
{
|
||||
AZ_CVAR(float, sv_SpatialEntityDomainWidth, 20.0f, nullptr, AZ::ConsoleFunctorFlags::Null, "This is the area around the non-overlapping map region over which the server is willing to control entities. This makes it so that if an entity is walking across the MapRegion boundry back and forth, they won't ping pong between servers.");
|
||||
|
||||
SpatialEntityDomain::SpatialEntityDomain(const AZ::Aabb& aabb)
|
||||
: m_aabb(aabb)
|
||||
, m_controllersActivatedHandler([this](const ConstNetworkEntityHandle& entityHandle, EntityIsMigrating entityIsMigrating) { OnControllersActivated(entityHandle, entityIsMigrating); })
|
||||
, m_controllersDeactivatedHandler([this](const ConstNetworkEntityHandle& entityHandle, EntityIsMigrating entityIsMigrating) { OnControllersDeactivated(entityHandle, entityIsMigrating); })
|
||||
{
|
||||
// Slightly expand our Aabb to avoid entities rapidly toggling back and forth between domains
|
||||
m_aabb.Expand(AZ::Vector3(sv_SpatialEntityDomainWidth, sv_SpatialEntityDomainWidth, sv_SpatialEntityDomainWidth));
|
||||
}
|
||||
|
||||
bool SpatialEntityDomain::IsInDomain(const ConstNetworkEntityHandle& entityHandle) const
|
||||
{
|
||||
if (const AZ::Entity* entity = entityHandle.GetEntity())
|
||||
{
|
||||
const AZ::Transform transform = entity->GetTransform()->GetWorldTM();
|
||||
return IsTransformInDomain(transform);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void SpatialEntityDomain::ActivateTracking(const INetworkEntityManager::OwnedEntitySet& ownedEntitySet)
|
||||
{
|
||||
for (auto& entityHandle : ownedEntitySet)
|
||||
{
|
||||
OnControllersActivated(entityHandle, EntityIsMigrating::False);
|
||||
}
|
||||
GetNetworkEntityManager()->AddControllersActivatedHandler(m_controllersActivatedHandler);
|
||||
GetNetworkEntityManager()->AddControllersDeactivatedHandler(m_controllersDeactivatedHandler);
|
||||
}
|
||||
|
||||
void SpatialEntityDomain::RetrieveEntitiesNotInDomain(EntitiesNotInDomain& outEntitiesNotInDomain) const
|
||||
{
|
||||
// validate all our entities did not come back into the domain
|
||||
for (ConstNetworkEntityHandle& entityHandle : m_dirtyEntities)
|
||||
{
|
||||
AZ::Entity* entity = entityHandle.GetEntity();
|
||||
|
||||
// If the entity no longer exists, we can safely skip it
|
||||
if (entity == nullptr)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
// Turn back on tracking, we need this if the entity is in or out of domain (since entities can walk back into our domain prior to migrating)
|
||||
AZ::TransformInterface* transformInterface = entity->GetTransform();
|
||||
auto locationDataIter = m_ownedEntities.find(entityHandle);
|
||||
AZ_Assert(locationDataIter != m_ownedEntities.end(), "This should always exist");
|
||||
transformInterface->BindTransformChangedEventHandler(locationDataIter->second.m_updateEventHandler);
|
||||
|
||||
if (!IsInDomain(entityHandle))
|
||||
{
|
||||
m_entitiesNotInDomain.insert(entityHandle.GetNetEntityId());
|
||||
}
|
||||
}
|
||||
m_dirtyEntities.clear();
|
||||
outEntitiesNotInDomain.insert(m_entitiesNotInDomain.begin(), m_entitiesNotInDomain.end());
|
||||
}
|
||||
|
||||
void SpatialEntityDomain::DebugDraw() const
|
||||
{
|
||||
static constexpr float BoundaryStripeHeight = 1.0f;
|
||||
static constexpr float BoundaryStripeSpacing = 0.5f;
|
||||
static constexpr int32_t BoundaryStripeCount = 10;
|
||||
|
||||
//auto* loc = draw.GetOwnerConst()->FindComponent<LocationComponent::Server>();
|
||||
//if (loc == nullptr)
|
||||
//{
|
||||
// return;
|
||||
//}
|
||||
//
|
||||
//Vec3 dmnMin = m_SpatialEntityDomainParams.GetMin();
|
||||
//Vec3 dmnMax = m_SpatialEntityDomainParams.GetMax();
|
||||
//
|
||||
//dmnMin.z = loc->GetPosition().z;
|
||||
//dmnMax.z = dmnMin.z + BoundaryStripeHeight;
|
||||
//
|
||||
//for (int i = 0; i < BoundaryStripeCount; ++i)
|
||||
//{
|
||||
// draw.AABB(dmnMin, dmnMax, color);
|
||||
// dmnMin.z += BoundaryStripeSpacing;
|
||||
// dmnMax.z += BoundaryStripeSpacing;
|
||||
//}
|
||||
}
|
||||
|
||||
const AZ::Aabb& SpatialEntityDomain::GetAabb() const
|
||||
{
|
||||
return m_aabb;
|
||||
}
|
||||
|
||||
bool SpatialEntityDomain::IsTransformInDomain(const AZ::Transform& transform) const
|
||||
{
|
||||
return m_aabb.Contains(transform.GetTranslation());
|
||||
}
|
||||
|
||||
void SpatialEntityDomain::EntityTransformUpdated(const ConstNetworkEntityHandle& entityHandle)
|
||||
{
|
||||
m_dirtyEntities.push_back(entityHandle);
|
||||
LocationData& locationData = m_ownedEntities[entityHandle];
|
||||
// we marked this entity as dirty, we don't need to be attached to the movement event anymore
|
||||
locationData.m_updateEventHandler.Disconnect();
|
||||
}
|
||||
|
||||
void SpatialEntityDomain::OnControllersActivated(const ConstNetworkEntityHandle& entityHandle, [[maybe_unused]] EntityIsMigrating entityIsMigrating)
|
||||
{
|
||||
const AZ::Entity* entity = entityHandle.GetEntity();
|
||||
|
||||
// If the entity no longer exists, we can safely skip it
|
||||
if (entity != nullptr)
|
||||
{
|
||||
LocationData& locationData = m_ownedEntities[entityHandle];
|
||||
locationData.m_parent = this;
|
||||
locationData.m_entityHandle = entityHandle;
|
||||
|
||||
// Turn back on tracking, we need this if the entity is in or out of domain (since entities can walk back into our domain prior to migrating)
|
||||
AZ::TransformInterface* transformInterface = entity->GetTransform();
|
||||
transformInterface->BindTransformChangedEventHandler(locationData.m_updateEventHandler);
|
||||
}
|
||||
|
||||
if (!IsInDomain(entityHandle))
|
||||
{
|
||||
m_entitiesNotInDomain.insert(entityHandle.GetNetEntityId());
|
||||
}
|
||||
}
|
||||
|
||||
void SpatialEntityDomain::OnControllersDeactivated(const ConstNetworkEntityHandle& entityHandle, [[maybe_unused]] EntityIsMigrating entityIsMigrating)
|
||||
{
|
||||
m_entitiesNotInDomain.erase(entityHandle.GetNetEntityId());
|
||||
m_ownedEntities.erase(entityHandle);
|
||||
}
|
||||
}
|
||||
@@ -1,78 +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/EntityDomains/IEntityDomain.h>
|
||||
#include <AzCore/Component/TransformBus.h>
|
||||
#include <AzCore/Math/Transform.h>
|
||||
#include <AzCore/Math/Aabb.h>
|
||||
|
||||
namespace Multiplayer
|
||||
{
|
||||
class MapRegion;
|
||||
struct SpatialEntityDomainParams;
|
||||
|
||||
class SpatialEntityDomain
|
||||
: public IEntityDomain
|
||||
{
|
||||
public:
|
||||
SpatialEntityDomain(const AZ::Aabb& aabb);
|
||||
|
||||
//! IEntityDomain overrides.
|
||||
//! @{
|
||||
bool IsInDomain(const ConstNetworkEntityHandle& entityHandle) const override;
|
||||
void ActivateTracking(const INetworkEntityManager::OwnedEntitySet& ownedEntitySet) override;
|
||||
void RetrieveEntitiesNotInDomain(EntitiesNotInDomain& outEntitiesNotInDomain) const override;
|
||||
void DebugDraw() const override;
|
||||
//! @}
|
||||
|
||||
const AZ::Aabb& GetAabb() const;
|
||||
|
||||
private:
|
||||
bool IsTransformInDomain(const AZ::Transform& transform) const;
|
||||
void EntityTransformUpdated(const ConstNetworkEntityHandle& entityHandle);
|
||||
|
||||
void OnControllersActivated(const ConstNetworkEntityHandle& entityHandle, EntityIsMigrating entityIsMigrating);
|
||||
void OnControllersDeactivated(const ConstNetworkEntityHandle& entityHandle, EntityIsMigrating entityIsMigrating);
|
||||
|
||||
struct LocationData
|
||||
{
|
||||
LocationData() = default;
|
||||
LocationData(LocationData&& rhs)
|
||||
: m_parent(rhs.m_parent)
|
||||
, m_entityHandle(rhs.m_entityHandle)
|
||||
{
|
||||
;
|
||||
}
|
||||
|
||||
SpatialEntityDomain* m_parent = nullptr;
|
||||
ConstNetworkEntityHandle m_entityHandle;
|
||||
AZ::TransformChangedEvent::Handler m_updateEventHandler = AZ::TransformChangedEvent::Handler
|
||||
(
|
||||
[this]([[maybe_unused]] const AZ::Transform& localTransform, [[maybe_unused]] const AZ::Transform& worldTransform)
|
||||
{
|
||||
m_parent->EntityTransformUpdated(m_entityHandle);
|
||||
}
|
||||
);
|
||||
};
|
||||
|
||||
AZ::Aabb m_aabb;
|
||||
|
||||
// cached data
|
||||
mutable EntitiesNotInDomain m_entitiesNotInDomain;
|
||||
mutable AZStd::vector<ConstNetworkEntityHandle> m_dirtyEntities;
|
||||
mutable AZStd::unordered_map<ConstNetworkEntityHandle, LocationData> m_ownedEntities;
|
||||
ControllersActivatedEvent::Handler m_controllersActivatedHandler;
|
||||
ControllersDeactivatedEvent::Handler m_controllersDeactivatedHandler;
|
||||
};
|
||||
}
|
||||
@@ -1,17 +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
|
||||
|
||||
namespace Multiplayer
|
||||
{
|
||||
}
|
||||
@@ -1,176 +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/EntityDomains/SpatialMapPartitioner.h>
|
||||
#include <AzCore/std/containers/fixed_vector.h>
|
||||
|
||||
namespace Multiplayer
|
||||
{
|
||||
static constexpr uint32_t MaxFactors = 32;
|
||||
using FactorSet = AZStd::fixed_vector<uint32_t, MaxFactors>;
|
||||
|
||||
// Computes factors of N, but does not return the factors 1 and N
|
||||
void ComputeFactors(uint32_t integer, FactorSet& output)
|
||||
{
|
||||
output.clear();
|
||||
|
||||
while (integer > 2)
|
||||
{
|
||||
for (uint32_t test = 2; test <= (integer / 2); ++test)
|
||||
{
|
||||
if ((integer % test) == 0)
|
||||
{
|
||||
output.push_back(test);
|
||||
integer /= test;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (integer > 1)
|
||||
{
|
||||
output.push_back(integer);
|
||||
}
|
||||
}
|
||||
|
||||
ServerMapPartitioner::ServerMapPartitioner()
|
||||
: m_regionCount(0)
|
||||
, m_shardCount(0)
|
||||
{
|
||||
;
|
||||
}
|
||||
|
||||
void ServerMapPartitioner::PartitionMap(uint32_t totalRegions, uint32_t shardCount)
|
||||
{
|
||||
AZ_Assert(totalRegions > 0, "Total number of regions for map partitioner must be positive");
|
||||
|
||||
// Factor totalRegions
|
||||
FactorSet factors;
|
||||
ComputeFactors(totalRegions, factors);
|
||||
|
||||
// Compute map extents
|
||||
AZ::Vector3 mapMinBounds, mapMaxBounds;
|
||||
//AZ::Interface<IPhysics>::Get()->GetWorldBounds(mapMinBounds, mapMaxBounds);
|
||||
//m_wholeMap = AZ::Aabb::CreateFromMinMax(mapMinBounds, mapMaxBounds);
|
||||
|
||||
// This part could use some work
|
||||
// Basically we want to now distribute the factors in some way related to the extents of the map
|
||||
// The ideal result I guess being that the output regions are as close to square as possible?
|
||||
|
||||
// For now distribute the factors evenly, and then bias for the larger map extent..
|
||||
const AZ::Vector3 delta = mapMaxBounds - mapMinBounds;
|
||||
|
||||
uint32_t divisions[2] = { 1, 1 };
|
||||
uint32_t divIndex = 0;
|
||||
|
||||
for (uint32_t i = 0; i < factors.size(); ++i)
|
||||
{
|
||||
divisions[divIndex] *= factors[i];
|
||||
divIndex = 1 - divIndex;
|
||||
}
|
||||
|
||||
// Sort.. since I don't know which came out greater
|
||||
if (divisions[1] > divisions[0])
|
||||
{
|
||||
uint32_t temp = divisions[1];
|
||||
divisions[1] = divisions[0];
|
||||
divisions[0] = temp;
|
||||
}
|
||||
|
||||
const bool xGreater = (delta.GetX() >= delta.GetY());
|
||||
|
||||
const uint32_t xAxisDiv = xGreater ? divisions[0] : divisions[1];
|
||||
const uint32_t yAxisDiv = xGreater ? divisions[1] : divisions[0];
|
||||
|
||||
const float mapWidth = mapMaxBounds.GetX() - mapMinBounds.GetX();
|
||||
const float mapHeight = mapMaxBounds.GetY() - mapMinBounds.GetY();
|
||||
|
||||
const float partitionWidth = mapWidth / xAxisDiv;
|
||||
const float partitionHeight = mapHeight / yAxisDiv;
|
||||
|
||||
const uint32_t regionCount = xAxisDiv * yAxisDiv;
|
||||
|
||||
AZ_Assert(regionCount == totalRegions, "Was not able to partition the map into the requested region count, invalid region count specified");
|
||||
|
||||
m_regions.resize(regionCount);
|
||||
m_shardCount = shardCount;
|
||||
m_regionCount = totalRegions;
|
||||
|
||||
AZ::Vector3 regionMinBounds;
|
||||
AZ::Vector3 regionMaxBounds;
|
||||
uint32_t regionIndex = 0;
|
||||
|
||||
regionMaxBounds.SetY(mapMinBounds.GetY());
|
||||
|
||||
for (int32_t y = yAxisDiv - 1; y >= 0; --y)
|
||||
{
|
||||
regionMinBounds.SetY(regionMaxBounds.GetY());
|
||||
|
||||
if (y > 0)
|
||||
{
|
||||
regionMaxBounds.SetY(regionMaxBounds.GetY() + partitionHeight);
|
||||
}
|
||||
else
|
||||
{
|
||||
regionMaxBounds.SetY(mapMaxBounds.GetY());
|
||||
}
|
||||
|
||||
regionMaxBounds.SetX(mapMinBounds.GetX());
|
||||
|
||||
for (int32_t x = xAxisDiv - 1; x >= 0; --x)
|
||||
{
|
||||
regionMinBounds.SetX(regionMaxBounds.GetX());
|
||||
|
||||
if (x > 0)
|
||||
{
|
||||
regionMaxBounds.SetX(regionMaxBounds.GetX() + partitionWidth);
|
||||
}
|
||||
else
|
||||
{
|
||||
regionMaxBounds.SetX(mapMaxBounds.GetX());
|
||||
}
|
||||
|
||||
m_regions[regionIndex++] = AZ::Aabb::CreateFromMinMax(regionMinBounds, regionMaxBounds);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
uint32_t ServerMapPartitioner::GetRegionCount() const
|
||||
{
|
||||
return static_cast<uint32_t>(m_regions.size());
|
||||
}
|
||||
|
||||
AZ::Aabb ServerMapPartitioner::GetMapRegion(uint32_t index) const
|
||||
{
|
||||
if ((index >= 0) && (index < GetRegionCount()))
|
||||
{
|
||||
return m_regions[index];
|
||||
}
|
||||
|
||||
return AZ::Aabb();
|
||||
}
|
||||
|
||||
AZ::Aabb ServerMapPartitioner::GetMapRegionForHost(HostId hostId)
|
||||
{
|
||||
// TODO: This is not the best place for this logic, though I'm not sure where is yet -- potentially this should be a parameter returned by the game service?
|
||||
// If there are global shards, those will be the lowest index, so we need to offset correctly to find the correct region for an EntityManagerId()
|
||||
int offset = m_shardCount - m_regionCount;
|
||||
int32_t index = aznumeric_cast<int32_t>(hostId) - 1 - offset;
|
||||
AZ_Assert(index >= 0 && index < GetRegionCount(), "No region for Entity Manager");
|
||||
return GetMapRegion(index);
|
||||
}
|
||||
|
||||
const AZ::Aabb& ServerMapPartitioner::GetWholeMap() const
|
||||
{
|
||||
return m_wholeMap;
|
||||
}
|
||||
}
|
||||
@@ -1,38 +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 <AzCore/Math/Aabb.h>
|
||||
#include <Source/MultiplayerTypes.h>
|
||||
|
||||
namespace Multiplayer
|
||||
{
|
||||
class ServerMapPartitioner
|
||||
{
|
||||
public:
|
||||
ServerMapPartitioner();
|
||||
|
||||
void PartitionMap(uint32_t regionCount, uint32_t shardCount);
|
||||
|
||||
uint32_t GetRegionCount() const;
|
||||
AZ::Aabb GetMapRegion(uint32_t index) const;
|
||||
AZ::Aabb GetMapRegionForHost(HostId hostId);
|
||||
|
||||
const AZ::Aabb& GetWholeMap() const;
|
||||
private:
|
||||
AZ::Aabb m_wholeMap;
|
||||
AZStd::vector<AZ::Aabb> m_regions;
|
||||
uint32_t m_regionCount;
|
||||
uint32_t m_shardCount;
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user