Some cleanups with ActivePlayer. Moved it to StateManager, because that's where active players are created and stored - this will be less confusing than hiding it inside a configuration class. More work is still to be done if we want to make this code really clean, though.
git-svn-id: svn+ssh://svn.code.sf.net/p/supertuxkart/code/main/trunk@4764 178a84e3-b1eb-0310-8ba1-8eac791a3b58
This commit is contained in:
parent
626ef5f30c
commit
b868909efe
@ -1,49 +0,0 @@
|
||||
|
||||
#include "config/player.hpp"
|
||||
|
||||
#include "karts/controller/player_controller.hpp"
|
||||
#include "modes/world.hpp"
|
||||
|
||||
ActivePlayer::ActivePlayer(PlayerProfile* player, InputDevice *device)
|
||||
{
|
||||
m_player = player;
|
||||
m_device = NULL;
|
||||
setDevice(device);
|
||||
} // ActivePlayer
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
ActivePlayer::~ActivePlayer()
|
||||
{
|
||||
setDevice(NULL);
|
||||
} // ~ActivePlayer
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
PlayerProfile* ActivePlayer::getProfile()
|
||||
{
|
||||
return m_player;
|
||||
} // getProfile
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
void ActivePlayer::setPlayerProfile(PlayerProfile* player)
|
||||
{
|
||||
m_player = player;
|
||||
} // setPlayerProfile
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
InputDevice* ActivePlayer::getDevice() const
|
||||
{
|
||||
return m_device;
|
||||
} // getDevice
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
void ActivePlayer::setDevice(InputDevice* device)
|
||||
{
|
||||
// unset player from previous device he was assigned to, if any
|
||||
if (m_device != NULL) m_device->setPlayer(NULL);
|
||||
|
||||
m_device = device;
|
||||
|
||||
// inform the devce of its new owner
|
||||
if (device != NULL) device->setPlayer(this);
|
||||
} // setDevice
|
||||
|
@ -22,10 +22,6 @@
|
||||
|
||||
#include <string>
|
||||
#include "config/user_config.hpp"
|
||||
#include "input/input_device.hpp"
|
||||
|
||||
class InputDevice;
|
||||
class Kart;
|
||||
|
||||
/**
|
||||
* class for managing player profiles (name, control configuration, etc.)
|
||||
@ -51,42 +47,12 @@ public:
|
||||
|
||||
void setName(const std::string &name_){ m_name = name_;}
|
||||
|
||||
const char* getName() { return m_name.c_str(); }
|
||||
const char* getName() const { 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. It helps manage associating with a
|
||||
* player profile and an input device (we're very flexible on this; ActivePlayer #1
|
||||
* can choose to e.g. use profile #5 and device #2)
|
||||
*/
|
||||
class ActivePlayer
|
||||
{
|
||||
PlayerProfile *m_player;
|
||||
InputDevice *m_device;
|
||||
|
||||
/** Pointer to the kart of this player, only valid during the game. */
|
||||
Kart *m_kart;
|
||||
public:
|
||||
/** ID of this player within the list of active players */
|
||||
int m_id;
|
||||
|
||||
ActivePlayer(PlayerProfile* player, InputDevice* device);
|
||||
~ActivePlayer();
|
||||
|
||||
PlayerProfile* getProfile();
|
||||
void setPlayerProfile(PlayerProfile* player);
|
||||
|
||||
InputDevice* getDevice() const;
|
||||
void setDevice(InputDevice* device);
|
||||
/** Sets the kart for this player. */
|
||||
void setKart(Kart *kart) { m_kart = kart; }
|
||||
/** Returns the kart of this player. Only valid while world exists. */
|
||||
Kart* getKart() { return m_kart; }
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
/*EOF*/
|
||||
|
@ -248,7 +248,6 @@
|
||||
956C6ED51128D3FB004336C8 /* end_controller.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 956C6ECC1128D3FB004336C8 /* end_controller.cpp */; };
|
||||
956C6ED61128D3FB004336C8 /* new_ai_controller.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 956C6ECF1128D3FB004336C8 /* new_ai_controller.cpp */; };
|
||||
956C6ED71128D3FB004336C8 /* player_controller.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 956C6ED11128D3FB004336C8 /* player_controller.cpp */; };
|
||||
956D36A710095035007FCB95 /* player.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 956D36A610095035007FCB95 /* player.cpp */; };
|
||||
9574F17C11206881008D202E /* world_status.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 9574F17A11206881008D202E /* world_status.cpp */; };
|
||||
958330CC10122B4A00C5137E /* engine.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 958330B210122B4A00C5137E /* engine.cpp */; };
|
||||
958330CD10122B4A00C5137E /* event_handler.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 958330B410122B4A00C5137E /* event_handler.cpp */; };
|
||||
@ -456,7 +455,6 @@
|
||||
956C6ED01128D3FB004336C8 /* new_ai_controller.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; name = new_ai_controller.hpp; path = ../../karts/controller/new_ai_controller.hpp; sourceTree = SOURCE_ROOT; };
|
||||
956C6ED11128D3FB004336C8 /* player_controller.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = player_controller.cpp; path = ../../karts/controller/player_controller.cpp; sourceTree = SOURCE_ROOT; };
|
||||
956C6ED21128D3FB004336C8 /* player_controller.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; name = player_controller.hpp; path = ../../karts/controller/player_controller.hpp; sourceTree = SOURCE_ROOT; };
|
||||
956D36A610095035007FCB95 /* player.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = player.cpp; path = ../../config/player.cpp; sourceTree = SOURCE_ROOT; };
|
||||
9574F17A11206881008D202E /* world_status.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = world_status.cpp; path = ../../modes/world_status.cpp; sourceTree = SOURCE_ROOT; };
|
||||
9574F17B11206881008D202E /* world_status.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; name = world_status.hpp; path = ../../modes/world_status.hpp; sourceTree = SOURCE_ROOT; };
|
||||
958330B210122B4A00C5137E /* engine.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = engine.cpp; path = ../../guiengine/engine.cpp; sourceTree = SOURCE_ROOT; };
|
||||
@ -2238,7 +2236,6 @@
|
||||
children = (
|
||||
95B5CD13102DE08F00EF2001 /* device_config.cpp */,
|
||||
95B5CD12102DE08F00EF2001 /* device_config.hpp */,
|
||||
956D36A610095035007FCB95 /* player.cpp */,
|
||||
95D950CD0FE473CA002E10AD /* player.hpp */,
|
||||
95D950CE0FE473CA002E10AD /* stk_config.cpp */,
|
||||
95D950CF0FE473CA002E10AD /* stk_config.hpp */,
|
||||
@ -2544,7 +2541,6 @@
|
||||
951BC65E0FFAF290006B5FF1 /* ipo.cpp in Sources */,
|
||||
955DE88310042701006A4F3C /* check_manager.cpp in Sources */,
|
||||
955DE88C1004273B006A4F3C /* check_structure.cpp in Sources */,
|
||||
956D36A710095035007FCB95 /* player.cpp in Sources */,
|
||||
958330CC10122B4A00C5137E /* engine.cpp in Sources */,
|
||||
958330CD10122B4A00C5137E /* event_handler.cpp in Sources */,
|
||||
958330CE10122B4A00C5137E /* modaldialog.cpp in Sources */,
|
||||
|
@ -183,7 +183,7 @@ void DeviceManager::addGamepad(GamePadDevice* d)
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
InputDevice* DeviceManager::mapKeyboardInput( int btnID,
|
||||
ActivePlayer **player /* out */,
|
||||
StateManager::ActivePlayer **player /* out */,
|
||||
PlayerAction *action /* out */ )
|
||||
{
|
||||
const int keyboard_amount = m_keyboards.size();
|
||||
@ -218,7 +218,7 @@ InputDevice *DeviceManager::mapGamepadInput( Input::InputType type,
|
||||
int btnID,
|
||||
int axisDir,
|
||||
int value,
|
||||
ActivePlayer **player /* out */,
|
||||
StateManager::ActivePlayer **player /* out */,
|
||||
PlayerAction *action /* out */)
|
||||
{
|
||||
GamePadDevice *gPad = getGamePadFromIrrID(deviceID);
|
||||
@ -248,7 +248,7 @@ bool DeviceManager::translateInput( Input::InputType type,
|
||||
int btnID,
|
||||
int axisDir,
|
||||
int value,
|
||||
ActivePlayer** player /* out */,
|
||||
StateManager::ActivePlayer** player /* out */,
|
||||
PlayerAction* action /* out */ )
|
||||
{
|
||||
InputDevice *device = NULL;
|
||||
|
@ -48,7 +48,7 @@ private:
|
||||
int btnID,
|
||||
int axisDir,
|
||||
int value,
|
||||
ActivePlayer **player /* out */,
|
||||
StateManager::ActivePlayer **player /* out */,
|
||||
PlayerAction *action /* out */);
|
||||
|
||||
/**
|
||||
@ -59,7 +59,7 @@ private:
|
||||
* \return The device to which this input belongs
|
||||
*/
|
||||
InputDevice *mapKeyboardInput ( int btnID,
|
||||
ActivePlayer **player /* out */,
|
||||
StateManager::ActivePlayer **player /* out */,
|
||||
PlayerAction *action /* out */);
|
||||
|
||||
bool deserialize();
|
||||
@ -108,7 +108,7 @@ public:
|
||||
int btnID,
|
||||
int axisDir,
|
||||
int value,
|
||||
ActivePlayer** player /* out */,
|
||||
StateManager::ActivePlayer** player /* out */,
|
||||
PlayerAction* action /* out */ );
|
||||
|
||||
InputDevice* getLatestUsedDevice();
|
||||
|
@ -18,7 +18,7 @@ InputDevice::InputDevice()
|
||||
/**
|
||||
* Sets which players uses this device; or pass NULL to say no player uses it.
|
||||
*/
|
||||
void InputDevice::setPlayer(ActivePlayer* owner)
|
||||
void InputDevice::setPlayer(StateManager::ActivePlayer* owner)
|
||||
{
|
||||
m_player = owner;
|
||||
}
|
||||
@ -95,7 +95,7 @@ void GamePadDevice::setButtonPressed(const int i, bool isButtonPressed)
|
||||
|
||||
void GamePadDevice::resetAxisDirection(const int axis,
|
||||
Input::AxisDirection direction,
|
||||
ActivePlayer* player)
|
||||
StateManager::ActivePlayer* player)
|
||||
{
|
||||
KeyBinding bind;
|
||||
if (StateManager::get()->getGameState() != GUIEngine::GAME) return; // ignore this while in menus
|
||||
@ -126,7 +126,8 @@ void GamePadDevice::resetAxisDirection(const int axis,
|
||||
*/
|
||||
|
||||
|
||||
bool GamePadDevice::hasBinding(Input::InputType type, const int id, const int value, ActivePlayer* player, PlayerAction* action /* out */)
|
||||
bool GamePadDevice::hasBinding(Input::InputType type, const int id, const int value,
|
||||
StateManager::ActivePlayer* player, PlayerAction* action /* out */)
|
||||
{
|
||||
bool success = false;
|
||||
if(m_prevAxisDirections == NULL) return false; // device not open
|
||||
|
@ -2,13 +2,13 @@
|
||||
#define INPUT_DEVICE_HPP
|
||||
|
||||
#include <string>
|
||||
#include "input/input.hpp"
|
||||
#include "config/device_config.hpp"
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
#include "io/xml_node.hpp"
|
||||
|
||||
class ActivePlayer;
|
||||
#include "config/device_config.hpp"
|
||||
#include "input/input.hpp"
|
||||
#include "io/xml_node.hpp"
|
||||
#include "states_screens/state_manager.hpp"
|
||||
|
||||
enum DeviceType
|
||||
{
|
||||
@ -21,7 +21,7 @@ class InputDevice
|
||||
friend class DeviceManager;
|
||||
protected:
|
||||
DeviceType m_type;
|
||||
ActivePlayer* m_player;
|
||||
StateManager::ActivePlayer* m_player;
|
||||
DeviceConfig* m_configuration;
|
||||
|
||||
public:
|
||||
@ -33,8 +33,8 @@ public:
|
||||
|
||||
DeviceType getType() const { return m_type; };
|
||||
|
||||
void setPlayer(ActivePlayer* owner);
|
||||
ActivePlayer *getPlayer() {return m_player;}
|
||||
void setPlayer(StateManager::ActivePlayer* owner);
|
||||
StateManager::ActivePlayer *getPlayer() { return m_player; }
|
||||
|
||||
/**
|
||||
* returns a human-readable string for the key binded with the given action
|
||||
@ -61,7 +61,7 @@ public:
|
||||
|
||||
class GamePadDevice : public InputDevice
|
||||
{
|
||||
void resetAxisDirection(const int axis, Input::AxisDirection direction, ActivePlayer* player);
|
||||
void resetAxisDirection(const int axis, Input::AxisDirection direction, StateManager::ActivePlayer* player);
|
||||
bool m_buttonPressed[SEvent::SJoystickEvent::NUMBER_OF_BUTTONS];
|
||||
|
||||
public:
|
||||
@ -85,7 +85,8 @@ public:
|
||||
* the value of the 'type' parameter)
|
||||
* \param[out] action The action associated to this input (only check this value if method returned true)
|
||||
*/
|
||||
bool hasBinding(Input::InputType type, const int id, const int value, ActivePlayer* player, PlayerAction* action);
|
||||
bool hasBinding(Input::InputType type, const int id, const int value,
|
||||
StateManager::ActivePlayer* player, PlayerAction* action);
|
||||
|
||||
};
|
||||
|
||||
|
@ -256,7 +256,7 @@ int InputManager::getPlayerKeyboardID() const
|
||||
if (m_device_manager->getKeyboard(k) != NULL &&
|
||||
m_device_manager->getKeyboard(k)->getPlayer() != NULL)
|
||||
{
|
||||
return m_device_manager->getKeyboard(k)->getPlayer()->m_id;
|
||||
return m_device_manager->getKeyboard(k)->getPlayer()->getID();
|
||||
}
|
||||
}
|
||||
|
||||
@ -277,7 +277,7 @@ int InputManager::getPlayerKeyboardID() const
|
||||
*/
|
||||
void InputManager::dispatchInput(Input::InputType type, int deviceID, int btnID, int axisDirection, int value)
|
||||
{
|
||||
ActivePlayer* player = NULL;
|
||||
StateManager::ActivePlayer* player = NULL;
|
||||
PlayerAction action;
|
||||
bool action_found = m_device_manager->translateInput( type, deviceID, btnID, axisDirection, value, &player, &action);
|
||||
|
||||
@ -413,7 +413,7 @@ void InputManager::dispatchInput(Input::InputType type, int deviceID, int btnID,
|
||||
m_timer = 0.25;
|
||||
}
|
||||
|
||||
int playerID = (player == NULL ? 0 : player->m_id);
|
||||
int playerID = (player == NULL ? 0 : player->getID());
|
||||
|
||||
// If only the master player can act, and this player is not the master, ignore his input
|
||||
if (m_device_manager->getAssignMode() == ASSIGN && m_master_player_only && playerID != 0) return;
|
||||
|
@ -26,7 +26,7 @@
|
||||
/** Constructor, saves the kart pointer and a pointer to the KartControl
|
||||
* of the kart.
|
||||
*/
|
||||
Controller::Controller(Kart *kart, ActivePlayer *player)
|
||||
Controller::Controller(Kart *kart, StateManager::ActivePlayer *player)
|
||||
{
|
||||
m_controls = &(kart->getControls());
|
||||
m_kart = kart;
|
||||
|
@ -22,10 +22,10 @@
|
||||
using namespace irr;
|
||||
|
||||
#include "karts/controller/kart_control.hpp"
|
||||
#include "states_screens/state_manager.hpp"
|
||||
|
||||
class Kart;
|
||||
class Item;
|
||||
class ActivePlayer;
|
||||
|
||||
/** This is the base class for kart controller - that can be a player
|
||||
* or a a robot.
|
||||
@ -42,13 +42,13 @@ protected:
|
||||
|
||||
/** If this belongs to a player, it stores the active player data
|
||||
* structure. Otherwise it is 0. */
|
||||
ActivePlayer *m_player;
|
||||
StateManager::ActivePlayer *m_player;
|
||||
public:
|
||||
Controller (Kart *kart, ActivePlayer *player=NULL);
|
||||
Controller (Kart *kart, StateManager::ActivePlayer *player=NULL);
|
||||
virtual ~Controller () {};
|
||||
/** Returns the active player for this controller (NULL
|
||||
* if this controller does not belong to a player. */
|
||||
ActivePlayer *getPlayer () {return m_player;}
|
||||
StateManager::ActivePlayer *getPlayer () {return m_player;}
|
||||
virtual void reset () {};
|
||||
virtual void update (float dt) {};
|
||||
virtual void handleZipper () {};
|
||||
|
@ -44,7 +44,7 @@
|
||||
#include "tracks/track.hpp"
|
||||
#include "utils/constants.hpp"
|
||||
|
||||
EndController::EndController(Kart *kart, ActivePlayer *player)
|
||||
EndController::EndController(Kart *kart, StateManager::ActivePlayer *player)
|
||||
: Controller(kart, player)
|
||||
{
|
||||
m_kart_length = m_kart->getKartProperties()->getKartModel()->getLength();
|
||||
|
@ -129,7 +129,7 @@ private:
|
||||
void setSteering(float angle, float dt);
|
||||
void findCurve();
|
||||
public:
|
||||
EndController(Kart *kart, ActivePlayer* player);
|
||||
EndController(Kart *kart, StateManager::ActivePlayer* player);
|
||||
~EndController();
|
||||
virtual void update (float delta) ;
|
||||
virtual void reset ();
|
||||
|
@ -40,7 +40,7 @@
|
||||
* \param init_pos The start coordinates and heading of the kart.
|
||||
* \param player_index Index of the player kart.
|
||||
*/
|
||||
PlayerController::PlayerController(Kart *kart, ActivePlayer *player,
|
||||
PlayerController::PlayerController(Kart *kart, StateManager::ActivePlayer *player,
|
||||
unsigned int player_index)
|
||||
: Controller(kart)
|
||||
{
|
||||
|
@ -47,7 +47,7 @@ private:
|
||||
|
||||
void steer(float, int);
|
||||
public:
|
||||
PlayerController (Kart *kart, ActivePlayer *_player,
|
||||
PlayerController (Kart *kart, StateManager::ActivePlayer *_player,
|
||||
unsigned int player_index);
|
||||
~PlayerController ();
|
||||
void update (float);
|
||||
|
@ -72,7 +72,7 @@ void ConnectMessage::setId()
|
||||
{
|
||||
char hostname[256];
|
||||
gethostname(hostname, 255);
|
||||
const std::string& id = StateManager::get()->getActivePlayer(0)->getProfile()->getName();
|
||||
const std::string& id = StateManager::get()->getActivePlayerProfile(0)->getName();
|
||||
std::ostringstream o;
|
||||
o << id << '@' << hostname;
|
||||
m_id = o.str();
|
||||
|
@ -91,7 +91,7 @@ void RaceManager::setLocalKartInfo(unsigned int player_id, const std::string& ka
|
||||
assert(0<=player_id && player_id <m_local_kart_info.size());
|
||||
|
||||
m_local_kart_info[player_id] = RemoteKartInfo(player_id, kart,
|
||||
StateManager::get()->getActivePlayer(player_id)->getProfile()->getName(),
|
||||
StateManager::get()->getActivePlayerProfile(player_id)->getName(),
|
||||
network_manager->getMyHostId());
|
||||
} // setLocalKartInfo
|
||||
|
||||
|
@ -182,7 +182,7 @@ FocusDispatcher* g_dispatcher = NULL;
|
||||
float x_speed, y_speed, w_speed, h_speed;
|
||||
|
||||
/** Object representing this player */
|
||||
ActivePlayer* m_associatedPlayer;
|
||||
StateManager::ActivePlayer* m_associatedPlayer;
|
||||
int m_playerID;
|
||||
|
||||
/** Internal name of the spinner; useful to interpret spinner events, which contain the name of the activated object */
|
||||
@ -201,7 +201,8 @@ FocusDispatcher* g_dispatcher = NULL;
|
||||
std::string deviceName;
|
||||
std::string m_kartInternalName;
|
||||
|
||||
PlayerKartWidget(KartSelectionScreen* parent, ActivePlayer* associatedPlayer, Widget* area, const int m_playerID, const int irrlichtWidgetID=-1) : Widget()
|
||||
PlayerKartWidget(KartSelectionScreen* parent,StateManager:: ActivePlayer* associatedPlayer,
|
||||
Widget* area, const int m_playerID, const int irrlichtWidgetID=-1) : Widget()
|
||||
{
|
||||
m_associatedPlayer = associatedPlayer;
|
||||
x_speed = 1.0f;
|
||||
@ -330,9 +331,10 @@ FocusDispatcher* g_dispatcher = NULL;
|
||||
/** Called when players are renumbered (changes the player ID) */
|
||||
void setPlayerID(const int newPlayerID)
|
||||
{
|
||||
if (StateManager::get()->getActivePlayers().get(newPlayerID) != m_associatedPlayer)
|
||||
if (StateManager::get()->getActivePlayer(newPlayerID) != m_associatedPlayer)
|
||||
{
|
||||
printf("Player: %p\nIndex: %d\nm_associatedPlayer: %p\n", StateManager::get()->getActivePlayers().get(newPlayerID), newPlayerID, m_associatedPlayer);
|
||||
printf("Player: %p\nIndex: %d\nm_associatedPlayer: %p\n",
|
||||
StateManager::get()->getActivePlayer(newPlayerID), newPlayerID, m_associatedPlayer);
|
||||
std::cerr << "Internal inconsistency, PlayerKartWidget has IDs and pointers that do not correspond to one player\n";
|
||||
assert(false);
|
||||
}
|
||||
@ -388,7 +390,7 @@ FocusDispatcher* g_dispatcher = NULL;
|
||||
}
|
||||
|
||||
/** Get the associated ActivePlayer object*/
|
||||
ActivePlayer* getAssociatedPlayer()
|
||||
StateManager::ActivePlayer* getAssociatedPlayer()
|
||||
{
|
||||
return m_associatedPlayer;
|
||||
}
|
||||
@ -763,7 +765,7 @@ bool KartSelectionScreen::playerJoin(InputDevice* device, bool firstPlayer)
|
||||
|
||||
// ---- Create new active player
|
||||
const int new_player_id = StateManager::get()->createActivePlayer( UserConfigParams::m_all_players.get(0), device );
|
||||
ActivePlayer* aplayer = StateManager::get()->getActivePlayer(new_player_id);
|
||||
StateManager::ActivePlayer* aplayer = StateManager::get()->getActivePlayer(new_player_id);
|
||||
|
||||
// ---- Create focus dispatcher
|
||||
if (firstPlayer)
|
||||
@ -812,7 +814,7 @@ PlayerKartWidget* removedWidget = NULL;
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
// Returns true if event was handled succesfully
|
||||
bool KartSelectionScreen::playerQuit(ActivePlayer* player)
|
||||
bool KartSelectionScreen::playerQuit(StateManager::ActivePlayer* player)
|
||||
{
|
||||
int playerID = -1;
|
||||
|
||||
@ -1013,13 +1015,14 @@ void KartSelectionScreen::allPlayersDone()
|
||||
DynamicRibbonWidget* w = this->getWidget<DynamicRibbonWidget>("karts");
|
||||
assert( w != NULL );
|
||||
|
||||
ptr_vector< ActivePlayer, HOLD >& players = StateManager::get()->getActivePlayers();
|
||||
const ptr_vector< StateManager::ActivePlayer, HOLD >& players = StateManager::get()->getActivePlayers();
|
||||
|
||||
// ---- Print selection (for debugging purposes)
|
||||
std::cout << "==========\n" << players.size() << " players :\n";
|
||||
for(int n=0; n<players.size(); n++)
|
||||
for (int n=0; n<players.size(); n++)
|
||||
{
|
||||
std::cout << " Player " << n << " is " << players[n].getProfile()->getName() << " on " << players[n].getDevice()->m_name << std::endl;
|
||||
std::cout << " Player " << n << " is " << players[n].getConstProfile()->getName()
|
||||
<< " on " << players[n].getDevice()->m_name << std::endl;
|
||||
}
|
||||
std::cout << "==========\n";
|
||||
|
||||
|
@ -19,13 +19,13 @@
|
||||
|
||||
#include <string>
|
||||
#include "guiengine/screen.hpp"
|
||||
#include "states_screens/state_manager.hpp"
|
||||
|
||||
namespace GUIEngine
|
||||
{
|
||||
class Widget;
|
||||
}
|
||||
class InputDevice;
|
||||
class ActivePlayer;
|
||||
class PlayerKartWidget;
|
||||
class KartHoverListener;
|
||||
|
||||
@ -61,7 +61,7 @@ public:
|
||||
bool playerJoin(InputDevice* device, bool firstPlayer);
|
||||
|
||||
/** Called when a player hits 'rescue' on his device to leave the game */
|
||||
bool playerQuit(ActivePlayer* player);
|
||||
bool playerQuit(StateManager::ActivePlayer* player);
|
||||
|
||||
/** Standard 'Screen' callback before screen is entered */
|
||||
void init();
|
||||
|
@ -21,6 +21,7 @@
|
||||
#include "guiengine/engine.hpp"
|
||||
#include "guiengine/modaldialog.hpp"
|
||||
#include "guiengine/screen.hpp"
|
||||
#include "input/input_device.hpp"
|
||||
#include "input/input_manager.hpp"
|
||||
#include "states_screens/dialogs/race_paused_dialog.hpp"
|
||||
#include "utils/translation.hpp"
|
||||
@ -35,16 +36,17 @@ StateManager* StateManager::get()
|
||||
return state_manager_singleton;
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
#if 0
|
||||
#pragma mark -
|
||||
#pragma mark Player Management
|
||||
#endif
|
||||
|
||||
ptr_vector<ActivePlayer, HOLD>& StateManager::getActivePlayers()
|
||||
{
|
||||
return m_active_players;
|
||||
}
|
||||
ActivePlayer* StateManager::getActivePlayer(const int id)
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
StateManager::ActivePlayer* StateManager::getActivePlayer(const int id)
|
||||
{
|
||||
ActivePlayer *returnPlayer = NULL;
|
||||
if (id < m_active_players.size() && id >= 0)
|
||||
@ -54,12 +56,25 @@ ActivePlayer* StateManager::getActivePlayer(const int id)
|
||||
else
|
||||
{
|
||||
fprintf(stderr, "getActivePlayer(): id out of bounds\n");
|
||||
return false;
|
||||
}
|
||||
|
||||
assert( returnPlayer->m_id == id );
|
||||
|
||||
return returnPlayer;
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
const PlayerProfile* StateManager::getActivePlayerProfile(const int id)
|
||||
{
|
||||
ActivePlayer* a = getActivePlayer(id);
|
||||
if (a == NULL) return NULL;
|
||||
return a->getProfile();
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
void StateManager::updateActivePlayerIDs()
|
||||
{
|
||||
const int amount = m_active_players.size();
|
||||
@ -69,6 +84,8 @@ void StateManager::updateActivePlayerIDs()
|
||||
}
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
int StateManager::createActivePlayer(PlayerProfile *profile, InputDevice *device)
|
||||
{
|
||||
ActivePlayer *p;
|
||||
@ -82,16 +99,23 @@ int StateManager::createActivePlayer(PlayerProfile *profile, InputDevice *device
|
||||
return i;
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
void StateManager::removeActivePlayer(int id)
|
||||
{
|
||||
m_active_players.erase(id);
|
||||
updateActivePlayerIDs();
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
int StateManager::activePlayerCount()
|
||||
{
|
||||
return m_active_players.size();
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
void StateManager::resetActivePlayers()
|
||||
{
|
||||
const int amount = m_active_players.size();
|
||||
@ -102,6 +126,9 @@ void StateManager::resetActivePlayers()
|
||||
m_active_players.clearAndDeleteAll();
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
#if 0
|
||||
#pragma mark -
|
||||
#pragma mark misc stuff
|
||||
@ -112,6 +139,8 @@ bool StateManager::throttleFPS()
|
||||
return m_game_mode != GUIEngine::GAME && GUIEngine::getCurrentScreen()->throttleFPS;
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
void StateManager::escapePressed()
|
||||
{
|
||||
// in input sensing mode
|
||||
@ -141,3 +170,41 @@ void StateManager::escapePressed()
|
||||
}
|
||||
|
||||
|
||||
#if 0
|
||||
#pragma mark -
|
||||
#pragma mark ActivePlayer
|
||||
#endif
|
||||
|
||||
StateManager::ActivePlayer::ActivePlayer(PlayerProfile* player, InputDevice *device)
|
||||
{
|
||||
m_player = player;
|
||||
m_device = NULL;
|
||||
m_kart = NULL;
|
||||
setDevice(device);
|
||||
} // ActivePlayer
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
StateManager::ActivePlayer::~ActivePlayer()
|
||||
{
|
||||
setDevice(NULL);
|
||||
} // ~ActivePlayer
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
void StateManager::ActivePlayer::setPlayerProfile(PlayerProfile* player)
|
||||
{
|
||||
m_player = player;
|
||||
} // setPlayerProfile
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
void StateManager::ActivePlayer::setDevice(InputDevice* device)
|
||||
{
|
||||
// unset player from previous device he was assigned to, if any
|
||||
if (m_device != NULL) m_device->setPlayer(NULL);
|
||||
|
||||
m_device = device;
|
||||
|
||||
// inform the devce of its new owner
|
||||
if (device != NULL) device->setPlayer(this);
|
||||
} // setDevice
|
||||
|
||||
|
||||
|
@ -22,11 +22,11 @@
|
||||
#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;
|
||||
class InputDevice;
|
||||
class Kart;
|
||||
|
||||
namespace GUIEngine
|
||||
{
|
||||
@ -37,18 +37,72 @@ const static int GUI_PLAYER_ID = 0;
|
||||
|
||||
class StateManager : public GUIEngine::AbstractStateManager
|
||||
{
|
||||
/**
|
||||
* A list of all currently playing players.
|
||||
*/
|
||||
ptr_vector<ActivePlayer, HOLD> m_active_players;
|
||||
|
||||
void updateActivePlayerIDs();
|
||||
|
||||
|
||||
public:
|
||||
ptr_vector<ActivePlayer, HOLD>& getActivePlayers();
|
||||
|
||||
/**
|
||||
* Represents a player that is currently playing.
|
||||
* Ties toghether :
|
||||
* - a player's identity (and thus his/her highscores)
|
||||
* - which input device is used by which player
|
||||
* (we're very flexible on this; ActivePlayer #1
|
||||
* can choose to e.g. use profile #5 and device #2)
|
||||
*/
|
||||
class ActivePlayer
|
||||
{
|
||||
friend class StateManager;
|
||||
|
||||
PlayerProfile *m_player;
|
||||
InputDevice *m_device;
|
||||
|
||||
/** Pointer to the kart of this player, only valid during the game. */
|
||||
Kart *m_kart;
|
||||
|
||||
/** ID of this player within the list of active players */
|
||||
int m_id;
|
||||
|
||||
ActivePlayer(PlayerProfile* player, InputDevice* device);
|
||||
|
||||
public:
|
||||
|
||||
~ActivePlayer();
|
||||
|
||||
/** \return the identity of this active player */
|
||||
PlayerProfile* getProfile() { return m_player; }
|
||||
|
||||
/** \return the identity of this active player */
|
||||
const PlayerProfile* getConstProfile() const { return m_player; }
|
||||
|
||||
/** Call to change the identity of this player (useful when player is selecting his identity) */
|
||||
void setPlayerProfile(PlayerProfile* player);
|
||||
|
||||
/** ID of this player within the list of active players */
|
||||
int getID() const { return m_id; }
|
||||
|
||||
/** \return Which input device this player is using, or NULL if none is set yet */
|
||||
InputDevice* getDevice() const { return m_device; }
|
||||
|
||||
void setDevice(InputDevice* device);
|
||||
|
||||
/** Sets the kart for this player. */
|
||||
void setKart(Kart *kart) { m_kart = kart; }
|
||||
|
||||
/** \return the kart of this player. Only valid while world exists. */
|
||||
Kart* getKart() { assert(m_kart != NULL); return m_kart; }
|
||||
};
|
||||
|
||||
|
||||
const ptr_vector<ActivePlayer, HOLD>& getActivePlayers() { return m_active_players; }
|
||||
ActivePlayer* getActivePlayer(const int id);
|
||||
|
||||
/** \return the PlayerProfile of a given ActivePlayer.
|
||||
* \param id the ID of the active player for whichyou want the profile
|
||||
*/
|
||||
const PlayerProfile* getActivePlayerProfile(const int id);
|
||||
|
||||
/**
|
||||
* Adds a new player to the list of active players. StateManager takes ownership of the object
|
||||
* so no need to delete it yourself.
|
||||
@ -68,6 +122,12 @@ public:
|
||||
|
||||
// singleton
|
||||
static StateManager* get();
|
||||
|
||||
private:
|
||||
/**
|
||||
* A list of all currently playing players.
|
||||
*/
|
||||
ptr_vector<ActivePlayer, HOLD> m_active_players;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
Loading…
x
Reference in New Issue
Block a user