1
0
mirror of synced 2024-11-23 22:51:02 +01:00

Update SDL to SDL3

This commit is contained in:
BroGamer 2023-09-09 21:01:01 +12:00
parent e28bb6bb46
commit 4ff4324cb1
6 changed files with 638 additions and 224 deletions

View File

@ -1,15 +1,14 @@
OUT = TAL OUT = TAL
CC := x86_64-w64-mingw32-gcc CC = x86_64-w64-mingw32-gcc
TARGET := x86_64-pc-windows-gnu TARGET = x86_64-pc-windows-gnu
SDL_TARGET := x86_64-w64-mingw32
SRC = src/dllmain.c src/helpers.c src/poll.c src/boilerplate.c tomlc99/toml.c minhook/src/buffer.c minhook/src/hook.c minhook/src/trampoline.c minhook/src/hde/hde32.c minhook/src/hde/hde64.c SRC = src/dllmain.c src/helpers.c src/poll.c src/boilerplate.c tomlc99/toml.c minhook/src/buffer.c minhook/src/hook.c minhook/src/trampoline.c minhook/src/hde/hde32.c minhook/src/hde/hde64.c
OBJ = ${addprefix ${TARGET}/,${SRC:.c=.o}} OBJ = ${addprefix ${TARGET}/,${SRC:.c=.o}}
CFLAGS = -std=c99 -Iminhook/include -ISDL/${SDL_TARGET}/include -ISDL/include -Itomlc99 -Wall -Ofast -DWIN32_LEAN_AND_MEAN -D_WIN32_WINNT=_WIN32_WINNT_WIN7 CFLAGS = -std=c99 -Iminhook/include -ISDL/include -ISDL/build/include -Itomlc99 -Wall -Ofast -DWIN32_LEAN_AND_MEAN -D_WIN32_WINNT=_WIN32_WINNT_WIN7
LDFLAGS := -shared -static -static-libgcc -s LDFLAGS = -shared -static -static-libgcc -s
LIBS := SDL/${SDL_TARGET}/build/.libs/libSDL2.a SDL/${SDL_TARGET}/build/.libs/libSDL2main.a -lmingw32 -luuid -lgdi32 -lwinmm -limm32 -lole32 -loleaut32 -lsetupapi -lversion LIBS = SDL/build/libSDL3.a SDL/build/libSDL3_main.a -lmingw32 -luuid -lgdi32 -lwinmm -limm32 -lole32 -loleaut32 -lsetupapi -lversion
DEPS = SDL DEPS = SDL
all: options ${OUT} all: options ${OUT} plugins
.PHONY: dirs .PHONY: dirs
dirs: dirs:
@ -29,9 +28,7 @@ ${TARGET}/%.o: %.c
.PHONY: SDL .PHONY: SDL
SDL: SDL:
@mkdir -p SDL/${SDL_TARGET} @cd SDL && cmake -S . -B build -DCMAKE_TOOLCHAIN_FILE=build-scripts/cmake-toolchain-mingw64-x86_64.cmake && cmake --build build
@cd SDL/${SDL_TARGET} && ../configure --build=x86_64-linux-gnu --host=${SDL_TARGET} --disable-sdl2-config --disable-shared --enable-assertions=release --enable-directx --enable-haptic
@make -s -C SDL/${SDL_TARGET}
.PHONY: ${OUT} .PHONY: ${OUT}
${OUT}: dirs ${DEPS} ${OBJ} ${OUT}: dirs ${DEPS} ${OBJ}

2
SDL

@ -1 +1 @@
Subproject commit b9e1d1b4de713c031353ec300113bd776961625c Subproject commit 180afcdf3998e5175b744d3f2d87147802809450

File diff suppressed because it is too large Load Diff

View File

@ -32,12 +32,12 @@ Keybindings SERVICE = { .keycodes = { VK_F2 } };
Keybindings DEBUG_UP = { .keycodes = { VK_UP } }; Keybindings DEBUG_UP = { .keycodes = { VK_UP } };
Keybindings DEBUG_DOWN = { .keycodes = { VK_DOWN } }; Keybindings DEBUG_DOWN = { .keycodes = { VK_DOWN } };
Keybindings DEBUG_ENTER = { .keycodes = { VK_RETURN } }; Keybindings DEBUG_ENTER = { .keycodes = { VK_RETURN } };
Keybindings COIN_ADD = { .keycodes = { VK_RETURN }, .buttons = { SDL_CONTROLLER_BUTTON_START } }; Keybindings COIN_ADD = { .keycodes = { VK_RETURN }, .buttons = { SDL_GAMEPAD_BUTTON_START } };
Keybindings CARD_INSERT_1 = { .keycodes = { 'P' } }; Keybindings CARD_INSERT_1 = { .keycodes = { 'P' } };
Keybindings CARD_INSERT_2 = {}; Keybindings CARD_INSERT_2 = {};
Keybindings P1_LEFT_BLUE = { .keycodes = { 'D' }, .axis = { SDL_AXIS_LTRIGGER_DOWN } }; Keybindings P1_LEFT_BLUE = { .keycodes = { 'D' }, .axis = { SDL_AXIS_LTRIGGER_DOWN } };
Keybindings P1_LEFT_RED = { .keycodes = { 'F' }, .buttons = { SDL_CONTROLLER_BUTTON_LEFTSTICK } }; Keybindings P1_LEFT_RED = { .keycodes = { 'F' }, .buttons = { SDL_GAMEPAD_BUTTON_LEFT_STICK } };
Keybindings P1_RIGHT_RED = { .keycodes = { 'J' }, .buttons = { SDL_CONTROLLER_BUTTON_RIGHTSTICK } }; Keybindings P1_RIGHT_RED = { .keycodes = { 'J' }, .buttons = { SDL_GAMEPAD_BUTTON_RIGHT_STICK } };
Keybindings P1_RIGHT_BLUE = { .keycodes = { 'K' }, .axis = { SDL_AXIS_RTRIGGER_DOWN } }; Keybindings P1_RIGHT_BLUE = { .keycodes = { 'K' }, .axis = { SDL_AXIS_RTRIGGER_DOWN } };
Keybindings P2_LEFT_BLUE = {}; Keybindings P2_LEFT_BLUE = {};
Keybindings P2_LEFT_RED = {}; Keybindings P2_LEFT_RED = {};

View File

@ -1,4 +1,6 @@
#include "poll.h" #include "poll.h"
#include "SDL3/SDL_gamepad.h"
#include "SDL3/SDL_joystick.h"
#include "helpers.h" #include "helpers.h"
#include <windows.h> #include <windows.h>
@ -20,29 +22,29 @@ struct {
struct { struct {
const char *string; const char *string;
SDL_GameControllerButton button; SDL_GamepadButton button;
} ConfigControllerButtons[] = { } ConfigControllerButtons[] = {
{ "SDL_A", SDL_CONTROLLER_BUTTON_A }, { "SDL_A", SDL_GAMEPAD_BUTTON_A },
{ "SDL_B", SDL_CONTROLLER_BUTTON_B }, { "SDL_B", SDL_GAMEPAD_BUTTON_B },
{ "SDL_X", SDL_CONTROLLER_BUTTON_X }, { "SDL_X", SDL_GAMEPAD_BUTTON_X },
{ "SDL_Y", SDL_CONTROLLER_BUTTON_Y }, { "SDL_Y", SDL_GAMEPAD_BUTTON_Y },
{ "SDL_BACK", SDL_CONTROLLER_BUTTON_BACK }, { "SDL_BACK", SDL_GAMEPAD_BUTTON_BACK },
{ "SDL_GUIDE", SDL_CONTROLLER_BUTTON_GUIDE }, { "SDL_GUIDE", SDL_GAMEPAD_BUTTON_GUIDE },
{ "SDL_START", SDL_CONTROLLER_BUTTON_START }, { "SDL_START", SDL_GAMEPAD_BUTTON_START },
{ "SDL_LSTICK_PRESS", SDL_CONTROLLER_BUTTON_LEFTSTICK }, { "SDL_LSTICK_PRESS", SDL_GAMEPAD_BUTTON_LEFT_STICK },
{ "SDL_RSTICK_PRESS", SDL_CONTROLLER_BUTTON_RIGHTSTICK }, { "SDL_RSTICK_PRESS", SDL_GAMEPAD_BUTTON_RIGHT_STICK },
{ "SDL_LSHOULDER", SDL_CONTROLLER_BUTTON_LEFTSHOULDER }, { "SDL_LSHOULDER", SDL_GAMEPAD_BUTTON_LEFT_SHOULDER },
{ "SDL_RSHOULDER", SDL_CONTROLLER_BUTTON_RIGHTSHOULDER }, { "SDL_RSHOULDER", SDL_GAMEPAD_BUTTON_RIGHT_SHOULDER },
{ "SDL_DPAD_UP", SDL_CONTROLLER_BUTTON_DPAD_UP }, { "SDL_DPAD_UP", SDL_GAMEPAD_BUTTON_DPAD_UP },
{ "SDL_DPAD_DOWN", SDL_CONTROLLER_BUTTON_DPAD_DOWN }, { "SDL_DPAD_DOWN", SDL_GAMEPAD_BUTTON_DPAD_DOWN },
{ "SDL_DPAD_LEFT", SDL_CONTROLLER_BUTTON_DPAD_LEFT }, { "SDL_DPAD_LEFT", SDL_GAMEPAD_BUTTON_DPAD_LEFT },
{ "SDL_DPAD_RIGHT", SDL_CONTROLLER_BUTTON_DPAD_RIGHT }, { "SDL_DPAD_RIGHT", SDL_GAMEPAD_BUTTON_DPAD_RIGHT },
{ "SDL_MISC", SDL_CONTROLLER_BUTTON_MISC1 }, { "SDL_MISC", SDL_GAMEPAD_BUTTON_MISC1 },
{ "SDL_PADDLE1", SDL_CONTROLLER_BUTTON_PADDLE1 }, { "SDL_PADDLE1", SDL_GAMEPAD_BUTTON_PADDLE1 },
{ "SDL_PADDLE2", SDL_CONTROLLER_BUTTON_PADDLE2 }, { "SDL_PADDLE2", SDL_GAMEPAD_BUTTON_PADDLE2 },
{ "SDL_PADDLE3", SDL_CONTROLLER_BUTTON_PADDLE3 }, { "SDL_PADDLE3", SDL_GAMEPAD_BUTTON_PADDLE3 },
{ "SDL_PADDLE4", SDL_CONTROLLER_BUTTON_PADDLE4 }, { "SDL_PADDLE4", SDL_GAMEPAD_BUTTON_PADDLE4 },
{ "SDL_TOUCHPAD", SDL_CONTROLLER_BUTTON_TOUCHPAD }, { "SDL_TOUCHPAD", SDL_GAMEPAD_BUTTON_TOUCHPAD },
}; };
struct { struct {
@ -73,13 +75,13 @@ struct MouseState {
bool currentKeyboardState[0xFF]; bool currentKeyboardState[0xFF];
bool lastKeyboardState[0xFF]; bool lastKeyboardState[0xFF];
bool currentControllerButtonsState[SDL_CONTROLLER_BUTTON_MAX]; bool currentControllerButtonsState[SDL_GAMEPAD_BUTTON_MAX];
bool lastControllerButtonsState[SDL_CONTROLLER_BUTTON_MAX]; bool lastControllerButtonsState[SDL_GAMEPAD_BUTTON_MAX];
struct SDLAxisState currentControllerAxisState; struct SDLAxisState currentControllerAxisState;
struct SDLAxisState lastControllerAxisState; struct SDLAxisState lastControllerAxisState;
SDL_Window *window; SDL_Window *window;
SDL_GameController *controllers[255]; SDL_Gamepad *controllers[255];
void void
SetConfigValue (toml_table_t *table, char *key, struct Keybindings *keybind) { SetConfigValue (toml_table_t *table, char *key, struct Keybindings *keybind) {
@ -91,7 +93,7 @@ SetConfigValue (toml_table_t *table, char *key, struct Keybindings *keybind) {
memset (keybind, 0, sizeof (*keybind)); memset (keybind, 0, sizeof (*keybind));
for (int i = 0; i < COUNTOFARR (keybind->buttons); i++) for (int i = 0; i < COUNTOFARR (keybind->buttons); i++)
keybind->buttons[i] = SDL_CONTROLLER_BUTTON_INVALID; keybind->buttons[i] = SDL_GAMEPAD_BUTTON_INVALID;
for (int i = 0;; i++) { for (int i = 0;; i++) {
toml_datum_t bind = toml_string_at (array, i); toml_datum_t bind = toml_string_at (array, i);
@ -110,7 +112,7 @@ SetConfigValue (toml_table_t *table, char *key, struct Keybindings *keybind) {
break; break;
case button: case button:
for (int i = 0; i < COUNTOFARR (keybind->buttons); i++) { for (int i = 0; i < COUNTOFARR (keybind->buttons); i++) {
if (keybind->buttons[i] == SDL_CONTROLLER_BUTTON_INVALID) { if (keybind->buttons[i] == SDL_GAMEPAD_BUTTON_INVALID) {
keybind->buttons[i] = value.button; keybind->buttons[i] = value.button;
break; break;
} }
@ -137,7 +139,7 @@ SetConfigValue (toml_table_t *table, char *key, struct Keybindings *keybind) {
} }
bool bool
InitializePoll (void *DivaWindowHandle) { InitializePoll (void *windowHandle) {
bool hasRumble = true; bool hasRumble = true;
SDL_SetMainReady (); SDL_SetMainReady ();
@ -146,8 +148,8 @@ InitializePoll (void *DivaWindowHandle) {
SDL_SetHint (SDL_HINT_JOYSTICK_HIDAPI_PS5, "1"); SDL_SetHint (SDL_HINT_JOYSTICK_HIDAPI_PS5, "1");
SDL_SetHint (SDL_HINT_JOYSTICK_HIDAPI_PS5_RUMBLE, "1"); SDL_SetHint (SDL_HINT_JOYSTICK_HIDAPI_PS5_RUMBLE, "1");
if (SDL_Init (SDL_INIT_JOYSTICK | SDL_INIT_HAPTIC | SDL_INIT_GAMECONTROLLER | SDL_INIT_EVENTS | SDL_INIT_VIDEO) != 0) { if (SDL_Init (SDL_INIT_JOYSTICK | SDL_INIT_HAPTIC | SDL_INIT_GAMEPAD | SDL_INIT_EVENTS | SDL_INIT_VIDEO) != 0) {
if (SDL_Init (SDL_INIT_JOYSTICK | SDL_INIT_GAMECONTROLLER | SDL_INIT_EVENTS | SDL_INIT_VIDEO) == 0) { if (SDL_Init (SDL_INIT_JOYSTICK | SDL_INIT_GAMEPAD | SDL_INIT_EVENTS | SDL_INIT_VIDEO) == 0) {
hasRumble = false; hasRumble = false;
} else { } else {
printError ("SDL_Init (SDL_INIT_JOYSTICK | SDL_INIT_HAPTIC | SDL_INIT_GAMECONTROLLER | SDL_INIT_EVENTS | SDL_INIT_VIDEO): " printError ("SDL_Init (SDL_INIT_JOYSTICK | SDL_INIT_HAPTIC | SDL_INIT_GAMECONTROLLER | SDL_INIT_EVENTS | SDL_INIT_VIDEO): "
@ -157,27 +159,26 @@ InitializePoll (void *DivaWindowHandle) {
} }
} }
if (SDL_GameControllerAddMappingsFromFile (configPath ("gamecontrollerdb.txt")) == -1) if (SDL_AddGamepadMappingsFromFile (configPath ("gamecontrollerdb.txt")) == -1)
printError ("%s (): Cannot read gamecontrollerdb.txt\n", __func__); printError ("%s (): Cannot read gamecontrollerdb.txt\n", __func__);
SDL_GameControllerEventState (SDL_ENABLE);
SDL_JoystickEventState (SDL_ENABLE);
for (int i = 0; i < SDL_NumJoysticks (); i++) { int count = 0;
if (!SDL_IsGameController (i)) continue; SDL_JoystickID *joysticks = SDL_GetJoysticks (&count);
if (joysticks == 0) { return hasRumble; }
for (int i = 0; i < count; i++) {
if (!SDL_IsGamepad (joysticks[i])) continue;
SDL_GameController *controller = SDL_GameControllerOpen (i); SDL_Gamepad *controller = SDL_OpenGamepad (joysticks[i]);
if (!controller) { if (!controller) { continue; }
printWarning ("Could not open gamecontroller %s: %s\n", SDL_GameControllerNameForIndex (i), SDL_GetError ());
continue;
}
printInfo ("%s: %s\n", SDL_GetGamepadName (controller), SDL_GetGamepadMapping (controller));
controllers[i] = controller; controllers[i] = controller;
} }
window = SDL_CreateWindowFrom (DivaWindowHandle); window = SDL_CreateWindowFrom (windowHandle);
if (window != NULL) SDL_SetWindowResizable (window, true); if (window != NULL) SDL_SetWindowResizable (window, true);
else printError ("SDL_CreateWindowFrom (DivaWindowHandle): %s\n", SDL_GetError ()); else printError ("SDL_CreateWindowFrom (windowHandle): %s\n", SDL_GetError ());
return hasRumble; return hasRumble;
} }
@ -200,67 +201,67 @@ UpdatePoll (void *DivaWindowHandle) {
SDL_Event event; SDL_Event event;
while (SDL_PollEvent (&event) != 0) { while (SDL_PollEvent (&event) != 0) {
switch (event.type) { switch (event.type) {
case SDL_CONTROLLERDEVICEADDED: case SDL_GAMEPADADDED:
if (!SDL_IsGameController (event.cdevice.which)) break; if (!SDL_IsGamepad (event.cdevice.which)) break;
SDL_GameController *controller = SDL_GameControllerOpen (event.cdevice.which); SDL_Gamepad *controller = SDL_OpenGamepad (event.cdevice.which);
if (!controller) {
printError ("%s (): Could not open gamecontroller %s: %s\n", __func__, SDL_GameControllerNameForIndex (event.cdevice.which),
SDL_GetError ());
continue;
}
if (!controller) { continue; }
printInfo ("%s: %s\n", SDL_GetGamepadName (controller), SDL_GetGamepadMapping (controller));
controllers[event.cdevice.which] = controller; controllers[event.cdevice.which] = controller;
break; break;
case SDL_CONTROLLERDEVICEREMOVED: case SDL_GAMEPADREMOVED:
if (!SDL_IsGameController (event.cdevice.which)) break; printInfo ("%s: %s\n", SDL_GetGamepadName (controllers[event.cdevice.which]), SDL_GetGamepadMapping (controllers[event.cdevice.which]));
SDL_GameControllerClose (controllers[event.cdevice.which]); if (!SDL_IsGamepad (event.cdevice.which)) break;
SDL_CloseGamepad (controllers[event.cdevice.which]);
break; break;
case SDL_MOUSEWHEEL: case SDL_MOUSEWHEEL:
if (event.wheel.y > 0) currentMouseState.ScrolledUp = true; if (event.wheel.y > 0) currentMouseState.ScrolledUp = true;
else if (event.wheel.y < 0) currentMouseState.ScrolledDown = true; else if (event.wheel.y < 0) currentMouseState.ScrolledDown = true;
break; break;
case SDL_CONTROLLERBUTTONUP: case SDL_GAMEPADBUTTONUP:
case SDL_CONTROLLERBUTTONDOWN: currentControllerButtonsState[event.cbutton.button] = event.cbutton.state; break; case SDL_GAMEPADBUTTONDOWN:
case SDL_CONTROLLERAXISMOTION: currentControllerButtonsState[event.cbutton.button] = event.cbutton.state;
printInfo ("%s\n", SDL_GetGamepadStringForButton (event.cbutton.button));
break;
case SDL_GAMEPADAXISMOTION:
if (event.caxis.value > 8000) { if (event.caxis.value > 8000) {
switch (event.caxis.axis) { switch (event.caxis.axis) {
case SDL_CONTROLLER_AXIS_LEFTX: currentControllerAxisState.LeftRight = 1; break; case SDL_GAMEPAD_AXIS_LEFTX: currentControllerAxisState.LeftRight = 1; break;
case SDL_CONTROLLER_AXIS_LEFTY: currentControllerAxisState.LeftDown = 1; break; case SDL_GAMEPAD_AXIS_LEFTY: currentControllerAxisState.LeftDown = 1; break;
case SDL_CONTROLLER_AXIS_RIGHTX: currentControllerAxisState.RightRight = 1; break; case SDL_GAMEPAD_AXIS_RIGHTX: currentControllerAxisState.RightRight = 1; break;
case SDL_CONTROLLER_AXIS_RIGHTY: currentControllerAxisState.RightDown = 1; break; case SDL_GAMEPAD_AXIS_RIGHTY: currentControllerAxisState.RightDown = 1; break;
case SDL_CONTROLLER_AXIS_TRIGGERLEFT: currentControllerAxisState.LTriggerDown = 1; break; case SDL_GAMEPAD_AXIS_LEFT_TRIGGER: currentControllerAxisState.LTriggerDown = 1; break;
case SDL_CONTROLLER_AXIS_TRIGGERRIGHT: currentControllerAxisState.RTriggerDown = 1; break; case SDL_GAMEPAD_AXIS_RIGHT_TRIGGER: currentControllerAxisState.RTriggerDown = 1; break;
} }
} else if (event.caxis.value < -8000) { } else if (event.caxis.value < -8000) {
switch (event.caxis.axis) { switch (event.caxis.axis) {
case SDL_CONTROLLER_AXIS_LEFTX: currentControllerAxisState.LeftLeft = 1; break; case SDL_GAMEPAD_AXIS_LEFTX: currentControllerAxisState.LeftLeft = 1; break;
case SDL_CONTROLLER_AXIS_LEFTY: currentControllerAxisState.LeftUp = 1; break; case SDL_GAMEPAD_AXIS_LEFTY: currentControllerAxisState.LeftUp = 1; break;
case SDL_CONTROLLER_AXIS_RIGHTX: currentControllerAxisState.RightLeft = 1; break; case SDL_GAMEPAD_AXIS_RIGHTX: currentControllerAxisState.RightLeft = 1; break;
case SDL_CONTROLLER_AXIS_RIGHTY: currentControllerAxisState.RightUp = 1; break; case SDL_GAMEPAD_AXIS_RIGHTY: currentControllerAxisState.RightUp = 1; break;
} }
} else { } else {
switch (event.caxis.axis) { switch (event.caxis.axis) {
case SDL_CONTROLLER_AXIS_LEFTX: case SDL_GAMEPAD_AXIS_LEFTX:
currentControllerAxisState.LeftRight = 0; currentControllerAxisState.LeftRight = 0;
currentControllerAxisState.LeftLeft = 0; currentControllerAxisState.LeftLeft = 0;
break; break;
case SDL_CONTROLLER_AXIS_LEFTY: case SDL_GAMEPAD_AXIS_LEFTY:
currentControllerAxisState.LeftDown = 0; currentControllerAxisState.LeftDown = 0;
currentControllerAxisState.LeftUp = 0; currentControllerAxisState.LeftUp = 0;
break; break;
case SDL_CONTROLLER_AXIS_RIGHTX: case SDL_GAMEPAD_AXIS_RIGHTX:
currentControllerAxisState.RightRight = 0; currentControllerAxisState.RightRight = 0;
currentControllerAxisState.RightLeft = 0; currentControllerAxisState.RightLeft = 0;
break; break;
case SDL_CONTROLLER_AXIS_RIGHTY: case SDL_GAMEPAD_AXIS_RIGHTY:
currentControllerAxisState.RightDown = 0; currentControllerAxisState.RightDown = 0;
currentControllerAxisState.RightUp = 0; currentControllerAxisState.RightUp = 0;
break; break;
case SDL_CONTROLLER_AXIS_TRIGGERLEFT: currentControllerAxisState.LTriggerDown = 0; break; case SDL_GAMEPAD_AXIS_LEFT_TRIGGER: currentControllerAxisState.LTriggerDown = 0; break;
case SDL_CONTROLLER_AXIS_TRIGGERRIGHT: currentControllerAxisState.RTriggerDown = 0; break; case SDL_GAMEPAD_AXIS_RIGHT_TRIGGER: currentControllerAxisState.RTriggerDown = 0; break;
} }
} }
break; break;
@ -317,7 +318,7 @@ GetInternalButtonState (struct Keybindings bindings) {
if (KeyboardIsTapped (bindings.keycodes[i])) buttons.Tapped = 1; if (KeyboardIsTapped (bindings.keycodes[i])) buttons.Tapped = 1;
} }
for (int i = 0; i < COUNTOFARR (ConfigControllerButtons); i++) { for (int i = 0; i < COUNTOFARR (ConfigControllerButtons); i++) {
if (bindings.buttons[i] == SDL_CONTROLLER_BUTTON_INVALID) continue; if (bindings.buttons[i] == SDL_GAMEPAD_BUTTON_INVALID) continue;
if (ControllerButtonIsReleased (bindings.buttons[i])) buttons.Released = 1; if (ControllerButtonIsReleased (bindings.buttons[i])) buttons.Released = 1;
if (ControllerButtonIsDown (bindings.buttons[i])) buttons.Down = 1; if (ControllerButtonIsDown (bindings.buttons[i])) buttons.Down = 1;
if (ControllerButtonIsTapped (bindings.buttons[i])) buttons.Tapped = 1; if (ControllerButtonIsTapped (bindings.buttons[i])) buttons.Tapped = 1;
@ -341,9 +342,9 @@ GetInternalButtonState (struct Keybindings bindings) {
void void
SetRumble (int left, int right) { SetRumble (int left, int right) {
for (int i = 0; i < COUNTOFARR (controllers); i++) { for (int i = 0; i < COUNTOFARR (controllers); i++) {
if (!controllers[i] || !SDL_GameControllerHasRumble (controllers[i])) continue; if (!controllers[i] || !SDL_GamepadHasRumble (controllers[i])) continue;
SDL_GameControllerRumble (controllers[i], left, right, 1000); SDL_RumbleGamepad (controllers[i], left, right, 1000);
} }
} }
@ -433,32 +434,32 @@ GetMouseScrollIsTapped (enum Scroll scroll) {
} }
bool bool
ControllerButtonIsDown (SDL_GameControllerButton button) { ControllerButtonIsDown (SDL_GamepadButton button) {
return currentControllerButtonsState[button]; return currentControllerButtonsState[button];
} }
bool bool
ControllerButtonIsUp (SDL_GameControllerButton button) { ControllerButtonIsUp (SDL_GamepadButton button) {
return !ControllerButtonIsDown (button); return !ControllerButtonIsDown (button);
} }
bool bool
ControllerButtonWasDown (SDL_GameControllerButton button) { ControllerButtonWasDown (SDL_GamepadButton button) {
return lastControllerButtonsState[button]; return lastControllerButtonsState[button];
} }
bool bool
ControllerButtonWasUp (SDL_GameControllerButton button) { ControllerButtonWasUp (SDL_GamepadButton button) {
return !ControllerButtonWasDown (button); return !ControllerButtonWasDown (button);
} }
bool bool
ControllerButtonIsTapped (SDL_GameControllerButton button) { ControllerButtonIsTapped (SDL_GamepadButton button) {
return ControllerButtonIsDown (button) && ControllerButtonWasUp (button); return ControllerButtonIsDown (button) && ControllerButtonWasUp (button);
} }
bool bool
ControllerButtonIsReleased (SDL_GameControllerButton button) { ControllerButtonIsReleased (SDL_GamepadButton button) {
return ControllerButtonIsUp (button) && ControllerButtonWasDown (button); return ControllerButtonIsUp (button) && ControllerButtonWasDown (button);
} }
@ -529,4 +530,4 @@ IsButtonReleased (struct Keybindings bindings) {
bool bool
IsButtonDown (struct Keybindings bindings) { IsButtonDown (struct Keybindings bindings) {
return GetInternalButtonState (bindings).Down; return GetInternalButtonState (bindings).Down;
} }

View File

@ -1,5 +1,5 @@
#pragma once #pragma once
#include <SDL.h> #include <SDL3/SDL.h>
#include <stdbool.h> #include <stdbool.h>
#include <stdint.h> #include <stdint.h>
#include <toml.h> #include <toml.h>
@ -37,7 +37,7 @@ enum Scroll { MOUSE_SCROLL_INVALID, MOUSE_SCROLL_UP, MOUSE_SCROLL_DOWN };
struct Keybindings { struct Keybindings {
uint8_t keycodes[255]; uint8_t keycodes[255];
SDL_GameControllerButton buttons[255]; SDL_GamepadButton buttons[255];
enum SDLAxis axis[255]; enum SDLAxis axis[255];
enum Scroll scroll[2]; enum Scroll scroll[2];
}; };
@ -50,7 +50,7 @@ struct ConfigValue {
enum EnumType type; enum EnumType type;
union { union {
uint8_t keycode; uint8_t keycode;
SDL_GameControllerButton button; SDL_GamepadButton button;
enum SDLAxis axis; enum SDLAxis axis;
enum Scroll scroll; enum Scroll scroll;
}; };
@ -89,12 +89,12 @@ bool GetWasMouseScrollDown ();
bool GetMouseScrollIsReleased (enum Scroll scroll); bool GetMouseScrollIsReleased (enum Scroll scroll);
bool GetMouseScrollIsDown (enum Scroll scroll); bool GetMouseScrollIsDown (enum Scroll scroll);
bool GetMouseScrollIsTapped (enum Scroll scroll); bool GetMouseScrollIsTapped (enum Scroll scroll);
bool ControllerButtonIsDown (SDL_GameControllerButton button); bool ControllerButtonIsDown (SDL_GamepadButton button);
bool ControllerButtonIsUp (SDL_GameControllerButton button); bool ControllerButtonIsUp (SDL_GamepadButton button);
bool ControllerButtonWasDown (SDL_GameControllerButton button); bool ControllerButtonWasDown (SDL_GamepadButton button);
bool ControllerButtonWasUp (SDL_GameControllerButton button); bool ControllerButtonWasUp (SDL_GamepadButton button);
bool ControllerButtonIsTapped (SDL_GameControllerButton button); bool ControllerButtonIsTapped (SDL_GamepadButton button);
bool ControllerButtonIsReleased (SDL_GameControllerButton button); bool ControllerButtonIsReleased (SDL_GamepadButton button);
bool ControllerAxisIsDown (enum SDLAxis axis); bool ControllerAxisIsDown (enum SDLAxis axis);
bool ControllerAxisIsUp (enum SDLAxis axis); bool ControllerAxisIsUp (enum SDLAxis axis);
bool ControllerAxisWasDown (enum SDLAxis axis); bool ControllerAxisWasDown (enum SDLAxis axis);