GamepadState.ixx File
Representation of current gamepad input state. More...
Included Headers
#include <algorithm>
#include <cassert>
#include <helios-engine-config.h>
#include <helios.engine.input.types.Gamepad>
#include <helios.engine.util.log.LogManager>
#include <helios.engine.util.log.Logger>
#include <helios.math.types>
Namespaces Index
| namespace | helios |
| namespace | engine |
| namespace | input |
| namespace | gamepad |
Classes Index
| class | GamepadState |
|
A lightweight class for transferring the state of a Gamepad. More... | |
Macro Definitions Index
| #define | HELIOS_LOG_SCOPE "helios::engine::input::gamepad::GamepadState" |
Description
Representation of current gamepad input state.
Macro Definitions
HELIOS_LOG_SCOPE
|
Definition at line 20 of file GamepadState.ixx.
20#define HELIOS_LOG_SCOPE "helios::engine::input::gamepad::GamepadState"
File Listing
The file content with the documentation metadata removed is:
9#include <helios-engine-config.h>
20#define HELIOS_LOG_SCOPE "helios::engine::input::gamepad::GamepadState"
22using namespace helios::engine::input::types;
24export namespace helios::engine::input::gamepad {
60 class GamepadState {
63 uint32_t currInput_ = 0;
64 uint32_t prevInput_ = 0;
69 inline static const helios::engine::util::log::Logger& logger_ = helios::engine::util::log::LogManager::loggerForScope(HELIOS_LOG_SCOPE);
217 ~GamepadState() = default;
224 GamepadState() = default;
233 explicit GamepadState(
234 float axisLeftX, float axisLeftY, float axisRightX,
235 float axisRightY, float triggerLeft, float triggerRight,
238 bool buttonStart, bool buttonBack, bool buttonGuide,
239 bool buttonLeftBumper, bool buttonRightBumper, bool buttonLeftThumb,
240 bool buttonRightThumb, bool buttonDpadUp, bool buttonDpadRight,
241 bool buttonDpadDown, bool buttonDpadLeft
244 updateAxes(
247 buttonA, buttonB, buttonX, buttonY, buttonStart, buttonBack, buttonGuide, buttonLeftBumper,
249 buttonDpadDown, buttonDpadLeft);
288 void updateAxes(
289 float axisLeftX, float axisLeftY, float axisRightX, float axisRightY,
290 float triggerLeft, float triggerRight,
293 bool buttonStart, bool buttonBack, bool buttonGuide,
294 bool buttonLeftBumper, bool buttonRightBumper, bool buttonLeftThumb,
295 bool buttonRightThumb, bool buttonDpadUp, bool buttonDpadRight,
296 bool buttonDpadDown, bool buttonDpadLeft
300 if(axisLeftX < -1.0f || axisLeftX > 1.0f) {
301 logger_.warn("axisLeftX is out of bounds.");
303 if(axisLeftY < -1.0f || axisLeftY > 1.0f) {
304 logger_.warn("axisLeftY is out of bounds.");
306 if(axisRightX < -1.0f || axisRightX > 1.0f) {
307 logger_.warn("axisRightX is out of bounds.");
309 if(axisRightY < -1.0f || axisRightY > 1.0f) {
310 logger_.warn("axisRightY is out of bounds.");
312 if(triggerLeft < 0.0f || triggerLeft > 1.0f) {
313 logger_.warn("triggerLeft is out of bounds.");
315 if(triggerRight < 0.0f || triggerRight > 1.0f) {
316 logger_.warn("triggerRight is out of bounds.");
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);
329 buttonA_ = buttonA;
332 buttonB_ = buttonB;
334 buttonX_ = buttonX;
336 buttonY_ = buttonY;
339 buttonStart_ = buttonStart;
341 buttonBack_ = buttonBack;
343 buttonGuide_ = buttonGuide;
345 buttonLeftBumper_ = buttonLeftBumper;
347 buttonRightBumper_ = buttonRightBumper;
349 buttonLeftThumb_ = buttonLeftThumb;
351 buttonRightThumb_ = buttonRightThumb;
354 buttonDpadUp_ = buttonDpadUp;
356 buttonDpadRight_ = buttonDpadRight;
359 buttonDpadDown_ = buttonDpadDown;
361 buttonDpadLeft_ = buttonDpadLeft;
411 [[nodiscard]] float triggerLeft() const noexcept {
421 [[nodiscard]] float triggerRight() const noexcept {
509 [[nodiscard]] bool isButtonDown(const GamepadInput input) const {
523 assert(false && "Unexpected input");
535 [[nodiscard]] bool isButtonHeld(const GamepadInput input) const {
549 assert(false && "Unexpected input");
561 [[nodiscard]] bool isButtonUp(const GamepadInput input) const {
575 assert(false && "Unexpected input");
588 [[nodiscard]] bool isButtonPressed(const GamepadInput input) const {
602 assert(false && "Unexpected input");
613 [[nodiscard]] bool buttonStart() const noexcept {
622 [[nodiscard]] bool buttonPressedStart() const noexcept {
631 [[nodiscard]] bool buttonBack() const noexcept {
640 [[nodiscard]] bool buttonGuide() const noexcept {
649 [[nodiscard]] bool buttonLeftBumper() const noexcept {
658 [[nodiscard]] bool buttonRightBumper() const noexcept {
667 [[nodiscard]] bool buttonLeftThumb() const noexcept {
676 [[nodiscard]] bool buttonRightThumb() const noexcept {
685 [[nodiscard]] bool buttonDpadUp() const noexcept {
694 [[nodiscard]] bool buttonDpadRight() const noexcept {
703 [[nodiscard]] bool buttonDpadDown() const noexcept {
712 [[nodiscard]] bool buttonDpadLeft() const noexcept {
Generated via doxygen2docusaurus 2.0.0 by Doxygen 1.9.8.