Technically working

This commit is contained in:
2026-03-08 11:35:21 -05:00
parent 8efdf59ebd
commit edf1b5a0a3
29 changed files with 490 additions and 485 deletions
+37 -5
View File
@@ -6,12 +6,40 @@
*/
#include "input/input.h"
#include "assert/assert.h"
void inputUpdateSDL2(void) {
#if INPUT_GAMEPAD == 1
INPUT.controller = NULL;
for(int32_t i = 0; i < SDL_NumJoysticks(); i++) {
if(!SDL_IsGameController(i)) continue;
INPUT.controller = SDL_GameControllerOpen(i);
if(INPUT.controller) break;
}
#endif
#if INPUT_KEYBOARD == 1
INPUT.keyboardState = SDL_GetKeyboardState(NULL);
#endif
#if INPUT_POINTER == 1
int pointerX, pointerY;
SDL_GetMouseState(&pointerX, &pointerY);
int windowWidth, windowHeight;
SDL_GetWindowSize(DISPLAY.window, &windowWidth, &windowHeight);
INPUT.mouseX = (float_t)pointerX / (float_t)windowWidth;
INPUT.mouseY = (float_t)pointerY / (float_t)windowHeight;
#endif
}
float_t inputButtonGetValue(const inputbutton_t button) {
switch(button.type) {
#ifdef DUSK_INPUT_KEYBOARD
case INPUT_BUTTON_TYPE_KEYBOARD: {
return INPUT.keyboardState[button.scancode] ? 1.0f : 0.0f;
return INPUT.platform.keyboardState[button.scancode] ? 1.0f : 0.0f;
}
#endif
@@ -19,10 +47,10 @@ float_t inputButtonGetValue(const inputbutton_t button) {
case INPUT_BUTTON_TYPE_POINTER: {
switch(button.pointerAxis) {
case INPUT_POINTER_AXIS_X:
return INPUT.mouseX;
return INPUT.platform.mouseX;
case INPUT_POINTER_AXIS_Y:
return INPUT.mouseY;
return INPUT.platform.mouseY;
default:
assertUnreachable("Unknown pointer axis");
@@ -33,7 +61,9 @@ float_t inputButtonGetValue(const inputbutton_t button) {
#ifdef DUSK_INPUT_GAMEPAD
case INPUT_BUTTON_TYPE_GAMEPAD: {
if(SDL_GameControllerGetButton(INPUT.controller, button.gpButton)) {
if(SDL_GameControllerGetButton(
INPUT.platform.controller, button.gpButton
)) {
return 1.0f;
}
return 0.0f;
@@ -42,7 +72,9 @@ float_t inputButtonGetValue(const inputbutton_t button) {
case INPUT_BUTTON_TYPE_GAMEPAD_AXIS: {
float_t value = 0.0f;
Sint16 axis = SDL_GameControllerGetAxis(INPUT.controller, button.gpAxis.axis);
Sint16 axis = SDL_GameControllerGetAxis(
INPUT.platform.controller, button.gpAxis.axis
);
value = (float_t)axis / 32767.0f;
if(!button.gpAxis.positive) value = -value;