more work on multiplayer kart selection screen & multioplayer input

git-svn-id: svn+ssh://svn.code.sf.net/p/supertuxkart/code/main/branches/irrlicht@3731 178a84e3-b1eb-0310-8ba1-8eac791a3b58
This commit is contained in:
auria
2009-07-11 16:50:57 +00:00
parent c92c33ccb8
commit f987fff348
8 changed files with 55 additions and 24 deletions

View File

@@ -42,17 +42,47 @@ private:
int m_last_kart_id;
InputDevice* m_device;
public:
Player(const char* name) : m_player_group("Player", "Represents one human player"),
m_name(name, "name", &m_player_group),
m_last_kart_id(-1)
{
}
void setName(const std::string &name_){m_name = name_;}
const char* getName() { return m_name.c_str(); }
int getLastKartId(){ return m_last_kart_id; }
void setLastKartId(int newLastKartId){ m_last_kart_id = newLastKartId; }
};
/**
* Represents a player that is currently playing.
*/
class ActivePlayer
{
Player* m_player;
InputDevice* m_device;
public:
ActivePlayer(Player* player)
{
m_player = player;
m_device = NULL;
}
Player* getPlayer()
{
return m_player;
}
void setPlayer(Player* player)
{
m_player = player;
}
InputDevice* getDevice() const { return m_device; }
void setDevice(InputDevice* device)
{
@@ -61,13 +91,6 @@ public:
if(device != NULL)
device->setPlayer(this);
}
void setName(const std::string &name_){m_name = name_;}
const char* getName() { return m_name.c_str(); }
int getLastKartId(){ return m_last_kart_id; }
void setLastKartId(int newLastKartId){ m_last_kart_id = newLastKartId; }
};
#endif

View File

@@ -352,8 +352,10 @@ void setPlayer0Device(InputDevice* device)
}
// TODO : support more than 1 player
StateManager::addActivePlayer( UserConfigParams::m_player.get(0) );
UserConfigParams::m_player[0].setDevice(device);
ActivePlayer* newPlayer = new ActivePlayer(UserConfigParams::m_player.get(0));
StateManager::addActivePlayer( newPlayer );
newPlayer->setDevice(device);
input_manager->getDeviceList()->setAssignMode(DETECT_NEW);
// TODO : fall back in no-assign mode when aborting a game and going back to the menu

View File

@@ -52,16 +52,15 @@ namespace StateManager
std::vector<std::string> g_menu_stack;
/**
* A list of all currently playing players. (only storing references since
* the original is in UserConfig)
* A list of all currently playing players.
*/
ptr_vector<Player, REF> g_active_players;
ptr_vector<ActivePlayer, HOLD> g_active_players;
const ptr_vector<Player, REF>& getActivePlayers()
const ptr_vector<ActivePlayer, HOLD>& getActivePlayers()
{
return g_active_players;
}
void addActivePlayer(Player* p)
void addActivePlayer(ActivePlayer* p)
{
g_active_players.push_back(p);
}

View File

@@ -23,7 +23,7 @@
#include "utils/ptr_vector.hpp"
struct Input;
class Player;
class ActivePlayer;
namespace StateManager
{
@@ -37,8 +37,14 @@ namespace StateManager
bool isGameState();
void reshowTopMostMenu();
const ptr_vector<Player, REF>& getActivePlayers();
void addActivePlayer(Player* p);
const ptr_vector<ActivePlayer, HOLD>& getActivePlayers();
/**
* 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 resetActivePlayers();
void escapePressed();

View File

@@ -144,7 +144,7 @@ bool DeviceManager::mapInputToPlayerAndAction( Input::InputType type, int device
// In assign mode, find to which active player this binding belongs
// FIXME : in order to speed this use, a Player* pointer could be
// stored inside the device so we don't need to iterate through devices
const ptr_vector<Player, REF>& players = StateManager::getActivePlayers();
const ptr_vector<ActivePlayer, HOLD>& players = StateManager::getActivePlayers();
const int playerAmount = players.size();
for(int n=0; n<playerAmount; n++)
{

View File

@@ -19,7 +19,7 @@ InputDevice::InputDevice()
/**
* Sets which players uses this device; or pass NULL to say no player uses it.
*/
void InputDevice::setPlayer(Player* owner)
void InputDevice::setPlayer(ActivePlayer* owner)
{
if(owner == NULL)
{
@@ -27,7 +27,7 @@ void InputDevice::setPlayer(Player* owner)
return;
}
const ptr_vector<Player, REF>& players = StateManager::getActivePlayers();
const ptr_vector<ActivePlayer, HOLD>& players = StateManager::getActivePlayers();
const int playerAmount = players.size();
for(int n=0; n<playerAmount; n++)
{

View File

@@ -7,7 +7,7 @@
#include <fstream>
#include "io/xml_node.hpp"
class Player;
class ActivePlayer;
enum DeviceType
{
@@ -41,7 +41,7 @@ public:
DeviceType getType() const { return m_type; };
void setPlayer(Player* owner);
void setPlayer(ActivePlayer* owner);
/**
* returns a human-readable string for the key binded with the given action

View File

@@ -23,6 +23,7 @@
#include "math.h"
#include <algorithm>
#include <cstring>
#include <stdio.h>
namespace StringUtils
{