Преглед на файлове

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

Next setaylor
Sean Paul Taylor преди 13 години
родител
ревизия
a26b4f11f1
променени са 4 файла, в които са добавени 86 реда и са изтрити 100 реда
  1. 58 60
      gameplay/src/Game.cpp
  2. 25 36
      gameplay/src/Game.h
  3. 2 3
      gameplay/src/ParticleEmitter.cpp
  4. 1 1
      gameplay/src/ParticleEmitter.h

+ 58 - 60
gameplay/src/Game.cpp

@@ -5,7 +5,6 @@
 #include "FileSystem.h"
 #include "FrameBuffer.h"
 
-// Extern global variables
 GLenum __gl_error_code = GL_NO_ERROR;
 ALenum __al_error_code = AL_NO_ERROR;
 
@@ -130,7 +129,7 @@ bool Game::startup()
     _physicsController = new PhysicsController();
     _physicsController->initialize();
 
-    loadGamepad();
+    loadGamepads();
     
     _state = RUNNING;
 
@@ -181,7 +180,6 @@ void Game::pause()
         GP_ASSERT(_animationController);
         GP_ASSERT(_audioController);
         GP_ASSERT(_physicsController);
-
         _state = PAUSED;
         _pausedTimeLast = Platform::getAbsoluteTime();
         _animationController->pause();
@@ -197,7 +195,6 @@ void Game::resume()
         GP_ASSERT(_animationController);
         GP_ASSERT(_audioController);
         GP_ASSERT(_physicsController);
-
         _state = RUNNING;
         _pausedTimeTotal += Platform::getAbsoluteTime() - _pausedTimeLast;
         _animationController->resume();
@@ -268,6 +265,24 @@ void Game::frame()
     }
 }
 
+void Game::updateOnce()
+{
+    GP_ASSERT(_animationController);
+    GP_ASSERT(_audioController);
+    GP_ASSERT(_physicsController);
+
+    // Update Time.
+    static double lastFrameTime = getGameTime();
+    double frameTime = getGameTime();
+    float elapsedTime = (frameTime - lastFrameTime);
+    lastFrameTime = frameTime;
+
+    // Update the internal controllers.
+    _animationController->update(elapsedTime);
+    _physicsController->update(elapsedTime);
+    _audioController->update(elapsedTime);
+}
+
 void Game::setViewport(const Rectangle& viewport)
 {
     _viewport = viewport;
@@ -326,7 +341,7 @@ AudioListener* Game::getAudioListener()
     return _audioListener;
 }
 
-void Game::menu()
+void Game::menuEvent()
 {
 }
 
@@ -338,6 +353,11 @@ void Game::touchEvent(Touch::TouchEvent evt, int x, int y, unsigned int contactI
 {
 }
 
+bool Game::mouseEvent(Mouse::MouseEvent evt, int x, int y, int wheelDelta)
+{
+    return false;
+}
+
 void Game::gamepadEvent(Gamepad::GamepadEvent evt, Gamepad* gamepad)
 {
 }
@@ -349,27 +369,32 @@ void Game::schedule(float timeOffset, TimeListener* timeListener, void* cookie)
     _timeEvents->push(timeEvent);
 }
 
-bool Game::mouseEvent(Mouse::MouseEvent evt, int x, int y, int wheelDelta)
+void Game::fireTimeEvents(double frameTime)
 {
-    return false;
+    while (_timeEvents->size() > 0)
+    {
+        const TimeEvent* timeEvent = &_timeEvents->top();
+        if (timeEvent->time > frameTime)
+        {
+            break;
+        }
+        if (timeEvent->listener)
+        {
+            timeEvent->listener->timeEvent(frameTime - timeEvent->time, timeEvent->cookie);
+        }
+        _timeEvents->pop();
+    }
 }
 
-void Game::updateOnce()
+Game::TimeEvent::TimeEvent(double time, TimeListener* timeListener, void* cookie)
+    : time(time), listener(timeListener), cookie(cookie)
 {
-    GP_ASSERT(_animationController);
-    GP_ASSERT(_audioController);
-    GP_ASSERT(_physicsController);
-
-    // Update Time.
-    static double lastFrameTime = getGameTime();
-    double frameTime = getGameTime();
-    float elapsedTime = (frameTime - lastFrameTime);
-    lastFrameTime = frameTime;
+}
 
-    // Update the internal controllers.
-    _animationController->update(elapsedTime);
-    _physicsController->update(elapsedTime);
-    _audioController->update(elapsedTime);
+bool Game::TimeEvent::operator<(const TimeEvent& v) const
+{
+    // The first element of std::priority_queue is the greatest.
+    return time > v.time;
 }
 
 Properties* Game::getConfig() const
@@ -392,65 +417,38 @@ void Game::loadConfig()
             // Load filesystem aliases.
             Properties* aliases = _properties->getNamespace("aliases", true);
             if (aliases)
+            {
                 FileSystem::loadResourceAliases(aliases);
+            }
         }
     }
 }
 
-void Game::fireTimeEvents(double frameTime)
+void Game::loadGamepads()
 {
-    while (_timeEvents->size() > 0)
+    if (_properties)
     {
-        const TimeEvent* timeEvent = &_timeEvents->top();
-        if (timeEvent->time > frameTime)
+        // Check if there is a virtual keyboard included in the .config file.
+        // If there is, try to create it and assign it to "player one".
+        Properties* gamepadProperties = _properties->getNamespace("gamepads", true);
+        if (gamepadProperties && gamepadProperties->exists("form"))
         {
-            break;
+            const char* gamepadFormPath = gamepadProperties->getString("form");
+            GP_ASSERT(gamepadFormPath);
+            Gamepad* gamepad = createGamepad(gamepadProperties->getId(), gamepadFormPath);
+            GP_ASSERT(gamepad);
         }
-        if (timeEvent->listener)
-            timeEvent->listener->timeEvent(frameTime - timeEvent->time, timeEvent->cookie);
-        _timeEvents->pop();
     }
 }
 
-Game::TimeEvent::TimeEvent(double time, TimeListener* timeListener, void* cookie)
-            : time(time), listener(timeListener), cookie(cookie)
-{
-}
-
-bool Game::TimeEvent::operator<(const TimeEvent& v) const
-{
-    // The first element of std::priority_queue is the greatest.
-    return time > v.time;
-}
-
 Gamepad* Game::createGamepad(const char* gamepadId, const char* gamepadFormPath)
 {
     GP_ASSERT(gamepadFormPath);
-
     Gamepad* gamepad = new Gamepad(gamepadId, gamepadFormPath);
     GP_ASSERT(gamepad);
-
     _gamepads.push_back(gamepad);
 
     return gamepad;
 }
 
-void Game::loadGamepad()
-{
-    if (_properties)
-    {
-        // Check if there is a virtual keyboard included in the .config file.
-        // If there is, try to create it and assign it to "player one".
-        Properties* gamepadProperties = _properties->getNamespace("gamepads", true);
-        if (gamepadProperties && gamepadProperties->exists("form"))
-        {
-            const char* gamepadFormPath = gamepadProperties->getString("form");
-            GP_ASSERT(gamepadFormPath);
-
-            Gamepad* gamepad = createGamepad(gamepadProperties->getId(), gamepadFormPath);
-            GP_ASSERT(gamepad);
-        }
-    }
-}
-
 }

+ 25 - 36
gameplay/src/Game.h

@@ -23,7 +23,6 @@ namespace gameplay
  */
 class Game
 {
-
 public:
     
     /**
@@ -273,9 +272,9 @@ public:
     AudioListener* getAudioListener();
 
     /**
-     * Menu callback on menu events.
+     * Menu callback on menu events for platforms with special menu keys or gestures.
      */
-    virtual void menu();
+    virtual void menuEvent();
     
     /**
      * Shows or hides the virtual keyboard (if supported).
@@ -331,6 +330,20 @@ public:
      */
     virtual void gamepadEvent(Gamepad::GamepadEvent evt, Gamepad* gamepad);
 
+    /**
+     * Gets the number of gamepad's connected to the game.
+     * 
+     * @return The number of gamepad's connected to the game.
+     */
+    inline unsigned int getGamepadCount() const;
+
+    /**
+     * Gets the gamepad at the specified index.
+     *
+     * @param index The index to get the gamepad for: 0 <= index <= Game::getGamepadCount()
+     */
+    inline Gamepad* getGamepad(unsigned int index) const;
+
     /**
      * Sets muli-touch is to be enabled/disabled. Default is disabled.
      *
@@ -362,20 +375,6 @@ public:
      * @param cookie The cookie data that the time event will contain.
      */
     void schedule(float timeOffset, TimeListener* timeListener, void* cookie = 0);
-    
-    /**
-     * Gets the number of gamepad's connected to the game.
-     * 
-     * @return The number of gamepad's connected to the game.
-     */
-    inline unsigned int getGamepadCount() const;
-
-    /**
-     * Gets the gamepad at the specified index.
-     *
-     * @param index The index to get the gamepad for (0 <= index <= Game::getGamepadCount) 
-     */
-    inline Gamepad* getGamepad(unsigned int index = 0) const;
 
 protected:
 
@@ -434,21 +433,14 @@ protected:
 private:
 
     /**
-     * TimeEvent represents the event that is sent to TimeListeners as a result of 
-     * calling Game::schedule().
+     * TimeEvent represents the event that is sent to TimeListeners as a result of calling Game::schedule().
      */
     class TimeEvent
     {
     public:
 
         TimeEvent(double time, TimeListener* timeListener, void* cookie);
-        // The comparator is used to determine the order of time events in the priority queue.
         bool operator<(const TimeEvent& v) const;
-        
-        /**
-         * The game time.
-         * @see Game::getGameTime()
-         */
         double time;
         TimeListener* listener;
         void* cookie;
@@ -462,7 +454,7 @@ private:
     Game(const Game& copy);
 
     /**
-     * Starts core game.
+     * Starts the game.
      */
     bool startup();
 
@@ -483,19 +475,16 @@ private:
      */
     void loadConfig();
 
+    /**
+     * Loads the gamepads from the configuration file.
+     */
+    void loadGamepads();
+
     /** 
      * Creates a Gamepad object from a .form file.
-     *
-     * @param playerIndex
-     * @param formPath
      */
     Gamepad* createGamepad(const char* gamepadId, const char* gamepadFormPath);
 
-    /**
-     * Loads a gamepad from the configuration file.
-     */
-    void loadGamepad();
-
     bool _initialized;                          // If game has initialized yet.
     State _state;                               // The game state.
     static double _pausedTimeLast;              // The last time paused.
@@ -514,8 +503,8 @@ private:
     AudioController* _audioController;          // Controls audio sources that are playing in the game.
     PhysicsController* _physicsController;      // Controls the simulation of a physics scene and entities.
     AudioListener* _audioListener;              // The audio listener in 3D space.
-    std::vector<Gamepad*> _gamepads;
-    std::priority_queue<TimeEvent, std::vector<TimeEvent>, std::less<TimeEvent> >* _timeEvents; // Contains the scheduled time events.
+    std::vector<Gamepad*> _gamepads;            // The connected gamepads.
+    std::priority_queue<TimeEvent, std::vector<TimeEvent>, std::less<TimeEvent> >* _timeEvents;     // Contains the scheduled time events.
 
     // Note: Do not add STL object member variables on the stack; this will cause false memory leaks to be reported.
 

+ 2 - 3
gameplay/src/ParticleEmitter.cpp

@@ -262,7 +262,7 @@ bool ParticleEmitter::isActive() const
     return active;
 }
 
-void ParticleEmitter::emit(unsigned int particleCount)
+void ParticleEmitter::emitOnce(unsigned int particleCount)
 {
     GP_ASSERT(_node);
     GP_ASSERT(_particles);
@@ -810,8 +810,7 @@ void ParticleEmitter::update(float elapsedTime)
             {
                 _timeRunning = fmodl(_timeRunning, _timePerEmission);
             }
-
-            emit(emitCount);
+            emitOnce(emitCount);
         }
     }
 

+ 1 - 1
gameplay/src/ParticleEmitter.h

@@ -235,7 +235,7 @@ public:
      *
      * @param particleCount The number of particles to emit immediately.
      */
-    void emit(unsigned int particleCount);
+    void emitOnce(unsigned int particleCount);
 
     /**
      * Gets the current number of particles.