Files
o3de/Gems/BarrierInput/Code/Source/BarrierInputSystemComponent.h
T
bosnichd 90e45a5bbd Barrier (formerly Synergy) Input Gem (#2336)
Synergy (now Barrier) input was lost when we removed the CryLegacy Gem. This resurrects the code, updates it to work with Barrier (which is the open source project based on the original Synergy core), and updates it to be more conformant with the AzFramework Input framework.

Notes:

- The majority of code in BarrierInputClient.cpp is still largely unmodified from the original Cry drop and could use some love to make it more robust, but it works so at least gives us somewhere to start.
- The current iteration replaces the host platform's default mouse/keyboard implementation upon creation of the BarrierInputClient, and if the connection fails or is later lost we don't restore the default implementations which we should for a better use experience. On a related note, for some use cases it would be better to create additional mouse/keyboard input devices (that use the Barrier implementations) in addition to the existing devices (that use the host platform's default implementation), however this would mean that any system assuming only one mouse/keyboard device exists would not work with the additional Barrier input devices. We can iterate on both of the above issues in the future as needed, perhaps providing configurable options to control the behaviour.

Signed-off-by: bosnichd <bosnichd@amazon.com>
2021-07-26 12:19:00 -06:00

87 lines
4.1 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 <BarrierInputClient.h>
#include <AzCore/EBus/EBus.h>
#include <AzCore/Component/Component.h>
#include <AzCore/std/smart_ptr/unique_ptr.h>
////////////////////////////////////////////////////////////////////////////////////////////////////
namespace BarrierInput
{
////////////////////////////////////////////////////////////////////////////////////////////////
//! EBus interface used to listen for changes to Barrier connection related CVars.
class BarrierInputConnectionNotifications : public AZ::EBusTraits
{
public:
////////////////////////////////////////////////////////////////////////////////////////////
//! Called when a CVar relating to the Barrier input connection changes.
virtual void OnBarrierConnectionCVarChanged() {}
};
using BarrierInputConnectionNotificationBus = AZ::EBus<BarrierInputConnectionNotifications>;
////////////////////////////////////////////////////////////////////////////////////////////////
//! A system component providing functionality related to Barrier input.
class BarrierInputSystemComponent : public AZ::Component
, public BarrierInputConnectionNotificationBus::Handler
{
public:
////////////////////////////////////////////////////////////////////////////////////////////
// AZ::Component Setup
AZ_COMPONENT(BarrierInputSystemComponent, "{720B6420-8A76-46F9-80C7-0DBF0CD467C2}");
////////////////////////////////////////////////////////////////////////////////////////////
//! \ref AZ::ComponentDescriptor::Reflect
static void Reflect(AZ::ReflectContext* context);
////////////////////////////////////////////////////////////////////////////////////////////
//! \ref AZ::ComponentDescriptor::GetProvidedServices
static void GetProvidedServices(AZ::ComponentDescriptor::DependencyArrayType& provided);
////////////////////////////////////////////////////////////////////////////////////////////
//! \ref AZ::ComponentDescriptor::GetIncompatibleServices
static void GetIncompatibleServices(AZ::ComponentDescriptor::DependencyArrayType& incompatible);
////////////////////////////////////////////////////////////////////////////////////////////
//! Default constructor
BarrierInputSystemComponent() = default;
////////////////////////////////////////////////////////////////////////////////////////////
//! Default destructor
~BarrierInputSystemComponent() override = default;
////////////////////////////////////////////////////////////////////////////////////////////
//! \ref AZ::Component::Activate
void Activate() override;
////////////////////////////////////////////////////////////////////////////////////////////
//! \ref AZ::Component::Deactivate
void Deactivate() override;
protected:
////////////////////////////////////////////////////////////////////////////////////////////
//! \ref BarrierInput::BarrierInputConnectionNotifications::OnBarrierConnectionCVarChanged
void OnBarrierConnectionCVarChanged() override;
////////////////////////////////////////////////////////////////////////////////////////////
//! Try to create the Barrier client and input device implementations.
void TryCreateBarrierClientAndInputDeviceImplementations();
////////////////////////////////////////////////////////////////////////////////////////////
//! Destroy the Barrier client and input device implementations (if they've been created).
void DestroyBarrierClientAndInputDeviceImplementations();
private:
////////////////////////////////////////////////////////////////////////////////////////////
//! The Barrier client instance.
AZStd::unique_ptr<BarrierClient> m_barrierClient;
};
} // namespace BarrierInput