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

Fixes issue where disabled UI controls were receiving input events.
Changes Game::pause() to behave like pausing a game (vs. the old behavior, which was like pausing a system process).
Removes mipmapping from Theme (so that scaled containers don't have rendering artifacts).

Chris Culy 14 лет назад
Родитель
Сommit
c82de3a543

+ 9 - 0
gameplay/src/Container.cpp

@@ -279,6 +279,9 @@ namespace gameplay
 
     void Container::touchEvent(Touch::TouchEvent evt, int x, int y, unsigned int contactIndex)
     {
+        if (getState() == Control::STATE_DISABLED)
+            return;
+
         std::vector<Control*>::const_iterator it;
         for (it = _controls.begin(); it < _controls.end(); it++)
         {
@@ -297,6 +300,9 @@ namespace gameplay
             }
         }
 
+        if (getState() == Control::STATE_DISABLED)
+            return;
+
         switch (evt)
         {
         case Touch::TOUCH_PRESS:
@@ -310,6 +316,9 @@ namespace gameplay
 
     void Container::keyEvent(Keyboard::KeyEvent evt, int key)
     {
+        if (getState() == Control::STATE_DISABLED)
+            return;
+
         std::vector<Control*>::const_iterator it;
         for (it = _controls.begin(); it < _controls.end(); it++)
         {

+ 6 - 0
gameplay/src/Form.cpp

@@ -298,6 +298,9 @@ namespace gameplay
         {
             Form* form = *it;
 
+            if (form->getState() == Control::STATE_DISABLED)
+                continue;
+
             Node* node = form->_node;
             if (node)
             {
@@ -371,6 +374,9 @@ namespace gameplay
         for (it = __forms.begin(); it < __forms.end(); it++)
         {
             Form* form = *it;
+            if (form->getState() == Control::STATE_DISABLED)
+                continue;
+
             form->keyEvent(evt, key);
         }
     }

+ 36 - 32
gameplay/src/Game.cpp

@@ -161,45 +161,49 @@ void Game::exit()
 
 void Game::frame()
 {
-    if (_state != RUNNING)
+    if (!_initialized)
     {
-        return;
+        initialize();
+        _initialized = true;
     }
-    else
+
+    if (_state == Game::RUNNING)
     {
-        if (!_initialized)
+        // Update Time.
+        static long lastFrameTime = Game::getGameTime();
+        long frameTime = Game::getGameTime();
+        long elapsedTime = (frameTime - lastFrameTime);
+        lastFrameTime = frameTime;
+
+        // Update the scheduled and running animations.
+        _animationController->update(elapsedTime);
+    
+        // Update the physics.
+        _physicsController->update(elapsedTime);
+        // Application Update.
+        update(elapsedTime);
+
+        // Audio Rendering.
+        _audioController->update(elapsedTime);
+        // Graphics Rendering.
+        render(elapsedTime);
+
+        // Update FPS.
+        ++_frameCount;
+        if ((Game::getGameTime() - _frameLastFPS) >= 1000)
         {
-            initialize();
-            _initialized = true;
+            _frameRate = _frameCount;
+            _frameCount = 0;
+            _frameLastFPS = Game::getGameTime();
         }
     }
-
-    // Update Time.
-    static long lastFrameTime = Game::getGameTime();
-    long frameTime = Game::getGameTime();
-    long elapsedTime = (frameTime - lastFrameTime);
-    lastFrameTime = frameTime;
-
-    // Update the scheduled and running animations.
-    _animationController->update(elapsedTime);
-    
-    // Update the physics.
-    _physicsController->update(elapsedTime);
-    // Application Update.
-    update(elapsedTime);
-
-    // Audio Rendering.
-    _audioController->update(elapsedTime);
-    // Graphics Rendering.
-    render(elapsedTime);
-
-    // Update FPS.
-    ++_frameCount;
-    if ((Game::getGameTime() - _frameLastFPS) >= 1000)
+    else
     {
-        _frameRate = _frameCount;
-        _frameCount = 0;
-        _frameLastFPS = Game::getGameTime();
+        // Application Update.
+        update(0);
+
+        // Graphics Rendering.
+        render(0);
     }
 }
 

+ 3 - 0
gameplay/src/Label.cpp

@@ -92,6 +92,9 @@ namespace gameplay
 
     void Label::drawText(const Vector2& position)
     {
+        if (_text.size() <= 0)
+            return;
+
         // TODO: Batch all labels that use the same font.
         Theme::Style::Overlay* overlay = _style->getOverlay(getOverlayType());
         Font* font = overlay->getFont();

+ 20 - 25
gameplay/src/PlatformQNX.cpp

@@ -970,32 +970,27 @@ int Platform::enterMessagePump()
         if (_game->getState() == Game::UNINITIALIZED)
             break;
 
-        // Idle time (no events left to process) is spent rendering.
-        // We skip rendering when the app is paused.
-        if (_game->getState() != Game::PAUSED)
+        _game->frame();
+
+        // Post the new frame to the display.
+        // Note that there are a couple cases where eglSwapBuffers could fail
+        // with an error code that requires a certain level of re-initialization:
+        //
+        // 1) EGL_BAD_NATIVE_WINDOW - Called when the surface we're currently using
+        //    is invalidated. This would require us to destroy our EGL surface,
+        //    close our OpenKODE window, and start again.
+        //
+        // 2) EGL_CONTEXT_LOST - Power management event that led to our EGL context
+        //    being lost. Requires us to re-create and re-initalize our EGL context
+        //    and all OpenGL ES state.
+        //
+        // For now, if we get these, we'll simply exit.
+        rc = eglSwapBuffers(__eglDisplay, __eglSurface);
+        if (rc != EGL_TRUE)
         {
-            _game->frame();
-
-            // Post the new frame to the display.
-            // Note that there are a couple cases where eglSwapBuffers could fail
-            // with an error code that requires a certain level of re-initialization:
-            //
-            // 1) EGL_BAD_NATIVE_WINDOW - Called when the surface we're currently using
-            //    is invalidated. This would require us to destroy our EGL surface,
-            //    close our OpenKODE window, and start again.
-            //
-            // 2) EGL_CONTEXT_LOST - Power management event that led to our EGL context
-            //    being lost. Requires us to re-create and re-initalize our EGL context
-            //    and all OpenGL ES state.
-            //
-            // For now, if we get these, we'll simply exit.
-            rc = eglSwapBuffers(__eglDisplay, __eglSurface);
-            if (rc != EGL_TRUE)
-            {
-                _game->exit();
-                perror("eglSwapBuffers");
-                break;
-            }
+            _game->exit();
+            perror("eglSwapBuffers");
+            break;
         }
     }
 

+ 1 - 1
gameplay/src/Theme.cpp

@@ -101,7 +101,7 @@ namespace gameplay
         
         // Parse the Properties object and set up the theme.
         const char* textureFile = themeProperties->getString("texture");
-        theme->_texture = Texture::create(textureFile, true);
+        theme->_texture = Texture::create(textureFile, false);
         theme->_spriteBatch = SpriteBatch::create(theme->_texture);
 
         Properties* space = themeProperties->getNextNamespace();