diff --git a/src/config/player.cpp b/src/config/player.cpp index 5143b2187..fb65f5d5e 100644 --- a/src/config/player.cpp +++ b/src/config/player.cpp @@ -3,10 +3,11 @@ #include "race/race_manager.hpp" #include "modes/world.hpp" -ActivePlayer::ActivePlayer(PlayerProfile* player) +ActivePlayer::ActivePlayer(PlayerProfile* player, InputDevice *device) { m_player = player; m_device = NULL; + setDevice(device); } ActivePlayer::~ActivePlayer() { @@ -33,8 +34,7 @@ void ActivePlayer::setDevice(InputDevice* device) m_device = device; - if(device != NULL) - device->setPlayer(this); + if(device != NULL) device->setPlayer(this); } PlayerKart* ActivePlayer::getKart() diff --git a/src/config/player.hpp b/src/config/player.hpp index 86354d17d..05edac4a3 100644 --- a/src/config/player.hpp +++ b/src/config/player.hpp @@ -70,7 +70,7 @@ class ActivePlayer InputDevice* m_device; public: - ActivePlayer(PlayerProfile* player); + ActivePlayer(PlayerProfile* player, InputDevice* device); ~ActivePlayer(); PlayerProfile* getProfile(); diff --git a/src/main.cpp b/src/main.cpp index 75ea458c0..06ef5462a 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -607,15 +607,12 @@ int main(int argc, char *argv[] ) else { InputDevice *device; - ActivePlayer* newPlayer; // Use keyboard by default in --no-start-screen device = input_manager->getDeviceList()->getKeyboard(0); // Create player and associate player with keyboard - newPlayer = new ActivePlayer( UserConfigParams::m_all_players.get(0) ); - StateManager::get()->addActivePlayer(newPlayer); - newPlayer->setDevice(device); + StateManager::get()->createActivePlayer( UserConfigParams::m_all_players.get(0), device ); // Set up race manager appropriately race_manager->setNumLocalPlayers(1); diff --git a/src/race/race_manager.cpp b/src/race/race_manager.cpp index 0982b6822..43bc0d494 100644 --- a/src/race/race_manager.cpp +++ b/src/race/race_manager.cpp @@ -187,14 +187,6 @@ void RaceManager::computeRandomKartList() */ void RaceManager::startNew() { - if(UserConfigParams::m_no_start_screen == true) - { - InputDevice* device = input_manager->getDeviceList()->getLatestUsedDevice(); - ActivePlayer* newPlayer = new ActivePlayer(UserConfigParams::m_all_players.get(0)); - StateManager::get()->addActivePlayer( newPlayer ); - newPlayer->setDevice(device); - device->setPlayer(newPlayer); - } if(m_major_mode==MAJOR_MODE_GRAND_PRIX) // GP: get tracks and laps from grand prix { m_tracks = m_grand_prix.getTracks(); diff --git a/src/states_screens/kart_selection.cpp b/src/states_screens/kart_selection.cpp index 5e00da2a0..18af80d9a 100644 --- a/src/states_screens/kart_selection.cpp +++ b/src/states_screens/kart_selection.cpp @@ -436,30 +436,22 @@ bool playerJoin(InputDevice* device) RibbonGridWidget* w = getCurrentScreen()->getWidget("karts"); if (w == NULL ) { - std::cout << "playerJoin() called outside of kart selection screen.\n"; + std::cerr << "playerJoin(): Called outside of kart selection screen.\n"; return false; } - if(device == NULL) + else if (device == NULL) { - std::cout << "I don't know which device was pressed :'(\n"; + std::cerr << "playerJoin(): Passed null pointer\n"; return false; } - else if(device->getType() == DT_KEYBOARD) - { - std::cout << "Fire was pressed on a keyboard\n"; - } - else if(device->getType() == DT_GAMEPAD) - { - std::cout << "Fire was pressed on a gamepad\n"; - } // make a copy of the area, ands move it to be outside the screen Widget rightarea = *getCurrentScreen()->getWidget("playerskarts"); rightarea.x = irr_driver->getFrameSize().Width; - ActivePlayer* aplayer = new ActivePlayer( UserConfigParams::m_all_players.get(0) ); - StateManager::get()->addActivePlayer(aplayer); - aplayer->setDevice(device); + // Create new active player + int id = StateManager::get()->createActivePlayer( UserConfigParams::m_all_players.get(0), device ); + ActivePlayer *aplayer = StateManager::get()->getActivePlayer(id); // FIXME : player ID needs to be synced with active player list PlayerKartWidget* newPlayer = new PlayerKartWidget(aplayer, &rightarea, g_player_karts.size()); @@ -467,11 +459,7 @@ bool playerJoin(InputDevice* device) newPlayer->add(); g_player_karts.push_back(newPlayer); - - - const int amount = g_player_karts.size(); - Widget* fullarea = getCurrentScreen()->getWidget("playerskarts"); const int splitWidth = fullarea->w / amount; diff --git a/src/states_screens/state_manager.cpp b/src/states_screens/state_manager.cpp index 455251807..397e47d72 100644 --- a/src/states_screens/state_manager.cpp +++ b/src/states_screens/state_manager.cpp @@ -30,6 +30,7 @@ #include "guiengine/widget.hpp" #include "input/device_manager.hpp" #include "input/input_manager.hpp" +#include "input/input_device.hpp" #include "io/file_manager.hpp" #include "network/network_manager.hpp" #include "race/race_manager.hpp" @@ -73,10 +74,21 @@ ActivePlayer* StateManager::getActivePlayer(const int id) } return returnPlayer; } +/* void StateManager::addActivePlayer(ActivePlayer* p) { m_active_players.push_back(p); } +*/ +int StateManager::createActivePlayer(PlayerProfile *profile, InputDevice *device) +{ + ActivePlayer *p; + int i; + p = new ActivePlayer(profile, device); + i = m_active_players.size(); + m_active_players.push_back(p); + return i; +} void StateManager::removeActivePlayer(int id) { m_active_players.erase(id); diff --git a/src/states_screens/state_manager.hpp b/src/states_screens/state_manager.hpp index e6fe632f8..7388c361c 100644 --- a/src/states_screens/state_manager.hpp +++ b/src/states_screens/state_manager.hpp @@ -22,6 +22,8 @@ #include #include "guiengine/abstract_state_manager.hpp" #include "utils/ptr_vector.hpp" +#include "input/input_device.hpp" +#include "config/player.hpp" struct Input; class ActivePlayer; @@ -55,7 +57,8 @@ public: * Adds a new player to the list of active players. StateManager takes ownership of the object * so no need to delete it yourself. */ - void addActivePlayer(ActivePlayer* p); +// void addActivePlayer(ActivePlayer* p); + int createActivePlayer(PlayerProfile *profile, InputDevice *device); void removeActivePlayer(int id); int activePlayerCount();