From 54667d3ebc41dac8b96095136368bf2678568f07 Mon Sep 17 00:00:00 2001 From: Raimon Zamora Date: Wed, 2 Oct 2024 13:06:25 +0200 Subject: [PATCH] - [NEW] Afegit soport per a gamepad en JInput --- source/jgame.cpp | 8 ++++++ source/jinput.cpp | 66 +++++++++++++++++++++++++++++++++++++++++++++++ source/jinput.h | 34 ++++++++++++++++++++++++ 3 files changed, 108 insertions(+) diff --git a/source/jgame.cpp b/source/jgame.cpp index 5b9aa6f..80b3484 100644 --- a/source/jgame.cpp +++ b/source/jgame.cpp @@ -62,6 +62,12 @@ int main(int argc, char *argv[]) { input::updateWheel(e.wheel.y); } + if (e.type==SDL_CONTROLLERBUTTONDOWN) { + input::updatePadBtn(e.cbutton.button); + } + if (e.type==SDL_CONTROLLERBUTTONUP) { + input::updatePadBtnPressed(e.cbutton.button); + } } if (SDL_GetTicks()-current_ticks >= game::ticks_per_frame) @@ -71,6 +77,8 @@ int main(int argc, char *argv[]) input::updateKeypressed(SDL_SCANCODE_UNKNOWN); input::updateClk(0); input::updateWheel(0); + input::updatePadBtn(SDL_CONTROLLER_BUTTON_INVALID); + input::updatePadBtnPressed(SDL_CONTROLLER_BUTTON_INVALID); current_ticks = SDL_GetTicks(); } } diff --git a/source/jinput.cpp b/source/jinput.cpp index 3cc4f04..83c1e11 100644 --- a/source/jinput.cpp +++ b/source/jinput.cpp @@ -9,10 +9,30 @@ namespace input static uint8_t keydown = 0; static uint8_t btnClicked = 0; static int wheel = 0; + static SDL_GameController *gamepad = NULL; + static int8_t pad_btn_pressed = SDL_CONTROLLER_BUTTON_INVALID; + static int8_t pad_btn_down = SDL_CONTROLLER_BUTTON_INVALID; + + void initGamePad() + { + const int num_joysticks = SDL_NumJoysticks(); + if (num_joysticks>=1) { + for (int i=0; i