Skip to main content

GamepadState Class

A lightweight class for transferring the state of a Gamepad. More...

Declaration

class helios::input::gamepad::GamepadState { ... }

Public Constructors Index

GamepadState ()=default

Default constructor. More...

GamepadState (float axisLeftX, float axisLeftY, float axisRightX, float axisRightY, float triggerLeft, float triggerRight, bool buttonA, bool buttonB, bool buttonX, bool buttonY, bool buttonStart, bool buttonBack, bool buttonGuide, bool buttonLeftBumper, bool buttonRightBumper, bool buttonLeftThumb, bool buttonRightThumb, bool buttonDpadUp, bool buttonDpadRight, bool buttonDpadDown, bool buttonDpadLeft) noexcept

Creates a new GamepadState object. More...

Public Destructor Index

~GamepadState ()=default

Public Member Functions Index

voidupdateAxes (float axisLeftX, float axisLeftY, float axisRightX, float axisRightY, float triggerLeft, float triggerRight, bool buttonA, bool buttonB, bool buttonX, bool buttonY, bool buttonStart, bool buttonBack, bool buttonGuide, bool buttonLeftBumper, bool buttonRightBumper, bool buttonLeftThumb, bool buttonRightThumb, bool buttonDpadUp, bool buttonDpadRight, bool buttonDpadDown, bool buttonDpadLeft) noexcept

Updates the axes and button states of this GamepadState object. More...

floatleftX () const noexcept

Returns the current value of the left stick's x-axis. More...

floatleftY () const noexcept

Returns the current value of the left stick's y-axis. More...

floatrightX () const noexcept

Returns the current value of the right stick's x-axis. More...

floatrightY () const noexcept

Returns the current value of the right stick's y-axis. More...

floattriggerLeft () const noexcept

Returns the current value of the left trigger. More...

floattriggerRight () const noexcept

Returns the current value of the right trigger. More...

helios::math::vec2fleft () const noexcept

Returns the state of the left stick as a helios::math::vec2f. More...

helios::math::vec2fright () const noexcept

Returns the state of the right stick as a helios::math::vec2f. More...

helios::math::vec2ftrigger () const noexcept

Returns the state of the triggers as a helios::math::vec2f. More...

boolbuttonA () const noexcept

Returns true when the A button is pressed. More...

boolbuttonB () const noexcept

Returns true when the B button is pressed. More...

boolbuttonX () const noexcept

Returns true when the X button is pressed. More...

boolbuttonY () const noexcept

Returns true when the Y button is pressed. More...

boolisButtonDown (const GamepadInput input) const

Checks if a button is currently held down. More...

boolisButtonHeld (const GamepadInput input) const

Checks if a button has been held for at least 2 frames. More...

boolisButtonUp (const GamepadInput input) const

Checks if a button was released this frame. More...

boolisButtonPressed (const GamepadInput input) const

Checks if a button was pressed this frame. More...

boolbuttonStart () const noexcept

Returns true when the Start button is pressed. More...

boolbuttonPressedStart () const noexcept

Returns true if Start was pressed this frame. More...

boolbuttonBack () const noexcept

Returns true when the Back button is pressed. More...

boolbuttonGuide () const noexcept

Returns true when the Guide button is pressed. More...

boolbuttonLeftBumper () const noexcept

Returns true when the left bumper is pressed. More...

boolbuttonRightBumper () const noexcept

Returns true when the right bumper is pressed. More...

boolbuttonLeftThumb () const noexcept

Returns true when the left thumbstick button is pressed. More...

boolbuttonRightThumb () const noexcept

Returns true when the right thumbstick button is pressed. More...

boolbuttonDpadUp () const noexcept

Returns true when the D-pad Up button is pressed. More...

boolbuttonDpadRight () const noexcept

Returns true when the D-pad Right button is pressed. More...

boolbuttonDpadDown () const noexcept

Returns true when the D-pad Down button is pressed. More...

boolbuttonDpadLeft () const noexcept

Returns true when the D-pad Left button is pressed. More...

Private Member Functions Index

voidupdate () const noexcept

Internal method to update the cached vec2f representations. This method should be called when the current values of the axes are queried in vec2f form and `needsUpdate_` evaluates to `true`. More...

Private Member Attributes Index

uint32_tcurrInput_ = 0
uint32_tprevInput_ = 0
boolbuttonA_ = false

State of the A button (true if pressed). More...

boolprevButtonA_ = false
boolbuttonB_ = false

State of the B button (true if pressed). More...

boolprevButtonB_ = false
boolbuttonX_ = false

State of the X button (true if pressed). More...

boolbuttonY_ = false

State of the Y button (true if pressed). More...

boolbuttonStart_ = false

State of the Start button (true if pressed). More...

boolprevButtonStart_ = false
boolbuttonBack_ = false

State of the Back button (true if pressed). More...

boolbuttonGuide_ = false

State of the Guide button (true if pressed). More...

boolbuttonLeftBumper_ = false

State of the left bumper button (true if pressed). More...

boolbuttonRightBumper_ = false

State of the right bumper button (true if pressed). More...

boolbuttonLeftThumb_ = false

State of the left thumbstick button (true if pressed). More...

boolbuttonRightThumb_ = false

State of the right thumbstick button (true if pressed). More...

boolbuttonDpadUp_ = false

State of the D-pad up button (true if pressed). More...

boolprevButtonDpadUp_ = false
boolbuttonDpadRight_ = false

State of the D-pad right button (true if pressed). More...

boolbuttonDpadDown_ = false

State of the D-pad down button (true if pressed). More...

boolprevButtonDpadDown_ = false
boolbuttonDpadLeft_ = false

State of the D-pad left button (true if pressed). More...

boolneedsUpdate_ = true

Flag to indicate if the cached vec2f members need to be recalculated. More...

floataxisLeftX_ {}

Raw float value of the left stick's x-axis. More...

floataxisLeftY_ {}

Raw float value of the left stick's y-axis. More...

floataxisRightX_ {}

Raw float value of the right stick's x-axis. More...

floataxisRightY_ {}

Raw float value of the right stick's y-axis. More...

floattriggerLeft_ {}

Raw float value of the left trigger. More...

floattriggerRight_ {}

Raw float value of the right trigger. More...

helios::math::vec2fleft_

Cached vec2f representation of the left stick (x, y). More...

helios::math::vec2fright_

Cached vec2f representation of the right stick (x, y). More...

helios::math::vec2ftrigger_

Cached vec2f representation of the triggers (left, right). More...

Private Static Attributes Index

static const helios::util::log::Logger &logger_ = helios::util::log::LogManager::loggerForScope(HELIOS_LOG_SCOPE)

Shared logger instance for all GamepadState objects. More...

Description

A lightweight class for transferring the state of a Gamepad.

This class models a reusable object representing the input state of a gamepad. The input state of a gamepad consists of the state of the left and right trigger, ranging from [0, 1], where 1 means fully pressed and 0 means not pressed at all.

Similarly, a GamepadState provides information about the left and the right gamepad axes. Both the x- and the y-axis range from [-1, 1]. For the x-axis, the following holds:

  • 0.00 => not moved at all
  • -1.00 => moved all the way to the left
  • 1.00 => moved all the way to the right

For the y-axis the positive direction corresponds to "up" and the negative direction corresponds to "down".

Updating the values is done by calling `updateAxes` on this object.

For convenient access of the axes in 2D coordinates, the class provides accessors to the sticks' axes in `vec2f` form.

Button states are generally represented with boolean values, i.e. true for pressed, otherwise false.

info

Implementations must account for joystick drift: achieving exactly 0.0 for x/y when no human input occurred is rare. Consider applying a dead zone when processing the GamepadState. Axis values are individually clipped to [-1.0, 1.0], but the magnitude of the resulting (x, y) vector may exceed 1.0. Applications should normalize input vectors where appropriate and possibly offer calibration.

This implementation is inspired by the GLFW gamepad input model.

See Also

https://www.glfw.org/docs/latest/input_guide.html#joystick

Definition at line 60 of file GamepadState.ixx.

Public Constructors

GamepadState()

helios::input::gamepad::GamepadState::GamepadState ()
default

Default constructor.

Initializes all the values with 0.0f.

Definition at line 224 of file GamepadState.ixx.

GamepadState()

helios::input::gamepad::GamepadState::GamepadState (float axisLeftX, float axisLeftY, float axisRightX, float axisRightY, float triggerLeft, float triggerRight, bool buttonA, bool buttonB, bool buttonX, bool buttonY, bool buttonStart, bool buttonBack, bool buttonGuide, bool buttonLeftBumper, bool buttonRightBumper, bool buttonLeftThumb, bool buttonRightThumb, bool buttonDpadUp, bool buttonDpadRight, bool buttonDpadDown, bool buttonDpadLeft)
inline explicit noexcept

Creates a new GamepadState object.

Delegates to `updateAxes` for value initialization.

See Also

updateAxes

Definition at line 233 of file GamepadState.ixx.

233 explicit GamepadState(
234 float axisLeftX, float axisLeftY, float axisRightX,
235 float axisRightY, float triggerLeft, float triggerRight,
236
237 bool buttonA, bool buttonB, bool buttonX, bool buttonY,
238 bool buttonStart, bool buttonBack, bool buttonGuide,
242
243 ) noexcept {
245 axisLeftX, axisLeftY, axisRightX, axisRightY, triggerLeft, triggerRight,
246
250 }

References buttonA, buttonB, buttonBack, buttonDpadDown, buttonDpadLeft, buttonDpadRight, buttonDpadUp, buttonGuide, buttonLeftBumper, buttonLeftThumb, buttonRightBumper, buttonRightThumb, buttonStart, buttonX, buttonY, triggerLeft, triggerRight and updateAxes.

Public Destructor

~GamepadState()

helios::input::gamepad::GamepadState::~GamepadState ()
default

Definition at line 217 of file GamepadState.ixx.

Public Member Functions

buttonA()

bool helios::input::gamepad::GamepadState::buttonA ()
inline nodiscard noexcept

Returns true when the A button is pressed.

Returns

true if pressed, false otherwise.

Definition at line 470 of file GamepadState.ixx.

470 [[nodiscard]] bool buttonA() const noexcept {
471 return buttonA_;
472 };

Referenced by GamepadState and updateAxes.

buttonB()

bool helios::input::gamepad::GamepadState::buttonB ()
inline nodiscard noexcept

Returns true when the B button is pressed.

Returns

true if pressed, false otherwise.

Definition at line 479 of file GamepadState.ixx.

479 [[nodiscard]] bool buttonB() const noexcept {
480 return buttonB_;
481 };

Referenced by GamepadState and updateAxes.

buttonBack()

bool helios::input::gamepad::GamepadState::buttonBack ()
inline nodiscard noexcept

Returns true when the Back button is pressed.

Returns

true if pressed, false otherwise.

Definition at line 631 of file GamepadState.ixx.

631 [[nodiscard]] bool buttonBack() const noexcept {
632 return buttonBack_;
633 };

Referenced by GamepadState and updateAxes.

buttonDpadDown()

bool helios::input::gamepad::GamepadState::buttonDpadDown ()
inline nodiscard noexcept

Returns true when the D-pad Down button is pressed.

Returns

true if pressed, false otherwise.

Definition at line 703 of file GamepadState.ixx.

703 [[nodiscard]] bool buttonDpadDown() const noexcept {
704 return buttonDpadDown_;
705 };

Referenced by GamepadState and updateAxes.

buttonDpadLeft()

bool helios::input::gamepad::GamepadState::buttonDpadLeft ()
inline nodiscard noexcept

Returns true when the D-pad Left button is pressed.

Returns

true if pressed, false otherwise.

Definition at line 712 of file GamepadState.ixx.

712 [[nodiscard]] bool buttonDpadLeft() const noexcept {
713 return buttonDpadLeft_;
714 };

Referenced by GamepadState and updateAxes.

buttonDpadRight()

bool helios::input::gamepad::GamepadState::buttonDpadRight ()
inline nodiscard noexcept

Returns true when the D-pad Right button is pressed.

Returns

true if pressed, false otherwise.

Definition at line 694 of file GamepadState.ixx.

694 [[nodiscard]] bool buttonDpadRight() const noexcept {
695 return buttonDpadRight_;
696 };

Referenced by GamepadState and updateAxes.

buttonDpadUp()

bool helios::input::gamepad::GamepadState::buttonDpadUp ()
inline nodiscard noexcept

Returns true when the D-pad Up button is pressed.

Returns

true if pressed, false otherwise.

Definition at line 685 of file GamepadState.ixx.

685 [[nodiscard]] bool buttonDpadUp() const noexcept {
686 return buttonDpadUp_;
687 };

Referenced by GamepadState and updateAxes.

buttonGuide()

bool helios::input::gamepad::GamepadState::buttonGuide ()
inline nodiscard noexcept

Returns true when the Guide button is pressed.

Returns

true if pressed, false otherwise.

Definition at line 640 of file GamepadState.ixx.

640 [[nodiscard]] bool buttonGuide() const noexcept {
641 return buttonGuide_;
642 };

Referenced by GamepadState and updateAxes.

buttonLeftBumper()

bool helios::input::gamepad::GamepadState::buttonLeftBumper ()
inline nodiscard noexcept

Returns true when the left bumper is pressed.

Returns

true if pressed, false otherwise.

Definition at line 649 of file GamepadState.ixx.

649 [[nodiscard]] bool buttonLeftBumper() const noexcept {
650 return buttonLeftBumper_;
651 };

Referenced by GamepadState and updateAxes.

buttonLeftThumb()

bool helios::input::gamepad::GamepadState::buttonLeftThumb ()
inline nodiscard noexcept

Returns true when the left thumbstick button is pressed.

Returns

true if pressed, false otherwise.

Definition at line 667 of file GamepadState.ixx.

667 [[nodiscard]] bool buttonLeftThumb() const noexcept {
668 return buttonLeftThumb_;
669 };

Referenced by GamepadState and updateAxes.

buttonPressedStart()

bool helios::input::gamepad::GamepadState::buttonPressedStart ()
inline nodiscard noexcept

Returns true if Start was pressed this frame.

Returns

True if Start was just pressed.

Definition at line 622 of file GamepadState.ixx.

622 [[nodiscard]] bool buttonPressedStart() const noexcept {
623 return !prevButtonStart_ && buttonStart_;
624 };

buttonRightBumper()

bool helios::input::gamepad::GamepadState::buttonRightBumper ()
inline nodiscard noexcept

Returns true when the right bumper is pressed.

Returns

true if pressed, false otherwise.

Definition at line 658 of file GamepadState.ixx.

658 [[nodiscard]] bool buttonRightBumper() const noexcept {
659 return buttonRightBumper_;
660 };

Referenced by GamepadState and updateAxes.

buttonRightThumb()

bool helios::input::gamepad::GamepadState::buttonRightThumb ()
inline nodiscard noexcept

Returns true when the right thumbstick button is pressed.

Returns

true if pressed, false otherwise.

Definition at line 676 of file GamepadState.ixx.

676 [[nodiscard]] bool buttonRightThumb() const noexcept {
677 return buttonRightThumb_;
678 };

Referenced by GamepadState and updateAxes.

buttonStart()

bool helios::input::gamepad::GamepadState::buttonStart ()
inline nodiscard noexcept

Returns true when the Start button is pressed.

Returns

true if pressed, false otherwise.

Definition at line 613 of file GamepadState.ixx.

613 [[nodiscard]] bool buttonStart() const noexcept {
614 return prevButtonStart_ && buttonStart_;
615 };

Referenced by GamepadState and updateAxes.

buttonX()

bool helios::input::gamepad::GamepadState::buttonX ()
inline nodiscard noexcept

Returns true when the X button is pressed.

Returns

true if pressed, false otherwise.

Definition at line 488 of file GamepadState.ixx.

488 [[nodiscard]] bool buttonX() const noexcept {
489 return buttonX_;
490 };

Referenced by GamepadState and updateAxes.

buttonY()

bool helios::input::gamepad::GamepadState::buttonY ()
inline nodiscard noexcept

Returns true when the Y button is pressed.

Returns

true if pressed, false otherwise.

Definition at line 497 of file GamepadState.ixx.

497 [[nodiscard]] bool buttonY() const noexcept {
498 return buttonY_;
499 };

Referenced by GamepadState and updateAxes.

isButtonDown()

bool helios::input::gamepad::GamepadState::isButtonDown (const GamepadInput input)
inline nodiscard

Checks if a button is currently held down.

Parameters
input

The button to check.

Returns

True if the button is currently pressed.

Definition at line 509 of file GamepadState.ixx.

509 [[nodiscard]] bool isButtonDown(const GamepadInput input) const {
510 switch (input) {
512 return buttonStart_;
514 return buttonDpadDown_;
516 return buttonDpadUp_;
517 case GamepadInput::A:
518 return buttonA_;
519 case GamepadInput::B:
520 return buttonB_;
521
522 default:
523 assert(false && "Unexpected input");
524 return false;
525 }
526 }

References helios::input::types::A, helios::input::types::B, helios::input::types::Down, helios::input::types::Start and helios::input::types::Up.

isButtonHeld()

bool helios::input::gamepad::GamepadState::isButtonHeld (const GamepadInput input)
inline nodiscard

Checks if a button has been held for at least 2 frames.

Parameters
input

The button to check.

Returns

True if the button was pressed last frame and is still pressed.

Definition at line 535 of file GamepadState.ixx.

535 [[nodiscard]] bool isButtonHeld(const GamepadInput input) const {
536 switch (input) {
538 return prevButtonStart_ && buttonStart_;
540 return prevButtonDpadDown_ && buttonDpadDown_;
542 return prevButtonDpadUp_ && buttonDpadUp_;
543 case GamepadInput::A:
544 return prevButtonA_ && buttonA_;
545 case GamepadInput::B:
546 return prevButtonB_ && buttonB_;
547
548 default:
549 assert(false && "Unexpected input");
550 return false;
551 }
552 }

References helios::input::types::A, helios::input::types::B, helios::input::types::Down, helios::input::types::Start and helios::input::types::Up.

isButtonPressed()

bool helios::input::gamepad::GamepadState::isButtonPressed (const GamepadInput input)
inline nodiscard

Checks if a button was pressed this frame.

Parameters
input

The button to check.

Returns

True if the button was not pressed last frame but is pressed now.

Definition at line 588 of file GamepadState.ixx.

588 [[nodiscard]] bool isButtonPressed(const GamepadInput input) const {
589 switch (input) {
591 return !prevButtonStart_ && buttonStart_;
593 return !prevButtonDpadDown_ && buttonDpadDown_;
595 return !prevButtonDpadUp_ && buttonDpadUp_;
596 case GamepadInput::A:
597 return !prevButtonA_ && buttonA_;
598 case GamepadInput::B:
599 return !prevButtonB_ && buttonB_;
600
601 default:
602 assert(false && "Unexpected input");
603 return false;
604 }
605 }

References helios::input::types::A, helios::input::types::B, helios::input::types::Down, helios::input::types::Start and helios::input::types::Up.

isButtonUp()

bool helios::input::gamepad::GamepadState::isButtonUp (const GamepadInput input)
inline nodiscard

Checks if a button was released this frame.

Parameters
input

The button to check.

Returns

True if the button was pressed last frame but is now released.

Definition at line 561 of file GamepadState.ixx.

561 [[nodiscard]] bool isButtonUp(const GamepadInput input) const {
562 switch (input) {
564 return prevButtonStart_ && !buttonStart_;
566 return prevButtonDpadDown_ && !buttonDpadDown_;
568 return prevButtonDpadUp_ && !buttonDpadUp_;
569 case GamepadInput::A:
570 return prevButtonA_ && !buttonA_;
571 case GamepadInput::B:
572 return prevButtonB_ && !buttonB_;
573
574 default:
575 assert(false && "Unexpected input");
576 return false;
577 }
578 }

References helios::input::types::A, helios::input::types::B, helios::input::types::Down, helios::input::types::Start and helios::input::types::Up.

left()

helios::math::vec2f helios::input::gamepad::GamepadState::left ()
inline nodiscard noexcept

Returns the state of the left stick as a helios::math::vec2f.

Returns

A helios::math::vec2f, with the first component being the x-axis, the second component the y-axis.

Definition at line 431 of file GamepadState.ixx.

431 [[nodiscard]] helios::math::vec2f left() const noexcept {
432 if (needsUpdate_) {
433 update();
434 }
435 return left_;
436 }

leftX()

float helios::input::gamepad::GamepadState::leftX ()
inline nodiscard noexcept

Returns the current value of the left stick's x-axis.

Returns

float value in the range [-1, 1]

Definition at line 371 of file GamepadState.ixx.

371 [[nodiscard]] float leftX() const noexcept {
372 return axisLeftX_;
373 }

leftY()

float helios::input::gamepad::GamepadState::leftY ()
inline nodiscard noexcept

Returns the current value of the left stick's y-axis.

Returns

float value in the range [-1, 1]

Definition at line 381 of file GamepadState.ixx.

381 [[nodiscard]] float leftY() const noexcept {
382 return axisLeftY_;
383 }

right()

helios::math::vec2f helios::input::gamepad::GamepadState::right ()
inline nodiscard noexcept

Returns the state of the right stick as a helios::math::vec2f.

Returns

A helios::math::vec2f, with the first component being the x-axis, the second component the y-axis.

Definition at line 444 of file GamepadState.ixx.

444 [[nodiscard]] helios::math::vec2f right() const noexcept {
445 if (needsUpdate_) {
446 update();
447 }
448 return right_;
449 }

rightX()

float helios::input::gamepad::GamepadState::rightX ()
inline nodiscard noexcept

Returns the current value of the right stick's x-axis.

Returns

float value in the range [-1, 1]

Definition at line 391 of file GamepadState.ixx.

391 [[nodiscard]] float rightX() const noexcept {
392 return axisRightX_;
393 }

rightY()

float helios::input::gamepad::GamepadState::rightY ()
inline nodiscard noexcept

Returns the current value of the right stick's y-axis.

Returns

float value in the range [-1, 1]

Definition at line 401 of file GamepadState.ixx.

401 [[nodiscard]] float rightY() const noexcept {
402 return axisRightY_;
403 }

trigger()

helios::math::vec2f helios::input::gamepad::GamepadState::trigger ()
inline nodiscard noexcept

Returns the state of the triggers as a helios::math::vec2f.

Returns

A helios::math::vec2f, with the first component being the left trigger-axis, the second component the right trigger-axis.

Definition at line 458 of file GamepadState.ixx.

458 [[nodiscard]] helios::math::vec2f trigger() const noexcept {
459 if (needsUpdate_) {
460 update();
461 }
462 return trigger_;
463 }

triggerLeft()

float helios::input::gamepad::GamepadState::triggerLeft ()
inline nodiscard noexcept

Returns the current value of the left trigger.

Returns

float value in the range [0, 1]

Definition at line 411 of file GamepadState.ixx.

411 [[nodiscard]] float triggerLeft() const noexcept {
412 return triggerLeft_;
413 }

Referenced by GamepadState and updateAxes.

triggerRight()

float helios::input::gamepad::GamepadState::triggerRight ()
inline nodiscard noexcept

Returns the current value of the right trigger.

Returns

float value in the range [0, 1]

Definition at line 421 of file GamepadState.ixx.

421 [[nodiscard]] float triggerRight() const noexcept {
422 return triggerRight_;
423 }

Referenced by GamepadState and updateAxes.

updateAxes()

void helios::input::gamepad::GamepadState::updateAxes (float axisLeftX, float axisLeftY, float axisRightX, float axisRightY, float triggerLeft, float triggerRight, bool buttonA, bool buttonB, bool buttonX, bool buttonY, bool buttonStart, bool buttonBack, bool buttonGuide, bool buttonLeftBumper, bool buttonRightBumper, bool buttonLeftThumb, bool buttonRightThumb, bool buttonDpadUp, bool buttonDpadRight, bool buttonDpadDown, bool buttonDpadLeft)
inline noexcept

Updates the axes and button states of this GamepadState object.

This method updates raw axis and trigger values and stores the boolean state of all standard gamepad buttons. Float parameters are asserted to be in their expected ranges and then clamped.

For the sticks' range [-1, 1] the following holds: -1 means moved all the way left/down, 0 means not moved at all, 1 means moved all the way right/up.

For the triggers' range of [0, 1] the following holds: 0 means not pressed, 1 means fully pressed.

Parameters
axisLeftX

The x-axis of the left stick, expected in [-1, 1].

axisLeftY

The y-axis of the left stick, expected in [-1, 1].

axisRightX

The x-axis of the right stick, expected in [-1, 1].

axisRightY

The y-axis of the right stick, expected in [-1, 1].

triggerLeft

The left trigger value, expected in [0, 1].

triggerRight

The right trigger value, expected in [0, 1].

buttonA

True if the A button is pressed.

buttonB

True if the B button is pressed.

buttonX

True if the X button is pressed.

buttonY

True if the Y button is pressed.

buttonStart

True if the Start button is pressed.

buttonBack

True if the Back button is pressed.

buttonGuide

True if the Guide (platform) button is pressed.

buttonLeftBumper

True if the left bumper is pressed.

buttonRightBumper

True if the right bumper is pressed.

buttonLeftThumb

True if the left thumbstick button is pressed.

buttonRightThumb

True if the right thumbstick button is pressed.

buttonDpadUp

True if the D-pad Up button is pressed.

buttonDpadRight

True if the D-pad Right button is pressed.

buttonDpadDown

True if the D-pad Down button is pressed.

buttonDpadLeft

True if the D-pad Left button is pressed.

Definition at line 288 of file GamepadState.ixx.

289 float axisLeftX, float axisLeftY, float axisRightX, float axisRightY,
290 float triggerLeft, float triggerRight,
291
292 bool buttonA, bool buttonB, bool buttonX, bool buttonY,
293 bool buttonStart, bool buttonBack, bool buttonGuide,
297 ) noexcept {
298
299#ifdef HELIOS_DEBUG
300 if(axisLeftX < -1.0f || axisLeftX > 1.0f) {
301 logger_.warn("axisLeftX is out of bounds.");
302 }
303 if(axisLeftY < -1.0f || axisLeftY > 1.0f) {
304 logger_.warn("axisLeftY is out of bounds.");
305 }
306 if(axisRightX < -1.0f || axisRightX > 1.0f) {
307 logger_.warn("axisRightX is out of bounds.");
308 }
309 if(axisRightY < -1.0f || axisRightY > 1.0f) {
310 logger_.warn("axisRightY is out of bounds.");
311 }
313 logger_.warn("triggerLeft is out of bounds.");
314 }
316 logger_.warn("triggerRight is out of bounds.");
317 }
318#endif
319
320 axisLeftX_ = std::clamp(axisLeftX, -1.0f, 1.0f);
321 axisLeftY_ = std::clamp(axisLeftY, -1.0f, 1.0f);
322 axisRightX_ = std::clamp(axisRightX, -1.0f, 1.0f);
323 axisRightY_ = std::clamp(axisRightY, -1.0f, 1.0f);
324 triggerLeft_ = std::clamp(triggerLeft, 0.0f, 1.0f);
325 triggerRight_ = std::clamp(triggerRight, 0.0f, 1.0f);
326;
327
328 prevButtonA_ = buttonA_;
329 buttonA_ = buttonA;
330
331 prevButtonB_ = buttonB_;
332 buttonB_ = buttonB;
333
334 buttonX_ = buttonX;
335
336 buttonY_ = buttonY;
337
338 prevButtonStart_ = buttonStart_;
339 buttonStart_ = buttonStart;
340
341 buttonBack_ = buttonBack;
342
343 buttonGuide_ = buttonGuide;
344
345 buttonLeftBumper_ = buttonLeftBumper;
346
347 buttonRightBumper_ = buttonRightBumper;
348
349 buttonLeftThumb_ = buttonLeftThumb;
350
351 buttonRightThumb_ = buttonRightThumb;
352
353 prevButtonDpadUp_ = buttonDpadUp_;
354 buttonDpadUp_ = buttonDpadUp;
355
356 buttonDpadRight_ = buttonDpadRight;
357
358 prevButtonDpadDown_ = buttonDpadDown_;
359 buttonDpadDown_ = buttonDpadDown;
360
361 buttonDpadLeft_ = buttonDpadLeft;
362
363 needsUpdate_ = true;
364 }

References buttonA, buttonB, buttonBack, buttonDpadDown, buttonDpadLeft, buttonDpadRight, buttonDpadUp, buttonGuide, buttonLeftBumper, buttonLeftThumb, buttonRightBumper, buttonRightThumb, buttonStart, buttonX, buttonY, triggerLeft and triggerRight.

Referenced by GamepadState.

Private Member Functions

update()

void helios::input::gamepad::GamepadState::update ()
inline noexcept

Internal method to update the cached vec2f representations. This method should be called when the current values of the axes are queried in vec2f form and `needsUpdate_` evaluates to `true`.

Definition at line 208 of file GamepadState.ixx.

208 void update() const noexcept {
209 left_ = helios::math::vec2f(axisLeftX_, axisLeftY_);
210 right_ = helios::math::vec2f(axisRightX_, axisRightY_);
211 trigger_ = helios::math::vec2f(triggerLeft_, triggerRight_);
212
213 needsUpdate_ = false;
214 }

Private Member Attributes

axisLeftX_

float helios::input::gamepad::GamepadState::axisLeftX_ {}

Raw float value of the left stick's x-axis.

Definition at line 161 of file GamepadState.ixx.

161 float axisLeftX_{};

axisLeftY_

float helios::input::gamepad::GamepadState::axisLeftY_ {}

Raw float value of the left stick's y-axis.

Definition at line 166 of file GamepadState.ixx.

166 float axisLeftY_{};

axisRightX_

float helios::input::gamepad::GamepadState::axisRightX_ {}

Raw float value of the right stick's x-axis.

Definition at line 171 of file GamepadState.ixx.

171 float axisRightX_{};

axisRightY_

float helios::input::gamepad::GamepadState::axisRightY_ {}

Raw float value of the right stick's y-axis.

Definition at line 176 of file GamepadState.ixx.

176 float axisRightY_{};

buttonA_

bool helios::input::gamepad::GamepadState::buttonA_ = false

State of the A button (true if pressed).

Definition at line 75 of file GamepadState.ixx.

75 bool buttonA_ = false;

buttonB_

bool helios::input::gamepad::GamepadState::buttonB_ = false

State of the B button (true if pressed).

Definition at line 81 of file GamepadState.ixx.

81 bool buttonB_ = false;

buttonBack_

bool helios::input::gamepad::GamepadState::buttonBack_ = false

State of the Back button (true if pressed).

Definition at line 104 of file GamepadState.ixx.

104 bool buttonBack_ = false;

buttonDpadDown_

bool helios::input::gamepad::GamepadState::buttonDpadDown_ = false

State of the D-pad down button (true if pressed).

Definition at line 145 of file GamepadState.ixx.

145 bool buttonDpadDown_ = false;

buttonDpadLeft_

bool helios::input::gamepad::GamepadState::buttonDpadLeft_ = false

State of the D-pad left button (true if pressed).

Definition at line 151 of file GamepadState.ixx.

151 bool buttonDpadLeft_ = false;

buttonDpadRight_

bool helios::input::gamepad::GamepadState::buttonDpadRight_ = false

State of the D-pad right button (true if pressed).

Definition at line 140 of file GamepadState.ixx.

140 bool buttonDpadRight_ = false;

buttonDpadUp_

bool helios::input::gamepad::GamepadState::buttonDpadUp_ = false

State of the D-pad up button (true if pressed).

Definition at line 134 of file GamepadState.ixx.

134 bool buttonDpadUp_ = false;

buttonGuide_

bool helios::input::gamepad::GamepadState::buttonGuide_ = false

State of the Guide button (true if pressed).

Definition at line 109 of file GamepadState.ixx.

109 bool buttonGuide_ = false;

buttonLeftBumper_

bool helios::input::gamepad::GamepadState::buttonLeftBumper_ = false

State of the left bumper button (true if pressed).

Definition at line 114 of file GamepadState.ixx.

114 bool buttonLeftBumper_ = false;

buttonLeftThumb_

bool helios::input::gamepad::GamepadState::buttonLeftThumb_ = false

State of the left thumbstick button (true if pressed).

Definition at line 124 of file GamepadState.ixx.

124 bool buttonLeftThumb_ = false;

buttonRightBumper_

bool helios::input::gamepad::GamepadState::buttonRightBumper_ = false

State of the right bumper button (true if pressed).

Definition at line 119 of file GamepadState.ixx.

119 bool buttonRightBumper_ = false;

buttonRightThumb_

bool helios::input::gamepad::GamepadState::buttonRightThumb_ = false

State of the right thumbstick button (true if pressed).

Definition at line 129 of file GamepadState.ixx.

129 bool buttonRightThumb_ = false;

buttonStart_

bool helios::input::gamepad::GamepadState::buttonStart_ = false

State of the Start button (true if pressed).

Definition at line 97 of file GamepadState.ixx.

97 bool buttonStart_ = false;

buttonX_

bool helios::input::gamepad::GamepadState::buttonX_ = false

State of the X button (true if pressed).

Definition at line 87 of file GamepadState.ixx.

87 bool buttonX_ = false;

buttonY_

bool helios::input::gamepad::GamepadState::buttonY_ = false

State of the Y button (true if pressed).

Definition at line 92 of file GamepadState.ixx.

92 bool buttonY_ = false;

currInput_

uint32_t helios::input::gamepad::GamepadState::currInput_ = 0

Definition at line 63 of file GamepadState.ixx.

63 uint32_t currInput_ = 0;

left_

helios::math::vec2f helios::input::gamepad::GamepadState::left_
mutable

Cached vec2f representation of the left stick (x, y).

Definition at line 191 of file GamepadState.ixx.

191 mutable helios::math::vec2f left_;

needsUpdate_

bool helios::input::gamepad::GamepadState::needsUpdate_ = true
mutable

Flag to indicate if the cached vec2f members need to be recalculated.

Definition at line 156 of file GamepadState.ixx.

156 mutable bool needsUpdate_ = true;

prevButtonA_

bool helios::input::gamepad::GamepadState::prevButtonA_ = false

Definition at line 76 of file GamepadState.ixx.

76 bool prevButtonA_ = false;

prevButtonB_

bool helios::input::gamepad::GamepadState::prevButtonB_ = false

Definition at line 82 of file GamepadState.ixx.

82 bool prevButtonB_ = false;

prevButtonDpadDown_

bool helios::input::gamepad::GamepadState::prevButtonDpadDown_ = false

Definition at line 146 of file GamepadState.ixx.

146 bool prevButtonDpadDown_ = false;

prevButtonDpadUp_

bool helios::input::gamepad::GamepadState::prevButtonDpadUp_ = false

Definition at line 135 of file GamepadState.ixx.

135 bool prevButtonDpadUp_ = false;

prevButtonStart_

bool helios::input::gamepad::GamepadState::prevButtonStart_ = false

Definition at line 99 of file GamepadState.ixx.

99 bool prevButtonStart_ = false;

prevInput_

uint32_t helios::input::gamepad::GamepadState::prevInput_ = 0

Definition at line 64 of file GamepadState.ixx.

64 uint32_t prevInput_ = 0;

right_

helios::math::vec2f helios::input::gamepad::GamepadState::right_
mutable

Cached vec2f representation of the right stick (x, y).

Definition at line 196 of file GamepadState.ixx.

196 mutable helios::math::vec2f right_;

trigger_

helios::math::vec2f helios::input::gamepad::GamepadState::trigger_
mutable

Cached vec2f representation of the triggers (left, right).

Definition at line 201 of file GamepadState.ixx.

201 mutable helios::math::vec2f trigger_;

triggerLeft_

float helios::input::gamepad::GamepadState::triggerLeft_ {}

Raw float value of the left trigger.

Definition at line 181 of file GamepadState.ixx.

181 float triggerLeft_{};

triggerRight_

float helios::input::gamepad::GamepadState::triggerRight_ {}

Raw float value of the right trigger.

Definition at line 186 of file GamepadState.ixx.

186 float triggerRight_{};

Private Static Attributes

logger_

const helios::util::log::Logger& helios::input::gamepad::GamepadState::logger_ = helios::util::log::LogManager::loggerForScope(HELIOS_LOG_SCOPE)
static

Shared logger instance for all GamepadState objects.

Definition at line 69 of file GamepadState.ixx.


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


Generated via doxygen2docusaurus 2.0.0 by Doxygen 1.15.0.