projects
/
physics.git
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (parent:
b6ef7e0
)
refactored game
author
Patrik Gornicz
<Gornicz.P@gmail.com>
Thu, 22 Jan 2009 01:27:30 +0000
(20:27 -0500)
committer
Patrik Gornicz
<Gornicz.P@gmail.com>
Thu, 22 Jan 2009 01:27:30 +0000
(20:27 -0500)
src/game.cpp
patch
|
blob
|
blame
|
history
diff --git
a/src/game.cpp
b/src/game.cpp
index
5098ed8
..
e8c37a2
100644
(file)
--- a/
src/game.cpp
+++ b/
src/game.cpp
@@
-33,37
+33,35
@@
using std::vector;
/// ***** Private Variables *****
// The stack of active game states
/// ***** Private Variables *****
// The stack of active game states
-
vector<GameState*>
active_States;
+
static vector<GameState*> s_
active_States;
// Pointers to each possible game state
// Pointers to each possible game state
-// inserted and removed from the active_States
-Running* running;
-Paused* paused;
-CreatingPolygon* creating_Polygon;
+// inserted and removed from the s_active_States
+static vector<GameState*> s_possible_States;
// true if the top state requested itself to be poped
// true if the top state requested itself to be poped
-
bool pop_
State;
+
static bool s_bPop
State;
// pointer to a state wishing to be added
// pointer to a state wishing to be added
-
GameState* push_
State;
+
static GameState* s_pPush
State;
/// ***** Public Methods *****
void game::init()
{
/// ***** Public Methods *****
void game::init()
{
- running = new Running();
- paused = new Paused();
- creating_Polygon = new CreatingPolygon();
-
- pop_State = false;
- push_State = NULL;
+ s_bPopState = false;
+ s_pPushState = NULL;
// create starting entities
creator::init();
// create starting entities
creator::init();
+ effect::init();
- active_States.push_back(running);
+ Running* pRunning = new Running();
+ s_possible_States.push_back(pRunning);
+ s_possible_States.push_back(new Paused());
+ s_possible_States.push_back(new CreatingPolygon());
-
effect::init(
);
+
s_active_States.push_back(pRunning
);
DPF(0, "World Created");
}
DPF(0, "World Created");
}
@@
-71,88
+69,85
@@
void game::init()
void game::clean()
{
effect::clean();
void game::clean()
{
effect::clean();
-
creator::clean();
creator::clean();
- delete creating_Polygon;
- delete paused;
- delete running;
+ for(unsigned int i=0; i < s_possible_States.size(); i++)
+ {
+ delete s_possible_States[i];
+ }
+ s_possible_States.clear();
+ s_active_States.clear();
}
void game::handleInput()
{
creator::handleInput();
}
void game::handleInput()
{
creator::handleInput();
- int
last =
active_States.size() -1;
+ int
iLast = s_
active_States.size() -1;
-
if(active_States[last] != running && running->pushMe()
)
+
for(unsigned int i=0; i < s_possible_States.size(); i++
)
{
{
- push_State = running;
- }
+ GameState* pState = s_possible_States[i];
- if(active_States[last] != paused && paused->pushMe())
- {
- push_State = paused;
- }
-
- if(active_States[last] != creating_Polygon && creating_Polygon->pushMe())
- {
- push_State = creating_Polygon;
+ if(s_active_States[iLast] != pState && pState->pushMe())
+ {
+ s_pPushState = pState;
+ }
}
for( int i = 0;
}
for( int i = 0;
- i <=
l
ast;
+ i <=
iL
ast;
i++ )
{
i++ )
{
- if( i ==
l
ast )
+ if( i ==
iL
ast )
{
{
- if(active_States[i]->popMe())
-
pop_
State = true;
+ if(
s_
active_States[i]->popMe())
+
s_bPop
State = true;
else
else
- active_States[i]->handleInput(true);
+
s_
active_States[i]->handleInput(true);
}
else
}
else
- active_States[i]->handleInput(false);
+
s_
active_States[i]->handleInput(false);
}
}
}
}
-void game::update(float
time_s
tep)
+void game::update(float
fTimeS
tep)
{
{
- if(
pop_
State)
+ if(
s_bPop
State)
{
{
- active_States.pop_back();
-
pop_
State = false;
+
s_
active_States.pop_back();
+
s_bPop
State = false;
}
}
- if(
push_
State != NULL)
+ if(
s_pPush
State != NULL)
{
{
-
active_States.push_back(push_
State);
-
push_
State = NULL;
+
s_active_States.push_back(s_pPush
State);
+
s_pPush
State = NULL;
}
}
- int
last =
active_States.size() -1;
+ int
iLast = s_
active_States.size() -1;
for( int i = 0;
for( int i = 0;
- i <=
l
ast;
+ i <=
iL
ast;
i++ )
{
i++ )
{
- if( i ==
l
ast )
-
active_States[i]->update(time_s
tep, true);
+ if( i ==
iL
ast )
+
s_active_States[i]->update(fTimeS
tep, true);
else
else
-
active_States[i]->update(time_s
tep, false);
+
s_active_States[i]->update(fTimeS
tep, false);
}
}
void game::draw()
{
}
}
void game::draw()
{
- int
last =
active_States.size() -1;
+ int
iLast = s_
active_States.size() -1;
for( int i = 0;
for( int i = 0;
- i <=
l
ast;
+ i <=
iL
ast;
i++ )
{
i++ )
{
- if( i ==
l
ast )
- active_States[i]->draw(true);
+ if( i ==
iL
ast )
+
s_
active_States[i]->draw(true);
else
else
- active_States[i]->draw(false);
+
s_
active_States[i]->draw(false);
}
}
}
}