From 9723dd04eeb090e2cc5ef44ec82907f95afe23bf Mon Sep 17 00:00:00 2001 From: "Tej A. Shah" Date: Tue, 24 Dec 2024 17:48:36 -0500 Subject: [PATCH] Added in feature to assign keyboard or gamepad with the -N or -R option Also cleaned up the help text --- src/config/user_config.hpp | 4 ++++ src/main.cpp | 33 ++++++++++++++++++++++++++++----- 2 files changed, 32 insertions(+), 5 deletions(-) diff --git a/src/config/user_config.hpp b/src/config/user_config.hpp index 92b9c54985..ecdca1be72 100644 --- a/src/config/user_config.hpp +++ b/src/config/user_config.hpp @@ -834,6 +834,10 @@ namespace UserConfigParams PARAM_PREFIX bool m_race_now PARAM_DEFAULT( false ); + PARAM_PREFIX int m_default_keyboard PARAM_DEFAULT( -1 ); + + PARAM_PREFIX int m_default_gamepad PARAM_DEFAULT( -1 ); + PARAM_PREFIX bool m_enforce_current_player PARAM_DEFAULT( false ); PARAM_PREFIX bool m_enable_sound PARAM_DEFAULT( true ); diff --git a/src/main.cpp b/src/main.cpp index 9d143f7888..7fa0f56761 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -516,10 +516,21 @@ void setupRaceStart() InputDevice *device; - // Use keyboard 0 by default in --no-start-screen - device = input_manager->getDeviceManager()->getKeyboard(0); + // Assign the player a device; check the command line params for preferences; by default use keyboard 0 - // Create player and associate player with keyboard + if(UserConfigParams::m_default_keyboard > -1) { + device = input_manager->getDeviceManager()->getKeyboard(UserConfigParams::m_default_keyboard); + } + else if(UserConfigParams::m_default_gamepad > -1) { + // getGamePad(int) returns a GamePadDevice which is a subclass of InputDevice + // However, the compiler doesn't like it so it has to be manually casted in + device = (InputDevice *) input_manager->getDeviceManager()->getGamePad(UserConfigParams::m_default_gamepad); + } + else { + device = input_manager->getDeviceManager()->getKeyboard(0); + } + + // Create player and associate player with device StateManager::get()->createActivePlayer( PlayerManager::get()->getPlayer(0), device); @@ -557,10 +568,14 @@ void cmdLineHelp() "menu.\n" " -R, --race-now Same as -N but also skip the ready-set-go phase" " and the music.\n" + " --use-keyboard=N Used in conjunction with the -N or -R option, will assign the player to the specified" + " keyboard. Is zero indexed.\n" + " --use-gamepad=N Used in conjunction with the -N or -R option, will assign the player to the specified" + " gamepad. Is zero indexed.\n" " -t, --track=NAME Start track NAME.\n" " --gp=NAME Start the specified Grand Prix.\n" - " --add-gp-dir=DIR Load Grand Prix files in DIR. Setting will be saved\n" - "in config.xml under additional_gp_directory. Use\n" + " --add-gp-dir=DIR Load Grand Prix files in DIR. Setting will be saved" + "in config.xml under additional_gp_directory. Use" "--add-gp-dir=\"\" to unset.\n" " --stk-config=FILE use ./data/FILE instead of " "./data/stk_config.xml\n" @@ -1675,6 +1690,14 @@ int handleCmdLine(bool has_server_config, bool has_parent_process) UserConfigParams::m_race_now = true; } // --race-now + if(CommandLine::has( "--use-keyboard",&n)) { + UserConfigParams::m_default_keyboard = n; + } //--use-keyboard + + if(CommandLine::has( "--use-gamepad",&n)) { + UserConfigParams::m_default_gamepad = n; + } //--use-gamepad + if(CommandLine::has("--laps", &s)) { int laps = atoi(s.c_str());