2009-06-19 20:28:25 -04:00
|
|
|
// SuperTuxKart - a fun racing game with go-kart
|
2015-03-29 20:31:42 -04:00
|
|
|
// Copyright (C) 2009-2015 Marianne Gagnon
|
2009-06-19 20:28:25 -04:00
|
|
|
//
|
|
|
|
// This program is free software; you can redistribute it and/or
|
|
|
|
// modify it under the terms of the GNU General Public License
|
|
|
|
// as published by the Free Software Foundation; either version 3
|
|
|
|
// of the License, or (at your option) any later version.
|
|
|
|
//
|
|
|
|
// This program is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
// GNU General Public License for more details.
|
|
|
|
//
|
|
|
|
// You should have received a copy of the GNU General Public License
|
|
|
|
// along with this program; if not, write to the Free Software
|
|
|
|
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|
|
|
|
|
|
|
|
2009-03-14 21:34:21 -04:00
|
|
|
#ifndef STATE_MANAGER_HPP
|
|
|
|
#define STATE_MANAGER_HPP
|
|
|
|
|
2011-10-25 13:46:14 -04:00
|
|
|
/**
|
|
|
|
* \defgroup states_screens
|
|
|
|
* Contains the various screens and dialogs of the STK user interface,
|
|
|
|
* using the facilities of the guiengine module.
|
|
|
|
*/
|
2010-04-23 16:48:56 -04:00
|
|
|
|
2009-03-14 21:34:21 -04:00
|
|
|
#include <string>
|
2011-08-16 19:45:46 -04:00
|
|
|
|
2014-02-17 04:10:29 -05:00
|
|
|
#include "config/player_profile.hpp"
|
2009-07-18 13:48:36 -04:00
|
|
|
#include "guiengine/abstract_state_manager.hpp"
|
2009-07-04 16:00:18 -04:00
|
|
|
#include "utils/ptr_vector.hpp"
|
2009-03-14 21:34:21 -04:00
|
|
|
|
2012-03-19 16:21:11 -04:00
|
|
|
class AbstractKart;
|
2010-02-18 16:28:32 -05:00
|
|
|
class InputDevice;
|
2012-03-19 16:21:11 -04:00
|
|
|
struct Input;
|
2013-07-31 14:03:11 -04:00
|
|
|
namespace Online
|
|
|
|
{
|
2014-03-06 19:02:07 -05:00
|
|
|
class OnlineProfile;
|
2013-07-31 14:03:11 -04:00
|
|
|
}
|
2009-05-29 21:41:09 -04:00
|
|
|
|
2009-07-18 13:48:36 -04:00
|
|
|
namespace GUIEngine
|
2009-03-14 21:34:21 -04:00
|
|
|
{
|
2009-07-18 13:48:36 -04:00
|
|
|
class Widget;
|
|
|
|
}
|
|
|
|
|
2010-04-23 16:48:56 -04:00
|
|
|
/**
|
|
|
|
* \brief the player ID of the "game master" player
|
|
|
|
* the game master is the player that can perform the game setup
|
|
|
|
* \ingroup states_screens
|
|
|
|
*/
|
2010-04-08 17:02:40 -04:00
|
|
|
const static int PLAYER_ID_GAME_MASTER = 0;
|
2009-08-27 14:50:56 -04:00
|
|
|
|
2010-04-23 16:48:56 -04:00
|
|
|
/**
|
2013-05-30 15:47:39 -04:00
|
|
|
* \brief A concrete scene manager, derived from GUIEngine's
|
2010-08-14 21:15:19 -04:00
|
|
|
* AbastractSceneManager
|
2010-04-23 16:48:56 -04:00
|
|
|
* \ingroup states_screens
|
|
|
|
*/
|
2009-07-18 13:48:36 -04:00
|
|
|
class StateManager : public GUIEngine::AbstractStateManager
|
|
|
|
{
|
2013-05-30 15:47:39 -04:00
|
|
|
|
2009-08-27 14:41:20 -04:00
|
|
|
void updateActivePlayerIDs();
|
2009-07-18 13:48:36 -04:00
|
|
|
|
2013-05-30 15:47:39 -04:00
|
|
|
|
2009-07-18 13:48:36 -04:00
|
|
|
public:
|
2010-02-18 16:28:32 -05:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Represents a player that is currently playing.
|
2013-04-18 18:44:18 -04:00
|
|
|
* Ties together :
|
2010-02-18 16:28:32 -05:00
|
|
|
* - 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;
|
2013-05-30 15:47:39 -04:00
|
|
|
|
2010-02-18 16:28:32 -05:00
|
|
|
PlayerProfile *m_player;
|
|
|
|
InputDevice *m_device;
|
2013-05-30 15:47:39 -04:00
|
|
|
|
2010-02-18 16:28:32 -05:00
|
|
|
/** Pointer to the kart of this player, only valid during the game. */
|
2012-03-19 16:21:11 -04:00
|
|
|
AbstractKart *m_kart;
|
2013-05-30 15:47:39 -04:00
|
|
|
|
2010-02-18 16:28:32 -05:00
|
|
|
/** ID of this player within the list of active players */
|
|
|
|
int m_id;
|
2013-05-30 15:47:39 -04:00
|
|
|
|
2014-05-30 20:26:02 -04:00
|
|
|
ActivePlayer(PlayerProfile* player, InputDevice* device);
|
2013-05-30 15:47:39 -04:00
|
|
|
|
2010-09-25 14:34:04 -04:00
|
|
|
#ifdef DEBUG
|
|
|
|
unsigned int m_magic_number;
|
|
|
|
#endif
|
2013-05-30 15:47:39 -04:00
|
|
|
|
2010-02-18 16:28:32 -05:00
|
|
|
public:
|
2013-05-30 15:47:39 -04:00
|
|
|
|
2010-02-18 16:28:32 -05:00
|
|
|
~ActivePlayer();
|
2013-05-30 15:47:39 -04:00
|
|
|
|
2010-09-25 14:34:04 -04:00
|
|
|
#ifdef DEBUG
|
|
|
|
bool ok()
|
|
|
|
{
|
|
|
|
return (m_magic_number == 0xAC1EF1AE);
|
2012-03-19 16:21:11 -04:00
|
|
|
} // ok
|
2010-09-25 14:34:04 -04:00
|
|
|
#endif
|
2013-05-30 15:47:39 -04:00
|
|
|
// --------------------------------------------------------------------
|
2010-02-18 16:28:32 -05:00
|
|
|
/** \return the identity of this active player */
|
2013-05-30 15:47:39 -04:00
|
|
|
PlayerProfile* getProfile()
|
|
|
|
{
|
2010-11-29 05:02:47 -05:00
|
|
|
#ifdef DEBUG
|
2013-12-01 23:27:55 -05:00
|
|
|
assert(m_magic_number == 0xAC1EF1AE);
|
2010-11-29 05:02:47 -05:00
|
|
|
#endif
|
2013-12-01 23:27:55 -05:00
|
|
|
return m_player;
|
2012-03-19 16:21:11 -04:00
|
|
|
} // getProfile
|
2013-05-30 15:47:39 -04:00
|
|
|
|
|
|
|
// --------------------------------------------------------------------
|
2010-02-18 16:28:32 -05:00
|
|
|
/** \return the identity of this active player */
|
2013-05-30 15:47:39 -04:00
|
|
|
const PlayerProfile* getConstProfile() const
|
2012-03-19 16:21:11 -04:00
|
|
|
{
|
2010-11-29 05:02:47 -05:00
|
|
|
#ifdef DEBUG
|
2013-12-01 23:27:55 -05:00
|
|
|
assert(m_magic_number == 0xAC1EF1AE);
|
2010-11-29 05:02:47 -05:00
|
|
|
#endif
|
2013-12-01 23:27:55 -05:00
|
|
|
return m_player;
|
2012-03-19 16:21:11 -04:00
|
|
|
} // getConstProfile
|
2010-02-18 16:28:32 -05:00
|
|
|
|
2013-05-30 15:47:39 -04:00
|
|
|
// --------------------------------------------------------------------
|
2010-08-14 21:15:19 -04:00
|
|
|
/** Call to change the identity of this player (useful when player is
|
|
|
|
* selecting his identity) */
|
2010-02-18 16:28:32 -05:00
|
|
|
void setPlayerProfile(PlayerProfile* player);
|
2013-05-30 15:47:39 -04:00
|
|
|
|
|
|
|
// --------------------------------------------------------------------
|
2010-02-18 16:28:32 -05:00
|
|
|
/** ID of this player within the list of active players */
|
2013-05-30 15:47:39 -04:00
|
|
|
int getID() const
|
2012-03-19 16:21:11 -04:00
|
|
|
{
|
2010-11-29 05:02:47 -05:00
|
|
|
#ifdef DEBUG
|
2013-12-01 23:27:55 -05:00
|
|
|
assert(m_magic_number == 0xAC1EF1AE);
|
2010-11-29 05:02:47 -05:00
|
|
|
#endif
|
2013-12-01 23:27:55 -05:00
|
|
|
return m_id;
|
2012-03-19 16:21:11 -04:00
|
|
|
} // getID
|
2013-05-30 15:47:39 -04:00
|
|
|
// --------------------------------------------------------------------
|
|
|
|
|
|
|
|
/** \return Which input device this player is using, or NULL if none
|
2010-08-14 21:15:19 -04:00
|
|
|
* is set yet */
|
2013-05-30 15:47:39 -04:00
|
|
|
InputDevice* getDevice() const
|
|
|
|
{
|
2010-11-29 05:02:47 -05:00
|
|
|
#ifdef DEBUG
|
2013-12-01 23:27:55 -05:00
|
|
|
assert(m_magic_number == 0xAC1EF1AE);
|
2010-11-29 05:02:47 -05:00
|
|
|
#endif
|
2013-12-01 23:27:55 -05:00
|
|
|
return m_device;
|
2012-03-19 16:21:11 -04:00
|
|
|
} // getDevice
|
2013-05-30 15:47:39 -04:00
|
|
|
|
|
|
|
// --------------------------------------------------------------------
|
2010-02-18 16:28:32 -05:00
|
|
|
void setDevice(InputDevice* device);
|
2013-05-30 15:47:39 -04:00
|
|
|
|
|
|
|
// --------------------------------------------------------------------
|
2010-02-18 16:28:32 -05:00
|
|
|
/** Sets the kart for this player. */
|
2013-05-30 15:47:39 -04:00
|
|
|
void setKart(AbstractKart *kart)
|
2012-03-19 16:21:11 -04:00
|
|
|
{
|
2010-11-29 05:02:47 -05:00
|
|
|
#ifdef DEBUG
|
2013-12-01 23:27:55 -05:00
|
|
|
assert(m_magic_number == 0xAC1EF1AE);
|
2010-11-29 05:02:47 -05:00
|
|
|
#endif
|
2013-12-01 23:27:55 -05:00
|
|
|
m_kart = kart;
|
2012-03-19 16:21:11 -04:00
|
|
|
} // setKart
|
2013-05-30 15:47:39 -04:00
|
|
|
|
|
|
|
// --------------------------------------------------------------------
|
2010-02-18 16:28:32 -05:00
|
|
|
/** \return the kart of this player. Only valid while world exists. */
|
2012-03-19 16:21:11 -04:00
|
|
|
AbstractKart* getKart()
|
2013-05-30 15:47:39 -04:00
|
|
|
{
|
2010-11-29 05:02:47 -05:00
|
|
|
#ifdef DEBUG
|
2013-12-01 23:27:55 -05:00
|
|
|
assert(m_magic_number == 0xAC1EF1AE);
|
2010-11-29 05:02:47 -05:00
|
|
|
#endif
|
2013-05-30 15:47:39 -04:00
|
|
|
return m_kart;
|
2012-03-19 16:21:11 -04:00
|
|
|
} // getKart
|
2010-02-18 16:28:32 -05:00
|
|
|
|
2012-03-19 16:21:11 -04:00
|
|
|
}; // ActivePlayer
|
2010-02-18 16:28:32 -05:00
|
|
|
|
2012-03-19 16:21:11 -04:00
|
|
|
// ========================================================================
|
2013-05-30 15:47:39 -04:00
|
|
|
const PtrVector<ActivePlayer, HOLD>& getActivePlayers()
|
2010-08-14 21:15:19 -04:00
|
|
|
{ return m_active_players; }
|
2009-07-18 11:21:16 -04:00
|
|
|
ActivePlayer* getActivePlayer(const int id);
|
2013-05-30 15:47:39 -04:00
|
|
|
|
2010-02-18 16:28:32 -05:00
|
|
|
/** \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);
|
2013-05-30 15:47:39 -04:00
|
|
|
|
2014-05-30 20:26:02 -04:00
|
|
|
int createActivePlayer(PlayerProfile *profile, InputDevice *device);
|
2009-07-11 15:24:42 -04:00
|
|
|
void removeActivePlayer(int id);
|
|
|
|
|
2014-01-06 19:09:19 -05:00
|
|
|
unsigned int activePlayerCount();
|
2009-07-04 16:09:49 -04:00
|
|
|
void resetActivePlayers();
|
2013-05-30 15:47:39 -04:00
|
|
|
|
2010-04-24 16:08:13 -04:00
|
|
|
/** \return whether to reduce FPS at the moment
|
2013-05-30 15:47:39 -04:00
|
|
|
* \note this can be useful to avoid being too CPU/GPU intensive in
|
|
|
|
* parts of the game that don't require high framerates, like
|
2010-08-14 21:15:19 -04:00
|
|
|
* menus
|
2010-04-24 16:08:13 -04:00
|
|
|
*/
|
2009-12-05 21:19:37 -05:00
|
|
|
bool throttleFPS();
|
2013-05-30 15:47:39 -04:00
|
|
|
|
2010-04-24 16:08:13 -04:00
|
|
|
/** \brief implementing callback from base class AbstractStateManager */
|
2009-03-16 20:19:52 -04:00
|
|
|
void escapePressed();
|
2010-04-24 16:08:13 -04:00
|
|
|
|
|
|
|
/** \brief implementing callback from base class AbstractStateManager */
|
2010-08-14 21:15:19 -04:00
|
|
|
virtual void onGameStateChange(GUIEngine::GameState new_state);
|
2010-04-24 16:08:13 -04:00
|
|
|
|
2010-04-24 16:21:04 -04:00
|
|
|
/** \brief implementing callback from base class AbstractStateManager */
|
|
|
|
virtual void onStackEmptied();
|
2013-05-30 15:47:39 -04:00
|
|
|
|
2010-06-13 14:25:49 -04:00
|
|
|
/** \brief implementing callback from base class AbstractStateManager */
|
|
|
|
virtual void onTopMostScreenChanged();
|
2013-05-30 15:47:39 -04:00
|
|
|
|
2009-07-18 13:48:36 -04:00
|
|
|
// singleton
|
|
|
|
static StateManager* get();
|
2011-09-22 20:07:24 -04:00
|
|
|
static void deallocate();
|
2013-05-30 15:47:39 -04:00
|
|
|
|
2010-02-18 16:28:32 -05:00
|
|
|
private:
|
|
|
|
/**
|
|
|
|
* A list of all currently playing players.
|
|
|
|
*/
|
2011-02-03 17:20:53 -05:00
|
|
|
PtrVector<ActivePlayer, HOLD> m_active_players;
|
2009-07-18 13:48:36 -04:00
|
|
|
};
|
2009-03-14 21:34:21 -04:00
|
|
|
|
2009-03-30 23:15:41 -04:00
|
|
|
#endif
|