Kaynağa Gözat

Merge pull request #425 from ablake/next

Adding simple menu to Racer, quick bug-fix.
Sean Paul Taylor 13 yıl önce
ebeveyn
işleme
7e7910cd6f
2 değiştirilmiş dosya ile 19 ekleme ve 11 silme
  1. 18 11
      gameplay/src/Game.cpp
  2. 1 0
      gameplay/src/Game.h

+ 18 - 11
gameplay/src/Game.cpp

@@ -19,7 +19,7 @@ double Game::_pausedTimeLast = 0.0;
 double Game::_pausedTimeTotal = 0.0;
 
 Game::Game() 
-    : _initialized(false), _state(UNINITIALIZED), 
+    : _initialized(false), _state(UNINITIALIZED), _pausedCount(0),
       _frameLastFPS(0), _frameCount(0), _frameRate(0), 
       _clearDepth(1.0f), _clearStencil(0), _properties(NULL),
       _animationController(NULL), _audioController(NULL), 
@@ -235,22 +235,29 @@ void Game::pause()
         _physicsController->pause();
         _aiController->pause();
     }
+
+    ++_pausedCount;
 }
 
 void Game::resume()
 {
     if (_state == PAUSED)
     {
-        GP_ASSERT(_animationController);
-        GP_ASSERT(_audioController);
-        GP_ASSERT(_physicsController);
-        GP_ASSERT(_aiController);
-        _state = RUNNING;
-        _pausedTimeTotal += Platform::getAbsoluteTime() - _pausedTimeLast;
-        _animationController->resume();
-        _audioController->resume();
-        _physicsController->resume();
-        _aiController->resume();
+        --_pausedCount;
+
+        if (_pausedCount == 0)
+		{
+			GP_ASSERT(_animationController);
+			GP_ASSERT(_audioController);
+			GP_ASSERT(_physicsController);
+			GP_ASSERT(_aiController);
+			_state = RUNNING;
+			_pausedTimeTotal += Platform::getAbsoluteTime() - _pausedTimeLast;
+			_animationController->resume();
+			_audioController->resume();
+			_physicsController->resume();
+			_aiController->resume();
+		}
     }
 }
 

+ 1 - 0
gameplay/src/Game.h

@@ -661,6 +661,7 @@ private:
 
     bool _initialized;                          // If game has initialized yet.
     State _state;                               // The game state.
+    unsigned int _pausedCount;                  // Number of times pause() has been called.
     static double _pausedTimeLast;              // The last time paused.
     static double _pausedTimeTotal;             // The total time paused.
     double _frameLastFPS;                       // The last time the frame count was updated.