More fixes to migration, plus some quality of life fixes to TimeoutQueue to allow lambda based handlers and a quick fix to OctreeSystemComponent to more gracefully handle enumerate calls that lie outside the vis system bounds

Signed-off-by: kberg-amzn <karlberg@amazon.com>
This commit is contained in:
kberg-amzn
2021-10-14 18:22:41 -07:00
parent 05e8b2941a
commit a6e7a81b79
16 changed files with 66 additions and 62 deletions
@@ -12,9 +12,9 @@
<Include File="Multiplayer/MultiplayerTypes.h"/>
<Include File="Multiplayer/NetworkInput/NetworkInput.h"/>
<Include File="Source/NetworkInput/NetworkInputArray.h"/>
<Include File="Source/NetworkInput/NetworkInputHistory.h"/>
<Include File="Source/NetworkInput/NetworkInputMigrationVector.h"/>
<Include File="Multiplayer/NetworkInput/NetworkInputArray.h"/>
<Include File="Multiplayer/NetworkInput/NetworkInputHistory.h"/>
<Include File="Multiplayer/NetworkInput/NetworkInputMigrationVector.h"/>
<Include File="AzNetworking/DataStructures/ByteBuffer.h"/>
<NetworkProperty Type="Multiplayer::ClientInputId" Name="LastInputId" Init="Multiplayer::ClientInputId{ 0 }" ReplicateFrom="Authority" ReplicateTo="Server" IsRewindable="false" IsPredictable="false" IsPublic="false" Container="Object" ExposeToEditor="false" ExposeToScript="false" GenerateEventBindings="false" />
@@ -353,6 +353,16 @@ namespace Multiplayer
}
}
void LocalPredictionPlayerInputComponentController::ForceEnableAutonomousUpdate()
{
m_autonomousUpdateEvent.Enqueue(AZ::TimeMs{ 1 }, true);
}
void LocalPredictionPlayerInputComponentController::ForceDisableAutonomousUpdate()
{
m_autonomousUpdateEvent.RemoveFromQueue();
}
bool LocalPredictionPlayerInputComponentController::IsMigrating() const
{
return m_lastMigratedInputId != ClientInputId{ 0 };
@@ -28,24 +28,29 @@ namespace Multiplayer
->Version(1);
}
}
void MultiplayerDebugSystemComponent::GetProvidedServices(AZ::ComponentDescriptor::DependencyArrayType& provided)
{
provided.push_back(AZ_CRC_CE("MultiplayerDebugSystemComponent"));
}
void MultiplayerDebugSystemComponent::GetRequiredServices([[maybe_unused]] AZ::ComponentDescriptor::DependencyArrayType& required)
{
;
}
void MultiplayerDebugSystemComponent::GetIncompatibleServices(AZ::ComponentDescriptor::DependencyArrayType& incompatbile)
{
incompatbile.push_back(AZ_CRC_CE("MultiplayerDebugSystemComponent"));
}
void MultiplayerDebugSystemComponent::Activate()
{
#ifdef IMGUI_ENABLED
ImGui::ImGuiUpdateListenerBus::Handler::BusConnect();
#endif
}
void MultiplayerDebugSystemComponent::Deactivate()
{
#ifdef IMGUI_ENABLED
@@ -74,6 +79,7 @@ namespace Multiplayer
ImGui::EndMenu();
}
}
void AccumulatePerSecondValues(const MultiplayerStats& stats, const MultiplayerStats::Metric& metric, float& outCallsPerSecond, float& outBytesPerSecond)
{
uint64_t summedCalls = 0;
@@ -106,6 +112,7 @@ namespace Multiplayer
ImGui::Text("%11.2f", bytesPerSecond);
return open;
}
bool DrawSummaryRow(const char* name, const MultiplayerStats& stats)
{
const MultiplayerStats::Metric propertyUpdatesSent = stats.CalculateTotalPropertyUpdateSentMetrics();
@@ -122,6 +129,7 @@ namespace Multiplayer
AccumulatePerSecondValues(stats, rpcsRecv, callsPerSecond, bytesPerSecond);
return DrawMetricsRow(name, true, totalCalls, totalBytes, callsPerSecond, bytesPerSecond);
}
bool DrawComponentRow(const char* name, const MultiplayerStats& stats, NetComponentId netComponentId)
{
const MultiplayerStats::Metric propertyUpdatesSent = stats.CalculateComponentPropertyUpdateSentMetrics(netComponentId);
@@ -138,6 +146,7 @@ namespace Multiplayer
AccumulatePerSecondValues(stats, rpcsRecv, callsPerSecond, bytesPerSecond);
return DrawMetricsRow(name, true, totalCalls, totalBytes, callsPerSecond, bytesPerSecond);
}
void DrawComponentDetails(const MultiplayerStats& stats, NetComponentId netComponentId)
{
MultiplayerComponentRegistry* componentRegistry = GetMultiplayerComponentRegistry();
@@ -479,4 +488,3 @@ void OnDebugEntities_ShowBandwidth_Changed(const bool& showBandwidth)
AZ::Interface<Multiplayer::IMultiplayerDebug>::Get()->HideEntityBandwidthDebugOverlay();
}
}
@@ -6,7 +6,7 @@
*
*/
#include <Source/NetworkInput/NetworkInputArray.h>
#include <Multiplayer/NetworkInput/NetworkInputArray.h>
#include <Multiplayer/NetworkEntity/INetworkEntityManager.h>
#include <AzNetworking/Serialization/ISerializer.h>
#include <AzNetworking/Serialization/DeltaSerializer.h>
@@ -1,46 +0,0 @@
/*
* Copyright (c) Contributors to the Open 3D Engine Project.
* For complete copyright and license terms please see the LICENSE at the root of this distribution.
*
* SPDX-License-Identifier: Apache-2.0 OR MIT
*
*/
#pragma once
#include <Multiplayer/NetworkInput/NetworkInput.h>
#include <Multiplayer/NetworkEntity/NetworkEntityHandle.h>
#include <AzCore/std/containers/array.h>
#include <AzCore/std/containers/fixed_vector.h>
namespace Multiplayer
{
//! @class NetworkInputArray
//! @brief An array of network inputs. Used to mitigate loss of input packets on the server. Compresses subsequent elements.
class NetworkInputArray final
{
public:
static constexpr uint32_t MaxElements = 8; // Never try to replicate a list larger than this amount
NetworkInputArray();
NetworkInputArray(const ConstNetworkEntityHandle& entityHandle);
~NetworkInputArray() = default;
NetworkInput& operator[](uint32_t index);
const NetworkInput& operator[](uint32_t index) const;
bool Serialize(AzNetworking::ISerializer& serializer);
private:
struct Wrapper // Strictly a workaround to deal with the private constructor of NetworkInput
{
Wrapper() : m_networkInput() {}
Wrapper(const NetworkInput& networkInput) : m_networkInput(networkInput) {}
NetworkInput m_networkInput;
};
ConstNetworkEntityHandle m_owner;
AZStd::array<Wrapper, MaxElements> m_inputs;
};
}
@@ -6,7 +6,7 @@
*
*/
#include <Source/NetworkInput/NetworkInputChild.h>
#include <Multiplayer/NetworkInput/NetworkInputChild.h>
#include <Multiplayer/IMultiplayer.h>
#include <AzNetworking/Serialization/ISerializer.h>
@@ -1,40 +0,0 @@
/*
* Copyright (c) Contributors to the Open 3D Engine Project.
* For complete copyright and license terms please see the LICENSE at the root of this distribution.
*
* SPDX-License-Identifier: Apache-2.0 OR MIT
*
*/
#pragma once
#include <Multiplayer/NetworkInput/NetworkInput.h>
namespace Multiplayer
{
//! Max number of entities that can be children of our netbound player entity.
static constexpr uint32_t MaxEntityHierarchyChildren = 16;
//! Used by the EntityHierarchyComponent. This component allows the gameplay programmer to specify inputs for dependent entities.
//! Since it is possible to for the Client/Server to disagree about the state of related entities,
//! this network input encodes the entity that is associated with it.
class NetworkInputChild
{
public:
NetworkInputChild() = default;
NetworkInputChild(const NetworkInputChild& rhs) = default;
NetworkInputChild(const ConstNetworkEntityHandle& entityHandle);
NetworkInputChild& operator= (const NetworkInputChild& rhs);
void Attach(const ConstNetworkEntityHandle& entityHandle);
const ConstNetworkEntityHandle& GetOwner() const;
const NetworkInput& GetNetworkInput() const;
NetworkInput& GetNetworkInput();
bool Serialize(AzNetworking::ISerializer& serializer);
private:
ConstNetworkEntityHandle m_owner;
NetworkInput m_networkInput;
};
}
@@ -6,7 +6,7 @@
*
*/
#include <Source/NetworkInput/NetworkInputHistory.h>
#include <Multiplayer/NetworkInput/NetworkInputHistory.h>
namespace Multiplayer
{
@@ -1,41 +0,0 @@
/*
* Copyright (c) Contributors to the Open 3D Engine Project.
* For complete copyright and license terms please see the LICENSE at the root of this distribution.
*
* SPDX-License-Identifier: Apache-2.0 OR MIT
*
*/
#pragma once
#include <Multiplayer/NetworkInput/NetworkInput.h>
#include <AzCore/std/containers/deque.h>
namespace Multiplayer
{
//! @class NetworkInputHistory
//! @brief A list of input commands, used for bookkeeping on the client.
class NetworkInputHistory final
{
public:
AZStd::size_t Size() const;
const NetworkInput& operator[](AZStd::size_t index) const;
NetworkInput& operator[](AZStd::size_t index);
void PushBack(NetworkInput& networkInput);
void PopFront();
const NetworkInput& Front() const;
private:
struct Wrapper // Strictly a workaround to deal with the private constructor of NetworkInput
{
Wrapper() : m_networkInput() {}
Wrapper(const NetworkInput& networkInput) : m_networkInput(networkInput) {}
NetworkInput m_networkInput;
};
AZStd::deque<Wrapper> m_history;
};
}
@@ -6,7 +6,7 @@
*
*/
#include <Source/NetworkInput/NetworkInputMigrationVector.h>
#include <Multiplayer/NetworkInput/NetworkInputMigrationVector.h>
#include <Multiplayer/IMultiplayer.h>
#include <AzNetworking/Serialization/ISerializer.h>
@@ -1,49 +0,0 @@
/*
* Copyright (c) Contributors to the Open 3D Engine Project.
* For complete copyright and license terms please see the LICENSE at the root of this distribution.
*
* SPDX-License-Identifier: Apache-2.0 OR MIT
*
*/
#pragma once
#include <Multiplayer/NetworkInput/NetworkInput.h>
#include <Multiplayer/NetworkEntity/NetworkEntityHandle.h>
#include <AzCore/std/containers/array.h>
#include <AzCore/std/containers/fixed_vector.h>
namespace Multiplayer
{
//! @class NetworkInputMigrationVector
//! @brief A variable sized array of input commands, used specifically when migrate a clients inputs.
class NetworkInputMigrationVector final
{
public:
static constexpr uint32_t MaxElements = 90; // Never try to migrate a list larger than this amount, bumped up to handle DTLS connection time
NetworkInputMigrationVector();
NetworkInputMigrationVector(const ConstNetworkEntityHandle& entityHandle);
virtual ~NetworkInputMigrationVector() = default;
uint32_t GetSize() const;
NetworkInput& operator[](uint32_t index);
const NetworkInput& operator[](uint32_t index) const;
bool PushBack(const NetworkInput& networkInput);
bool Serialize(AzNetworking::ISerializer& serializer);
private:
struct Wrapper // Strictly a workaround to deal with the private constructor of NetworkInput
{
Wrapper() : m_networkInput() {}
Wrapper(const NetworkInput& networkInput) : m_networkInput(networkInput) {}
bool Serialize(AzNetworking::ISerializer& serializer) { return m_networkInput.Serialize(serializer); }
NetworkInput m_networkInput;
};
ConstNetworkEntityHandle m_owner;
AZStd::fixed_vector<Wrapper, MaxElements> m_inputs;
};
}