Skip to content

Commit 53ff6e6

Browse files
authored
Command line parameters to assign keyboard or gamepad with the -N or -R option (#5230)
Authored-by: Tej A. Shah (DesiOtaku)
1 parent 4ea1a28 commit 53ff6e6

File tree

2 files changed

+32
-5
lines changed

2 files changed

+32
-5
lines changed

src/config/user_config.hpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -834,6 +834,10 @@ namespace UserConfigParams
834834

835835
PARAM_PREFIX bool m_race_now PARAM_DEFAULT( false );
836836

837+
PARAM_PREFIX int m_default_keyboard PARAM_DEFAULT( -1 );
838+
839+
PARAM_PREFIX int m_default_gamepad PARAM_DEFAULT( -1 );
840+
837841
PARAM_PREFIX bool m_enforce_current_player PARAM_DEFAULT( false );
838842

839843
PARAM_PREFIX bool m_enable_sound PARAM_DEFAULT( true );

src/main.cpp

Lines changed: 28 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -516,10 +516,21 @@ void setupRaceStart()
516516

517517
InputDevice *device;
518518

519-
// Use keyboard 0 by default in --no-start-screen
520-
device = input_manager->getDeviceManager()->getKeyboard(0);
519+
// Assign the player a device; check the command line params for preferences; by default use keyboard 0
521520

522-
// Create player and associate player with keyboard
521+
if(UserConfigParams::m_default_keyboard > -1) {
522+
device = input_manager->getDeviceManager()->getKeyboard(UserConfigParams::m_default_keyboard);
523+
}
524+
else if(UserConfigParams::m_default_gamepad > -1) {
525+
// getGamePad(int) returns a GamePadDevice which is a subclass of InputDevice
526+
// However, the compiler doesn't like it so it has to be manually casted in
527+
device = (InputDevice *) input_manager->getDeviceManager()->getGamePad(UserConfigParams::m_default_gamepad);
528+
}
529+
else {
530+
device = input_manager->getDeviceManager()->getKeyboard(0);
531+
}
532+
533+
// Create player and associate player with device
523534
StateManager::get()->createActivePlayer(
524535
PlayerManager::get()->getPlayer(0), device);
525536

@@ -557,10 +568,14 @@ void cmdLineHelp()
557568
"menu.\n"
558569
" -R, --race-now Same as -N but also skip the ready-set-go phase"
559570
" and the music.\n"
571+
" --use-keyboard=N Used in conjunction with the -N or -R option, will assign the player to the specified"
572+
" keyboard. Is zero indexed.\n"
573+
" --use-gamepad=N Used in conjunction with the -N or -R option, will assign the player to the specified"
574+
" gamepad. Is zero indexed.\n"
560575
" -t, --track=NAME Start track NAME.\n"
561576
" --gp=NAME Start the specified Grand Prix.\n"
562-
" --add-gp-dir=DIR Load Grand Prix files in DIR. Setting will be saved\n"
563-
"in config.xml under additional_gp_directory. Use\n"
577+
" --add-gp-dir=DIR Load Grand Prix files in DIR. Setting will be saved"
578+
"in config.xml under additional_gp_directory. Use"
564579
"--add-gp-dir=\"\" to unset.\n"
565580
" --stk-config=FILE use ./data/FILE instead of "
566581
"./data/stk_config.xml\n"
@@ -1675,6 +1690,14 @@ int handleCmdLine(bool has_server_config, bool has_parent_process)
16751690
UserConfigParams::m_race_now = true;
16761691
} // --race-now
16771692

1693+
if(CommandLine::has( "--use-keyboard",&n)) {
1694+
UserConfigParams::m_default_keyboard = n;
1695+
} //--use-keyboard
1696+
1697+
if(CommandLine::has( "--use-gamepad",&n)) {
1698+
UserConfigParams::m_default_gamepad = n;
1699+
} //--use-gamepad
1700+
16781701
if(CommandLine::has("--laps", &s))
16791702
{
16801703
int laps = atoi(s.c_str());

0 commit comments

Comments
 (0)