You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
126 lines
5.4 KiB
C++
126 lines
5.4 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 <InputManagementFramework/InputSubComponent.h>
|
|
#include <AzCore/RTTI/RTTI.h>
|
|
#include <AzCore/Component/TickBus.h>
|
|
#include <AzFramework/Input/Buses/Notifications/InputDeviceNotificationBus.h>
|
|
#include <AzFramework/Input/Events/InputChannelEventListener.h>
|
|
#include <InputNotificationBus.h>
|
|
#include <InputRequestBus.h>
|
|
|
|
namespace AZ
|
|
{
|
|
class ReflectContext;
|
|
}
|
|
|
|
namespace Input
|
|
{
|
|
//////////////////////////////////////////////////////////////////////////
|
|
/// Input handles raw input from any source and outputs Pressed, Held, and Released input events
|
|
class Input
|
|
: public InputSubComponent
|
|
, protected AzFramework::InputChannelEventListener
|
|
, protected AZ::GlobalInputRecordRequestBus::Handler
|
|
, protected AZ::InputRecordRequestBus::Handler
|
|
{
|
|
public:
|
|
Input();
|
|
~Input() override = default;
|
|
AZ_RTTI(Input, "{546C9EBC-90EF-4F03-891A-0736BE2A487E}", InputSubComponent);
|
|
static void Reflect(AZ::ReflectContext* reflection);
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
|
// InputSubComponent
|
|
void Activate(const AZ::InputEventNotificationId& eventNotificationId) override;
|
|
void Deactivate(const AZ::InputEventNotificationId& eventNotificationId) override;
|
|
|
|
protected:
|
|
AZStd::string GetEditorText() const;
|
|
virtual const AZStd::vector<AZStd::string> GetInputDeviceTypes() const;
|
|
virtual const AZStd::vector<AZStd::string> GetInputNamesBySelectedDevice() const;
|
|
|
|
AZ::Crc32 OnDeviceSelected();
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
|
// AZ::GlobalInputRecordRequests::Handler
|
|
void GatherEditableInputRecords(AZ::EditableInputRecords& outResults) override;
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
|
// AZ::EditableInputRecord::Handler
|
|
void SetInputRecord(const AZ::EditableInputRecord& newInputRecord) override;
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
|
// AzFramework::InputChannelEventListener
|
|
bool OnInputChannelEventFiltered(const AzFramework::InputChannel& inputChannel) override;
|
|
|
|
using InputEventType = void(AZ::InputEventNotificationBus::Events::*)(float);
|
|
virtual float CalculateEventValue(const AzFramework::InputChannel& inputChannel) const;
|
|
void SendEventsInternal(float value, const AzFramework::LocalUserId& localUserIdOfEvent, const AZ::InputEventNotificationId busId, InputEventType eventType);
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
|
// Non Reflected Data
|
|
AZ::InputEventNotificationId m_outgoingBusId;
|
|
bool m_wasPressed = false;
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
|
// Reflected Data
|
|
float m_eventValueMultiplier = 1.f;
|
|
AZStd::string m_inputName = "";
|
|
AZStd::string m_inputDeviceType = "";
|
|
float m_deadZone = 0.0f;
|
|
};
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
|
/// ThumbstickInput handles raw input from thumbstick sources, applies any
|
|
/// custom dead-zone or sensitivity curve calculations, and then outputs
|
|
/// Pressed, Held, and Released input events for the specified axis
|
|
class ThumbstickInput
|
|
: public Input
|
|
{
|
|
public:
|
|
ThumbstickInput();
|
|
~ThumbstickInput() override = default;
|
|
AZ_RTTI(ThumbstickInput, "{4881FA7C-0667-476C-8C77-4DBB6C69F646}", Input);
|
|
static void Reflect(AZ::ReflectContext* reflection);
|
|
|
|
protected:
|
|
//////////////////////////////////////////////////////////////////////////
|
|
// InputSubComponent
|
|
AZStd::string GetEditorText() const;
|
|
const AZStd::vector<AZStd::string> GetInputDeviceTypes() const override;
|
|
const AZStd::vector<AZStd::string> GetInputNamesBySelectedDevice() const override;
|
|
bool OnInputChannelEventFiltered(const AzFramework::InputChannel& inputChannel) override;
|
|
float CalculateEventValue(const AzFramework::InputChannel& inputChannel) const override;
|
|
|
|
static AZ::Vector2 ApplyDeadZonesAndSensitivity(const AZ::Vector2& inputValues,
|
|
float innerDeadZone,
|
|
float outerDeadZone,
|
|
float axisDeadZone,
|
|
float sensitivityExponent);
|
|
|
|
enum class OutputAxis
|
|
{
|
|
X,
|
|
Y
|
|
};
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
|
// Non Reflected Data
|
|
const AzFramework::InputDeviceId* m_wasLastPressedByInputDeviceId = nullptr;
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
|
// Reflected Data
|
|
float m_innerDeadZoneRadius = 0.0f;
|
|
float m_outerDeadZoneRadius = 1.0f;
|
|
float m_axisDeadZoneValue = 0.0f;
|
|
float m_sensitivityExponent = 1.0f;
|
|
OutputAxis m_outputAxis = OutputAxis::X;
|
|
};
|
|
} // namespace Input
|