d411c1d1d9
* WIP. Autonomous->Authority network properties now functional. Still need some research in regards to entity ownership when it comes to the PropertyPublisher. Signed-off-by: Gene Walters <genewalt@amazon.com> * WIP. Exposing Auton->Auth Properties accessors and onchange events Signed-off-by: Gene Walters <genewalt@amazon.com> * Fix propertypublisher constructor to skip the creation state if we arent the owner. Removing ClientToServerReplicationWindow, return to just using NullReplicationWindow. Signed-off-by: Gene Walters <genewalt@amazon.com> * Reverting some wip debug prints Signed-off-by: Gene Walters <genewalt@amazon.com> * Minor whitespacing fix Signed-off-by: Gene Walters <genewalt@amazon.com> * minor undoing of whitespacing Signed-off-by: Gene Walters <genewalt@amazon.com> * NullReplicationWindow MaxReplication is 0, but now Autonomous entity updates will always be added to the send list (ignoring the max replication limit) Signed-off-by: Gene Walters <genewalt@amazon.com> * Updating PropertyPublisher comment to explicitly call out if we dont own the entity locally, the remote replicator must exist Signed-off-by: Gene Walters <genewalt@amazon.com> * Renaming RepiclationWindow GetMaxEntityReplicatorSendCount to GetMaxProxyEntityReplicatorSendCount; this number only affects the number of proxy sends and allows autonomous properties to always send Signed-off-by: Gene Walters <genewalt@amazon.com>
87 lines
3.4 KiB
C++
87 lines
3.4 KiB
C++
/*
|
|
* 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/IMultiplayer.h>
|
|
#include <Multiplayer/NetworkEntity/NetworkEntityHandle.h>
|
|
#include <Multiplayer/ReplicationWindows/IReplicationWindow.h>
|
|
#include <AzNetworking/ConnectionLayer/IConnection.h>
|
|
#include <AzCore/Component/EntityBus.h>
|
|
#include <AzCore/EBus/ScheduledEvent.h>
|
|
#include <AzCore/Console/IConsole.h>
|
|
#include <AzCore/std/smart_ptr/unique_ptr.h>
|
|
|
|
namespace Multiplayer
|
|
{
|
|
class NetSystemComponent;
|
|
|
|
class ServerToClientReplicationWindow
|
|
: public IReplicationWindow
|
|
{
|
|
public:
|
|
|
|
struct PrioritizedReplicationCandidate
|
|
{
|
|
PrioritizedReplicationCandidate() = default;
|
|
PrioritizedReplicationCandidate(const ConstNetworkEntityHandle& entityHandle, float priority);
|
|
bool operator <(const PrioritizedReplicationCandidate& rhs) const;
|
|
bool operator >(const PrioritizedReplicationCandidate& rhs) const;
|
|
ConstNetworkEntityHandle m_entityHandle;
|
|
float m_priority;
|
|
};
|
|
// 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);
|
|
|
|
//! IReplicationWindow interface
|
|
//! @{
|
|
bool ReplicationSetUpdateReady() override;
|
|
const ReplicationSet& GetReplicationSet() const override;
|
|
uint32_t GetMaxProxyEntityReplicatorSendCount() const override;
|
|
bool IsInWindow(const ConstNetworkEntityHandle& entityPtr, NetEntityRole& outNetworkRole) const override;
|
|
void UpdateWindow() override;
|
|
void DebugDraw() const override;
|
|
//! @}
|
|
|
|
private:
|
|
void OnEntityActivated(AZ::Entity* entity);
|
|
void OnEntityDeactivated(AZ::Entity* entity);
|
|
|
|
//void CollectControlledEntitiesRecursive(ReplicationSet& replicationSet, EntityHierarchyComponent::Authority& hierarchyController);
|
|
|
|
void EvaluateConnection();
|
|
void AddEntityToReplicationSet(ConstNetworkEntityHandle& entityHandle, float priority, float distanceSquared);
|
|
|
|
ServerToClientReplicationWindow& operator=(const ServerToClientReplicationWindow&) = delete;
|
|
|
|
// sorted in reverse, lowest priority is the top()
|
|
ReplicationCandidateQueue m_candidateQueue;
|
|
ReplicationSet m_replicationSet;
|
|
|
|
AZ::ScheduledEvent m_updateWindowEvent;
|
|
|
|
NetworkEntityHandle m_controlledEntity;
|
|
AZ::TransformInterface* m_controlledEntityTransform = nullptr;
|
|
|
|
AZ::EntityActivatedEvent::Handler m_entityActivatedEventHandler;
|
|
AZ::EntityDeactivatedEvent::Handler m_entityDeactivatedEventHandler;
|
|
|
|
//NetBindComponent* m_controlledNetBindComponent = nullptr;
|
|
|
|
const AzNetworking::IConnection* m_connection = nullptr;
|
|
float m_minPriorityReplicated = 0.0f; ///< Lowest replicated entity priority in last update
|
|
|
|
// Cached values to detect a poor network connection
|
|
uint32_t m_lastCheckedSentPackets = 0;
|
|
uint32_t m_lastCheckedLostPackets = 0;
|
|
bool m_isPoorConnection = true;
|
|
};
|
|
}
|