Skip to main content

TwinStickInputSystem Class

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

Declaration

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

Public Member Typedefs Index

usingEngineRoleTag = helios::engine::common::tags::SystemRole

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

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 47 of file TwinStickInputSystem.ixx.

Public Member Typedefs

EngineRoleTag

using helios::engine::mechanics::input::systems::TwinStickInputSystem::EngineRoleTag = helios::engine::common::tags::SystemRole

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 71 of file TwinStickInputSystem.ixx.

72 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 156 of file TwinStickInputSystem.ixx.

156 void setUseDedicatedShootInput(bool useDedicatedInput) noexcept {
157 useDedicatedShootInput_ = useDedicatedInput;
158 }

update()

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

Processes gamepad input and generates movement/aiming commands.

Parameters
updateContext

Context containing input snapshot and command buffer.

Definition at line 79 of file TwinStickInputSystem.ixx.

80
81 auto& inputSnapshot = updateContext.inputSnapshot();
82
83 // Left stick: movement
84 const auto leftStick = inputSnapshot.gamepadState().left();
85 float finalSpeed = 0.0f;
86 float speed = leftStick.length();
87 auto ldir = helios::math::vec2f{0.0f, 0.0f};
88
89 // Right stick: aiming
90 const auto rightStick = inputSnapshot.gamepadState().right();
91 float freq = rightStick.length();
92 float finalFreq = 0.0f;
93 auto rdir = helios::math::vec2f{0.0f, 0.0f};
94
95 if (gameObject_.has<DeadTagComponent>()) {
97 gameObject_.entityHandle(), ldir, finalSpeed
98 );
100 gameObject_.entityHandle(), rdir, finalFreq
101 );
102 return;
103 }
104
105 if (speed > helios::math::EPSILON_LENGTH) {
106 ldir = leftStick.normalize();
107 finalSpeed = speed;
108 }
109 /**
110 * @todo DO NOT POST IF input is already inactive in shootComponent
111 * and no input was detected (after normalizing)
112 */
114 gameObject_.entityHandle(), ldir, finalSpeed
115 );
116
118 gameObject_.entityHandle(), ldir, finalSpeed
119 );
120
122 rdir = rightStick.normalize();
123 finalFreq = freq;
124 }
125
127 gameObject_.entityHandle(), rdir, finalFreq
128 );
129
130 if (useDedicatedShootInput_) {
131 // right trigger: shooting
132 const auto rightTrigger = inputSnapshot.gamepadState().triggerRight();
133 if (rightTrigger > 0.0f) {
135 gameObject_.entityHandle(), rightTrigger
136 );
137 }
138 } else {
139 if (finalFreq > 0.0f) {
141 gameObject_.entityHandle(), finalFreq
142 );
143 }
144 }
145
146
147
148 }

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 165 of file TwinStickInputSystem.ixx.

165 [[nodiscard]] bool useDedicatedShootInput() const noexcept {
166 return useDedicatedShootInput_;
167 }

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 60 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 55 of file TwinStickInputSystem.ixx.

55 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.