From 62564e68dec909b7315b520c05da9d6fa8478a3a Mon Sep 17 00:00:00 2001 From: pappeste Date: Thu, 15 Apr 2021 15:02:02 -0700 Subject: [PATCH 01/10] Fixing hang when parameters are passed --- Code/CryEngine/CrySystem/CmdLine.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/Code/CryEngine/CrySystem/CmdLine.cpp b/Code/CryEngine/CrySystem/CmdLine.cpp index 15e655ddcb..07fbf6aa15 100644 --- a/Code/CryEngine/CrySystem/CmdLine.cpp +++ b/Code/CryEngine/CrySystem/CmdLine.cpp @@ -185,6 +185,7 @@ string CCmdLine::Next(char*& src) return string(org, src - 1); case ' ': + ch = *src++; continue; default: org = src - 1; From c920e98da7f6c4879e99bc562e7ef518e9208d88 Mon Sep 17 00:00:00 2001 From: pereslav Date: Thu, 22 Apr 2021 17:29:49 +0100 Subject: [PATCH 02/10] Added optional activation of selective entities spawning --- Gems/Multiplayer/Code/Source/MultiplayerTypes.h | 6 ++++++ .../EntityReplication/EntityReplicationManager.cpp | 5 +---- .../Code/Source/NetworkEntity/INetworkEntityManager.h | 3 ++- .../Code/Source/NetworkEntity/NetworkEntityManager.cpp | 7 ++++++- .../Code/Source/NetworkEntity/NetworkEntityManager.h | 2 +- 5 files changed, 16 insertions(+), 7 deletions(-) diff --git a/Gems/Multiplayer/Code/Source/MultiplayerTypes.h b/Gems/Multiplayer/Code/Source/MultiplayerTypes.h index 7ffaa8a56e..db4517b90b 100644 --- a/Gems/Multiplayer/Code/Source/MultiplayerTypes.h +++ b/Gems/Multiplayer/Code/Source/MultiplayerTypes.h @@ -70,6 +70,12 @@ namespace Multiplayer True }; + enum class AutoActivate : uint8_t + { + DoNotActivate, + Activate + }; + // This is just a placeholder // The level/prefab cooking will devise the actual solution for identifying a dynamically spawnable entity within a prefab struct PrefabEntityId diff --git a/Gems/Multiplayer/Code/Source/NetworkEntity/EntityReplication/EntityReplicationManager.cpp b/Gems/Multiplayer/Code/Source/NetworkEntity/EntityReplication/EntityReplicationManager.cpp index 8db582f6e5..18fa338223 100644 --- a/Gems/Multiplayer/Code/Source/NetworkEntity/EntityReplication/EntityReplicationManager.cpp +++ b/Gems/Multiplayer/Code/Source/NetworkEntity/EntityReplication/EntityReplicationManager.cpp @@ -542,11 +542,8 @@ namespace Multiplayer // Create an entity if we don't have one if (createEntity) { - // @pereslav - //replicatorEntity = GetNetworkEntityManager()->CreateSingleEntityImmediateInternal(prefabEntityId, EntitySpawnType::Replicate, AutoActivate::DoNotActivate, netEntityId, localNetworkRole, AZ::Transform::Identity()); INetworkEntityManager::EntityList entityList = GetNetworkEntityManager()->CreateEntitiesImmediate( - prefabEntityId, netEntityId, localNetworkRole, - AZ::Transform::Identity()); + prefabEntityId, netEntityId, localNetworkRole, AutoActivate::DoNotActivate, AZ::Transform::Identity()); if (entityList.size() == 1) { diff --git a/Gems/Multiplayer/Code/Source/NetworkEntity/INetworkEntityManager.h b/Gems/Multiplayer/Code/Source/NetworkEntity/INetworkEntityManager.h index 557a912a31..c79e45864d 100644 --- a/Gems/Multiplayer/Code/Source/NetworkEntity/INetworkEntityManager.h +++ b/Gems/Multiplayer/Code/Source/NetworkEntity/INetworkEntityManager.h @@ -55,7 +55,8 @@ namespace Multiplayer //! Creates new entities of the given archetype //! @param prefabEntryId the name of the spawnable to spawn virtual EntityList CreateEntitiesImmediate( - const PrefabEntityId& prefabEntryId, NetEntityId netEntityId, NetEntityRole netEntityRole, const AZ::Transform& transform) = 0; + const PrefabEntityId& prefabEntryId, NetEntityId netEntityId, NetEntityRole netEntityRole, AutoActivate autoActivate, + const AZ::Transform& transform) = 0; //! Returns an ConstEntityPtr for the provided entityId. //! @param netEntityId the netEntityId to get an ConstEntityPtr for diff --git a/Gems/Multiplayer/Code/Source/NetworkEntity/NetworkEntityManager.cpp b/Gems/Multiplayer/Code/Source/NetworkEntity/NetworkEntityManager.cpp index 43302efdaa..2eb93d706d 100644 --- a/Gems/Multiplayer/Code/Source/NetworkEntity/NetworkEntityManager.cpp +++ b/Gems/Multiplayer/Code/Source/NetworkEntity/NetworkEntityManager.cpp @@ -356,7 +356,7 @@ namespace Multiplayer INetworkEntityManager::EntityList NetworkEntityManager::CreateEntitiesImmediate( const PrefabEntityId& prefabEntryId, NetEntityId netEntityId, NetEntityRole netEntityRole, - const AZ::Transform& transform) + AutoActivate autoActivate, const AZ::Transform& transform) { INetworkEntityManager::EntityList returnList; @@ -402,6 +402,11 @@ namespace Multiplayer transformComponent->SetWorldTM(transform); } + if (autoActivate == AutoActivate::DoNotActivate) + { + clone->SetRuntimeActiveByDefault(false); + } + AzFramework::GameEntityContextRequestBus::Broadcast( &AzFramework::GameEntityContextRequestBus::Events::AddGameEntity, clone); diff --git a/Gems/Multiplayer/Code/Source/NetworkEntity/NetworkEntityManager.h b/Gems/Multiplayer/Code/Source/NetworkEntity/NetworkEntityManager.h index 148645c638..f67d28bd7a 100644 --- a/Gems/Multiplayer/Code/Source/NetworkEntity/NetworkEntityManager.h +++ b/Gems/Multiplayer/Code/Source/NetworkEntity/NetworkEntityManager.h @@ -49,7 +49,7 @@ namespace Multiplayer EntityList CreateEntitiesImmediate( const PrefabEntityId& prefabEntryId, NetEntityId netEntityId, NetEntityRole netEntityRole, - const AZ::Transform& transform) override; + AutoActivate autoActivate, const AZ::Transform& transform) override; uint32_t GetEntityCount() const override; NetworkEntityHandle AddEntityToEntityMap(NetEntityId netEntityId, AZ::Entity* entity) override; From 57cbeaff0a74ad4a155746650cd7fa4300dff979 Mon Sep 17 00:00:00 2001 From: pereslav Date: Thu, 22 Apr 2021 17:32:06 +0100 Subject: [PATCH 03/10] Added a cmd argument support for custom cfg files --- Code/LauncherUnified/Launcher.cpp | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/Code/LauncherUnified/Launcher.cpp b/Code/LauncherUnified/Launcher.cpp index 36d6a432f5..4721e3f0a7 100644 --- a/Code/LauncherUnified/Launcher.cpp +++ b/Code/LauncherUnified/Launcher.cpp @@ -46,6 +46,21 @@ extern "C" void CreateStaticModules(AZStd::vector& modulesOut); namespace { + void ExecuteCustomConfig(AzFramework::Application& application) + { + const AZStd::string_view customCfgKey = "customcfg"; + const AZ::CommandLine* commandLine = application.GetCommandLine(); + if (commandLine->HasSwitch(customCfgKey) && commandLine->GetNumSwitchValues(customCfgKey) > 0) + { + const AZStd::string& customCfg = commandLine->GetSwitchValue(customCfgKey, 0); + if (!customCfg.empty()) + { + AZStd::string execString = "exec " + customCfg; + gEnv->pConsole->ExecuteString(execString.c_str()); + } + } + } + #if AZ_TRAIT_LAUNCHER_USE_CRY_DYNAMIC_MODULE_HANDLE // mimics AZ::DynamicModuleHandle but uses CryLibrary under the hood, // which is necessary to properly load legacy Cry libraries on some platforms @@ -639,6 +654,8 @@ namespace O3DELauncher // Execute autoexec.cfg to load the initial level gEnv->pConsole->ExecuteString("exec autoexec.cfg"); + ExecuteCustomConfig(gameApplication); + gEnv->pSystem->ExecuteCommandLine(false); // Run the main loop From 008c65352476feea64c7cc723ce5656ca3208d64 Mon Sep 17 00:00:00 2001 From: pereslav Date: Mon, 26 Apr 2021 13:30:35 +0100 Subject: [PATCH 04/10] Added ReadyForEntityUpdates message allowing the server to send entity updates --- Gems/Multiplayer/Code/Include/IMultiplayer.h | 4 ++++ .../AutoGen/Multiplayer.AutoPackets.xml | 4 ++++ .../ServerToClientConnectionData.h | 5 +++-- .../ServerToClientConnectionData.inl | 8 ++++++- .../Source/MultiplayerSystemComponent.cpp | 22 +++++++++++++++++++ .../Code/Source/MultiplayerSystemComponent.h | 2 ++ .../NetworkEntity/NetworkEntityManager.cpp | 20 ++++++++++++----- 7 files changed, 56 insertions(+), 9 deletions(-) diff --git a/Gems/Multiplayer/Code/Include/IMultiplayer.h b/Gems/Multiplayer/Code/Include/IMultiplayer.h index 94744dbb54..0f28bef403 100644 --- a/Gems/Multiplayer/Code/Include/IMultiplayer.h +++ b/Gems/Multiplayer/Code/Include/IMultiplayer.h @@ -92,6 +92,10 @@ namespace Multiplayer //! @return the stats object bound to this multiplayer instance MultiplayerStats& GetStats() { return m_stats; } + //! Sends a packet telling if entity update messages can be sent + //! @param readyForEntityUpdates Ready for entity updates or not + virtual void SendReadyForEntityUpdates(bool readyForEntityUpdates) = 0; + private: MultiplayerStats m_stats; }; diff --git a/Gems/Multiplayer/Code/Source/AutoGen/Multiplayer.AutoPackets.xml b/Gems/Multiplayer/Code/Source/AutoGen/Multiplayer.AutoPackets.xml index e5549e90d6..758ea27ad7 100644 --- a/Gems/Multiplayer/Code/Source/AutoGen/Multiplayer.AutoPackets.xml +++ b/Gems/Multiplayer/Code/Source/AutoGen/Multiplayer.AutoPackets.xml @@ -14,6 +14,10 @@ + + + + diff --git a/Gems/Multiplayer/Code/Source/ConnectionData/ServerToClientConnectionData.h b/Gems/Multiplayer/Code/Source/ConnectionData/ServerToClientConnectionData.h index 02b045e63f..596bdc88d9 100644 --- a/Gems/Multiplayer/Code/Source/ConnectionData/ServerToClientConnectionData.h +++ b/Gems/Multiplayer/Code/Source/ConnectionData/ServerToClientConnectionData.h @@ -36,7 +36,8 @@ namespace Multiplayer void Update(AZ::TimeMs serverGameTimeMs) override; //! @} - bool CanSendUpdates(); + bool CanSendUpdates() const; + void SetCanSendUpdates(bool canSendUpdates); NetworkEntityHandle GetPrimaryPlayerEntity(); const NetworkEntityHandle& GetPrimaryPlayerEntity() const; @@ -51,7 +52,7 @@ namespace Multiplayer EntityStopEvent::Handler m_controlledEntityRemovedHandler; EntityMigrationEvent::Handler m_controlledEntityMigrationHandler; AzNetworking::IConnection* m_connection = nullptr; - bool m_canSendUpdates = true; + bool m_canSendUpdates = false; }; } diff --git a/Gems/Multiplayer/Code/Source/ConnectionData/ServerToClientConnectionData.inl b/Gems/Multiplayer/Code/Source/ConnectionData/ServerToClientConnectionData.inl index 07bfb51536..0a4215a363 100644 --- a/Gems/Multiplayer/Code/Source/ConnectionData/ServerToClientConnectionData.inl +++ b/Gems/Multiplayer/Code/Source/ConnectionData/ServerToClientConnectionData.inl @@ -12,11 +12,17 @@ namespace Multiplayer { - inline bool ServerToClientConnectionData::CanSendUpdates() + inline bool ServerToClientConnectionData::CanSendUpdates() const { return m_canSendUpdates; } + inline void ServerToClientConnectionData::SetCanSendUpdates(bool canSendUpdates) + { + m_canSendUpdates = canSendUpdates; + } + + inline NetworkEntityHandle ServerToClientConnectionData::GetPrimaryPlayerEntity() { return m_controlledEntity; diff --git a/Gems/Multiplayer/Code/Source/MultiplayerSystemComponent.cpp b/Gems/Multiplayer/Code/Source/MultiplayerSystemComponent.cpp index e40e9e9d66..49a0f63b63 100644 --- a/Gems/Multiplayer/Code/Source/MultiplayerSystemComponent.cpp +++ b/Gems/Multiplayer/Code/Source/MultiplayerSystemComponent.cpp @@ -381,6 +381,19 @@ namespace Multiplayer return false; } + bool MultiplayerSystemComponent::HandleRequest( AzNetworking::IConnection* connection, + [[maybe_unused]] const AzNetworking::IPacketHeader& packetHeader, MultiplayerPackets::ReadyForEntityUpdates& packet) + { + auto* connectionData = reinterpret_cast(connection->GetUserData()); + if (connectionData) + { + connectionData->SetCanSendUpdates(packet.GetReadyForEntityUpdates()); + return true; + } + + return false; + } + ConnectResult MultiplayerSystemComponent::ValidateConnect ( [[maybe_unused]] const IpAddress& remoteAddress, @@ -503,6 +516,15 @@ namespace Multiplayer handler.Connect(m_shutdownEvent); } + void MultiplayerSystemComponent::SendReadyForEntityUpdates(bool readyForEntityUpdates) + { + IConnectionSet& connectionSet = m_networkInterface->GetConnectionSet(); + connectionSet.VisitConnections([readyForEntityUpdates](IConnection& connection) + { + connection.SendReliablePacket(MultiplayerPackets::ReadyForEntityUpdates(readyForEntityUpdates)); + }); + } + void MultiplayerSystemComponent::DumpStats([[maybe_unused]] const AZ::ConsoleCommandContainer& arguments) { const MultiplayerStats& stats = GetStats(); diff --git a/Gems/Multiplayer/Code/Source/MultiplayerSystemComponent.h b/Gems/Multiplayer/Code/Source/MultiplayerSystemComponent.h index 1e10f9841e..8695dea7dd 100644 --- a/Gems/Multiplayer/Code/Source/MultiplayerSystemComponent.h +++ b/Gems/Multiplayer/Code/Source/MultiplayerSystemComponent.h @@ -71,6 +71,7 @@ namespace Multiplayer bool HandleRequest(AzNetworking::IConnection* connection, const AzNetworking::IPacketHeader& packetHeader, MultiplayerPackets::ClientMigration& packet); bool HandleRequest(AzNetworking::IConnection* connection, const AzNetworking::IPacketHeader& packetHeader, MultiplayerPackets::NotifyClientMigration& packet); bool HandleRequest(AzNetworking::IConnection* connection, const AzNetworking::IPacketHeader& packetHeader, MultiplayerPackets::EntityMigration& packet); + bool HandleRequest(AzNetworking::IConnection* connection, const AzNetworking::IPacketHeader& packetHeader, MultiplayerPackets::ReadyForEntityUpdates& packet); //! IConnectionListener interface //! @{ @@ -88,6 +89,7 @@ namespace Multiplayer void AddConnectionAcquiredHandler(ConnectionAcquiredEvent::Handler& handler) override; void AddSessionInitHandler(SessionInitEvent::Handler& handler) override; void AddSessionShutdownHandler(SessionShutdownEvent::Handler& handler) override; + void SendReadyForEntityUpdates(bool readyForEntityUpdates) override; //! @} //! Console commands. diff --git a/Gems/Multiplayer/Code/Source/NetworkEntity/NetworkEntityManager.cpp b/Gems/Multiplayer/Code/Source/NetworkEntity/NetworkEntityManager.cpp index 2eb93d706d..131e7be3f1 100644 --- a/Gems/Multiplayer/Code/Source/NetworkEntity/NetworkEntityManager.cpp +++ b/Gems/Multiplayer/Code/Source/NetworkEntity/NetworkEntityManager.cpp @@ -11,19 +11,19 @@ */ #include -#include -#include -#include + +#include #include #include +#include #include #include +#include #include #include -#include #include #include -#include +#include namespace Multiplayer { @@ -462,7 +462,9 @@ namespace Multiplayer m_rootSpawnableAsset = netSpawnableAsset; - const auto agentType = AZ::Interface::Get()->GetAgentType(); + auto* iMultiplayer = AZ::Interface::Get(); + + const auto agentType = iMultiplayer->GetAgentType(); const bool spawnImmediately = (agentType == MultiplayerAgentType::ClientServer || agentType == MultiplayerAgentType::DedicatedServer); @@ -470,6 +472,12 @@ namespace Multiplayer { CreateEntitiesImmediate(*netSpawnable, NetEntityRole::Authority); } + else + { + // If we don't spawn net entities immediately (i.e. it is a client), + // tell the server/host it can start sending updates that will instantiate entities. + iMultiplayer->SendReadyForEntityUpdates(true); + } } void NetworkEntityManager::OnRootSpawnableReleased([[maybe_unused]] uint32_t generation) From 1db6c9236a668e6f91404f15c32913a433b7f8a3 Mon Sep 17 00:00:00 2001 From: pereslav Date: Mon, 26 Apr 2021 15:50:41 +0100 Subject: [PATCH 05/10] Made Launcher use AZ Console instead of CryConsole. Updated the exec function according to PR comments --- Code/LauncherUnified/Launcher.cpp | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/Code/LauncherUnified/Launcher.cpp b/Code/LauncherUnified/Launcher.cpp index 4721e3f0a7..568c202eee 100644 --- a/Code/LauncherUnified/Launcher.cpp +++ b/Code/LauncherUnified/Launcher.cpp @@ -26,7 +26,6 @@ #include #include -#include #include #include #include @@ -46,17 +45,20 @@ extern "C" void CreateStaticModules(AZStd::vector& modulesOut); namespace { - void ExecuteCustomConfig(AzFramework::Application& application) + void ExecuteConsoleCommandFile(AzFramework::Application& application) { - const AZStd::string_view customCfgKey = "customcfg"; + const AZStd::string_view customConCmdKey = "console_command_file"; const AZ::CommandLine* commandLine = application.GetCommandLine(); - if (commandLine->HasSwitch(customCfgKey) && commandLine->GetNumSwitchValues(customCfgKey) > 0) + AZStd::size_t numSwitchValues = commandLine->GetNumSwitchValues(customConCmdKey); + if (numSwitchValues > 0) { - const AZStd::string& customCfg = commandLine->GetSwitchValue(customCfgKey, 0); - if (!customCfg.empty()) + // The expectations for command line parameters is that the "last one wins" + // That way it allows users and test scripts to override previous command line options by just listing them later on the invocation line + const AZStd::string& consoleCmd = commandLine->GetSwitchValue(customConCmdKey, numSwitchValues - 1); + if (!consoleCmd.empty()) { - AZStd::string execString = "exec " + customCfg; - gEnv->pConsole->ExecuteString(execString.c_str()); + AZStd::string execString = "exec " + consoleCmd; + AZ::Interface::Get()->PerformCommand(execString.c_str()); } } } @@ -652,9 +654,11 @@ namespace O3DELauncher if (gEnv && gEnv->pConsole) { // Execute autoexec.cfg to load the initial level - gEnv->pConsole->ExecuteString("exec autoexec.cfg"); + AZ::Interface::Get()->PerformCommand("exec autoexec.cfg"); - ExecuteCustomConfig(gameApplication); + // Find out if console command file was passed + // via --console_command_file=%filename% and execute it + ExecuteConsoleCommandFile(gameApplication); gEnv->pSystem->ExecuteCommandLine(false); From 2b77d434353a21984198e29370f9d65a87c1d2de Mon Sep 17 00:00:00 2001 From: pereslav Date: Mon, 26 Apr 2021 21:30:52 +0100 Subject: [PATCH 06/10] Exposed exec console command to AZ Console --- Code/CryEngine/CrySystem/ConsoleBatchFile.cpp | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/Code/CryEngine/CrySystem/ConsoleBatchFile.cpp b/Code/CryEngine/CrySystem/ConsoleBatchFile.cpp index 946edb9b64..7d6bc3709f 100644 --- a/Code/CryEngine/CrySystem/ConsoleBatchFile.cpp +++ b/Code/CryEngine/CrySystem/ConsoleBatchFile.cpp @@ -23,9 +23,27 @@ #include #include "System.h" #include +#include IConsole* CConsoleBatchFile::m_pConsole = NULL; +namespace +{ + static void exec(const AZ::ConsoleCommandContainer& args) + { + if (args.size() == 1) + { + CConsoleBatchFile::ExecuteConfigFile(args.front().data()); + } + else + { + AZ_Warning("editor", false, "exec requires exactly one file name."); + } + } + + AZ_CONSOLEFREEFUNC(exec, AZ::ConsoleFunctorFlags::Null, "Executes a batch file of console commands."); +} + void CConsoleBatchFile::Init() { m_pConsole = gEnv->pConsole; From 44ce664730291cfdb22c38a0cca0f87bcd04f2c6 Mon Sep 17 00:00:00 2001 From: pereslav Date: Tue, 27 Apr 2021 12:36:17 +0100 Subject: [PATCH 07/10] Changed handling --console_command_file to use AZ::Console::ExecuteConfigFile --- Code/CryEngine/CrySystem/ConsoleBatchFile.cpp | 18 ------------------ Code/LauncherUnified/Launcher.cpp | 5 ++--- 2 files changed, 2 insertions(+), 21 deletions(-) diff --git a/Code/CryEngine/CrySystem/ConsoleBatchFile.cpp b/Code/CryEngine/CrySystem/ConsoleBatchFile.cpp index 7d6bc3709f..946edb9b64 100644 --- a/Code/CryEngine/CrySystem/ConsoleBatchFile.cpp +++ b/Code/CryEngine/CrySystem/ConsoleBatchFile.cpp @@ -23,27 +23,9 @@ #include #include "System.h" #include -#include IConsole* CConsoleBatchFile::m_pConsole = NULL; -namespace -{ - static void exec(const AZ::ConsoleCommandContainer& args) - { - if (args.size() == 1) - { - CConsoleBatchFile::ExecuteConfigFile(args.front().data()); - } - else - { - AZ_Warning("editor", false, "exec requires exactly one file name."); - } - } - - AZ_CONSOLEFREEFUNC(exec, AZ::ConsoleFunctorFlags::Null, "Executes a batch file of console commands."); -} - void CConsoleBatchFile::Init() { m_pConsole = gEnv->pConsole; diff --git a/Code/LauncherUnified/Launcher.cpp b/Code/LauncherUnified/Launcher.cpp index 568c202eee..1cc4450cea 100644 --- a/Code/LauncherUnified/Launcher.cpp +++ b/Code/LauncherUnified/Launcher.cpp @@ -57,8 +57,7 @@ namespace const AZStd::string& consoleCmd = commandLine->GetSwitchValue(customConCmdKey, numSwitchValues - 1); if (!consoleCmd.empty()) { - AZStd::string execString = "exec " + consoleCmd; - AZ::Interface::Get()->PerformCommand(execString.c_str()); + AZ::Interface::Get()->ExecuteConfigFile(consoleCmd.c_str()); } } } @@ -654,7 +653,7 @@ namespace O3DELauncher if (gEnv && gEnv->pConsole) { // Execute autoexec.cfg to load the initial level - AZ::Interface::Get()->PerformCommand("exec autoexec.cfg"); + AZ::Interface::Get()->ExecuteConfigFile("autoexec.cfg"); // Find out if console command file was passed // via --console_command_file=%filename% and execute it From e3b016debac7ec42b0745d195fe5f14a36a63b1d Mon Sep 17 00:00:00 2001 From: pereslav Date: Tue, 27 Apr 2021 14:57:36 +0100 Subject: [PATCH 08/10] PR feedback addressing --- .../Source/ConnectionData/ClientToServerConnectionData.h | 4 ++-- .../ConnectionData/ClientToServerConnectionData.inl | 7 ++++++- .../Code/Source/ConnectionData/IConnectionData.h | 8 ++++++++ .../Source/ConnectionData/ServerToClientConnectionData.h | 5 ++--- .../Code/Source/MultiplayerSystemComponent.cpp | 2 +- .../Code/Source/NetworkEntity/NetworkEntityManager.cpp | 6 +++--- 6 files changed, 22 insertions(+), 10 deletions(-) diff --git a/Gems/Multiplayer/Code/Source/ConnectionData/ClientToServerConnectionData.h b/Gems/Multiplayer/Code/Source/ConnectionData/ClientToServerConnectionData.h index b63ffee9a3..76a809b351 100644 --- a/Gems/Multiplayer/Code/Source/ConnectionData/ClientToServerConnectionData.h +++ b/Gems/Multiplayer/Code/Source/ConnectionData/ClientToServerConnectionData.h @@ -33,10 +33,10 @@ namespace Multiplayer AzNetworking::IConnection* GetConnection() const override; EntityReplicationManager& GetReplicationManager() override; void Update(AZ::TimeMs serverGameTimeMs) override; + bool CanSendUpdates() const override; + void SetCanSendUpdates(bool canSendUpdates) override; //! @} - bool CanSendUpdates(); - private: EntityReplicationManager m_entityReplicationManager; AzNetworking::IConnection* m_connection = nullptr; diff --git a/Gems/Multiplayer/Code/Source/ConnectionData/ClientToServerConnectionData.inl b/Gems/Multiplayer/Code/Source/ConnectionData/ClientToServerConnectionData.inl index 1ee5711341..6d4a332b6e 100644 --- a/Gems/Multiplayer/Code/Source/ConnectionData/ClientToServerConnectionData.inl +++ b/Gems/Multiplayer/Code/Source/ConnectionData/ClientToServerConnectionData.inl @@ -12,8 +12,13 @@ namespace Multiplayer { - inline bool ClientToServerConnectionData::CanSendUpdates() + inline bool ClientToServerConnectionData::CanSendUpdates() const { return m_canSendUpdates; } + + inline void ClientToServerConnectionData::SetCanSendUpdates(bool canSendUpdates) + { + m_canSendUpdates = canSendUpdates; + } } diff --git a/Gems/Multiplayer/Code/Source/ConnectionData/IConnectionData.h b/Gems/Multiplayer/Code/Source/ConnectionData/IConnectionData.h index ebff75fd9b..a7ceffd289 100644 --- a/Gems/Multiplayer/Code/Source/ConnectionData/IConnectionData.h +++ b/Gems/Multiplayer/Code/Source/ConnectionData/IConnectionData.h @@ -44,5 +44,13 @@ namespace Multiplayer //! Creates and manages sending updates to the remote endpoint. //! @param serverGameTimeMs current server game time in milliseconds virtual void Update(AZ::TimeMs serverGameTimeMs) = 0; + + //! Returns whether update messages can be sent to the connection. + //! @return true if update messages can be sent + virtual bool CanSendUpdates() const = 0; + + //! Sets the state of connection whether update messages can be sent or not. + //! @param canSendUpdates the state value + virtual void SetCanSendUpdates(bool canSendUpdates) = 0; }; } diff --git a/Gems/Multiplayer/Code/Source/ConnectionData/ServerToClientConnectionData.h b/Gems/Multiplayer/Code/Source/ConnectionData/ServerToClientConnectionData.h index 596bdc88d9..7ea62b15fd 100644 --- a/Gems/Multiplayer/Code/Source/ConnectionData/ServerToClientConnectionData.h +++ b/Gems/Multiplayer/Code/Source/ConnectionData/ServerToClientConnectionData.h @@ -34,11 +34,10 @@ namespace Multiplayer AzNetworking::IConnection* GetConnection() const override; EntityReplicationManager& GetReplicationManager() override; void Update(AZ::TimeMs serverGameTimeMs) override; + bool CanSendUpdates() const override; + void SetCanSendUpdates(bool canSendUpdates) override; //! @} - bool CanSendUpdates() const; - void SetCanSendUpdates(bool canSendUpdates); - NetworkEntityHandle GetPrimaryPlayerEntity(); const NetworkEntityHandle& GetPrimaryPlayerEntity() const; diff --git a/Gems/Multiplayer/Code/Source/MultiplayerSystemComponent.cpp b/Gems/Multiplayer/Code/Source/MultiplayerSystemComponent.cpp index 49a0f63b63..c0570b054e 100644 --- a/Gems/Multiplayer/Code/Source/MultiplayerSystemComponent.cpp +++ b/Gems/Multiplayer/Code/Source/MultiplayerSystemComponent.cpp @@ -384,7 +384,7 @@ namespace Multiplayer bool MultiplayerSystemComponent::HandleRequest( AzNetworking::IConnection* connection, [[maybe_unused]] const AzNetworking::IPacketHeader& packetHeader, MultiplayerPackets::ReadyForEntityUpdates& packet) { - auto* connectionData = reinterpret_cast(connection->GetUserData()); + IConnectionData* connectionData = reinterpret_cast(connection->GetUserData()); if (connectionData) { connectionData->SetCanSendUpdates(packet.GetReadyForEntityUpdates()); diff --git a/Gems/Multiplayer/Code/Source/NetworkEntity/NetworkEntityManager.cpp b/Gems/Multiplayer/Code/Source/NetworkEntity/NetworkEntityManager.cpp index 131e7be3f1..4832ba487a 100644 --- a/Gems/Multiplayer/Code/Source/NetworkEntity/NetworkEntityManager.cpp +++ b/Gems/Multiplayer/Code/Source/NetworkEntity/NetworkEntityManager.cpp @@ -462,9 +462,9 @@ namespace Multiplayer m_rootSpawnableAsset = netSpawnableAsset; - auto* iMultiplayer = AZ::Interface::Get(); + auto* multiplayer = AZ::Interface::Get(); - const auto agentType = iMultiplayer->GetAgentType(); + const auto agentType = multiplayer->GetAgentType(); const bool spawnImmediately = (agentType == MultiplayerAgentType::ClientServer || agentType == MultiplayerAgentType::DedicatedServer); @@ -476,7 +476,7 @@ namespace Multiplayer { // If we don't spawn net entities immediately (i.e. it is a client), // tell the server/host it can start sending updates that will instantiate entities. - iMultiplayer->SendReadyForEntityUpdates(true); + multiplayer->SendReadyForEntityUpdates(true); } } From ff3be54b683ea5e61314b97ff5ac8f0762266fe9 Mon Sep 17 00:00:00 2001 From: karlberg Date: Tue, 27 Apr 2021 19:31:30 -0700 Subject: [PATCH 09/10] This change got clobbered by the file move --- Gems/Multiplayer/Code/Include/MultiplayerTypes.h | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/Gems/Multiplayer/Code/Include/MultiplayerTypes.h b/Gems/Multiplayer/Code/Include/MultiplayerTypes.h index ca3734e4f0..5c690958b5 100644 --- a/Gems/Multiplayer/Code/Include/MultiplayerTypes.h +++ b/Gems/Multiplayer/Code/Include/MultiplayerTypes.h @@ -73,6 +73,12 @@ namespace Multiplayer True }; + enum class AutoActivate : uint8_t + { + DoNotActivate, + Activate + }; + // This is just a placeholder // The level/prefab cooking will devise the actual solution for identifying a dynamically spawnable entity within a prefab struct PrefabEntityId From b82627a24886ed4432a0c4dcd620287283be77c9 Mon Sep 17 00:00:00 2001 From: pereslav Date: Wed, 28 Apr 2021 07:44:11 +0100 Subject: [PATCH 10/10] Renamed console_command_file to console-command-file --- Code/LauncherUnified/Launcher.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Code/LauncherUnified/Launcher.cpp b/Code/LauncherUnified/Launcher.cpp index 1cc4450cea..93b5079929 100644 --- a/Code/LauncherUnified/Launcher.cpp +++ b/Code/LauncherUnified/Launcher.cpp @@ -47,7 +47,7 @@ namespace { void ExecuteConsoleCommandFile(AzFramework::Application& application) { - const AZStd::string_view customConCmdKey = "console_command_file"; + const AZStd::string_view customConCmdKey = "console-command-file"; const AZ::CommandLine* commandLine = application.GetCommandLine(); AZStd::size_t numSwitchValues = commandLine->GetNumSwitchValues(customConCmdKey); if (numSwitchValues > 0) @@ -656,7 +656,7 @@ namespace O3DELauncher AZ::Interface::Get()->ExecuteConfigFile("autoexec.cfg"); // Find out if console command file was passed - // via --console_command_file=%filename% and execute it + // via --console-command-file=%filename% and execute it ExecuteConsoleCommandFile(gameApplication); gEnv->pSystem->ExecuteCommandLine(false);