Fixes to sending entity updates and entity rpcs within an environment set up for cross host entity migration

Signed-off-by: kberg-amzn <karlberg@amazon.com>
This commit is contained in:
kberg-amzn
2021-09-28 19:25:04 -07:00
parent 0a829f9661
commit 02bc89cd92
21 changed files with 185 additions and 134 deletions
@@ -7,9 +7,16 @@
*/
#include <Source/ReplicationWindows/NullReplicationWindow.h>
#include <Source/AutoGen/Multiplayer.AutoPackets.h>
namespace Multiplayer
{
NullReplicationWindow::NullReplicationWindow(AzNetworking::IConnection* connection)
: m_connection(connection)
{
;
}
bool NullReplicationWindow::ReplicationSetUpdateReady()
{
return true;
@@ -36,6 +43,29 @@ namespace Multiplayer
;
}
AzNetworking::PacketId NullReplicationWindow::SendEntityUpdateMessages(NetworkEntityUpdateVector& entityUpdateVector)
{
MultiplayerPackets::EntityUpdates entityUpdatePacket;
entityUpdatePacket.SetHostTimeMs(GetNetworkTime()->GetHostTimeMs());
entityUpdatePacket.SetHostFrameId(GetNetworkTime()->GetHostFrameId());
entityUpdatePacket.SetEntityMessages(entityUpdateVector);
return m_connection->SendUnreliablePacket(entityUpdatePacket);
}
void NullReplicationWindow::SendEntityRpcs(NetworkEntityRpcVector& entityRpcVector, bool reliable)
{
MultiplayerPackets::EntityRpcs entityRpcsPacket;
entityRpcsPacket.SetEntityRpcs(entityRpcVector);
if (reliable)
{
m_connection->SendReliablePacket(entityRpcsPacket);
}
else
{
m_connection->SendUnreliablePacket(entityRpcsPacket);
}
}
void NullReplicationWindow::DebugDraw() const
{
// Nothing to draw
@@ -9,6 +9,7 @@
#pragma once
#include <Multiplayer/ReplicationWindows/IReplicationWindow.h>
#include <AzNetworking/ConnectionLayer/IConnection.h>
namespace Multiplayer
{
@@ -16,7 +17,7 @@ namespace Multiplayer
: public IReplicationWindow
{
public:
NullReplicationWindow() = default;
NullReplicationWindow(AzNetworking::IConnection* connection);
//! IReplicationWindow interface
//! @{
@@ -25,10 +26,13 @@ namespace Multiplayer
uint32_t GetMaxProxyEntityReplicatorSendCount() const override;
bool IsInWindow(const ConstNetworkEntityHandle& entityPtr, NetEntityRole& outNetworkRole) const override;
void UpdateWindow() override;
AzNetworking::PacketId SendEntityUpdateMessages(NetworkEntityUpdateVector& entityUpdateVector) override;
void SendEntityRpcs(NetworkEntityRpcVector& entityRpcVector, bool reliable) override;
void DebugDraw() const override;
//! @}
private:
ReplicationSet m_emptySet;
AzNetworking::IConnection* m_connection = nullptr;
};
}
@@ -7,6 +7,7 @@
*/
#include <Source/ReplicationWindows/ServerToClientReplicationWindow.h>
#include <Source/AutoGen/Multiplayer.AutoPackets.h>
#include <Multiplayer/Components/NetBindComponent.h>
#include <AzFramework/Visibility/IVisibilitySystem.h>
#include <AzCore/Component/TransformBus.h>
@@ -50,7 +51,7 @@ namespace Multiplayer
return m_priority < rhs.m_priority;
}
ServerToClientReplicationWindow::ServerToClientReplicationWindow(NetworkEntityHandle controlledEntity, const AzNetworking::IConnection* connection)
ServerToClientReplicationWindow::ServerToClientReplicationWindow(NetworkEntityHandle controlledEntity, AzNetworking::IConnection* connection)
: m_controlledEntity(controlledEntity)
, m_entityActivatedEventHandler([this](AZ::Entity* entity) { OnEntityActivated(entity); })
, m_entityDeactivatedEventHandler([this](AZ::Entity* entity) { OnEntityDeactivated(entity); })
@@ -179,6 +180,29 @@ namespace Multiplayer
//}
}
AzNetworking::PacketId ServerToClientReplicationWindow::SendEntityUpdateMessages(NetworkEntityUpdateVector& entityUpdateVector)
{
MultiplayerPackets::EntityUpdates entityUpdatePacket;
entityUpdatePacket.SetHostTimeMs(GetNetworkTime()->GetHostTimeMs());
entityUpdatePacket.SetHostFrameId(GetNetworkTime()->GetHostFrameId());
entityUpdatePacket.SetEntityMessages(entityUpdateVector);
return m_connection->SendUnreliablePacket(entityUpdatePacket);
}
void ServerToClientReplicationWindow::SendEntityRpcs(NetworkEntityRpcVector& entityRpcVector, bool reliable)
{
MultiplayerPackets::EntityRpcs entityRpcsPacket;
entityRpcsPacket.SetEntityRpcs(entityRpcVector);
if (reliable)
{
m_connection->SendReliablePacket(entityRpcsPacket);
}
else
{
m_connection->SendUnreliablePacket(entityRpcsPacket);
}
}
void ServerToClientReplicationWindow::DebugDraw() const
{
//static const float BoundaryStripeHeight = 1.0f;
@@ -38,7 +38,7 @@ namespace Multiplayer
// we sort lowest priority first, so that we can easily keep the biggest N priorities
using ReplicationCandidateQueue = AZStd::priority_queue<PrioritizedReplicationCandidate>;
ServerToClientReplicationWindow(NetworkEntityHandle controlledEntity, const AzNetworking::IConnection* connection);
ServerToClientReplicationWindow(NetworkEntityHandle controlledEntity, AzNetworking::IConnection* connection);
//! IReplicationWindow interface
//! @{
@@ -47,6 +47,8 @@ namespace Multiplayer
uint32_t GetMaxProxyEntityReplicatorSendCount() const override;
bool IsInWindow(const ConstNetworkEntityHandle& entityPtr, NetEntityRole& outNetworkRole) const override;
void UpdateWindow() override;
AzNetworking::PacketId SendEntityUpdateMessages(NetworkEntityUpdateVector& entityUpdateVector) override;
void SendEntityRpcs(NetworkEntityRpcVector& entityRpcVector, bool reliable) override;
void DebugDraw() const override;
//! @}
@@ -75,7 +77,7 @@ namespace Multiplayer
//NetBindComponent* m_controlledNetBindComponent = nullptr;
const AzNetworking::IConnection* m_connection = nullptr;
AzNetworking::IConnection* m_connection = nullptr;
// Cached values to detect a poor network connection
uint32_t m_lastCheckedSentPackets = 0;