Added much debug code to help detect bugs early in kart selection screen and player management (see recent ticket; although these checks can be useful outside of this particular ticket anyway)
git-svn-id: svn+ssh://svn.code.sf.net/p/supertuxkart/code/main/trunk@6145 178a84e3-b1eb-0310-8ba1-8eac791a3b58
This commit is contained in:
parent
90766a6118
commit
984030f990
@ -41,6 +41,10 @@ protected:
|
||||
|
||||
BoolUserConfigParam m_is_guest_account;
|
||||
|
||||
#ifdef DEBUG
|
||||
unsigned int m_magic_number;
|
||||
#endif
|
||||
|
||||
public:
|
||||
|
||||
IntUserConfigParam m_use_frequency;
|
||||
@ -53,6 +57,9 @@ public:
|
||||
m_is_guest_account(false, "guest", &m_player_group),
|
||||
m_use_frequency(0, "use_frequency", &m_player_group)
|
||||
{
|
||||
#ifdef DEBUG
|
||||
m_magic_number = 0xABCD1234;
|
||||
#endif
|
||||
}
|
||||
|
||||
/**
|
||||
@ -69,14 +76,25 @@ public:
|
||||
m_name.findYourDataInAnAttributeOf(node);
|
||||
m_is_guest_account.findYourDataInAnAttributeOf(node);
|
||||
m_use_frequency.findYourDataInAnAttributeOf(node);
|
||||
|
||||
#ifdef DEBUG
|
||||
m_magic_number = 0xABCD1234;
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
void setName(const std::string &name_){ m_name = name_; }
|
||||
~PlayerProfile()
|
||||
{
|
||||
#ifdef DEBUG
|
||||
m_magic_number = 0xDEADBEEF;
|
||||
#endif
|
||||
}
|
||||
|
||||
void setName(const std::string &name_){ assert(m_magic_number == 0xABCD1234); m_name = name_; }
|
||||
|
||||
const char* getName() const { return m_name.c_str(); }
|
||||
const char* getName() const { assert(m_magic_number == 0xABCD1234); return m_name.c_str(); }
|
||||
|
||||
bool isGuestAccount() const { return m_is_guest_account; }
|
||||
bool isGuestAccount() const { assert(m_magic_number == 0xABCD1234); return m_is_guest_account; }
|
||||
|
||||
//int getLastKartId(){ return m_last_kart_id; }
|
||||
//void setLastKartId(int newLastKartId){ m_last_kart_id = newLastKartId; }
|
||||
|
@ -350,6 +350,9 @@ void SpinnerWidget::setValue(irr::core::stringw new_value)
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
std::cerr << "ERROR [SpinnerWidget::setValue] : cannot find element named '"
|
||||
<< irr::core::stringc(new_value.c_str()).c_str() << "'\n";
|
||||
assert(false);
|
||||
}
|
||||
|
||||
|
@ -199,6 +199,10 @@ class PlayerKartWidget : public Widget
|
||||
/** Internal name of the spinner; useful to interpret spinner events, which contain the name of the activated object */
|
||||
std::string spinnerID;
|
||||
|
||||
#ifdef DEBUG
|
||||
long m_magic_number;
|
||||
#endif
|
||||
|
||||
public:
|
||||
/** Sub-widgets created by this widget */
|
||||
LabelWidget* m_player_ID_label;
|
||||
@ -212,9 +216,15 @@ public:
|
||||
std::string deviceName;
|
||||
std::string m_kartInternalName;
|
||||
|
||||
PlayerKartWidget(KartSelectionScreen* parent,StateManager:: ActivePlayer* associatedPlayer,
|
||||
PlayerKartWidget(KartSelectionScreen* parent, StateManager::ActivePlayer* associatedPlayer,
|
||||
core::recti area, const int playerID, const int irrlichtWidgetID=-1) : Widget(WTYPE_DIV)
|
||||
{
|
||||
assert(associatedPlayer->ok());
|
||||
|
||||
#ifdef DEBUG
|
||||
m_magic_number = 0x33445566;
|
||||
#endif
|
||||
|
||||
m_associatedPlayer = associatedPlayer;
|
||||
x_speed = 1.0f;
|
||||
y_speed = 1.0f;
|
||||
@ -363,12 +373,18 @@ public:
|
||||
m_kart_name->getIrrlichtElement()->remove();
|
||||
|
||||
getCurrentScreen()->manualRemoveWidget(this);
|
||||
|
||||
#ifdef DEBUG
|
||||
m_magic_number = 0xDEADBEEF;
|
||||
#endif
|
||||
} // ~PlayerKartWidget
|
||||
// -------------------------------------------------------------------------
|
||||
|
||||
/** Called when players are renumbered (changes the player ID) */
|
||||
void setPlayerID(const int newPlayerID)
|
||||
{
|
||||
assert(m_magic_number == 0x33445566);
|
||||
|
||||
if (StateManager::get()->getActivePlayer(newPlayerID) != m_associatedPlayer)
|
||||
{
|
||||
printf("Player: %p\nIndex: %d\nm_associatedPlayer: %p\n",
|
||||
@ -399,6 +415,7 @@ public:
|
||||
/** Returns the ID of this player */
|
||||
int getPlayerID() const
|
||||
{
|
||||
assert(m_magic_number == 0x33445566);
|
||||
return m_playerID;
|
||||
}
|
||||
|
||||
@ -406,6 +423,21 @@ public:
|
||||
/** Add the widgets to the current screen */
|
||||
virtual void add()
|
||||
{
|
||||
assert(m_magic_number == 0x33445566);
|
||||
|
||||
// FIXME: debug, remove
|
||||
assert(KartSelectionScreen::getInstance()->m_kart_widgets.contains(this));
|
||||
bool mineInList = false;
|
||||
for (int p=0; p<StateManager::get()->activePlayerCount(); p++)
|
||||
{
|
||||
assert(StateManager::get()->getActivePlayer(p)->ok());
|
||||
if (StateManager::get()->getActivePlayer(p) == m_associatedPlayer)
|
||||
{
|
||||
mineInList = true;
|
||||
}
|
||||
}
|
||||
assert(mineInList);
|
||||
|
||||
m_player_ID_label->add();
|
||||
|
||||
// the first player will have an ID of its own to allow for keyboard navigation despite this widget being added last
|
||||
@ -437,6 +469,7 @@ public:
|
||||
/** Get the associated ActivePlayer object*/
|
||||
StateManager::ActivePlayer* getAssociatedPlayer()
|
||||
{
|
||||
assert(m_magic_number == 0x33445566);
|
||||
return m_associatedPlayer;
|
||||
}
|
||||
|
||||
@ -445,6 +478,7 @@ public:
|
||||
will then occur on each call to 'onUpdate'. */
|
||||
void move(const int x, const int y, const int w, const int h)
|
||||
{
|
||||
assert(m_magic_number == 0x33445566);
|
||||
target_x = x;
|
||||
target_y = y;
|
||||
target_w = w;
|
||||
@ -460,6 +494,7 @@ public:
|
||||
/** Call when player confirmed his identity and kart */
|
||||
void markAsReady()
|
||||
{
|
||||
assert(m_magic_number == 0x33445566);
|
||||
if (m_ready) return; // already ready
|
||||
|
||||
m_ready = true;
|
||||
@ -486,6 +521,7 @@ public:
|
||||
/** \return Whether this player confirmed his kart and indent selection */
|
||||
bool isReady()
|
||||
{
|
||||
assert(m_magic_number == 0x33445566);
|
||||
return m_ready;
|
||||
}
|
||||
|
||||
@ -493,6 +529,7 @@ public:
|
||||
/** Updates the animation (moving/shrinking/etc.) */
|
||||
void onUpdate(float delta)
|
||||
{
|
||||
assert(m_magic_number == 0x33445566);
|
||||
if (target_x == m_x && target_y == m_y && target_w == m_w && target_h == m_h) return;
|
||||
|
||||
int move_step = (int)(delta*1000.0f);
|
||||
@ -573,6 +610,7 @@ public:
|
||||
/** Event callback */
|
||||
virtual GUIEngine::EventPropagation transmitEvent(Widget* w, const std::string& originator, const int m_playerID)
|
||||
{
|
||||
assert(m_magic_number == 0x33445566);
|
||||
if (m_ready) return EVENT_LET; // if it's declared ready, there is really nothing to process
|
||||
|
||||
//std::cout << "= kart selection :: transmitEvent " << originator << " =\n";
|
||||
@ -600,6 +638,7 @@ public:
|
||||
/** Sets the size of the widget as a whole, and placed children widgets inside itself */
|
||||
void setSize(const int x, const int y, const int w, const int h)
|
||||
{
|
||||
assert(m_magic_number == 0x33445566);
|
||||
m_x = x;
|
||||
m_y = y;
|
||||
m_w = w;
|
||||
@ -645,14 +684,19 @@ public:
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------------------
|
||||
|
||||
/** Sets which kart was selected for this player */
|
||||
void setKartInternalName(const std::string& whichKart)
|
||||
{
|
||||
assert(m_magic_number == 0x33445566);
|
||||
m_kartInternalName = whichKart;
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------------------
|
||||
|
||||
const std::string& getKartInternalName() const
|
||||
{
|
||||
assert(m_magic_number == 0x33445566);
|
||||
return m_kartInternalName;
|
||||
}
|
||||
};
|
||||
@ -970,10 +1014,10 @@ bool KartSelectionScreen::playerJoin(InputDevice* device, bool firstPlayer)
|
||||
PlayerKartWidget* newPlayerWidget = new PlayerKartWidget(this, aplayer, kartsArea, m_kart_widgets.size());
|
||||
|
||||
manualAddWidget(newPlayerWidget);
|
||||
newPlayerWidget->add();
|
||||
|
||||
m_kart_widgets.push_back(newPlayerWidget);
|
||||
|
||||
|
||||
newPlayerWidget->add();
|
||||
|
||||
// ---- Divide screen space among all karts
|
||||
const int amount = m_kart_widgets.size();
|
||||
Widget* fullarea = getWidget("playerskarts");
|
||||
@ -998,7 +1042,7 @@ bool KartSelectionScreen::playerJoin(InputDevice* device, bool firstPlayer)
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
// Returns true if event was handled succesfully
|
||||
|
||||
bool KartSelectionScreen::playerQuit(StateManager::ActivePlayer* player)
|
||||
{
|
||||
int playerID = -1;
|
||||
@ -1268,7 +1312,14 @@ void KartSelectionScreen::eventCallback(Widget* widget, const std::string& name,
|
||||
#endif
|
||||
|
||||
void KartSelectionScreen::allPlayersDone()
|
||||
{
|
||||
{
|
||||
// FIXME: debug, remove
|
||||
printf("all players done : %i players have joined the game\n", StateManager::get()->activePlayerCount());
|
||||
for (int p=0; p<StateManager::get()->activePlayerCount(); p++)
|
||||
{
|
||||
std::cout << " " << StateManager::get()->getActivePlayer(p)->getProfile()->getName() << std::endl;
|
||||
}
|
||||
|
||||
input_manager->setMasterPlayerOnly(true);
|
||||
|
||||
DynamicRibbonWidget* w = getWidget<DynamicRibbonWidget>("karts");
|
||||
|
@ -45,6 +45,8 @@ class KartSelectionScreen : public GUIEngine::Screen, public GUIEngine::ScreenSi
|
||||
ptr_vector<PlayerKartWidget, REF> m_kart_widgets;
|
||||
|
||||
friend class GUIEngine::ScreenSingleton<KartSelectionScreen>;
|
||||
friend class PlayerKartWidget;
|
||||
|
||||
KartSelectionScreen();
|
||||
|
||||
/** Stores whether any player confirmed their choice; then, some things are "frozen", for instance
|
||||
@ -81,7 +83,10 @@ public:
|
||||
/** \brief Called when a player hits 'fire'/'select' on his device to join the game */
|
||||
bool playerJoin(InputDevice* device, bool firstPlayer);
|
||||
|
||||
/** \brief Called when a player hits 'rescue'/'cancel' on his device to leave the game */
|
||||
/**
|
||||
* \brief Called when a player hits 'rescue'/'cancel' on his device to leave the game
|
||||
* \return true if event was handled succesfully
|
||||
*/
|
||||
bool playerQuit(StateManager::ActivePlayer* player);
|
||||
|
||||
/** \brief implement callback from parent class GUIEngine::Screen */
|
||||
|
@ -229,6 +229,10 @@ void StateManager::onStackEmptied()
|
||||
StateManager::ActivePlayer::ActivePlayer(PlayerProfile* player,
|
||||
InputDevice *device)
|
||||
{
|
||||
#ifdef DEBUG
|
||||
m_magic_number = 0xAC1EF1AE;
|
||||
#endif
|
||||
|
||||
m_player = player;
|
||||
m_device = NULL;
|
||||
m_kart = NULL;
|
||||
@ -239,12 +243,17 @@ StateManager::ActivePlayer::ActivePlayer(PlayerProfile* player,
|
||||
StateManager::ActivePlayer::~ActivePlayer()
|
||||
{
|
||||
setDevice(NULL);
|
||||
|
||||
#ifdef DEBUG
|
||||
m_magic_number = 0xDEADBEEF;
|
||||
#endif
|
||||
} // ~ActivePlayer
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
void StateManager::ActivePlayer::setPlayerProfile(PlayerProfile* player)
|
||||
{
|
||||
assert(m_magic_number == 0xAC1EF1AE);
|
||||
m_player = player;
|
||||
} // setPlayerProfile
|
||||
|
||||
@ -252,6 +261,8 @@ void StateManager::ActivePlayer::setPlayerProfile(PlayerProfile* player)
|
||||
|
||||
void StateManager::ActivePlayer::setDevice(InputDevice* device)
|
||||
{
|
||||
assert(m_magic_number == 0xAC1EF1AE);
|
||||
|
||||
// unset player from previous device he was assigned to, if any
|
||||
if (m_device != NULL) m_device->setPlayer(NULL);
|
||||
|
||||
|
@ -78,34 +78,45 @@ public:
|
||||
|
||||
ActivePlayer(PlayerProfile* player, InputDevice* device);
|
||||
|
||||
#ifdef DEBUG
|
||||
unsigned int m_magic_number;
|
||||
#endif
|
||||
|
||||
public:
|
||||
|
||||
~ActivePlayer();
|
||||
|
||||
/** \return the identity of this active player */
|
||||
PlayerProfile* getProfile() { return m_player; }
|
||||
#ifdef DEBUG
|
||||
bool ok()
|
||||
{
|
||||
return (m_magic_number == 0xAC1EF1AE);
|
||||
}
|
||||
#endif
|
||||
|
||||
/** \return the identity of this active player */
|
||||
const PlayerProfile* getConstProfile() const { return m_player; }
|
||||
PlayerProfile* getProfile() { assert(m_magic_number == 0xAC1EF1AE); return m_player; }
|
||||
|
||||
/** \return the identity of this active player */
|
||||
const PlayerProfile* getConstProfile() const { assert(m_magic_number == 0xAC1EF1AE); 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; }
|
||||
int getID() const { assert(m_magic_number == 0xAC1EF1AE); return m_id; }
|
||||
|
||||
/** \return Which input device this player is using, or NULL if none
|
||||
* is set yet */
|
||||
InputDevice* getDevice() const { return m_device; }
|
||||
InputDevice* getDevice() const { assert(m_magic_number == 0xAC1EF1AE); return m_device; }
|
||||
|
||||
void setDevice(InputDevice* device);
|
||||
|
||||
/** Sets the kart for this player. */
|
||||
void setKart(Kart *kart) { m_kart = kart; }
|
||||
void setKart(Kart *kart) { assert(m_magic_number == 0xAC1EF1AE); m_kart = kart; }
|
||||
|
||||
/** \return the kart of this player. Only valid while world exists. */
|
||||
Kart* getKart() { assert(m_kart != NULL); return m_kart; }
|
||||
Kart* getKart() { assert(m_magic_number == 0xAC1EF1AE); assert(m_kart != NULL); return m_kart; }
|
||||
};
|
||||
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user