Various bug fixes to get entity replication working

This commit is contained in:
karlberg
2021-04-13 20:24:08 -07:00
parent 7b3b1cd73e
commit ca3df5d6c8
29 changed files with 495 additions and 137 deletions
@@ -0,0 +1,59 @@
/*
* 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/ConnectionData/ClientToServerConnectionData.h>
namespace Multiplayer
{
static constexpr uint32_t Uint32Max = AZStd::numeric_limits<uint32_t>::max();
// This can be used to help mitigate client side performance when large numbers of entities are created off the network
AZ_CVAR(uint32_t, cl_ClientMaxRemoteEntitiesPendingCreationCount, Uint32Max, nullptr, AZ::ConsoleFunctorFlags::DontReplicate, "Maximum number of entities that we have sent to the client, but have not had a confirmation back from the client");
AZ_CVAR(AZ::TimeMs, cl_ClientEntityReplicatorPendingRemovalTimeMs, AZ::TimeMs{ 10000 }, nullptr, AZ::ConsoleFunctorFlags::DontReplicate, "How long should wait prior to removing an entity for the client through a change in the replication window, entity deletes are still immediate");
ClientToServerConnectionData::ClientToServerConnectionData
(
AzNetworking::IConnection* connection,
AzNetworking::IConnectionListener& connectionListener
)
: m_connection(connection)
, m_entityReplicationManager(*connection, connectionListener, EntityReplicationManager::Mode::LocalClientToRemoteServer)
{
m_entityReplicationManager.SetMaxRemoteEntitiesPendingCreationCount(cl_ClientMaxRemoteEntitiesPendingCreationCount);
m_entityReplicationManager.SetEntityPendingRemovalMs(cl_ClientEntityReplicatorPendingRemovalTimeMs);
}
ClientToServerConnectionData::~ClientToServerConnectionData()
{
m_entityReplicationManager.Clear(false);
}
ConnectionDataType ClientToServerConnectionData::GetConnectionDataType() const
{
return ConnectionDataType::ClientToServer;
}
AzNetworking::IConnection* ClientToServerConnectionData::GetConnection() const
{
return m_connection;
}
EntityReplicationManager& ClientToServerConnectionData::GetReplicationManager()
{
return m_entityReplicationManager;
}
void ClientToServerConnectionData::Update([[maybe_unused]] AZ::TimeMs serverGameTimeMs)
{
m_entityReplicationManager.ActivatePendingEntities();
}
}
@@ -0,0 +1,47 @@
/*
* 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/ConnectionData/IConnectionData.h>
namespace Multiplayer
{
class ClientToServerConnectionData final
: public IConnectionData
{
public:
ClientToServerConnectionData
(
AzNetworking::IConnection* connection,
AzNetworking::IConnectionListener& connectionListener
);
~ClientToServerConnectionData() override;
//! IConnectionData interface
//! @{
ConnectionDataType GetConnectionDataType() const override;
AzNetworking::IConnection* GetConnection() const override;
EntityReplicationManager& GetReplicationManager() override;
void Update(AZ::TimeMs serverGameTimeMs) override;
//! @}
bool CanSendUpdates();
private:
EntityReplicationManager m_entityReplicationManager;
AzNetworking::IConnection* m_connection = nullptr;
bool m_canSendUpdates = true;
};
}
#include <Source/ConnectionData/ClientToServerConnectionData.inl>
@@ -0,0 +1,19 @@
/*
* 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.
*
*/
namespace Multiplayer
{
inline bool ClientToServerConnectionData::CanSendUpdates()
{
return m_canSendUpdates;
}
}
@@ -19,6 +19,7 @@ namespace Multiplayer
{
enum class ConnectionDataType
{
ClientToServer,
ServerToClient,
ServerToServer
};