archivemuh
This commit is contained in:
44
archive/dusksdl2/dusksdl2input.c
Normal file
44
archive/dusksdl2/dusksdl2input.c
Normal file
@@ -0,0 +1,44 @@
|
||||
/**
|
||||
* Copyright (c) 2025 Dominic Masters
|
||||
*
|
||||
* This software is released under the MIT License.
|
||||
* https://opensource.org/licenses/MIT
|
||||
*/
|
||||
|
||||
#include "dusksdl2input.h"
|
||||
|
||||
inputstate_t inputStateGet() {
|
||||
inputstate_t state = 0;
|
||||
|
||||
#if INPUT_SUPPORT_GAMEPAD
|
||||
// Get gamepad state.
|
||||
for(int32_t i = 0; i < SDL_NumJoysticks(); i++) {
|
||||
if(!SDL_IsGameController(i)) continue;
|
||||
|
||||
SDL_GameController *controller = SDL_GameControllerOpen(i);
|
||||
if(!controller) continue;
|
||||
|
||||
inputsdlbuttonmap_t *map = INPUT_SDL_BUTTON_MAP;
|
||||
do {
|
||||
if(SDL_GameControllerGetButton(controller, map->button)) {
|
||||
state |= map->bind;
|
||||
}
|
||||
map++;
|
||||
} while(map->bind != 0);
|
||||
}
|
||||
#endif
|
||||
|
||||
// Get keyboard state.
|
||||
#if INPUT_SUPPORT_KEYBOARD
|
||||
const uint8_t *keyboardState = SDL_GetKeyboardState(NULL);
|
||||
inputsdlkbmap_t *kbmap = INPUT_SDL_KEYBOARD_MAP;
|
||||
do {
|
||||
if(keyboardState[kbmap->code]) {
|
||||
state |= kbmap->bind;
|
||||
}
|
||||
kbmap++;
|
||||
} while(kbmap->bind != 0);
|
||||
#endif
|
||||
|
||||
return state;
|
||||
}
|
Reference in New Issue
Block a user