diff --git a/include/akgl/SDL_GameControllerDB.h b/include/akgl/SDL_GameControllerDB.h index a222125..d0de86c 100644 --- a/include/akgl/SDL_GameControllerDB.h +++ b/include/akgl/SDL_GameControllerDB.h @@ -1,7 +1,7 @@ #ifndef _SDL_GAMECONTROLLERDB_H_ #define _SDL_GAMECONTROLLERDB_H_ -// Taken from https://raw.githubusercontent.com/mdqinc/SDL_GameControllerDB/refs/heads/master/gamecontrollerdb.txt on Fri May 15 11:05:32 AM EDT 2026 +// Taken from https://raw.githubusercontent.com/mdqinc/SDL_GameControllerDB/refs/heads/master/gamecontrollerdb.txt on Thu May 21 09:41:48 PM EDT 2026 #define AKGL_SDL_GAMECONTROLLER_DB_LEN 2228 diff --git a/include/akgl/controller.h b/include/akgl/controller.h index a4236e3..5431321 100644 --- a/include/akgl/controller.h +++ b/include/akgl/controller.h @@ -44,4 +44,6 @@ akerr_ErrorContext AKERR_NOIGNORE *akgl_controller_handle_removed(void *appstate akerr_ErrorContext AKERR_NOIGNORE *akgl_controller_pushmap(int controlmapid, akgl_Control *control); akerr_ErrorContext AKERR_NOIGNORE *akgl_controller_default(int controlmapid, char *actorname, int kbid, int jsid); + +akerr_ErrorContext AKERR_NOIGNORE *akgl_controller_open_gamepads(void); #endif // _CONTROLLER_H_ diff --git a/src/controller.c b/src/controller.c index 9ae8b98..3d3cb88 100644 --- a/src/controller.c +++ b/src/controller.c @@ -22,6 +22,33 @@ akerr_ErrorContext AKERR_NOIGNORE *akgl_controller_list_keyboards(void) SUCCEED_RETURN(e); } +akerr_ErrorContext AKERR_NOIGNORE *akgl_controller_open_gamepads(void) +{ + int count = 0; + int i = 0; + SDL_JoystickID *gamepads = NULL; + SDL_Gamepad *gamepad = NULL; + + PREPARE_ERROR(e); + if ( SDL_HasGamepad() ) { + gamepads = SDL_GetGamepads(&count); + if ( count > 0 ) { + FAIL_ZERO_RETURN(e, gamepads, AKERR_NULLPOINTER, "%s", SDL_GetError()); + for ( i = 0; i < count ; i++ ) { + gamepad = SDL_OpenGamepad(gamepads[i]); + FAIL_ZERO_RETURN(e, gamepad, AKERR_NULLPOINTER, "%s", SDL_GetError()); + SDL_Log("Gamepad %d is %s", i, SDL_GetGamepadNameForID(gamepads[i])); + } + SDL_free(gamepads); + } else { + SDL_Log("No gamepads enumerated"); + } + } else { + SDL_Log("No gamepads connected"); + } + SUCCEED_RETURN(e); +} + akerr_ErrorContext *akgl_controller_handle_event(void *appstate, SDL_Event *event) { int i = 0; diff --git a/src/game.c b/src/game.c index 6dd75db..32d00ea 100644 --- a/src/game.c +++ b/src/game.c @@ -85,6 +85,8 @@ akerr_ErrorContext AKERR_NOIGNORE *akgl_game_init() FAIL_ZERO_RETURN(errctx, 0, AKGL_ERR_SDL, "%s", SDL_GetError()); } } + PASS(errctx, akgl_controller_open_gamepads()); + SUCCEED_RETURN(errctx); } @@ -137,7 +139,7 @@ akerr_ErrorContext AKERR_NOIGNORE *akgl_game_init_screen() camera.y = 0; camera.w = screenwidth; camera.h = screenheight; - SUCCEED(e); + SUCCEED_RETURN(e); } void akgl_game_updateFPS() diff --git a/src/heap.c b/src/heap.c index dbc9d25..73692a8 100644 --- a/src/heap.c +++ b/src/heap.c @@ -115,7 +115,7 @@ akerr_ErrorContext *akgl_heap_release_actor(akgl_Actor *ptr) if ( ptr->refcount == 0 ) { for ( i = 0; i < AKGL_ACTOR_MAX_CHILDREN; i++ ) { if ( ptr->children[i] != NULL ) { - CATCH_AND_RETURN(errctx, akgl_heap_release_actor(ptr->children[i])); + PASS(errctx, akgl_heap_release_actor(ptr->children[i])); } } SDL_ClearProperty(AKGL_REGISTRY_ACTOR, (char *)&ptr->name); diff --git a/src/registry.c b/src/registry.c index 7dcd98c..da86bce 100644 --- a/src/registry.c +++ b/src/registry.c @@ -149,7 +149,7 @@ akerr_ErrorContext AKERR_NOIGNORE *akgl_registry_load_properties(char *fname) } FINISH(errctx, true); } SDL_Log("Properties loaded"); - SUCCEED(errctx); + SUCCEED_RETURN(errctx); } akerr_ErrorContext AKERR_NOIGNORE *akgl_set_property(char *name, char *src)