reworked ups/fps/paused logic
authorPatrik Gornicz <Gornicz.P@gmail.com>
Sun, 7 Dec 2008 19:57:11 +0000 (14:57 -0500)
committerPatrik Gornicz <Gornicz.P@gmail.com>
Sun, 7 Dec 2008 19:57:11 +0000 (14:57 -0500)
src/GameStates/Paused.cpp
src/config/config.cpp
src/config/config.h
src/debug.h
src/game.cpp
src/main.cpp

index 20ef061..fea6de4 100644 (file)
@@ -46,9 +46,9 @@ void Paused::draw(bool on_top) const
 
 bool Paused::pushMe() const
 {
-    return cfg::pause();
+    return cfg::paused();
 }
 bool Paused::popMe() const
 {
-    return cfg::unPause();
+    return !cfg::paused();
 }
index 3b694ba..69406bc 100644 (file)
@@ -27,6 +27,8 @@
 /// ***** Private Method Headers *****
 /// ***** Private Variables *****
 
+bool fPaused = false;
+
 /// ***** Initializers/Cleaners *****
 
 void cfg::init()
@@ -43,13 +45,10 @@ void cfg::clean()
 
 /// ***** Public Methods *****
 
-bool cfg::pause()
-{
-    return input::wasPressed(key::pause);
-}
-bool cfg::unPause()
+bool cfg::paused()
 {
-    return input::wasPressed(key::pause);
+    fPaused = input::wasPressed(key::pause) ? !fPaused : fPaused;
+    return fPaused;
 }
 
 bool cfg::endGame()
@@ -70,4 +69,13 @@ bool cfg::mouseWellOff()
     return input::wasReleased(key::well);
 }
 
+bool cfg::showFPS()
+{
+    return true;
+}
+bool cfg::showUPS()
+{
+    return true;
+}
+
 /// ***** Private Methods *****
index c794f65..8c7143f 100644 (file)
@@ -28,12 +28,14 @@ namespace cfg
 
     bool endGame();
 
-    bool pause();
-    bool unPause();
+    bool paused();
 
     bool mouseWellFollow();
     bool mouseWellOn();
     bool mouseWellOff();
+
+    bool showFPS();
+    bool showUPS();
 }
 
 #endif // CONFIG_H
index 2862cc2..6085003 100644 (file)
@@ -36,11 +36,5 @@ void DASSERT(bool fBreak);
 // comment out when not debugging
 #define DEBUGGING
 
-// comment out to suppress warnings
-#define WARNINGS
-
-// comment out to prevent FPS and UPS printing
-#define FPSUPS
-
 
 #endif // DEBUG_H
index 08f9530..5098ed8 100644 (file)
@@ -83,18 +83,24 @@ void game::handleInput()
 {
     creator::handleInput();
 
+    int last = active_States.size() -1;
 
-    if(running->pushMe())
+    if(active_States[last] != running && running->pushMe())
+    {
         push_State = running;
+    }
 
-    if(paused->pushMe())
+    if(active_States[last] != paused && paused->pushMe())
+    {
         push_State = paused;
+    }
 
-    if(creating_Polygon->pushMe())
+    if(active_States[last] != creating_Polygon && creating_Polygon->pushMe())
+    {
         push_State = creating_Polygon;
+    }
 
 
-    int last = active_States.size() -1;
     for( int i = 0;
          i <= last;
          i++ )
@@ -113,21 +119,18 @@ void game::handleInput()
 
 void game::update(float time_step)
 {
-    if(push_State != NULL)
-    {
-        // don't want to pop and push same state, pop wins arbitrary
-        if(!pop_State)
-            active_States.push_back(push_State);
-
-        push_State = NULL;
-    }
-
     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;
index e932742..0efd748 100644 (file)
@@ -182,10 +182,14 @@ void updateFPSCounters()
 
         last_Second = tickCountMicro();
 
-#ifdef FPSUPS
-        cout << "ups:\t" << ups << endl;
-        cout << "fps:\t" << fps << endl;
-#endif
+        if(cfg::showFPS())
+        {
+            cout << "fps:\t" << fps << endl;
+        }
+        if(cfg::showUPS())
+        {
+            cout << "ups:\t" << ups << endl;
+        }
     }
 }