reworked ups/fps/paused logic
[physics.git] / src / game.cpp
index 95cd04d..5098ed8 100644 (file)
@@ -41,6 +41,11 @@ Running* running;
 Paused* paused;
 CreatingPolygon* creating_Polygon;
 
+// true if the top state requested itself to be poped
+bool pop_State;
+// pointer to a state wishing to be added
+GameState* push_State;
+
 
 /// ***** Public Methods *****
 
@@ -50,6 +55,9 @@ void game::init()
     paused = new Paused();
     creating_Polygon = new CreatingPolygon();
 
+    pop_State = false;
+    push_State = NULL;
+
     // create starting entities
     creator::init();
 
@@ -57,9 +65,7 @@ void game::init()
 
     effect::init();
 
-#ifdef DEBUGGING
-    cout << "World Created" << endl;
-#endif
+    DPF(0, "World Created");
 }
 
 void game::clean()
@@ -73,15 +79,39 @@ void game::clean()
     delete running;
 }
 
-void game::input()
+void game::handleInput()
 {
+    creator::handleInput();
+
     int last = active_States.size() -1;
+
+    if(active_States[last] != running && running->pushMe())
+    {
+        push_State = running;
+    }
+
+    if(active_States[last] != paused && paused->pushMe())
+    {
+        push_State = paused;
+    }
+
+    if(active_States[last] != creating_Polygon && creating_Polygon->pushMe())
+    {
+        push_State = creating_Polygon;
+    }
+
+
     for( int i = 0;
          i <= last;
          i++ )
     {
         if( i == last )
-            active_States[i]->handleInput(true);
+        {
+            if(active_States[i]->popMe())
+                pop_State = true;
+            else
+                active_States[i]->handleInput(true);
+        }
         else
             active_States[i]->handleInput(false);
     }
@@ -89,6 +119,18 @@ void game::input()
 
 void game::update(float time_step)
 {
+    if(pop_State)
+    {
+        active_States.pop_back();
+        pop_State = false;
+    }
+
+    if(push_State != NULL)
+    {
+        active_States.push_back(push_State);
+        push_State = NULL;
+    }
+
     int last = active_States.size() -1;
     for( int i = 0;
          i <= last;