Merge pull request #271 from aws-lumberyard-dev/mpgem_editor

Adding Multiplayer.Editor which allows specifying a server process for use with Editor on Ctrl+G
This commit is contained in:
AMZN-puvvadar
2021-04-30 09:54:30 -07:00
committed by GitHub
10 changed files with 443 additions and 0 deletions
+45
View File
@@ -59,6 +59,7 @@ ly_add_target(
)
if (PAL_TRAIT_BUILD_HOST_TOOLS)
ly_add_target(
NAME Multiplayer.Tools MODULE
NAMESPACE Gem
@@ -76,6 +77,50 @@ if (PAL_TRAIT_BUILD_HOST_TOOLS)
AZ::AzToolsFramework
Gem::Multiplayer.Static
)
ly_add_target(
NAME Multiplayer.Editor.Static STATIC
NAMESPACE Gem
FILES_CMAKE
multiplayer_editor_files.cmake
COMPILE_DEFINITIONS
PUBLIC
MULTIPLAYER_EDITOR
INCLUDE_DIRECTORIES
PRIVATE
.
Source
${pal_source_dir}
PUBLIC
Include
BUILD_DEPENDENCIES
PUBLIC
Legacy::CryCommon
Legacy::Editor.Headers
AZ::AzCore
AZ::AzFramework
AZ::AzNetworking
AZ::AzToolsFramework
Gem::Multiplayer.Static
)
ly_add_target(
NAME Multiplayer.Editor GEM_MODULE
NAMESPACE Gem
FILES_CMAKE
multiplayer_editor_shared_files.cmake
INCLUDE_DIRECTORIES
PRIVATE
.
Source
${pal_source_dir}
PUBLIC
Include
BUILD_DEPENDENCIES
PRIVATE
Gem::Multiplayer.Editor.Static
)
endif()
if (PAL_TRAIT_BUILD_TESTS_SUPPORTED)
@@ -0,0 +1,21 @@
/*
* 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/Editor/MultiplayerEditorDispatcher.h>
namespace Multiplayer
{
MultiplayerEditorDispatcher::MultiplayerEditorDispatcher()
{
;
}
}
@@ -0,0 +1,36 @@
/*
* 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 <IEditor.h>
#include <AzCore/Component/Component.h>
#include <AzCore/Component/TickBus.h>
#include <AzCore/Console/IConsole.h>
#include <AzCore/Console/ILogger.h>
#include <AzToolsFramework/Entity/EditorEntityContextBus.h>
namespace Multiplayer
{
//! MultiplayerEditorDispatcher is responsible for dispatching delta from the Editor to an Editor launched local server
class MultiplayerEditorDispatcher final
{
public:
MultiplayerEditorDispatcher();
~MultiplayerEditorDispatcher() = default;
private:
};
}
@@ -0,0 +1,154 @@
/*
* 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/Editor/MultiplayerEditorSystemComponent.h>
#include <AzCore/Interface/Interface.h>
#include <AzCore/Console/IConsole.h>
#include <AzCore/Console/ILogger.h>
#include <AzCore/Serialization/SerializeContext.h>
#include <AzCore/Utils/Utils.h>
namespace Multiplayer
{
using namespace AzNetworking;
AZ_CVAR(bool, editorsv_enabled, false, nullptr, AZ::ConsoleFunctorFlags::DontReplicate,
"Whether Editor launching a local server to connect to is supported");
AZ_CVAR(AZ::CVarFixedString, editorsv_process, "", nullptr, AZ::ConsoleFunctorFlags::DontReplicate,
"The server executable that should be run. Empty to use the current project's ServerLauncher");
void MultiplayerEditorSystemComponent::Reflect(AZ::ReflectContext* context)
{
if (AZ::SerializeContext* serializeContext = azrtti_cast<AZ::SerializeContext*>(context))
{
serializeContext->Class<MultiplayerEditorSystemComponent, AZ::Component>()
->Version(1);
}
}
void MultiplayerEditorSystemComponent::GetRequiredServices(AZ::ComponentDescriptor::DependencyArrayType& required)
{
required.push_back(AZ_CRC_CE("MultiplayerService"));
}
void MultiplayerEditorSystemComponent::GetProvidedServices(AZ::ComponentDescriptor::DependencyArrayType& provided)
{
provided.push_back(AZ_CRC_CE("MultiplayerEditorService"));
}
void MultiplayerEditorSystemComponent::GetIncompatibleServices(AZ::ComponentDescriptor::DependencyArrayType& incompatible)
{
incompatible.push_back(AZ_CRC_CE("MultiplayerEditorService"));
}
MultiplayerEditorSystemComponent::MultiplayerEditorSystemComponent()
{
;
}
void MultiplayerEditorSystemComponent::Activate()
{
AzToolsFramework::EditorEvents::Bus::Handler::BusConnect();
}
void MultiplayerEditorSystemComponent::Deactivate()
{
AzToolsFramework::EditorEvents::Bus::Handler::BusDisconnect();
}
void MultiplayerEditorSystemComponent::NotifyRegisterViews()
{
AZ_Assert(m_editor == nullptr, "NotifyRegisterViews occurred twice!");
m_editor = nullptr;
AzToolsFramework::EditorRequests::Bus::BroadcastResult(m_editor, &AzToolsFramework::EditorRequests::GetEditor);
m_editor->RegisterNotifyListener(this);
}
void MultiplayerEditorSystemComponent::OnEditorNotifyEvent(EEditorNotifyEvent event)
{
switch (event)
{
case eNotify_OnBeginGameMode:
{
AZ::TickBus::Handler::BusConnect();
if (editorsv_enabled)
{
// Assemble the server's path
AZ::CVarFixedString serverProcess = editorsv_process;
if (serverProcess.empty())
{
// If enabled but no process name is supplied, try this project's ServerLauncher
serverProcess = AZ::Utils::GetProjectName() + ".ServerLauncher";
}
AZ::IO::FixedMaxPathString serverPath = AZ::Utils::GetExecutableDirectory();
if (!serverProcess.contains(AZ_TRAIT_OS_PATH_SEPARATOR))
{
// If only the process name is specified, append that as well
serverPath.append(AZ_TRAIT_OS_PATH_SEPARATOR + serverProcess);
}
else
{
// If any path was already specified, then simply assign
serverPath = serverProcess;
}
if (!serverProcess.ends_with(AZ_TRAIT_OS_EXECUTABLE_EXTENSION))
{
// Add this platform's exe extension if it's not specified
serverPath.append(AZ_TRAIT_OS_EXECUTABLE_EXTENSION);
}
// Start the configured server if it's available
AzFramework::ProcessLauncher::ProcessLaunchInfo processLaunchInfo;
processLaunchInfo.m_commandlineParameters =
AZStd::string::format("\"%s\"", serverPath.c_str());
processLaunchInfo.m_showWindow = true;
processLaunchInfo.m_processPriority = AzFramework::ProcessPriority::PROCESSPRIORITY_NORMAL;
m_serverProcess = AzFramework::ProcessWatcher::LaunchProcess(
processLaunchInfo, AzFramework::ProcessCommunicationType::COMMUNICATOR_TYPE_NONE);
}
break;
}
case eNotify_OnQuit:
AZ_Warning("Multiplayer Editor", m_editor != nullptr, "Multiplayer Editor received On Quit without an Editor pointer.");
if (m_editor)
{
m_editor->UnregisterNotifyListener(this);
m_editor = nullptr;
}
[[fallthrough]];
case eNotify_OnEndGameMode:
AZ::TickBus::Handler::BusDisconnect();
// Kill the configured server if it's active
if (m_serverProcess)
{
m_serverProcess->TerminateProcess(0);
m_serverProcess = nullptr;
}
break;
}
}
void MultiplayerEditorSystemComponent::OnTick([[maybe_unused]] float deltaTime, [[maybe_unused]] AZ::ScriptTimePoint time)
{
}
int MultiplayerEditorSystemComponent::GetTickOrder()
{
// Tick immediately after the network system component
return AZ::TICK_PLACEMENT + 1;
}
}
@@ -0,0 +1,75 @@
/*
* 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 <IEditor.h>
#include <AzCore/Component/Component.h>
#include <AzCore/Component/TickBus.h>
#include <AzCore/Console/IConsole.h>
#include <AzCore/Console/ILogger.h>
#include <AzFramework/Process/ProcessWatcher.h>
#include <AzToolsFramework/Entity/EditorEntityContextBus.h>
namespace AzNetworking
{
class INetworkInterface;
}
namespace Multiplayer
{
//! Multiplayer system component wraps the bridging logic between the game and transport layer.
class MultiplayerEditorSystemComponent final
: public AZ::Component
, private AZ::TickBus::Handler
, private AzToolsFramework::EditorEvents::Bus::Handler
, private IEditorNotifyListener
{
public:
AZ_COMPONENT(MultiplayerEditorSystemComponent, "{9F335CC0-5574-4AD3-A2D8-2FAEF356946C}");
static void Reflect(AZ::ReflectContext* context);
static void GetRequiredServices(AZ::ComponentDescriptor::DependencyArrayType& required);
static void GetProvidedServices(AZ::ComponentDescriptor::DependencyArrayType& provided);
static void GetIncompatibleServices(AZ::ComponentDescriptor::DependencyArrayType& incompatible);
MultiplayerEditorSystemComponent();
~MultiplayerEditorSystemComponent() override = default;
//! AZ::Component overrides.
//! @{
void Activate() override;
void Deactivate() override;
//! @}
//! EditorEvents::Bus::Handler overrides.
//! @{
void NotifyRegisterViews() override;
//! @}
private:
//! AZ::TickBus::Handler overrides.
//! @{
void OnTick(float deltaTime, AZ::ScriptTimePoint time) override;
int GetTickOrder() override;
//! @}
//!
void OnEditorNotifyEvent(EEditorNotifyEvent event) override;
IEditor* m_editor = nullptr;
AzFramework::ProcessWatcher* m_serverProcess = nullptr;
};
}
@@ -0,0 +1,46 @@
/*
* 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/Multiplayer_precompiled.h>
#include <Source/MultiplayerGem.h>
#include <Source/MultiplayerSystemComponent.h>
#include <Source/MultiplayerEditorGem.h>
#include <AzNetworking/Framework/NetworkingSystemComponent.h>
#include <Source/Editor/MultiplayerEditorSystemComponent.h>
namespace Multiplayer
{
AZ_CLASS_ALLOCATOR_IMPL(MultiplayerEditorModule, AZ::SystemAllocator, 0)
MultiplayerEditorModule::MultiplayerEditorModule()
: MultiplayerModule()
{
// Append Editor specific descriptors
m_descriptors.insert(
m_descriptors.end(),
{
MultiplayerEditorSystemComponent::CreateDescriptor(),
});
}
MultiplayerEditorModule::~MultiplayerEditorModule() = default;
AZ::ComponentTypeList MultiplayerEditorModule::GetRequiredSystemComponents() const
{
AZ::ComponentTypeList requiredComponents = MultiplayerModule::GetRequiredSystemComponents();
requiredComponents.push_back(azrtti_typeid<MultiplayerEditorSystemComponent>());
return requiredComponents;
}
} // namespace Multiplayer
AZ_DECLARE_MODULE_CLASS(Gem_MultiplayerEditor, Multiplayer::MultiplayerEditorModule)
@@ -0,0 +1,30 @@
/*
* 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 "MultiplayerGem.h"
namespace Multiplayer
{
class MultiplayerEditorModule: public MultiplayerModule
{
public:
AZ_CLASS_ALLOCATOR_DECL
AZ_RTTI(MultiplayerEditorModule, "{50273605-2BBF-4D43-A42D-ED140B92B4D4}", MultiplayerModule);
MultiplayerEditorModule();
~MultiplayerEditorModule();
AZ::ComponentTypeList GetRequiredSystemComponents() const override;
};
} // namespace Multiplayer
@@ -45,4 +45,6 @@ namespace Multiplayer
}
}
#if !defined(MULTIPLAYER_EDITOR)
AZ_DECLARE_MODULE_CLASS(Gem_Multiplayer, Multiplayer::MultiplayerModule);
#endif
@@ -0,0 +1,15 @@
#
# 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.
#
set(FILES
Source/Editor/MultiplayerEditorDispatcher.cpp
Source/Editor/MultiplayerEditorDispatcher.h
)
@@ -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.
#
set(FILES
Source/MultiplayerGem.cpp
Source/MultiplayerGem.h
Source/MultiplayerEditorGem.cpp
Source/MultiplayerEditorGem.h
Source/Editor/MultiplayerEditorSystemComponent.cpp
Source/Editor/MultiplayerEditorSystemComponent.h
)