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

Merge branch 'next' of https://github.com/blackberry-gaming/GamePlay into next-dgough

Darryl Gough 13 лет назад
Родитель
Сommit
8e6a99bed7

+ 8 - 8
README.md

@@ -1,9 +1,9 @@
-## gameplay v1.2.0
+## gameplay v1.3.0
 An open-source, cross-platform 3D native C++ game framework making it easy to learn and write mobile and desktop games. 
 
 ## Supported Mobile Platforms
-- BlackBerry PlayBook 2.0 (using BlackBerry Native SDK 2)
-- Google Android 2.3 (using Google Android NDK r7, SDK API level 9 and up)
+- BlackBerry 10 and PlayBook 2.0 (using BlackBerry Native SDK)
+- Google Android 2.3+ (using Google Android NDK r7, SDK API level 9+)
 - Apple iOS 5.1 (using Apple XCode 4.3.2)
 
 ## Supported Desktop Platforms
@@ -11,12 +11,12 @@ An open-source, cross-platform 3D native C++ game framework making it easy to le
 - Apple MacOS X (using Apple XCode 4.3.2)
 
 ## Roadmap for 'next' branch
-- Shadows
-- Lua Script Bindings
+- Gamepad support
+- Lua script bindings
+- Vehicle physics
 - Terrain
-- AI
-- Editor
-- Performance/Optimizations
+- Lightmaps
+- Shadows
 
 ## Licence
 The project is open sourced under the Apache 2.0 license.

+ 3 - 1
gameplay/src/Base.h

@@ -191,7 +191,9 @@ extern void printError(const char* format, ...);
     #define glClearDepth glClearDepthf
     #define OPENGL_ES
     #define USE_PVRTC
-	#define USE_NEON
+    #ifdef __ARM__
+        #define USE_NEON
+    #endif
 #elif __ANDROID__
 	#include <EGL/egl.h>
     #include <GLES2/gl2.h>

+ 91 - 3
gameplay/src/Container.cpp

@@ -31,6 +31,7 @@ Container::Container()
     : _layout(NULL), _scrollBarTopCap(NULL), _scrollBarVertical(NULL), _scrollBarBottomCap(NULL),
       _scrollBarLeftCap(NULL), _scrollBarHorizontal(NULL), _scrollBarRightCap(NULL),
       _scroll(SCROLL_NONE), _scrollBarBounds(Rectangle::empty()), _scrollPosition(Vector2::zero()),
+      _scrollBarsAlwaysVisible(false), _scrollBarOpacity(1.0f), _scrollBarOpacityClip(NULL),
       _scrolling(false), _firstX(0), _firstY(0),
       _lastX(0), _lastY(0),
       _startTimeX(0), _startTimeY(0), _lastTime(0),
@@ -84,7 +85,13 @@ Container* Container::create(Theme::Style* style, Properties* properties, Theme*
     Container* container = Container::create(getLayoutType(layoutString));
     container->initialize(style, properties);
     container->_scroll = getScroll(properties->getString("scroll"));
+    container->_scrollBarsAlwaysVisible = properties->getBool("scrollBarsAlwaysVisible");
+    if (!container->_scrollBarsAlwaysVisible)
+    {
+        container->_scrollBarOpacity = 0.0f;
+    }
     container->addControls(theme, properties);
+    container->_layout->update(container, container->_scrollPosition);
 
     return container;
 }
@@ -159,6 +166,9 @@ void Container::addControls(Theme* theme, Properties* properties)
         // Get the next control.
         controlSpace = properties->getNextNamespace();
     }
+
+    // Sort controls by Z-Order.
+    std::sort(_controls.begin(), _controls.end(), &sortControlsByZOrder);
 }
 
 Layout* Container::getLayout()
@@ -265,6 +275,20 @@ Container::Scroll Container::getScroll() const
     return _scroll;
 }
 
+void Container::setScrollBarsAlwaysVisible(bool alwaysVisible)
+{
+    if (alwaysVisible != _scrollBarsAlwaysVisible)
+    {
+        _scrollBarsAlwaysVisible = alwaysVisible;
+        _dirty = true;
+    }
+}
+
+bool Container::getScrollBarsAlwaysVisible() const
+{
+    return _scrollBarsAlwaysVisible;
+}
+
 Animation* Container::getAnimation(const char* id) const
 {
     std::vector<Control*>::const_iterator itr = _controls.begin();
@@ -365,26 +389,29 @@ void Container::draw(SpriteBatch* spriteBatch, const Rectangle& clip, bool needs
         }
     }
 
-    if (_scroll != SCROLL_NONE)
+    if (_scroll != SCROLL_NONE && (_scrollBarOpacity > 0.0f))
     {
         // Draw scroll bars.
         Rectangle clipRegion(_viewportClipBounds);
 
         spriteBatch->begin();
 
-        if (_scrollBarBounds.height > 0 && (_scrolling || _velocity.y))
+        if (_scrollBarBounds.height > 0)
         {
             const Rectangle& topRegion = _scrollBarTopCap->getRegion();
             const Theme::UVs& topUVs = _scrollBarTopCap->getUVs();
             Vector4 topColor = _scrollBarTopCap->getColor();
+            topColor.w *= _scrollBarOpacity * _opacity;
 
             const Rectangle& verticalRegion = _scrollBarVertical->getRegion();
             const Theme::UVs& verticalUVs = _scrollBarVertical->getUVs();
             Vector4 verticalColor = _scrollBarVertical->getColor();
+            verticalColor.w *= _scrollBarOpacity * _opacity;
 
             const Rectangle& bottomRegion = _scrollBarBottomCap->getRegion();
             const Theme::UVs& bottomUVs = _scrollBarBottomCap->getUVs();
             Vector4 bottomColor = _scrollBarBottomCap->getColor();
+            bottomColor.w *= _scrollBarOpacity * _opacity;
 
             clipRegion.width += verticalRegion.width;
 
@@ -402,19 +429,22 @@ void Container::draw(SpriteBatch* spriteBatch, const Rectangle& clip, bool needs
             spriteBatch->draw(bounds.x, bounds.y, bounds.width, bounds.height, bottomUVs.u1, bottomUVs.v1, bottomUVs.u2, bottomUVs.v2, bottomColor, clipRegion);
         }
 
-        if (_scrollBarBounds.width > 0 && (_scrolling || _velocity.x))
+        if (_scrollBarBounds.width > 0)
         {
             const Rectangle& leftRegion = _scrollBarLeftCap->getRegion();
             const Theme::UVs& leftUVs = _scrollBarLeftCap->getUVs();
             Vector4 leftColor = _scrollBarLeftCap->getColor();
+            leftColor.w *= _scrollBarOpacity * _opacity;
 
             const Rectangle& horizontalRegion = _scrollBarHorizontal->getRegion();
             const Theme::UVs& horizontalUVs = _scrollBarHorizontal->getUVs();
             Vector4 horizontalColor = _scrollBarHorizontal->getColor();
+            horizontalColor.w *= _scrollBarOpacity * _opacity;
 
             const Rectangle& rightRegion = _scrollBarRightCap->getRegion();
             const Theme::UVs& rightUVs = _scrollBarRightCap->getUVs();
             Vector4 rightColor = _scrollBarRightCap->getColor();
+            rightColor.w *= _scrollBarOpacity * _opacity;
 
             clipRegion.height += horizontalRegion.height;
         
@@ -696,6 +726,16 @@ void Container::updateScroll()
                          ((-_scrollPosition.y) / totalHeight) * clipHeight,
                          scrollWidth, scrollHeight);
 
+    // If scroll velocity is 0 and scrollbars are not always visible, trigger fade-out animation.
+    if (!_scrolling && _velocity.isZero() && !_scrollBarsAlwaysVisible && _scrollBarOpacity == 1.0f)
+    {
+        float to = 0;
+        _scrollBarOpacity = 0.99f;
+        Animation* animation = createAnimationFromTo("scrollbar-fade-out", ANIMATE_OPACITY, &_scrollBarOpacity, &to, Curve::QUADRATIC_IN_OUT, 500L);
+        _scrollBarOpacityClip = animation->getClip();
+        _scrollBarOpacityClip->play();
+    }
+
     // Position controls within scroll area.
     _layout->update(this, _scrollPosition);
 }
@@ -710,6 +750,13 @@ bool Container::touchEventScroll(Touch::TouchEvent evt, int x, int y, unsigned i
         _velocity.set(0, 0);
         _scrolling = true;
         _startTimeX = _startTimeY = 0;
+        
+        if (_scrollBarOpacityClip && _scrollBarOpacityClip->isPlaying())
+        {
+            _scrollBarOpacityClip->stop();
+            _scrollBarOpacityClip = NULL;
+        }
+        _scrollBarOpacity = 1.0f;
         return true;
 
     case Touch::TOUCH_MOVE:
@@ -822,4 +869,45 @@ bool sortControlsByZOrder(Control* c1, Control* c2)
     return false;
 }
 
+unsigned int Container::getAnimationPropertyComponentCount(int propertyId) const
+{
+    switch(propertyId)
+    {
+    case ANIMATE_OPACITY:
+        return 1;
+    default:
+        return Control::getAnimationPropertyComponentCount(propertyId);
+        break;
+    }
+}
+
+void Container::getAnimationPropertyValue(int propertyId, AnimationValue* value)
+{
+    GP_ASSERT(value);
+
+    switch(propertyId)
+    {
+    case ANIMATE_OPACITY:
+        value->setFloat(0, _scrollBarOpacity);
+    default:
+        Control::getAnimationPropertyValue(propertyId, value);
+        break;
+    }
+}
+
+void Container::setAnimationPropertyValue(int propertyId, AnimationValue* value, float blendWeight)
+{
+    GP_ASSERT(value);
+
+    switch(propertyId)
+    {
+    case ANIMATE_OPACITY:
+        _scrollBarOpacity = Curve::lerp(blendWeight, _opacity, value->getFloat(0));
+        _dirty = true;
+    default:
+        Control::setAnimationPropertyValue(propertyId, value, blendWeight);
+        break;
+    }
+}
+
 }

+ 45 - 2
gameplay/src/Container.h

@@ -57,6 +57,8 @@ public:
         SCROLL_BOTH = SCROLL_HORIZONTAL | SCROLL_VERTICAL
     };
 
+    static const int ANIMATE_SCROLLBAR_OPACITY = 8;
+
     /**
      * Get this container's layout.
      *
@@ -127,14 +129,33 @@ public:
     const std::vector<Control*>& getControls() const;
 
     /**
-     * Sets the scrolling for the container.
+     * Sets the allowed scroll directions for this container.
      *
-     * @param scroll The scroll for the 
+     * @param scroll The allowed scroll directions for this container.
      */
     void setScroll(Scroll scroll);
 
+    /**
+     * Gets the allowed scroll directions for this container.
+     *
+     * @return The allowed scroll directions for this container.
+     */
     Scroll getScroll() const;
 
+    /**
+     * Set whether scrollbars are always visible, or only visible while scrolling.
+     *
+     * @param alwaysVisible Whether scrollbars are always visible.
+     */
+    void setScrollBarsAlwaysVisible(bool alwaysVisible);
+
+    /**
+     * Get whether scrollbars are always visible, or only visible while scrolling.
+     *
+     * @return Whether scrollbars are always visible.
+     */
+    bool getScrollBarsAlwaysVisible() const;
+
     /**
      * Gets the first animation in the control with the specified ID.
      *
@@ -143,6 +164,21 @@ public:
      */
     Animation* getAnimation(const char* id = NULL) const;
 
+    /**
+     * @see AnimationTarget#getAnimationPropertyComponentCount
+     */
+    unsigned int getAnimationPropertyComponentCount(int propertyId) const;
+
+    /**
+     * @see AnimationTarget#getAnimationProperty
+     */
+    void getAnimationPropertyValue(int propertyId, AnimationValue* value);
+
+    /**
+     * @see AnimationTarget#setAnimationProperty
+     */
+    void setAnimationPropertyValue(int propertyId, AnimationValue* value, float blendWeight = 1.0f);
+
 protected:
 
     /**
@@ -271,6 +307,11 @@ protected:
     // How far this layout has been scrolled in each direction.
     Vector2 _scrollPosition;
 
+    bool _scrollBarsAlwaysVisible;
+
+    // Used to animate scrollbars fading out.
+    float _scrollBarOpacity;
+
     // Whether the user is currently touching / holding the mouse down
     // within this layout's container.
     bool _scrolling;
@@ -303,6 +344,8 @@ private:
     Container(const Container& copy);
 
     int _zIndexDefault;
+
+    AnimationClip* _scrollBarOpacityClip;
 };
 
 // Sort funtion for use with _controls.sort(), based on Z-Order.

+ 2 - 0
gameplay/src/MathUtil.h

@@ -28,6 +28,8 @@ private:
 };
 }
 
+#define MATRIX_SIZE ( sizeof(float) * 16)
+
 #ifdef USE_NEON
 #include "MathUtilNeon.inl"
 #else

+ 10 - 6
gameplay/src/MathUtil.inl

@@ -1,5 +1,3 @@
-#define MATRIX_SIZE ( sizeof(float) * 16)
-
 namespace gameplay
 {
 
@@ -140,10 +138,16 @@ inline void MathUtil::transformVectorMatrix(const float* m, float x, float y, fl
 
 inline void MathUtil::transformVectorMatrix(const float* m, const float* v, float* dst)
 {
-	dst[0] = v[0] * m[0] + v[1] * m[4] + v[2] * m[8] + v[3] * m[12];
-	dst[1] = v[0] * m[1] + v[1] * m[5] + v[2] * m[9] + v[3] * m[13];
-	dst[2] = v[0] * m[2] + v[1] * m[6] + v[2] * m[10] + v[3] * m[14];
-	dst[3] = v[0] * m[3] + v[1] * m[7] + v[2] * m[11] + v[3] * m[15];
+    // Handle case where v == dst.
+    float x = v[0] * m[0] + v[1] * m[4] + v[2] * m[8] + v[3] * m[12];
+	float y = v[0] * m[1] + v[1] * m[5] + v[2] * m[9] + v[3] * m[13];
+    float z = v[0] * m[2] + v[1] * m[6] + v[2] * m[10] + v[3] * m[14];
+    float w = v[0] * m[3] + v[1] * m[7] + v[2] * m[11] + v[3] * m[15];
+
+    dst[0] = x;
+    dst[1] = y;
+	dst[2] = z;
+	dst[3] = w;
 }
 
 inline void MathUtil::transposeMatrix(const float* m, float* dst)

+ 0 - 4
gameplay/src/Matrix.cpp

@@ -3,10 +3,6 @@
 #include "Quaternion.h"
 #include "MathUtil.h"
 
-#ifndef MATRIX_SIZE
-#define MATRIX_SIZE     ( sizeof(float) * 16 )
-#endif
-
 namespace gameplay
 {