mirror of
https://github.com/KartKrewDev/RingRacers.git
synced 2026-01-04 14:12:41 +00:00
Merge branch 'pad-diagnostics' into 'master'
Gamepad GUID and Name logging, gamecontrollerdb.txt See merge request KartKrew/Kart!1092
This commit is contained in:
commit
0cad27d7fe
3 changed files with 78 additions and 2 deletions
10
src/d_main.c
10
src/d_main.c
|
|
@ -38,6 +38,7 @@
|
|||
#include "f_finale.h"
|
||||
#include "g_game.h"
|
||||
#include "hu_stuff.h"
|
||||
#include "i_joy.h"
|
||||
#include "i_sound.h"
|
||||
#include "i_system.h"
|
||||
#include "i_time.h"
|
||||
|
|
@ -174,11 +175,16 @@ boolean capslock = 0; // gee i wonder what this does.
|
|||
|
||||
static void HandleGamepadDeviceAdded(event_t *ev)
|
||||
{
|
||||
char guid[64];
|
||||
char name[256];
|
||||
|
||||
I_Assert(ev != NULL);
|
||||
I_Assert(ev->type == ev_gamepad_device_added);
|
||||
|
||||
G_RegisterAvailableGamepad(ev->device);
|
||||
CONS_Debug(DBG_GAMELOGIC, "Registered available gamepad device %d\n", ev->device);
|
||||
I_GetGamepadGuid(ev->device, guid, sizeof(guid));
|
||||
I_GetGamepadName(ev->device, name, sizeof(name));
|
||||
CONS_Alert(CONS_NOTICE, "Gamepad device %d connected: %s (%s)\n", ev->device, name, guid);
|
||||
}
|
||||
|
||||
static void HandleGamepadDeviceRemoved(event_t *ev)
|
||||
|
|
@ -188,7 +194,7 @@ static void HandleGamepadDeviceRemoved(event_t *ev)
|
|||
I_Assert(ev->type == ev_gamepad_device_removed);
|
||||
|
||||
G_UnregisterAvailableGamepad(ev->device);
|
||||
CONS_Debug(DBG_GAMELOGIC, "Unregistered available gamepad device %d\n", ev->device);
|
||||
CONS_Alert(CONS_NOTICE, "Gamepad device %d disconnected\n", ev->device);
|
||||
|
||||
// Downstream responders need to update player gamepad assignments, pause, etc
|
||||
|
||||
|
|
|
|||
|
|
@ -60,6 +60,8 @@ extern JoyType_t Joystick[MAXSPLITSCREENPLAYERS];
|
|||
|
||||
void I_SetGamepadPlayerIndex(INT32 device_id, INT32 index);
|
||||
void I_SetGamepadIndicatorColor(INT32 device_id, UINT8 red, UINT8 green, UINT8 blue);
|
||||
void I_GetGamepadGuid(INT32 device_id, char *out, int out_len);
|
||||
void I_GetGamepadName(INT32 device_id, char *out, int out_len);
|
||||
|
||||
#ifdef __cplusplus
|
||||
} // extern "C"
|
||||
|
|
|
|||
|
|
@ -963,6 +963,62 @@ void I_SetGamepadIndicatorColor(INT32 device_id, UINT8 red, UINT8 green, UINT8 b
|
|||
#endif
|
||||
}
|
||||
|
||||
void I_GetGamepadGuid(INT32 device_id, char *out, int out_len)
|
||||
{
|
||||
SDL_GameController *controller;
|
||||
SDL_Joystick *joystick;
|
||||
SDL_JoystickGUID guid;
|
||||
|
||||
I_Assert(device_id > 0);
|
||||
I_Assert(out != NULL);
|
||||
I_Assert(out_len > 0);
|
||||
|
||||
if (out_len < 33)
|
||||
{
|
||||
out[0] = 0;
|
||||
return;
|
||||
}
|
||||
|
||||
controller = SDL_GameControllerFromInstanceID(device_id - 1);
|
||||
if (controller == NULL)
|
||||
{
|
||||
out[0] = 0;
|
||||
return;
|
||||
}
|
||||
joystick = SDL_GameControllerGetJoystick(controller);
|
||||
if (joystick == NULL)
|
||||
{
|
||||
out[0] = 0;
|
||||
return;
|
||||
}
|
||||
|
||||
guid = SDL_JoystickGetGUID(joystick);
|
||||
SDL_JoystickGetGUIDString(guid, out, out_len);
|
||||
}
|
||||
|
||||
void I_GetGamepadName(INT32 device_id, char *out, int out_len)
|
||||
{
|
||||
SDL_GameController *controller;
|
||||
const char *name;
|
||||
int name_len;
|
||||
|
||||
I_Assert(device_id > 0);
|
||||
I_Assert(out != NULL);
|
||||
I_Assert(out_len > 0);
|
||||
|
||||
controller = SDL_GameControllerFromInstanceID(device_id - 1);
|
||||
if (controller == NULL)
|
||||
{
|
||||
out[0] = 0;
|
||||
return;
|
||||
}
|
||||
|
||||
name = SDL_GameControllerName(controller);
|
||||
name_len = strlen(name) + 1;
|
||||
memcpy(out, name, out_len < name_len ? out_len : name_len);
|
||||
out[out_len - 1] = 0;
|
||||
}
|
||||
|
||||
//
|
||||
// I_StartupInput
|
||||
//
|
||||
|
|
@ -990,6 +1046,18 @@ void I_StartupInput(void)
|
|||
return;
|
||||
}
|
||||
|
||||
{
|
||||
char dbpath[1024];
|
||||
sprintf(dbpath, "%s" PATHSEP "gamecontrollerdb.txt", srb2path);
|
||||
SDL_GameControllerAddMappingsFromFile(dbpath);
|
||||
}
|
||||
|
||||
{
|
||||
char dbpath[1024];
|
||||
sprintf(dbpath, "%s" PATHSEP "gamecontrollerdb_user.txt", srb2home);
|
||||
SDL_GameControllerAddMappingsFromFile(dbpath);
|
||||
}
|
||||
|
||||
// Upon initialization, the gamecontroller subsystem will automatically dispatch controller device added events
|
||||
// for controllers connected before initialization.
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue