Skip to content

Commit

Permalink
Added in feature to assign keyboard or gamepad with the -N or -R option
Browse files Browse the repository at this point in the history
Also cleaned up the help text
  • Loading branch information
Tej A. Shah committed Dec 24, 2024
1 parent 2fac72b commit 9723dd0
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 5 deletions.
4 changes: 4 additions & 0 deletions src/config/user_config.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
Expand Down
33 changes: 28 additions & 5 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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());
Expand Down

0 comments on commit 9723dd0

Please sign in to comment.