SuperTuxKart
Loading...
Searching...
No Matches
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
34class AbstractKart;
35class InputDevice;
36struct Input;
37namespace Online
38{
39 class OnlineProfile;
40}
41
42namespace GUIEngine
43{
44 class Widget;
45}
46
52const static int PLAYER_ID_GAME_MASTER = 0;
53
60{
61
62 void updateActivePlayerIDs();
63
64
65public:
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
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 // --------------------------------------------------------------------
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
192 void escapePressed();
193
195 virtual void onGameStateChange(GUIEngine::GameState new_state);
196
198 virtual void onStackEmptied();
199
201 virtual void onTopMostScreenChanged();
202
203 // singleton
204 static StateManager* get();
205 static void deallocate();
206 static void clear();
207 void clearMenuStack() { m_menu_stack.clear(); }
208private:
213};
214
215#endif
An abstract interface for the actual karts.
Definition: abstract_kart.hpp:62
Abstract base class you must override from to use the GUI engine.
Definition: abstract_state_manager.hpp:54
std::vector< std::pair< std::string, Screen * > > m_menu_stack
This stack will contain menu names (e.g.
Definition: abstract_state_manager.hpp:65
base class for input devices
Definition: input_device.hpp:48
Class for managing player profiles (name, usage frequency, etc.).
Definition: player_profile.hpp:54
Definition: ptr_vector.hpp:44
Represents a player that is currently playing.
Definition: state_manager.hpp:76
int getID() const
ID of this player within the list of active players.
Definition: state_manager.hpp:131
void setKart(AbstractKart *kart)
Sets the kart for this player.
Definition: state_manager.hpp:155
AbstractKart * getKart()
Definition: state_manager.hpp:165
void setPlayerProfile(PlayerProfile *player)
Call to change the identity of this player (useful when player is selecting his identity)
Definition: state_manager.cpp:289
PlayerProfile * getProfile()
Definition: state_manager.hpp:106
InputDevice * getDevice() const
Definition: state_manager.hpp:142
int m_id
ID of this player within the list of active players.
Definition: state_manager.hpp:86
AbstractKart * m_kart
Pointer to the kart of this player, only valid during the game.
Definition: state_manager.hpp:83
const PlayerProfile * getConstProfile() const
Definition: state_manager.hpp:116
A concrete scene manager, derived from GUIEngine's AbastractSceneManager.
Definition: state_manager.hpp:60
void escapePressed()
implementing callback from base class AbstractStateManager
Definition: state_manager.cpp:156
virtual void onGameStateChange(GUIEngine::GameState new_state)
implementing callback from base class AbstractStateManager
Definition: state_manager.cpp:195
virtual void onTopMostScreenChanged()
implementing callback from base class AbstractStateManager
Definition: state_manager.cpp:226
PtrVector< ActivePlayer, HOLD > m_active_players
A list of all currently playing players.
Definition: state_manager.hpp:212
virtual void onStackEmptied()
implementing callback from base class AbstractStateManager
Definition: state_manager.cpp:250
const PlayerProfile * getActivePlayerProfile(const int id)
Definition: state_manager.cpp:93
GameState
Definition: abstract_state_manager.hpp:41
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
Contains all GUI engine related classes and functions.
Definition: abstract_state_manager.hpp:33
Definition: input.hpp:35