Bläddra i källkod

Changed behavior of Scene::visit to stop child traversal, but continue sibling traversal when false is returned from visitMethod, instead of stopping traversal entirely.
Fixed Terrain compile error on BlackBerry.
Fixed process shutdown issue on BlackBerry.
Fixed a few compile warnings.
Minor terrain test updates.

sgrenier 13 år sedan
förälder
incheckning
b55432e36a

+ 16 - 12
gameplay/res/shaders/terrain.frag

@@ -24,42 +24,46 @@ vec3 v_normalVector;                            // Normal vector variable (from
 varying vec3 v_normalVector;					// Normal vector from vertex shader
 #endif
 varying vec2 v_texCoord0;
+#if (LAYER_COUNT > 0)
+varying vec2 v_texCoordLayer0;
+#endif
+#if (LAYER_COUNT > 1)
+varying vec2 v_texCoordLayer1;
+#endif
+#if (LAYER_COUNT > 2)
+varying vec2 v_texCoordLayer2;
+#endif
 
 // Lighting
 #include "lighting.frag"
 #include "lighting-directional.frag"
 
 #if (LAYER_COUNT > 1)
-void blendLayer(sampler2D textureMap, vec2 textureRepeat, float alphaBlend)
+void blendLayer(sampler2D textureMap, vec2 texCoord, float alphaBlend)
 {
-    vec2 uv = mod(v_texCoord0 * textureRepeat, vec2(1,1));
-
     // Sample full intensity diffuse color
-    vec3 diffuse = texture2D(textureMap, uv).rgb;
+    vec3 diffuse = texture2D(textureMap,  mod(texCoord, vec2(1,1))).rgb;
 
     _baseColor.rgb = _baseColor.rgb * (1.0 - alphaBlend) + diffuse * alphaBlend;
 }
 #endif
 
-
 void main()
 {
 #if (LAYER_COUNT > 0)
-    // Set base diffuse color
-    vec2 uvCoord = mod(v_texCoord0 * TEXTURE_REPEAT_0, vec2(1,1));
-	_baseColor.rgb = texture2D(u_samplers[TEXTURE_INDEX_0], uvCoord).rgb;
+    // Sample base texture
+	_baseColor.rgb = texture2D(u_samplers[TEXTURE_INDEX_0], mod(v_texCoordLayer0, vec2(1,1))).rgb;
     _baseColor.a = 1.0;
 #else
-    // If no layers are defined, simple use a white color
+    // If no layers are defined, simply use a white color
     _baseColor = vec4(1,1,1,1);
 #endif
 
 #if (LAYER_COUNT > 1)
-    blendLayer(u_samplers[TEXTURE_INDEX_1], TEXTURE_REPEAT_1, texture2D(u_samplers[BLEND_INDEX_1], v_texCoord0)[BLEND_CHANNEL_1]);
+    blendLayer(u_samplers[TEXTURE_INDEX_1], v_texCoordLayer1, texture2D(u_samplers[BLEND_INDEX_1], v_texCoord0)[BLEND_CHANNEL_1]);
 #endif
-
 #if (LAYER_COUNT > 2)
-    blendLayer(u_samplers[TEXTURE_INDEX_2], TEXTURE_REPEAT_2, texture2D(u_samplers[BLEND_INDEX_2], v_texCoord0)[BLEND_CHANNEL_2]);
+    blendLayer(u_samplers[TEXTURE_INDEX_2], v_texCoordLayer2, texture2D(u_samplers[BLEND_INDEX_2], v_texCoord0)[BLEND_CHANNEL_2]);
 #endif
 
 #if defined(DEBUG_PATCHES)

+ 14 - 20
gameplay/res/shaders/terrain.vert

@@ -4,15 +4,6 @@ attribute vec4 a_position;									// Vertex Position							(x, y, z, w)
 attribute vec3 a_normal;									// Vertex Normal							(x, y, z)
 #endif
 attribute vec2 a_texCoord0;
-#if LAYER_COUNT > 1
-attribute vec2 a_texCoord1;
-#endif
-#if LAYER_COUNT > 2
-attribute vec2 a_texCoord2;
-#endif
-#if LAYER_COUNT > 3
-attribute vec2 a_texCoord3;
-#endif
 
 // Uniforms
 uniform mat4 u_worldViewProjectionMatrix;					// World view projection matrix
@@ -26,16 +17,15 @@ uniform vec3 u_lightDirection;								// Direction of light
 varying vec3 v_normalVector;								// Normal vector out
 #endif
 varying vec2 v_texCoord0;
+#if LAYER_COUNT > 0
+varying vec2 v_texCoordLayer0;
+#endif
 #if LAYER_COUNT > 1
-varying vec2 v_texCoord1;
+varying vec2 v_texCoordLayer1;
 #endif
 #if LAYER_COUNT > 2
-varying vec2 v_texCoord2;
+varying vec2 v_texCoordLayer2;
 #endif
-#if LAYER_COUNT > 3
-varying vec2 v_texCoord3;
-#endif
-
 
 void main()
 {
@@ -46,14 +36,18 @@ void main()
     // Pass normal to fragment shader
     v_normalVector = (u_normalMatrix * vec4(a_normal.x, a_normal.y, a_normal.z, 0)).xyz;
 #endif
+
+    // Pass base texture coord
     v_texCoord0 = a_texCoord0;
+
+    // Pass repeated texture coordinates for each layer
+#if LAYER_COUNT > 0
+    v_texCoordLayer0 = a_texCoord0 * TEXTURE_REPEAT_0;
+#endif
 #if LAYER_COUNT > 1
-    v_texCoord1 = a_texCoord1;
+    v_texCoordLayer1 = a_texCoord0 * TEXTURE_REPEAT_1;
 #endif
 #if LAYER_COUNT > 2
-    v_texCoord2 = a_texCoord2;
-#endif
-#if LAYER_COUNT > 3
-    v_texCoord3 = a_texCoord3;
+    v_texCoordLayer2 = a_texCoord0 * TEXTURE_REPEAT_2;
 #endif
 }

+ 0 - 1
gameplay/src/Form.cpp

@@ -26,7 +26,6 @@ Form::Form() : _theme(NULL), _frameBuffer(NULL), _spriteBatch(NULL), _node(NULL)
 
 Form::~Form()
 {
-    SAFE_RELEASE(_node);
     SAFE_DELETE(_spriteBatch);
     SAFE_RELEASE(_frameBuffer);
     SAFE_RELEASE(_theme);

+ 22 - 3
gameplay/src/Gamepad.cpp

@@ -8,8 +8,26 @@ namespace gameplay
 
 static std::vector<Gamepad*> __gamepads;
 
+
+
+GamepadHandle _handle;        // The handle of the Gamepad.
+unsigned int _buttonCount;    // Number of buttons.
+unsigned int _joystickCount;  // Number of joysticks.
+unsigned int _triggerCount;   // Number of triggers.
+unsigned int _vendorId;
+unsigned int _productId;
+std::string _vendorString;
+std::string _productString;
+Form* _form;
+Joystick* _uiJoysticks[2];
+Button* _uiButtons[20];
+unsigned int _buttons;
+Vector2 _joysticks[2];
+float _triggers[2];
+
+
 Gamepad::Gamepad(const char* formPath)
-    : _handle((GamepadHandle)INT_MAX), _vendorId(0), _productId(0), _buttonCount(0), _joystickCount(0), _triggerCount(0), _form(NULL), _buttons(0)
+    : _handle((GamepadHandle)INT_MAX),  _buttonCount(0), _joystickCount(0), _triggerCount(0), _vendorId(0), _productId(0), _form(NULL), _buttons(0)
 {
     GP_ASSERT(formPath);
     _form = Form::create(formPath);
@@ -33,8 +51,9 @@ Gamepad::Gamepad(const char* formPath)
 
 Gamepad::Gamepad(GamepadHandle handle, unsigned int buttonCount, unsigned int joystickCount, unsigned int triggerCount,
                  unsigned int vendorId, unsigned int productId, const char* vendorString, const char* productString)
-    : _handle(handle), _vendorId(vendorId), _productId(productId), _vendorString(vendorString), _productString(productString),
-      _buttonCount(buttonCount), _joystickCount(joystickCount), _triggerCount(triggerCount), _form(NULL), _buttons(0)
+    : _handle(handle), _buttonCount(buttonCount), _joystickCount(joystickCount), _triggerCount(triggerCount),
+      _vendorId(vendorId), _productId(productId), _vendorString(vendorString), _productString(productString),
+      _form(NULL), _buttons(0)
 {
 }
 

+ 0 - 1
gameplay/src/Node.cpp

@@ -844,7 +844,6 @@ void Node::setForm(Form* form)
     }
 }
 
-
 const BoundingSphere& Node::getBoundingSphere() const
 {
     if (_dirtyBits & NODE_DIRTY_BOUNDS)

+ 1 - 1
gameplay/src/PhysicsCollisionObject.cpp

@@ -35,7 +35,7 @@ struct CollidesWithCallback : public btCollisionWorld::ContactResultCallback
 };
 
 PhysicsCollisionObject::PhysicsCollisionObject(Node* node)
-    : _node(node), _motionState(NULL), _collisionShape(NULL), _enabled(true), _scriptListeners(NULL)
+    : _node(node), _collisionShape(NULL), _enabled(true), _scriptListeners(NULL), _motionState(NULL)
 {
 }
 

+ 5 - 2
gameplay/src/PlatformBlackBerry.cpp

@@ -1288,7 +1288,10 @@ int Platform::enterMessagePump()
                     break;
                 }
                 case NAVIGATOR_EXIT:
-                    _game->exit();
+                	// Call Game::shutdown directly, instead of Game::exit.
+                	// We need to do this since exit() queues a request to shutdown for the
+                	// next frame, which will never get executed because we are suspended.
+                    _game->shutdown();
                     break;
                 }
             }
@@ -1326,7 +1329,7 @@ int Platform::enterMessagePump()
             rc = eglSwapBuffers(__eglDisplay, __eglSurface);
             if (rc != EGL_TRUE)
             {
-                _game->exit();
+                _game->shutdown();
                 perror("eglSwapBuffers");
                 break;
             }

+ 31 - 30
gameplay/src/Scene.h

@@ -239,6 +239,10 @@ public:
      * The visitMethod parameter must be a pointer to a method that has a bool
      * return type and accepts a single parameter of type Node*.
      *
+     * A depth-first traversal of the scene continues while the visit method
+     * returns true. Returning false will stop traversing further children for
+     * the given node and the traversal will continue at the next sibling.
+     *
      * @param instance The pointer to an instance of the object that contains visitMethod.
      * @param visitMethod The pointer to the class method to call for each node in the scene.
      */
@@ -253,8 +257,11 @@ public:
      * 
      * The visitMethod parameter must be a pointer to a method that has a bool
      * return type and accepts two parameters: a Node pointer and a cookie of a
-     * user-specified type. The scene traversal continues while visitMethod return
-     * true. Returning false will cause the traversal to stop.
+     * user-specified type.
+     *
+     * A depth-first traversal of the scene continues while the visit method
+     * returns true. Returning false will stop traversing further children for
+     * the given node and the traversal will continue at the next sibling.
      *
      * @param instance The pointer to an instance of the object that contains visitMethod.
      * @param visitMethod The pointer to the class method to call for each node in the scene.
@@ -273,6 +280,10 @@ public:
      * valid Lua function that has a boolean return type and accepts a 
      * single parameter of type Node*.
      *
+     * A depth-first traversal of the scene continues while the visit method
+     * returns true. Returning false will stop traversing further children for
+     * the given node and the traversal will continue at the next sibling.
+     *
      * @param visitMethod The name of the Lua function to call for each node in the scene.
      */
     inline void visit(const char* visitMethod);
@@ -311,18 +322,18 @@ private:
      * Visits the given node and all of its children recursively.
      */
     template <class T>
-    bool visitNode(Node* node, T* instance, bool (T::*visitMethod)(Node*));
+    void visitNode(Node* node, T* instance, bool (T::*visitMethod)(Node*));
 
     /**
      * Visits the given node and all of its children recursively.
      */
     template <class T, class C>
-    bool visitNode(Node* node, T* instance, bool (T::*visitMethod)(Node*,C), C cookie);
+    void visitNode(Node* node, T* instance, bool (T::*visitMethod)(Node*,C), C cookie);
 
     /**
      * Visits the given node and all of its children recursively.
      */
-    inline bool visitNode(Node* node, const char* visitMethod);
+    inline void visitNode(Node* node, const char* visitMethod);
 
     std::string _id;
     Camera* _activeCamera;
@@ -341,8 +352,7 @@ void Scene::visit(T* instance, bool (T::*visitMethod)(Node*))
 {
     for (Node* node = getFirstNode(); node != NULL; node = node->getNextSibling())
     {
-        if (!visitNode(node, instance, visitMethod))
-            return;
+        visitNode(node, instance, visitMethod);
     }
 }
 
@@ -352,8 +362,7 @@ void Scene::visit(T* instance, bool (T::*visitMethod)(Node*,C), C cookie)
 {
     for (Node* node = getFirstNode(); node != NULL; node = node->getNextSibling())
     {
-        if (!visitNode(node, instance, visitMethod, cookie))
-            return;
+        visitNode(node, instance, visitMethod, cookie);
     }
 }
 
@@ -361,59 +370,51 @@ inline void Scene::visit(const char* visitMethod)
 {
     for (Node* node = getFirstNode(); node != NULL; node = node->getNextSibling())
     {
-        if (!visitNode(node, visitMethod))
-            return;
+        visitNode(node, visitMethod);
     }
 }
 
 template <class T>
-bool Scene::visitNode(Node* node, T* instance, bool (T::*visitMethod)(Node*))
+void Scene::visitNode(Node* node, T* instance, bool (T::*visitMethod)(Node*))
 {
     // Invoke the visit method for this node.
     if (!(instance->*visitMethod)(node))
-        return false;
+        return;
 
     // Recurse for all children.
     for (Node* child = node->getFirstChild(); child != NULL; child = child->getNextSibling())
     {
-        if (!visitNode(child, instance, visitMethod))
-            return false;
+        visitNode(child, instance, visitMethod);
     }
-
-    return true;
 }
 
 template <class T, class C>
-bool Scene::visitNode(Node* node, T* instance, bool (T::*visitMethod)(Node*,C), C cookie)
+void Scene::visitNode(Node* node, T* instance, bool (T::*visitMethod)(Node*,C), C cookie)
 {
     // Invoke the visit method for this node.
     if (!(instance->*visitMethod)(node, cookie))
-        return false;
+        return;
 
     // Recurse for all children.
     for (Node* child = node->getFirstChild(); child != NULL; child = child->getNextSibling())
     {
-        if (!visitNode(child, instance, visitMethod, cookie))
-            return false;
+        visitNode(child, instance, visitMethod, cookie);
     }
-
-    return true;
 }
 
-inline bool Scene::visitNode(Node* node, const char* visitMethod)
+inline void Scene::visitNode(Node* node, const char* visitMethod)
 {
+    ScriptController* sc = Game::getInstance()->getScriptController();
+
     // Invoke the visit method for this node.
-    if (!Game::getInstance()->getScriptController()->executeFunction<bool>(visitMethod, "<Node>", node))
-        return false;
+    if (!sc->executeFunction<bool>(visitMethod, "<Node>", node))
+        return;
 
     // Recurse for all children.
     for (Node* child = node->getFirstChild(); child != NULL; child = child->getNextSibling())
     {
-        if (!Game::getInstance()->getScriptController()->executeFunction<bool>(visitMethod, "<Node>", child))
-            return false;
+        visitNode(child, visitMethod);
     }
-
-    return true;
 }
 
 }

+ 12 - 0
gameplay/src/Terrain.cpp

@@ -554,6 +554,18 @@ const Matrix& Terrain::getNormalMatrix() const
     return _normalMatrix;
 }
 
+const Matrix& Terrain::getWorldViewMatrix() const
+{
+    static Matrix worldView;
+
+    if (_node)
+        Matrix::multiply(_node->getViewMatrix(), getWorldMatrix(), &worldView);
+    else
+        worldView = getWorldMatrix(); // no node, so nothing to get view from
+
+    return worldView;
+}
+
 const Matrix& Terrain::getWorldViewProjectionMatrix() const
 {
     static Matrix worldViewProj;

+ 6 - 0
gameplay/src/Terrain.h

@@ -11,6 +11,7 @@ namespace gameplay
 {
 
 class Node;
+class TerrainPatch;
 
 /**
  * Defines a Terrain that is capable of rendering large landscapes from 2D heightmap images.
@@ -350,6 +351,11 @@ private:
      */
     const Matrix& getNormalMatrix() const;
 
+    /**
+     * Returns the world view matrix for the terrain, factoring in terrain local scaling.
+     */
+    const Matrix& getWorldViewMatrix() const;
+
     /**
      * Returns the world view projection matrix for the terrain, factoring in terrain local scaling.
      */