Browse Source

Add game controller DB repo

Include mapping in build instead of having to download file manually.
master
TheoryOfNekomata 1 year ago
parent
commit
486211074e
5 changed files with 11 additions and 1848 deletions
  1. +3
    -0
      .gitmodules
  2. +5
    -0
      CMakeLists.txt
  3. +0
    -1846
      assets/gamecontrollerdb.txt
  4. +2
    -2
      src/packages/game/input/IZ_gamecontroller.c
  5. +1
    -0
      subprojects/SDL_GameControllerDB

+ 3
- 0
.gitmodules View File

@@ -40,3 +40,6 @@
[submodule "subprojects/ini-config"]
path = subprojects/ini-config
url = https://code.modal.sh/TheoryOfNekomata/ini-config.git
[submodule "subprojects/SDL_GameControllerDB"]
path = subprojects/SDL_GameControllerDB
url = https://github.com/gabomdq/SDL_GameControllerDB

+ 5
- 0
CMakeLists.txt View File

@@ -477,6 +477,11 @@ add_custom_command(TARGET game POST_BUILD
"${CMAKE_HOME_DIRECTORY}/assets"
$<TARGET_FILE_DIR:game>/assets)

add_custom_command(TARGET game POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_if_different
"${CMAKE_HOME_DIRECTORY}/subprojects/SDL_GameControllerDB/gamecontrollerdb.txt"
$<TARGET_FILE_DIR:game>/assets)

add_custom_command(TARGET asset-inv POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_directory
"${CMAKE_HOME_DIRECTORY}/assets"


+ 0
- 1846
assets/gamecontrollerdb.txt
File diff suppressed because it is too large
View File


+ 2
- 2
src/packages/game/input/IZ_gamecontroller.c View File

@@ -164,7 +164,6 @@ void IZ_GameControllerBindStateToConfig(IZ_GameControllerState(* state)[IZ_PLAYE
u8 player_index;
u8 control_index;
for (player_index = 0; player_index < IZ_PLAYERS; player_index += 1) {
// The `+ 3` corresponds to the first three config items. Add as appropriate.
u8 base_index = (player_index * (IZ_CONTROLS + IZ_GAME_CONTROLLER_DEFAULT_CONFIGS));
config_items[base_index + 0].dest = &((*state)[player_index].config.axis_threshold);
config_items[base_index + 1].dest = &((*state)[player_index].config.guid);
@@ -187,7 +186,6 @@ void IZ_GameControllerInitializeConfigItems(INI_ConfigItem config_items[]) {
for (player_index = 0; player_index < IZ_PLAYERS; player_index += 1) {
main_section_name = IZ_calloc(64, sizeof(char));
sprintf(main_section_name, "GameController.%d", player_index);
// The `+ 3` corresponds to the first three config items. Add as appropriate.
u8 base_index = (player_index * (IZ_CONTROLS + IZ_GAME_CONTROLLER_DEFAULT_CONFIGS));
config_items[base_index + 0] = (INI_ConfigItem) {
INI_CONFIG_TYPE_U16,
@@ -243,6 +241,8 @@ IZ_ProcedureResult IZ_GameControllerInitialize(IZ_GameControllerState(* state)[I
IZ_memcpy(state, sizeof(IZ_GameControllerState) * IZ_PLAYERS, &IZ_GAME_CONTROLLER_DEFAULT_STATE, sizeof(IZ_GameControllerState) * IZ_PLAYERS);

// TODO query this file from the internet?
// Download from https://raw.githubusercontent.com/gabomdq/SDL_GameControllerDB/master/gamecontrollerdb.txt
// Add the subproject
IZ_LogInfo(IZ_LOG_CATEGORY_GENERIC, "input", "Loading game controller mappings file: %s", "assets/gamecontrollerdb.txt");
const i16 loaded_mappings = SDL_GameControllerAddMappingsFromFile("assets/gamecontrollerdb.txt");
if (loaded_mappings <= 0) {


+ 1
- 0
subprojects/SDL_GameControllerDB

@@ -0,0 +1 @@
Subproject commit 436c7e3d54a57189ea0ab44d05f36b7cc7ea496c

Loading…
Cancel
Save