More cleanup. Replaced StateManager::addActivePlayer(PlayerProfile *) with StateManager::createActivePlayer(PlayerProfile *, InputDevice *) . This will ensure that in the future no active players will accidentally be added without an associated device and also removes some redundant code.

git-svn-id: svn+ssh://svn.code.sf.net/p/supertuxkart/code/main/branches/irrlicht@3860 178a84e3-b1eb-0310-8ba1-8eac791a3b58
This commit is contained in:
rforder 2009-08-14 17:36:47 +00:00
parent 8b3b8e3d28
commit 47cfe64301
7 changed files with 27 additions and 35 deletions

View File

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

View File

@ -70,7 +70,7 @@ class ActivePlayer
InputDevice* m_device;
public:
ActivePlayer(PlayerProfile* player);
ActivePlayer(PlayerProfile* player, InputDevice* device);
~ActivePlayer();
PlayerProfile* getProfile();

View File

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

View File

@ -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();

View File

@ -436,30 +436,22 @@ bool playerJoin(InputDevice* device)
RibbonGridWidget* w = getCurrentScreen()->getWidget<RibbonGridWidget>("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;

View File

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

View File

@ -22,6 +22,8 @@
#include <string>
#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();