port: load gamecontrollerdb if available

This commit is contained in:
fgsfds committed 2023-11-27 01:20:09 +01:00
1 parent 116dc7e8b6
commit 31ad9351f5
1 file changed
+12
+12
View File
@@ -10,6 +10,9 @@
#include "config.h"
#include "utils.h"
#include "system.h"
#include "fs.h"
#define CONTROLLERDB_FNAME "gamecontrollerdb.txt"
#define MAX_BIND_STR 256
@@ -637,6 +640,15 @@ s32 inputInit(void)
SDL_InitSubSystem(SDL_INIT_GAMECONTROLLER | SDL_INIT_HAPTIC);
}
// try to load controller db from an external file in the save folder
if (fsFileSize("$S/" CONTROLLERDB_FNAME)) {
const char *dbpath = fsFullPath("$S/" CONTROLLERDB_FNAME);
const s32 dbcount = SDL_GameControllerAddMappingsFromFile(dbpath);
if (dbcount >= 0) {
sysLogPrintf(LOG_NOTE, "input: added %d controller mappings from %s", dbcount, dbpath);
}
}
inputInitAllControllers();
// since the main event loop is elsewhere, we can receive some events we need using a watcher