You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
126 lines
5.6 KiB
C++
126 lines
5.6 KiB
C++
/*
|
|
* 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 <AzNetworking/Serialization/ISerializer.h>
|
|
#include <AzNetworking/DataStructures/ByteBuffer.h>
|
|
#include <AzCore/Name/Name.h>
|
|
#include <Include/MultiplayerTypes.h>
|
|
|
|
namespace Multiplayer
|
|
{
|
|
// The maximum number of entity updates we can stuff into a single update packet
|
|
static const uint32_t MaxAggregateEntityMessages = 2048;
|
|
|
|
//! @class NetworkEntityUpdateMessage
|
|
//! @brief Property replication packet.
|
|
class NetworkEntityUpdateMessage
|
|
{
|
|
public:
|
|
AZ_TYPE_INFO(NetworkEntityUpdateMessage, "{CFCA08F7-547B-4B89-9794-37A8679608DF}");
|
|
|
|
NetworkEntityUpdateMessage() = default;
|
|
NetworkEntityUpdateMessage(NetworkEntityUpdateMessage&& rhs);
|
|
NetworkEntityUpdateMessage(const NetworkEntityUpdateMessage& rhs);
|
|
|
|
//! Constructor for update without a slice name (remote replicator established).
|
|
//! @param entityRole the role of the entity being replicated
|
|
//! @param entityId the networkId of the entity being replicated
|
|
explicit NetworkEntityUpdateMessage(NetEntityRole entityRole, NetEntityId entityId);
|
|
|
|
//! Constructor for update with a slice name (no remote replicator established).
|
|
//! @param entityRole the role of the entity being replicated
|
|
//! @param entityId the networkId of the entity being replicated
|
|
//! @param prefabEntityId the prefab entityId to clone this replicated entity from
|
|
explicit NetworkEntityUpdateMessage(NetEntityRole entityRole, NetEntityId entityId, const PrefabEntityId& prefabEntityId);
|
|
|
|
//! Constructor for an entity delete message.
|
|
//! @param entityId the networkId of the entity being deleted
|
|
//! @param isMigrated whether or not the entity is being migrated or deleted
|
|
//! @param takeOwnership true if the remote replicator should take ownership of the entity
|
|
explicit NetworkEntityUpdateMessage(NetEntityId entityId, bool isMigrated, bool takeOwnership);
|
|
|
|
NetworkEntityUpdateMessage& operator =(NetworkEntityUpdateMessage&& rhs);
|
|
NetworkEntityUpdateMessage& operator =(const NetworkEntityUpdateMessage& rhs);
|
|
bool operator ==(const NetworkEntityUpdateMessage& rhs) const;
|
|
bool operator !=(const NetworkEntityUpdateMessage& rhs) const;
|
|
|
|
//! Returns an estimated serialization footprint for this NetworkEntityUpdateMessage.
|
|
//! @return an estimated serialization footprint for this NetworkEntityUpdateMessage
|
|
uint32_t GetEstimatedSerializeSize() const;
|
|
|
|
//! Gets the current value of NetworkRole.
|
|
//! @return the current value of NetworkRole
|
|
NetEntityRole GetNetworkRole() const;
|
|
|
|
//! Gets the entities networkId.
|
|
//! @return the entities networkId
|
|
NetEntityId GetEntityId() const;
|
|
|
|
//! Gets the current value of IsDelete (true if this represents a DeleteProxy message).
|
|
//! @return the current value of IsDelete
|
|
bool GetIsDelete() const;
|
|
|
|
//! Returns whether or not the entity was migrated.
|
|
//! @return whether or not the entity was migrated
|
|
bool GetWasMigrated() const;
|
|
|
|
//! Gets the current value of TakeOwnership.
|
|
//! @return the current value of TakeOwnership
|
|
bool GetTakeOwnership() const;
|
|
|
|
//! Gets the current value of HasValidPrefabId.
|
|
//! @return the current value of HasValidPrefabId
|
|
bool GetHasValidPrefabId() const;
|
|
|
|
//! Sets the current value for PrefabEntityId.
|
|
//! @param value the value to set PrefabEntityId to
|
|
void SetPrefabEntityId(const PrefabEntityId& value);
|
|
|
|
//! Gets the current value of PrefabEntityId.
|
|
//! @return the current value of PrefabEntityId
|
|
const PrefabEntityId& GetPrefabEntityId() const;
|
|
|
|
//! Sets the current value for Data
|
|
//! @param value the value to set Data to
|
|
void SetData(const AzNetworking::PacketEncodingBuffer& value);
|
|
|
|
//! Gets the current value of Data.
|
|
//! @return the current value of Data
|
|
const AzNetworking::PacketEncodingBuffer* GetData() const;
|
|
|
|
//! Retrieves a non-const reference to the value of Data.
|
|
//! @return a non-const reference to the value of Data
|
|
AzNetworking::PacketEncodingBuffer& ModifyData();
|
|
|
|
//! Base serialize method for all serializable structures or classes to implement.
|
|
//! @param serializer ISerializer instance to use for serialization
|
|
//! @return boolean true for success, false for serialization failure
|
|
bool Serialize(AzNetworking::ISerializer& serializer);
|
|
|
|
private:
|
|
|
|
NetEntityRole m_networkRole = NetEntityRole::InvalidRole;
|
|
NetEntityId m_entityId = InvalidNetEntityId;
|
|
bool m_isDelete = false;
|
|
bool m_wasMigrated = false;
|
|
bool m_takeOwnership = false;
|
|
bool m_hasValidPrefabId = false;
|
|
PrefabEntityId m_prefabEntityId;
|
|
|
|
// Only allocated if we actually have data
|
|
// This is to prevent blowing out stack memory if we declare an array of these EntityUpdateMessages
|
|
AZStd::unique_ptr<AzNetworking::PacketEncodingBuffer> m_data;
|
|
};
|
|
}
|