2 * Copyright (C) 2008 Patrik Gornicz, Gornicz_P (at) hotmail (dot) com.
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 3 of the License, or
7 * (at your option) any later version.
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.
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
26 #include "entityCreator.h"
27 #include "effectManager.h"
29 #include "GameStates/GameState.h"
30 #include "GameStates/Running.h"
31 #include "GameStates/Paused.h"
32 #include "GameStates/CreatingPolygon.h"
35 /// ***** Private Variables *****
37 // The stack of active game states
38 static vector<GameState*> s_active_States;
40 // Pointers to each possible game state
41 // inserted and removed from the s_active_States
42 static vector<GameState*> s_possible_States;
44 // true if the top state requested itself to be poped
45 static bool s_bPopState;
46 // pointer to a state wishing to be added
47 static GameState* s_pPushState;
50 /// ***** Public Methods *****
57 // create starting entities
61 Running* pRunning = new Running();
62 s_possible_States.push_back(pRunning);
63 s_possible_States.push_back(new Paused());
64 s_possible_States.push_back(new CreatingPolygon());
66 s_active_States.push_back(pRunning);
68 DPF(0, "World Created");
76 for(unsigned int i=0; i < s_possible_States.size(); i++)
78 delete s_possible_States[i];
80 s_possible_States.clear();
81 s_active_States.clear();
84 void game::handleInput()
86 creator::handleInput();
88 int iLast = s_active_States.size() -1;
90 for(unsigned int i=0; i < s_possible_States.size(); i++)
92 GameState* pState = s_possible_States[i];
94 if(s_active_States[iLast] != pState && pState->pushMe())
96 s_pPushState = pState;
107 if(s_active_States[i]->popMe())
110 s_active_States[i]->handleInput(true);
113 s_active_States[i]->handleInput(false);
117 void game::update(float fTimeStep)
121 s_active_States.pop_back();
125 if(s_pPushState != NULL)
127 s_active_States.push_back(s_pPushState);
131 int iLast = s_active_States.size() -1;
137 s_active_States[i]->update(fTimeStep, true);
139 s_active_States[i]->update(fTimeStep, false);
145 int iLast = s_active_States.size() -1;
151 s_active_States[i]->draw(true);
153 s_active_States[i]->draw(false);