فهرست منبع

#424 -- Added _pausedCount to Game. The game won't resume until Game::resume() has been called as many times as Game::pause() was called. This lets us continue to
automatically pause the game when minimized without resuming games that were paused by the user.

Adam Blake 13 سال پیش
والد
کامیت
2bfcd54eb6
2فایلهای تغییر یافته به همراه19 افزوده شده و 11 حذف شده
  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.