Просмотр исходного кода

Merge pull request #76 from blackberry-gaming/next-setaylor

Next setaylor
Sean Paul Taylor 14 лет назад
Родитель
Сommit
198ffac370
2 измененных файлов с 15 добавлено и 7 удалено
  1. 9 4
      gameplay/src/Game.cpp
  2. 6 3
      gameplay/src/Game.h

+ 9 - 4
gameplay/src/Game.cpp

@@ -14,7 +14,7 @@ long Game::_pausedTimeLast = 0L;
 long Game::_pausedTimeTotal = 0L;
 
 Game::Game() 
-    : _state(UNINITIALIZED), 
+    : _initialized(false), _state(UNINITIALIZED), 
       _frameLastFPS(0), _frameCount(0), _frameRate(0), 
       _clearDepth(1.0f), _clearStencil(0),
       _animationController(NULL), _audioController(NULL)
@@ -63,7 +63,6 @@ bool Game::isVsync()
     return Platform::isVsync();
 }
 
-
 int Game::run(int width, int height)
 {
     if (_state != UNINITIALIZED)
@@ -97,8 +96,6 @@ bool Game::startup()
     _physicsController = new PhysicsController();
     _physicsController->initialize();
 
-    // Call user initialization.
-    initialize();
     _state = RUNNING;
 
     return true;
@@ -158,7 +155,15 @@ void Game::exit()
 void Game::frame()
 {
     if (_state != RUNNING)
+    {
         return;
+    }
+    else
+    {
+        if (!_initialized)
+            initialize();
+        _initialized = true;
+    }
 
     // Update Time.
     static long lastFrameTime = Game::getGameTime();

+ 6 - 3
gameplay/src/Game.h

@@ -221,12 +221,12 @@ protected:
     Game();
 
     /**
-     * Initializes the game on startup.
+     * Initialize callback that is called just before the first frame when the game starts.
      */
     virtual void initialize() = 0;
 
     /**
-     * Finalizes the game on exit.
+     * Finalize callback that is called when the game on exits.
      */
     virtual void finalize() = 0;
 
@@ -252,6 +252,8 @@ protected:
 
     /**
      * Renders a single frame once and then swaps it to the display.
+     *
+     * This is useful for rendering splash screens.
      */
     template <class T>
     void renderOnce(T* instance, void (T::*method)(long), long cookie);
@@ -275,9 +277,10 @@ private:
      */
     void shutdown();
 
+    bool _initialized;                          // If game has initialized yet.
+    State _state;                               // The game state.
     static long _pausedTimeLast;                // The last time paused.
     static long _pausedTimeTotal;               // The total time paused.
-    State _state;                               // The game state.
     long _frameLastFPS;                         // The last time the frame count was updated.
     unsigned int _frameCount;                   // The current frame count.
     unsigned int _frameRate;                    // The current frame rate.