SuperTuxKart
state_manager.hpp
1 // SuperTuxKart - a fun racing game with go-kart
2 // Copyright (C) 2009-2015 Marianne Gagnon
3 //
4 // This program is free software; you can redistribute it and/or
5 // modify it under the terms of the GNU General Public License
6 // as published by the Free Software Foundation; either version 3
7 // of the License, or (at your option) any later version.
8 //
9 // This program is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
13 //
14 // You should have received a copy of the GNU General Public License
15 // along with this program; if not, write to the Free Software
16 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
17 
18 
19 #ifndef STATE_MANAGER_HPP
20 #define STATE_MANAGER_HPP
21 
28 #include <string>
29 
30 #include "config/player_profile.hpp"
31 #include "guiengine/abstract_state_manager.hpp"
32 #include "utils/ptr_vector.hpp"
33 
34 class AbstractKart;
35 class InputDevice;
36 struct Input;
37 namespace Online
38 {
39  class OnlineProfile;
40 }
41 
42 namespace GUIEngine
43 {
44  class Widget;
45 }
46 
52 const static int PLAYER_ID_GAME_MASTER = 0;
53 
60 {
61 
62  void updateActivePlayerIDs();
63 
64 
65 public:
66 
76  {
77  friend class StateManager;
78 
79  PlayerProfile *m_player;
80  InputDevice *m_device;
81 
84 
86  int m_id;
87 
88  ActivePlayer(PlayerProfile* player, InputDevice* device);
89 
90 #ifdef DEBUG
91  unsigned int m_magic_number;
92 #endif
93 
94  public:
95 
96  ~ActivePlayer();
97 
98 #ifdef DEBUG
99  bool ok()
100  {
101  return (m_magic_number == 0xAC1EF1AE);
102  } // ok
103 #endif
104  // --------------------------------------------------------------------
107  {
108 #ifdef DEBUG
109  assert(m_magic_number == 0xAC1EF1AE);
110 #endif
111  return m_player;
112  } // getProfile
113 
114  // --------------------------------------------------------------------
117  {
118 #ifdef DEBUG
119  assert(m_magic_number == 0xAC1EF1AE);
120 #endif
121  return m_player;
122  } // getConstProfile
123 
124  // --------------------------------------------------------------------
127  void setPlayerProfile(PlayerProfile* player);
128 
129  // --------------------------------------------------------------------
131  int getID() const
132  {
133 #ifdef DEBUG
134  assert(m_magic_number == 0xAC1EF1AE);
135 #endif
136  return m_id;
137  } // getID
138  // --------------------------------------------------------------------
139 
143  {
144 #ifdef DEBUG
145  assert(m_magic_number == 0xAC1EF1AE);
146 #endif
147  return m_device;
148  } // getDevice
149 
150  // --------------------------------------------------------------------
151  void setDevice(InputDevice* device);
152 
153  // --------------------------------------------------------------------
155  void setKart(AbstractKart *kart)
156  {
157 #ifdef DEBUG
158  assert(m_magic_number == 0xAC1EF1AE);
159 #endif
160  m_kart = kart;
161  } // setKart
162 
163  // --------------------------------------------------------------------
166  {
167 #ifdef DEBUG
168  assert(m_magic_number == 0xAC1EF1AE);
169 #endif
170  return m_kart;
171  } // getKart
172 
173  }; // ActivePlayer
174 
175  // ========================================================================
176  const PtrVector<ActivePlayer, HOLD>& getActivePlayers()
177  { return m_active_players; }
178  ActivePlayer* getActivePlayer(const int id);
179 
183  const PlayerProfile* getActivePlayerProfile(const int id);
184 
185  int createActivePlayer(PlayerProfile *profile, InputDevice *device);
186  void removeActivePlayer(int id);
187 
188  unsigned int activePlayerCount();
189  void resetActivePlayers();
190 
196  bool throttleFPS();
197 
199  void escapePressed();
200 
202  virtual void onGameStateChange(GUIEngine::GameState new_state);
203 
205  virtual void onStackEmptied();
206 
208  virtual void onTopMostScreenChanged();
209 
210  // singleton
211  static StateManager* get();
212  static void deallocate();
213  void clearMenuStack() { m_menu_stack.clear(); }
214 private:
219 };
220 
221 #endif
AbstractKart * getKart()
Definition: state_manager.hpp:165
Represents a player that is currently playing.
Definition: state_manager.hpp:75
virtual void onGameStateChange(GUIEngine::GameState new_state)
implementing callback from base class AbstractStateManager
Definition: state_manager.cpp:204
Contains all GUI engine related classes and functions.
Definition: abstract_state_manager.hpp:31
void escapePressed()
implementing callback from base class AbstractStateManager
Definition: state_manager.cpp:165
void setKart(AbstractKart *kart)
Sets the kart for this player.
Definition: state_manager.hpp:155
A concrete scene manager, derived from GUIEngine's AbastractSceneManager.
Definition: state_manager.hpp:59
static const int PLAYER_ID_GAME_MASTER
the player ID of the "game master" player the game master is the player that can perform the game set...
Definition: state_manager.hpp:52
Definition: input.hpp:34
PtrVector< ActivePlayer, HOLD > m_active_players
A list of all currently playing players.
Definition: state_manager.hpp:218
base class for input devices
Definition: input_device.hpp:47
GameState
Definition: abstract_state_manager.hpp:39
bool throttleFPS()
Definition: state_manager.cpp:153
void setPlayerProfile(PlayerProfile *player)
Call to change the identity of this player (useful when player is selecting his identity)
Definition: state_manager.cpp:292
Class for managing player profiles (name, usage frequency, etc.).
Definition: player_profile.hpp:53
virtual void onTopMostScreenChanged()
implementing callback from base class AbstractStateManager
Definition: state_manager.cpp:232
PlayerProfile * getProfile()
Definition: state_manager.hpp:106
Definition: ptr_vector.hpp:43
InputDevice * getDevice() const
Definition: state_manager.hpp:142
virtual void onStackEmptied()
implementing callback from base class AbstractStateManager
Definition: state_manager.cpp:253
std::vector< std::pair< std::string, Screen * > > m_menu_stack
This stack will contain menu names (e.g.
Definition: abstract_state_manager.hpp:64
const PlayerProfile * getConstProfile() const
Definition: state_manager.hpp:116
AbstractKart * m_kart
Pointer to the kart of this player, only valid during the game.
Definition: state_manager.hpp:83
int m_id
ID of this player within the list of active players.
Definition: state_manager.hpp:86
An abstract interface for the actual karts.
Definition: abstract_kart.hpp:61
Abstract base class you must override from to use the GUI engine.
Definition: abstract_state_manager.hpp:52
int getID() const
ID of this player within the list of active players.
Definition: state_manager.hpp:131
const PlayerProfile * getActivePlayerProfile(const int id)
Definition: state_manager.cpp:85