Files
o3de/Gems/BarrierInput/Code/Source/BarrierInputMouse.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

106 lines
5.5 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 <BarrierInput/RawInputNotificationBus_Barrier.h>
#include <AzFramework/Input/Devices/Mouse/InputDeviceMouse.h>
#include <AzCore/std/parallel/mutex.h>
////////////////////////////////////////////////////////////////////////////////////////////////////
namespace BarrierInput
{
////////////////////////////////////////////////////////////////////////////////////////////////
//! Barrier specific implementation for mouse input devices.
class InputDeviceMouseBarrier : public AzFramework::InputDeviceMouse::Implementation
, public RawInputNotificationBusBarrier::Handler
{
public:
////////////////////////////////////////////////////////////////////////////////////////////
// Allocator
AZ_CLASS_ALLOCATOR(InputDeviceMouseBarrier, AZ::SystemAllocator, 0);
////////////////////////////////////////////////////////////////////////////////////////////
//! Custom factory create function
//! \param[in] inputDevice Reference to the input device being implemented
static Implementation* Create(AzFramework::InputDeviceMouse& inputDevice);
////////////////////////////////////////////////////////////////////////////////////////////
//! Constructor
//! \param[in] inputDevice Reference to the input device being implemented
InputDeviceMouseBarrier(AzFramework::InputDeviceMouse& inputDevice);
////////////////////////////////////////////////////////////////////////////////////////////
//! Destructor
~InputDeviceMouseBarrier() override;
private:
////////////////////////////////////////////////////////////////////////////////////////////
//! \ref AzFramework::InputDeviceMouse::Implementation::IsConnected
bool IsConnected() const override;
////////////////////////////////////////////////////////////////////////////////////////////
//! \ref AzFramework::InputDeviceMouse::Implementation::SetSystemCursorState
void SetSystemCursorState(AzFramework::SystemCursorState systemCursorState) override;
////////////////////////////////////////////////////////////////////////////////////////////
//! \ref AzFramework::InputDeviceMouse::Implementation::GetSystemCursorState
AzFramework::SystemCursorState GetSystemCursorState() const override;
////////////////////////////////////////////////////////////////////////////////////////////
//! \ref AzFramework::InputDeviceMouse::Implementation::SetSystemCursorPositionNormalized
void SetSystemCursorPositionNormalized(AZ::Vector2 positionNormalized) override;
////////////////////////////////////////////////////////////////////////////////////////////
//! \ref AzFramework::InputDeviceMouse::Implementation::GetSystemCursorPositionNormalized
AZ::Vector2 GetSystemCursorPositionNormalized() const override;
////////////////////////////////////////////////////////////////////////////////////////////
//! \ref AzFramework::InputDeviceMouse::Implementation::TickInputDevice
void TickInputDevice() override;
////////////////////////////////////////////////////////////////////////////////////////////
//! \ref RawInputNotificationsBarrier::OnRawMouseButtonDownEvent
void OnRawMouseButtonDownEvent(uint32_t buttonIndex) override;
////////////////////////////////////////////////////////////////////////////////////////////
//! \ref RawInputNotificationsBarrier::OnRawMouseButtonUpEvent
void OnRawMouseButtonUpEvent(uint32_t buttonIndex) override;
////////////////////////////////////////////////////////////////////////////////////////////
//! \ref RawInputNotificationsBarrier::OnRawMouseMovementEvent
void OnRawMouseMovementEvent(float movementX, float movementY) override;
////////////////////////////////////////////////////////////////////////////////////////////
//! \ref RawInputNotificationsBarrier::OnRawMousePositionEvent
void OnRawMousePositionEvent(float positionX, float positionY) override;
////////////////////////////////////////////////////////////////////////////////////////////
//! Thread safe method to queue raw button events to be processed in the main thread update
//! \param[in] buttonIndex The index of the button
//! \param[in] rawButtonState The raw button state
void ThreadSafeQueueRawButtonEvent(uint32_t buttonIndex, bool rawButtonState);
////////////////////////////////////////////////////////////////////////////////////////////
// Variables
AzFramework::SystemCursorState m_systemCursorState;
AZ::Vector2 m_systemCursorPositionNormalized;
RawButtonEventQueueByIdMap m_threadAwareRawButtonEventQueuesById;
AZStd::mutex m_threadAwareRawButtonEventQueuesByIdMutex;
RawMovementEventQueueByIdMap m_threadAwareRawMovementEventQueuesById;
AZStd::mutex m_threadAwareRawMovementEventQueuesByIdMutex;
AZ::Vector2 m_threadAwareSystemCursorPosition;
AZStd::mutex m_threadAwareSystemCursorPositionMutex;
};
} // namespace BarrierInput