Skip to main content

TwinStickInputSystem Class

Input component for twin-stick gamepad control schemes. More...

Declaration

class helios::engine::mechanics::input::systems::TwinStickInputSystem { ... }

Base class

classSystem

Abstract base class for game systems. More...

Public Constructors Index

TwinStickInputSystem (helios::engine::ecs::GameObject gameObject)

Constructs a TwinStickInputSystem for the specified GameObject. More...

Public Member Functions Index

voidupdate (helios::engine::runtime::world::UpdateContext &updateContext) noexcept override

Processes gamepad input and generates movement/aiming commands. More...

voidsetUseDedicatedShootInput (bool useDedicatedInput) noexcept

Enables or disables dedicated shoot input mode. More...

booluseDedicatedShootInput () const noexcept

Returns whether dedicated shoot input mode is enabled. More...

Private Member Attributes Index

booluseDedicatedShootInput_ = false

Flag to indicate whether shoot commands should be derived from the aim component. More...

helios::engine::ecs::GameObjectgameObject_

Reference to the GameObject this system reads input for. More...

Description

Input component for twin-stick gamepad control schemes.

Translates gamepad analog stick input into movement and aiming commands. The left stick controls movement direction and speed, while the right stick controls aiming direction and intensity.

Each frame, this component reads the current input snapshot and generates Move2DCommand, SteeringCommand and Aim2DCommand instances that are queued in the CommandBuffer for later execution.

info

Requires the owning GameObject to have Move2DComponent and Aim2DComponent attached for the generated commands to have any effect.

Definition at line 39 of file TwinStickInputSystem.ixx.

Public Constructors

TwinStickInputSystem()

helios::engine::mechanics::input::systems::TwinStickInputSystem::TwinStickInputSystem (helios::engine::ecs::GameObject gameObject)
inline explicit

Constructs a TwinStickInputSystem for the specified GameObject.

Parameters
gameObject

Reference to the GameObject to generate input commands for.

Definition at line 61 of file TwinStickInputSystem.ixx.

62 gameObject_(gameObject) {}

Public Member Functions

setUseDedicatedShootInput()

void helios::engine::mechanics::input::systems::TwinStickInputSystem::setUseDedicatedShootInput (bool useDedicatedInput)
inline noexcept

Enables or disables dedicated shoot input mode.

Parameters
useDedicatedInput

If true, ShootCommands use the right trigger. If false, the aim stick magnitude is used.

Definition at line 137 of file TwinStickInputSystem.ixx.

137 void setUseDedicatedShootInput(bool useDedicatedInput) noexcept {
138 useDedicatedShootInput_ = useDedicatedInput;
139 }

update()

void helios::engine::mechanics::input::systems::TwinStickInputSystem::update (helios::engine::runtime::world::UpdateContext & updateContext)
inline noexcept virtual

Processes gamepad input and generates movement/aiming commands.

Parameters
updateContext

Context containing input snapshot and command buffer.

Definition at line 69 of file TwinStickInputSystem.ixx.

69 void update(helios::engine::runtime::world::UpdateContext& updateContext) noexcept override {
70
71 auto& inputSnapshot = updateContext.inputSnapshot();
72 auto& commandBuffer = updateContext.commandBuffer();
73
74 // Left stick: movement
75 const auto leftStick = inputSnapshot.gamepadState().left();
76 float finalSpeed = 0.0f;
77 float speed = leftStick.length();
78 auto ldir = helios::math::vec2f{0.0f, 0.0f};
79
81 ldir = leftStick.normalize();
82 finalSpeed = speed;
83 }
84 /**
85 * @todo DO NOT POST IF input is already inactive in shootComponent
86 * and no input was detected (after normalizing)
87 */
89 gameObject_.entityHandle(), ldir, finalSpeed
90 );
91
93 gameObject_.entityHandle(), ldir, finalSpeed
94 );
95
96 // Right stick: aiming
97 const auto rightStick = inputSnapshot.gamepadState().right();
98 float freq = rightStick.length();
99 float finalFreq = 0.0f;
100 auto rdir = helios::math::vec2f{0.0f, 0.0f};
101
103 rdir = rightStick.normalize();
104 finalFreq = freq;
105 }
106
108 gameObject_.entityHandle(), rdir, finalFreq
109 );
110
111 if (useDedicatedShootInput_) {
112 // right trigger: shooting
113 const auto rightTrigger = inputSnapshot.gamepadState().triggerRight();
114 if (rightTrigger > 0.0f) {
116 gameObject_.entityHandle(), rightTrigger
117 );
118 }
119 } else {
120 if (finalFreq > 0.0f) {
122 gameObject_.entityHandle(), finalFreq
123 );
124 }
125 }
126
127
128
129 }

Reference helios::math::EPSILON_LENGTH.

useDedicatedShootInput()

bool helios::engine::mechanics::input::systems::TwinStickInputSystem::useDedicatedShootInput ()
inline nodiscard noexcept

Returns whether dedicated shoot input mode is enabled.

Returns

True if ShootCommands use the right trigger, false if aim magnitude is used.

Definition at line 146 of file TwinStickInputSystem.ixx.

146 [[nodiscard]] bool useDedicatedShootInput() const noexcept {
147 return useDedicatedShootInput_;
148 }

Private Member Attributes

gameObject_

helios::engine::ecs::GameObject helios::engine::mechanics::input::systems::TwinStickInputSystem::gameObject_

Reference to the GameObject this system reads input for.

Definition at line 52 of file TwinStickInputSystem.ixx.

useDedicatedShootInput_

bool helios::engine::mechanics::input::systems::TwinStickInputSystem::useDedicatedShootInput_ = false

Flag to indicate whether shoot commands should be derived from the aim component.

If true, ShootCommands will be created from dedicated input.

Definition at line 47 of file TwinStickInputSystem.ixx.

47 bool useDedicatedShootInput_ = false;

The documentation for this class was generated from the following file:


Generated via doxygen2docusaurus 2.0.0 by Doxygen 1.15.0.