@@ -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