Merge branch 'development' into cmake/linux_fix_warn_unused

Signed-off-by: Esteban Papp <81431996+amznestebanpapp@users.noreply.github.com>
This commit is contained in:
Esteban Papp
2021-08-20 14:51:35 -07:00
241 changed files with 5654 additions and 5352 deletions
@@ -59,7 +59,8 @@ namespace Multiplayer
(
const PrefabEntityId& prefabEntryId,
NetEntityRole netEntityRole,
const AZ::Transform& transform
const AZ::Transform& transform,
AutoActivate autoActivate = AutoActivate::Activate
) = 0;
//! Creates new entities of the given archetype
@@ -89,6 +90,11 @@ namespace Multiplayer
//! @return the total number of entities tracked by this INetworkEntityManager instance
virtual uint32_t GetEntityCount() const = 0;
//! Returns the Net Entity ID for a given AZ Entity ID.
//! @param entityId the AZ Entity ID
//! @return the Net Entity ID
virtual NetEntityId GetNetEntityIdById(const AZ::EntityId& entityId) const = 0;
//! Adds the provided entity to the internal entity map identified by the provided netEntityId.
//! @param netEntityId the identifier to use for the added entity
//! @param entity the entity to add to the internal entity map
@@ -130,9 +130,9 @@ void {{ PropertyName }}({{ ', '.join(paramDefines) }});
{#
#}
{% macro DeclareRpcInvocations(Component, Section, HandleOn, ProctectedSection) %}
{% macro DeclareRpcInvocations(Component, Section, HandleOn, IsProtected) %}
{% call(Property) AutoComponentMacros.ParseRemoteProcedures(Component, Section, HandleOn) %}
{% if Property.attrib['IsPublic']|booleanTrue == ProctectedSection %}
{% if Property.attrib['IsPublic']|booleanTrue != IsProtected %}
{{ DeclareRpcInvocation(Property, HandleOn) -}}
{% endif %}
{% endcall %}
@@ -386,8 +386,6 @@ namespace {{ Component.attrib['Namespace'] }}
{{ DeclareNetworkPropertyAccessors(Component, 'Autonomous', 'Authority', false)|indent(8) -}}
{{ DeclareNetworkPropertyAccessors(Component, 'Autonomous', 'Authority', true)|indent(8) -}}
{{ DeclareArchetypePropertyGetters(Component)|indent(8) -}}
{{ DeclareRpcInvocations(Component, 'Server', 'Authority', false)|indent(8) -}}
{{ DeclareRpcInvocations(Component, 'Server', 'Authority', true)|indent(8) -}}
{{ DeclareRpcInvocations(Component, 'Client', 'Authority', false)|indent(8) -}}
{{ DeclareRpcInvocations(Component, 'Client', 'Authority', true)|indent(8) -}}
{{ DeclareRpcInvocations(Component, 'Autonomous', 'Authority', false)|indent(8) -}}
@@ -445,8 +443,8 @@ namespace {{ Component.attrib['Namespace'] }}
static AZStd::unique_ptr<Multiplayer::IMultiplayerComponentInput> AllocateComponentInput();
{{ ComponentBaseName }}() = default;
~{{ ComponentBaseName }}() override = default;
{{ ComponentBaseName }}();
~{{ ComponentBaseName }}() override;
void Init() override;
void Activate() override;
@@ -318,7 +318,11 @@ void {{ ClassName }}::{{ UpperFirst(Property.attrib['Name']) }}({{ ', '.join(par
constexpr AzNetworking::ReliabilityType isReliable = Multiplayer::ReliabilityType::Unreliable;
{% endif %}
{% if InvokeFrom == 'Server' or InvokeFrom =='Client' %}
const Multiplayer::NetComponentId netComponentId = GetNetComponentId();
{% else %}
const Multiplayer::NetComponentId netComponentId = GetParent().GetNetComponentId();
{% endif %}
Multiplayer::NetworkEntityRpcMessage rpcMessage(Multiplayer::RpcDeliveryType::{{ InvokeFrom }}To{{ HandleOn }}, GetNetEntityId(), netComponentId, rpcId, isReliable);
{% if paramNames|count > 0 %}
{{ UpperFirst(Component.attrib['Name']) }}Internal::{{ UpperFirst(Property.attrib['Name']) }}RpcStruct rpcStruct({{ ', '.join(paramNames) }});
@@ -345,9 +349,9 @@ void {{ ClassName }}::Signal{{ UpperFirst(Property.attrib['Name']) }}({{ ', '.jo
{#
#}
{% macro DefineRpcInvocations(Component, ClassName, InvokeFrom, HandleOn, ProctectedSection) %}
{% macro DefineRpcInvocations(Component, ClassName, InvokeFrom, HandleOn, IsProtected) %}
{% call(Property) AutoComponentMacros.ParseRemoteProcedures(Component, InvokeFrom, HandleOn) %}
{% if Property.attrib['IsPublic']|booleanTrue == ProctectedSection %}
{% if Property.attrib['IsPublic']|booleanTrue != IsProtected %}
{{ DefineRpcInvocation(Component, ClassName, Property, InvokeFrom, HandleOn) -}}
{% if Property.attrib['GenerateEventBindings']|booleanTrue == true %}
{{ DefineRpcSignal(Component, ClassName, Property, InvokeFrom) -}}
@@ -1250,10 +1254,12 @@ namespace {{ Component.attrib['Namespace'] }}
bool {{ RecordName }}::CanAttachRecord(Multiplayer::ReplicationRecord& replicationRecord)
{
bool canAttach{ true };
AZ_PUSH_DISABLE_WARNING(4296, "-Wunknown-warning-option") // expression is always true
canAttach &= replicationRecord.ContainsAuthorityToClientBits() ? (replicationRecord.GetRemainingAuthorityToClientBits() >= static_cast<uint32_t>({{ AutoComponentMacros.GetNetPropertiesDirtyEnumName(ComponentName, 'Authority', 'Client') }}::Count)) : true;
canAttach &= replicationRecord.ContainsAuthorityToServerBits() ? (replicationRecord.GetRemainingAuthorityToServerBits() >= static_cast<uint32_t>({{ AutoComponentMacros.GetNetPropertiesDirtyEnumName(ComponentName, 'Authority', 'Server') }}::Count)) : true;
canAttach &= replicationRecord.ContainsAuthorityToAutonomousBits() ? (replicationRecord.GetRemainingAuthorityToAutonomousBits() >= static_cast<uint32_t>({{ AutoComponentMacros.GetNetPropertiesDirtyEnumName(ComponentName, 'Authority', 'Autonomous') }}::Count)) : true;
canAttach &= replicationRecord.ContainsAutonomousToAuthorityBits() ? (replicationRecord.GetRemainingAutonomousToAuthorityBits() >= static_cast<uint32_t>({{ AutoComponentMacros.GetNetPropertiesDirtyEnumName(ComponentName, 'Autonomous', 'Authority') }}::Count)) : true;
AZ_POP_DISABLE_WARNING
return canAttach;
}
@@ -1490,6 +1496,10 @@ namespace {{ Component.attrib['Namespace'] }}
{% endif %}
}
{{ ComponentBaseName }}::{{ ComponentBaseName }}() = default;
{{ ComponentBaseName }}::~{{ ComponentBaseName }}() = default;
void {{ ComponentBaseName }}::Init()
{
if (m_netBindComponent == nullptr)
@@ -8,6 +8,8 @@
#include "MultiplayerDebugByteReporter.h"
#include <AzCore/Casting/numeric_cast.h>
#include <iomanip> // for std::setfill
#include <sstream>
#include <AzCore/std/sort.h>
@@ -643,6 +643,7 @@ namespace Multiplayer
{
controlledEntity.GetNetBindComponent()->SetOwningConnectionId(connection->GetConnectionId());
}
controlledEntity.Activate();
if (connection->GetUserData() == nullptr) // Only add user data if the connect event handler has not already done so
{
@@ -762,6 +763,7 @@ namespace Multiplayer
{
controlledEntityNetBindComponent->SetAllowAutonomy(true);
}
controlledEntity.Activate();
}
AZLOG_INFO("Multiplayer operating in %s mode", GetEnumString(m_agentType));
@@ -967,7 +969,7 @@ namespace Multiplayer
NetworkEntityHandle MultiplayerSystemComponent::SpawnDefaultPlayerPrefab()
{
PrefabEntityId playerPrefabEntityId(AZ::Name(static_cast<AZ::CVarFixedString>(sv_defaultPlayerSpawnAsset).c_str()));
INetworkEntityManager::EntityList entityList = m_networkEntityManager.CreateEntitiesImmediate(playerPrefabEntityId, NetEntityRole::Authority, AZ::Transform::CreateIdentity());
INetworkEntityManager::EntityList entityList = m_networkEntityManager.CreateEntitiesImmediate(playerPrefabEntityId, NetEntityRole::Authority, AZ::Transform::CreateIdentity(), Multiplayer::AutoActivate::DoNotActivate);
NetworkEntityHandle controlledEntity;
if (entityList.size() > 0)
@@ -73,6 +73,11 @@ namespace Multiplayer
return m_networkEntityTracker.Get(netEntityId);
}
NetEntityId NetworkEntityManager::GetNetEntityIdById(const AZ::EntityId& entityId) const
{
return m_networkEntityTracker.Get(entityId);
}
uint32_t NetworkEntityManager::GetEntityCount() const
{
return static_cast<uint32_t>(m_networkEntityTracker.size());
@@ -304,7 +309,7 @@ namespace Multiplayer
}
INetworkEntityManager::EntityList NetworkEntityManager::CreateEntitiesImmediate(
const AzFramework::Spawnable& spawnable, NetEntityRole netEntityRole)
const AzFramework::Spawnable& spawnable, NetEntityRole netEntityRole, AutoActivate autoActivate)
{
INetworkEntityManager::EntityList returnList;
@@ -354,6 +359,11 @@ namespace Multiplayer
const NetEntityId netEntityId = NextId();
netBindComponent->PreInit(clone, prefabEntityId, netEntityId, netEntityRole);
if (autoActivate == AutoActivate::DoNotActivate)
{
clone->SetRuntimeActiveByDefault(false);
}
AzFramework::GameEntityContextRequestBus::Broadcast(
&AzFramework::GameEntityContextRequestBus::Events::AddGameEntity, clone);
@@ -373,10 +383,11 @@ namespace Multiplayer
(
const PrefabEntityId& prefabEntryId,
NetEntityRole netEntityRole,
const AZ::Transform& transform
const AZ::Transform& transform,
AutoActivate autoActivate
)
{
return CreateEntitiesImmediate(prefabEntryId, NextId(), netEntityRole, AutoActivate::Activate, transform);
return CreateEntitiesImmediate(prefabEntryId, NextId(), netEntityRole, autoActivate, transform);
}
INetworkEntityManager::EntityList NetworkEntityManager::CreateEntitiesImmediate
@@ -409,7 +420,7 @@ namespace Multiplayer
if (entityIndex == PrefabEntityId::AllIndices)
{
return CreateEntitiesImmediate(*netSpawnable, netEntityRole);
return CreateEntitiesImmediate(*netSpawnable, netEntityRole, autoActivate);
}
const AzFramework::Spawnable::EntityList& entities = netSpawnable->GetEntities();
@@ -41,13 +41,15 @@ namespace Multiplayer
MultiplayerComponentRegistry* GetMultiplayerComponentRegistry() override;
HostId GetHostId() const override;
ConstNetworkEntityHandle GetEntity(NetEntityId netEntityId) const override;
NetEntityId GetNetEntityIdById(const AZ::EntityId& entityId) const override;
EntityList CreateEntitiesImmediate(const AzFramework::Spawnable& spawnable, NetEntityRole netEntityRole);
EntityList CreateEntitiesImmediate(const AzFramework::Spawnable& spawnable, NetEntityRole netEntityRole, AutoActivate autoActivate);
EntityList CreateEntitiesImmediate
(
const PrefabEntityId& prefabEntryId,
NetEntityRole netEntityRole,
const AZ::Transform& transform
const AZ::Transform& transform,
AutoActivate autoActivate = AutoActivate::Activate
) override;
EntityList CreateEntitiesImmediate
(
@@ -18,6 +18,7 @@ namespace Multiplayer
++m_addChangeDirty;
AZ_Assert(m_entityMap.end() == m_entityMap.find(netEntityId), "Attempting to add the same entity to the entity map multiple times");
m_entityMap[netEntityId] = entity;
m_netEntityIdMap[entity->GetId()] = netEntityId;
}
NetworkEntityHandle NetworkEntityTracker::Get(NetEntityId netEntityId)
@@ -32,6 +33,16 @@ namespace Multiplayer
return ConstNetworkEntityHandle(entity, netEntityId, this);
}
NetEntityId NetworkEntityTracker::Get(const AZ::EntityId& entityId) const
{
auto found = m_netEntityIdMap.find(entityId);
if (found != m_netEntityIdMap.end())
{
return found->second;
}
return Multiplayer::InvalidNetEntityId;
}
bool NetworkEntityTracker::Exists(NetEntityId netEntityId) const
{
return (m_entityMap.find(netEntityId) != m_entityMap.end());
@@ -50,12 +61,22 @@ namespace Multiplayer
void NetworkEntityTracker::erase(NetEntityId netEntityId)
{
++m_deleteChangeDirty;
m_entityMap.erase(netEntityId);
auto found = m_entityMap.find(netEntityId);
if (found != m_entityMap.end())
{
m_netEntityIdMap.erase(found->second->GetId());
m_entityMap.erase(found);
}
}
NetworkEntityTracker::EntityMap::iterator NetworkEntityTracker::erase(EntityMap::iterator iter)
{
++m_deleteChangeDirty;
if (iter != m_entityMap.end())
{
m_netEntityIdMap.erase(iter->second->GetId());
}
return m_entityMap.erase(iter);
}
@@ -22,6 +22,7 @@ namespace Multiplayer
public:
using EntityMap = AZStd::unordered_map<NetEntityId, AZ::Entity*>;
using NetEntityIdMap = AZStd::unordered_map<AZ::EntityId, NetEntityId>;
using iterator = EntityMap::iterator;
using const_iterator = EntityMap::const_iterator;
@@ -36,6 +37,8 @@ namespace Multiplayer
NetworkEntityHandle Get(NetEntityId netEntityId);
ConstNetworkEntityHandle Get(NetEntityId netEntityId) const;
NetEntityId Get(const AZ::EntityId& entityId) const;
//! Returns true if the netEntityId exists.
bool Exists(NetEntityId netEntityId) const;
@@ -74,6 +77,7 @@ namespace Multiplayer
private:
EntityMap m_entityMap;
NetEntityIdMap m_netEntityIdMap;
uint32_t m_deleteChangeDirty = 0;
uint32_t m_addChangeDirty = 0;
};
@@ -48,6 +48,7 @@ namespace Multiplayer
inline void NetworkEntityTracker::clear()
{
m_entityMap.clear();
m_netEntityIdMap.clear();
}
inline uint32_t NetworkEntityTracker::GetChangeDirty(const AZ::Entity* entity) const