Procházet zdrojové kódy

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

Steve Grenier před 13 roky
rodič
revize
f4b1fa3bfa

+ 1 - 0
CHANGES.md

@@ -15,6 +15,7 @@
 - Fixes Lua print logging.
 - Fixes Lua print logging.
 - Fixes Lua errors to be treated as runtime warnings.
 - Fixes Lua errors to be treated as runtime warnings.
 - Fixes setVertexData to pointers instead of constant data.
 - Fixes setVertexData to pointers instead of constant data.
+- Fixed AudioSource so that it doesn't loop by default.
 
 
 ## v1.4.0
 ## v1.4.0
 
 

+ 1 - 1
gameplay/src/AudioSource.cpp

@@ -10,7 +10,7 @@ namespace gameplay
 {
 {
 
 
 AudioSource::AudioSource(AudioBuffer* buffer, ALuint source) 
 AudioSource::AudioSource(AudioBuffer* buffer, ALuint source) 
-    : _alSource(source), _buffer(buffer), _looped(true), _gain(1.0f), _pitch(1.0f), _node(NULL)
+    : _alSource(source), _buffer(buffer), _looped(false), _gain(1.0f), _pitch(1.0f), _node(NULL)
 {
 {
     GP_ASSERT(buffer);
     GP_ASSERT(buffer);
     AL_CHECK( alSourcei(_alSource, AL_BUFFER, buffer->_alBuffer) );
     AL_CHECK( alSourcei(_alSource, AL_BUFFER, buffer->_alBuffer) );

+ 1 - 1
gameplay/src/Container.cpp

@@ -601,7 +601,7 @@ bool Container::keyEvent(Keyboard::KeyEvent evt, int key)
             if (control->keyEvent(evt, key))
             if (control->keyEvent(evt, key))
             {
             {
                 release();
                 release();
-                return _consumeInputEvents;
+                return true;
             }
             }
             else if (evt == Keyboard::KEY_CHAR && key == Keyboard::KEY_TAB)
             else if (evt == Keyboard::KEY_CHAR && key == Keyboard::KEY_TAB)
             {
             {

+ 6 - 1
gameplay/src/PhysicsVehicle.cpp

@@ -226,6 +226,11 @@ PhysicsRigidBody* PhysicsVehicle::getRigidBody() const
     return _rigidBody;
     return _rigidBody;
 }
 }
 
 
+void PhysicsVehicle::setEnabled(bool enable)
+{
+    getRigidBody()->setEnabled(enable);
+}
+
 unsigned int PhysicsVehicle::getNumWheels() const
 unsigned int PhysicsVehicle::getNumWheels() const
 {
 {
     return _wheels.size();
     return _wheels.size();
@@ -276,7 +281,7 @@ void PhysicsVehicle::update(float elapsedTime, float steering, float braking, fl
     {
     {
         wheel = getWheel(i);
         wheel = getWheel(i);
 
 
-        if (wheel->isFront())
+        if (wheel->isSteerable())
         {
         {
             _vehicle->setSteeringValue(steering * _steeringGain, i);
             _vehicle->setSteeringValue(steering * _steeringGain, i);
         }
         }

+ 13 - 5
gameplay/src/PhysicsVehicle.h

@@ -72,6 +72,14 @@ public:
      */
      */
     PhysicsRigidBody* getRigidBody() const;
     PhysicsRigidBody* getRigidBody() const;
 
 
+    /**
+     * Sets whether the associated rigid body is enabled or disabled
+     * in the physics world.
+     *
+     * @param enable true enables the collision object, false disables it.
+     */
+    void setEnabled(bool enable);
+
     /**
     /**
      * Returns the number of wheels on this vehicle.
      * Returns the number of wheels on this vehicle.
      *
      *
@@ -361,6 +369,11 @@ private:
      */
      */
     void initialize();
     void initialize();
 
 
+    /**
+     * Destructor.
+     */
+    ~PhysicsVehicle();
+
     /**
     /**
      * Returns adjusted steering value.
      * Returns adjusted steering value.
      *
      *
@@ -391,11 +404,6 @@ private:
      */
      */
     void applyDownforce();
     void applyDownforce();
 
 
-    /**
-     * Destructor.
-     */
-    ~PhysicsVehicle();
-
     float _steeringGain;
     float _steeringGain;
     float _brakingForce;
     float _brakingForce;
     float _drivingForce;
     float _drivingForce;

+ 56 - 22
gameplay/src/PhysicsVehicleWheel.cpp

@@ -14,8 +14,6 @@ PhysicsVehicleWheel::PhysicsVehicleWheel(Node* node, const PhysicsCollisionShape
     _rigidBody = new PhysicsRigidBody(node, shape, parameters);
     _rigidBody = new PhysicsRigidBody(node, shape, parameters);
 
 
     findAncestorAndBind();
     findAncestorAndBind();
-
-    _initialOffset = node->getTranslation();
 }
 }
 
 
 PhysicsVehicleWheel::PhysicsVehicleWheel(Node* node, PhysicsRigidBody* rigidBody)
 PhysicsVehicleWheel::PhysicsVehicleWheel(Node* node, PhysicsRigidBody* rigidBody)
@@ -24,8 +22,6 @@ PhysicsVehicleWheel::PhysicsVehicleWheel(Node* node, PhysicsRigidBody* rigidBody
     _rigidBody = rigidBody;
     _rigidBody = rigidBody;
 
 
     findAncestorAndBind();
     findAncestorAndBind();
-
-    _initialOffset = node->getTranslation();
 }
 }
 
 
 PhysicsVehicleWheel* PhysicsVehicleWheel::create(Node* node, Properties* properties)
 PhysicsVehicleWheel* PhysicsVehicleWheel::create(Node* node, Properties* properties)
@@ -41,9 +37,9 @@ PhysicsVehicleWheel* PhysicsVehicleWheel::create(Node* node, Properties* propert
     const char* name;
     const char* name;
     while ((name = properties->getNextProperty()) != NULL)
     while ((name = properties->getNextProperty()) != NULL)
     {
     {
-        if (strcmp(name, "isFront") == 0)
+        if (strcmp(name, "steerable") == 0)
         {
         {
-            wheel->setFront(properties->getBool(name));
+            wheel->setSteerable(properties->getBool(name));
         }
         }
         else if (strcmp(name, "wheelDirection") == 0 && properties->getVector3(name, &v))
         else if (strcmp(name, "wheelDirection") == 0 && properties->getVector3(name, &v))
         {
         {
@@ -53,9 +49,9 @@ PhysicsVehicleWheel* PhysicsVehicleWheel::create(Node* node, Properties* propert
         {
         {
             wheel->setWheelAxle(v);
             wheel->setWheelAxle(v);
         }
         }
-        else if (strcmp(name, "strutConnectionPoint") == 0 && properties->getVector3(name, &v))
+        else if (strcmp(name, "strutConnectionOffset") == 0 && properties->getVector3(name, &v))
         {
         {
-            wheel->setStrutConnectionPoint(v);
+            wheel->setStrutConnectionOffset(v);
         }
         }
         else if (strcmp(name, "strutRestLength") == 0)
         else if (strcmp(name, "strutRestLength") == 0)
         {
         {
@@ -119,6 +115,11 @@ PhysicsCollisionObject::Type PhysicsVehicleWheel::getType() const
     return PhysicsCollisionObject::VEHICLE_WHEEL;
     return PhysicsCollisionObject::VEHICLE_WHEEL;
 }
 }
 
 
+void PhysicsVehicleWheel::setEnabled(bool enable)
+{
+    GP_ERROR("Operation not supported (PhysicsVehicleWheel::setEnabled(bool)). Use host vehicle instead.");
+}
+
 void PhysicsVehicleWheel::findAncestorAndBind()
 void PhysicsVehicleWheel::findAncestorAndBind()
 {
 {
     GP_ASSERT(getNode());
     GP_ASSERT(getNode());
@@ -152,6 +153,7 @@ void PhysicsVehicleWheel::findAncestorAndBind()
     if (host)
     if (host)
     {
     {
         host->addWheel(this);
         host->addWheel(this);
+        _initialOffset = _node->getTranslation() - host->_node->getTranslation();
     }
     }
 }
 }
 
 
@@ -181,18 +183,16 @@ void PhysicsVehicleWheel::addToVehicle(btRaycastVehicle* vehicle)
 void PhysicsVehicleWheel::transform(Node* node) const
 void PhysicsVehicleWheel::transform(Node* node) const
 {
 {
     GP_ASSERT(_host);
     GP_ASSERT(_host);
-    GP_ASSERT(_host->_vehicle);
     GP_ASSERT(_host->_node);
     GP_ASSERT(_host->_node);
 
 
-    const btTransform& trans = _host->_vehicle->getWheelInfo(_indexInHost).m_worldTransform;
-    const btVector3& pos = trans.getOrigin();
     node->setRotation(_orientation);
     node->setRotation(_orientation);
 
 
     // Use only the component parallel to the defined strut line
     // Use only the component parallel to the defined strut line
     Vector3 strutLine;
     Vector3 strutLine;
     getWheelDirection(&strutLine);
     getWheelDirection(&strutLine);
-    Vector3 wheelPos = _initialOffset;
-    _host->_node->getMatrix().transformPoint(&wheelPos);
+    _host->_node->getMatrix().transformVector(&strutLine);
+    Vector3 wheelPos;
+    getWheelPos(&wheelPos);
     node->setTranslation(wheelPos + strutLine*(strutLine.dot(_positionDelta) / strutLine.lengthSquared()));
     node->setTranslation(wheelPos + strutLine*(strutLine.dot(_positionDelta) / strutLine.lengthSquared()));
 }
 }
 
 
@@ -200,7 +200,6 @@ void PhysicsVehicleWheel::update(float elapsedTime)
 {
 {
     GP_ASSERT(_host);
     GP_ASSERT(_host);
     GP_ASSERT(_host->_vehicle);
     GP_ASSERT(_host->_vehicle);
-    GP_ASSERT(_host->_node);
 
 
     const btTransform& trans = _host->_vehicle->getWheelInfo(_indexInHost).m_worldTransform;
     const btTransform& trans = _host->_vehicle->getWheelInfo(_indexInHost).m_worldTransform;
     const btQuaternion& rot = trans.getRotation();
     const btQuaternion& rot = trans.getRotation();
@@ -208,8 +207,8 @@ void PhysicsVehicleWheel::update(float elapsedTime)
     _orientation.set(rot.x(), rot.y(), rot.z(), rot.w());
     _orientation.set(rot.x(), rot.y(), rot.z(), rot.w());
 
 
     Vector3 commandedPosition(pos.x(), pos.y(), pos.z());
     Vector3 commandedPosition(pos.x(), pos.y(), pos.z());
-    Vector3 wheelPos = _initialOffset;
-    _host->_node->getMatrix().transformPoint(&wheelPos);
+    Vector3 wheelPos;
+    getWheelPos(&wheelPos);
     commandedPosition -= wheelPos;
     commandedPosition -= wheelPos;
 
 
     // Filter out noise from Bullet
     // Filter out noise from Bullet
@@ -219,7 +218,35 @@ void PhysicsVehicleWheel::update(float elapsedTime)
     _positionDelta.smooth(commandedPosition, elapsedTime, responseTime);
     _positionDelta.smooth(commandedPosition, elapsedTime, responseTime);
 }
 }
 
 
-bool PhysicsVehicleWheel::isFront() const
+void PhysicsVehicleWheel::getConnectionDefault(Vector3* result) const
+{
+    // projected strut length
+    getWheelDirection(result);
+    result->normalize();
+    float length = 0.58f * getStrutRestLength();
+    *result *= -length;
+
+    // nudge wheel contact point to outer edge of tire for stability
+    Vector3 nudge;
+    getWheelAxle(&nudge);
+    nudge *= nudge.dot(_initialOffset);
+    nudge.normalize();
+    *result += nudge * 0.068f * getWheelRadius(); // rough-in for tire width
+
+    // offset at bind time
+    *result += _initialOffset;
+}
+
+void PhysicsVehicleWheel::getWheelPos(Vector3* result) const
+{
+    GP_ASSERT(_host);
+    GP_ASSERT(_host->_node);
+
+    *result = _initialOffset;
+    _host->_node->getMatrix().transformPoint(result);
+}
+
+bool PhysicsVehicleWheel::isSteerable() const
 {
 {
     GP_ASSERT(_host);
     GP_ASSERT(_host);
     GP_ASSERT(_host->_vehicle);
     GP_ASSERT(_host->_vehicle);
@@ -227,12 +254,12 @@ bool PhysicsVehicleWheel::isFront() const
     return _host->_vehicle->getWheelInfo(_indexInHost).m_bIsFrontWheel;
     return _host->_vehicle->getWheelInfo(_indexInHost).m_bIsFrontWheel;
 }
 }
 
 
-void PhysicsVehicleWheel::setFront(bool front)
+void PhysicsVehicleWheel::setSteerable(bool steerable)
 {
 {
     GP_ASSERT(_host);
     GP_ASSERT(_host);
     GP_ASSERT(_host->_vehicle);
     GP_ASSERT(_host->_vehicle);
 
 
-    _host->_vehicle->getWheelInfo(_indexInHost).m_bIsFrontWheel = front;
+    _host->_vehicle->getWheelInfo(_indexInHost).m_bIsFrontWheel = steerable;
 }
 }
 
 
 void PhysicsVehicleWheel::getWheelDirection(Vector3* wheelDirection) const
 void PhysicsVehicleWheel::getWheelDirection(Vector3* wheelDirection) const
@@ -269,19 +296,26 @@ void PhysicsVehicleWheel::setWheelAxle(const Vector3& wheelAxle)
     _host->_vehicle->getWheelInfo(_indexInHost).m_wheelAxleCS.setValue( wheelAxle.x, wheelAxle.y, wheelAxle.z);
     _host->_vehicle->getWheelInfo(_indexInHost).m_wheelAxleCS.setValue( wheelAxle.x, wheelAxle.y, wheelAxle.z);
 }
 }
 
 
-void PhysicsVehicleWheel::getStrutConnectionPoint(Vector3* strutConnectionPoint) const
+void PhysicsVehicleWheel::getStrutConnectionOffset(Vector3* strutConnectionOffset) const
 {
 {
     GP_ASSERT(_host);
     GP_ASSERT(_host);
     GP_ASSERT(_host->_vehicle);
     GP_ASSERT(_host->_vehicle);
 
 
     const btVector3& v = _host->_vehicle->getWheelInfo(_indexInHost).m_chassisConnectionPointCS;
     const btVector3& v = _host->_vehicle->getWheelInfo(_indexInHost).m_chassisConnectionPointCS;
-    strutConnectionPoint->set(v.x(), v.y(), v.z());
+    strutConnectionOffset->set(v.x(), v.y(), v.z());
+    Vector3 strutConnectionDefault;
+    getConnectionDefault(&strutConnectionDefault);
+    *strutConnectionOffset -= strutConnectionDefault;
 }
 }
 
 
-void PhysicsVehicleWheel::setStrutConnectionPoint(const Vector3& strutConnectionPoint)
+void PhysicsVehicleWheel::setStrutConnectionOffset(const Vector3& strutConnectionOffset)
 {
 {
     GP_ASSERT(_host);
     GP_ASSERT(_host);
     GP_ASSERT(_host->_vehicle);
     GP_ASSERT(_host->_vehicle);
+
+    Vector3 strutConnectionPoint;
+    getConnectionDefault(&strutConnectionPoint);
+    strutConnectionPoint += strutConnectionOffset;
     _host->_vehicle->getWheelInfo(_indexInHost).m_chassisConnectionPointCS.setValue(strutConnectionPoint.x,
     _host->_vehicle->getWheelInfo(_indexInHost).m_chassisConnectionPointCS.setValue(strutConnectionPoint.x,
                                                                                     strutConnectionPoint.y,
                                                                                     strutConnectionPoint.y,
                                                                                     strutConnectionPoint.z);
                                                                                     strutConnectionPoint.z);

+ 54 - 14
gameplay/src/PhysicsVehicleWheel.h

@@ -21,10 +21,10 @@ class PhysicsVehicle;
     {
     {
         type                     = VEHICLE_WHEEL
         type                     = VEHICLE_WHEEL
 
 
-        isFront                  = <bool>                // indicates whether this is a front wheel
+        steerable                = <bool>                // indicates whether wheel is steerable
         wheelDirection           = <float, float, float> // direction strut extension, in chassis space
         wheelDirection           = <float, float, float> // direction strut extension, in chassis space
         wheelAxle                = <float, float, float> // direction of axle (spin axis), in chassis space
         wheelAxle                = <float, float, float> // direction of axle (spin axis), in chassis space
-        strutConnectionPoint     = <float, float, float> // strut connection point, in chassis space
+        strutConnectionOffset    = <float, float, float> // offset from default strut connection point
         strutRestLength          = <float>               // strut rest length
         strutRestLength          = <float>               // strut rest length
         strutTravelMax           = <float>               // maximum strut travel
         strutTravelMax           = <float>               // maximum strut travel
         strutStiffness           = <float>               // strut stiffness, normalized to chassis mass
         strutStiffness           = <float>               // strut stiffness, normalized to chassis mass
@@ -50,6 +50,11 @@ public:
      */
      */
     PhysicsCollisionObject::Type getType() const;
     PhysicsCollisionObject::Type getType() const;
 
 
+    /**
+     * Operation not supported. Use host vehicle's setEnabled() instead.
+     */
+    void setEnabled(bool enable);
+
     /**
     /**
      * Apply this wheel's world transform to the specified node.
      * Apply this wheel's world transform to the specified node.
      * Useful for updating the specified visual node with the current
      * Useful for updating the specified visual node with the current
@@ -61,18 +66,18 @@ public:
     void transform(Node* node) const;
     void transform(Node* node) const;
 
 
     /**
     /**
-     * Returns true if this is a front wheel, false otherwise.
+     * Returns true if this wheel is steerable, false otherwise.
      *
      *
-     * @return true if this is a front wheel, false otherwise.
+     * @return true if this wheel is steerable, false otherwise.
      */
      */
-    bool isFront() const;
+    bool isSteerable() const;
 
 
     /**
     /**
-     * Sets whether this is a front wheel.
+     * Sets whether this wheel is steerable.
      *
      *
-     * @param front true if this is a front wheel, false otherwise.
+     * @param steerable true if this wheel is steerable, false otherwise.
      */
      */
-    void setFront(bool front);
+    void setSteerable(bool steerable);
 
 
     /**
     /**
      * Gets direction of strut extension, in chassis space.
      * Gets direction of strut extension, in chassis space.
@@ -103,18 +108,33 @@ public:
     void setWheelAxle(const Vector3& wheelAxle);
     void setWheelAxle(const Vector3& wheelAxle);
 
 
     /**
     /**
-     * Gets strut connection point, in chassis space.
+     * Gets offset from the default strut connection point.
+     * The default strut connection point is determined from the position
+     * of the wheel node relative to the chassis node, and uses the
+     * specified value for strut rest length to locate the connection
+     * point above it (i.e., in the specified direction of strut
+     * compression).
+     * Any non-zero strut connection offset acts as a delta from the
+     * computed default.
      *
      *
-     * @param strutConnectionPoint address of where to store the result.
+     * @param strutConnectionOffset address of where to store the result.
      */
      */
-    void getStrutConnectionPoint(Vector3* strutConnectionPoint) const;
+    void getStrutConnectionOffset(Vector3* strutConnectionOffset) const;
 
 
     /**
     /**
-     * Sets strut connection point, in chassis space.
+     * Sets offset from the default strut connection point.
+     * The default strut connection point is determined from the position
+     * of the wheel node relative to the chassis node, and uses the
+     * specified value for strut rest length to locate the connection
+     * point above it (i.e., in the specified direction of strut
+     * compression).
+     * Any non-zero strutConnectionOffset acts as a delta from the
+     * computed default.
      *
      *
-     * @param strutConnectionPoint strut connection point.
+     * @param strutConnectionOffset offset from the default strut connection
+     *     point.
      */
      */
-    void setStrutConnectionPoint(const Vector3& strutConnectionPoint);
+    void setStrutConnectionOffset(const Vector3& strutConnectionOffset);
 
 
     /**
     /**
      * Gets the strut rest length.
      * Gets the strut rest length.
@@ -333,6 +353,26 @@ private:
      */
      */
     void update(float elapsedTime);
     void update(float elapsedTime);
 
 
+    /**
+     * Computes the default strut connection point for
+     * this wheel.
+     * The default strut connection point is determined from the position
+     * of the wheel node relative to the chassis node, and uses the
+     * specified value for maximum strut travel to locate the connection
+     * point above it (i.e., in the specified direction of strut
+     * compression).
+     *
+     * @param result where to store the result.
+     */
+    void getConnectionDefault(Vector3* result) const;
+
+    /**
+     * Get wheel position at bind time relative to chassis.
+     *
+     * @param result where to store the result.
+     */
+    void getWheelPos(Vector3* result) const;
+
     PhysicsRigidBody* _rigidBody;
     PhysicsRigidBody* _rigidBody;
     PhysicsVehicle* _host;
     PhysicsVehicle* _host;
     unsigned int _indexInHost;
     unsigned int _indexInHost;

+ 2 - 1
gameplay/src/PlatformQNX.cpp

@@ -1077,7 +1077,8 @@ int Platform::enterMessagePump()
                         break;
                         break;
                     case NAVIGATOR_WINDOW_THUMBNAIL:
                     case NAVIGATOR_WINDOW_THUMBNAIL:
                     case NAVIGATOR_WINDOW_INVISIBLE:
                     case NAVIGATOR_WINDOW_INVISIBLE:
-                        _game->pause();
+                        if (!suspended)
+                            _game->pause();
                         suspended = true;
                         suspended = true;
                         break;
                         break;
                     }
                     }

+ 44 - 13
gameplay/src/TextBox.cpp

@@ -64,8 +64,8 @@ bool TextBox::touchEvent(Touch::TouchEvent evt, int x, int y, unsigned int conta
 
 
             if (_state == NORMAL)
             if (_state == NORMAL)
                 Game::getInstance()->displayKeyboard(true);
                 Game::getInstance()->displayKeyboard(true);
-            else
-                setCaretLocation(x, y);
+
+            setCaretLocation(x, y);
 
 
             _state = ACTIVE;
             _state = ACTIVE;
             _dirty = true;
             _dirty = true;
@@ -110,8 +110,6 @@ bool TextBox::touchEvent(Touch::TouchEvent evt, int x, int y, unsigned int conta
 
 
 bool TextBox::keyEvent(Keyboard::KeyEvent evt, int key)
 bool TextBox::keyEvent(Keyboard::KeyEvent evt, int key)
 {
 {
-    bool consume = false;
-
     if (_state == FOCUS)
     if (_state == FOCUS)
     {
     {
         switch (evt)
         switch (evt)
@@ -149,7 +147,6 @@ bool TextBox::keyEvent(Keyboard::KeyEvent evt, int key)
                         font->getLocationAtIndex(_text.c_str(), _textBounds, fontSize, &_caretLocation, textIndex,
                         font->getLocationAtIndex(_text.c_str(), _textBounds, fontSize, &_caretLocation, textIndex,
                             textAlignment, true, rightToLeft);
                             textAlignment, true, rightToLeft);
                         _dirty = true;
                         _dirty = true;
-                        consume = true;
                         notifyListeners(Listener::TEXT_CHANGED);
                         notifyListeners(Listener::TEXT_CHANGED);
                         break;
                         break;
                     }
                     }
@@ -166,7 +163,6 @@ bool TextBox::keyEvent(Keyboard::KeyEvent evt, int key)
                         font->getLocationAtIndex(_text.c_str(), _textBounds, fontSize, &_caretLocation, textIndex - 1,
                         font->getLocationAtIndex(_text.c_str(), _textBounds, fontSize, &_caretLocation, textIndex - 1,
                             textAlignment, true, rightToLeft);
                             textAlignment, true, rightToLeft);
                         _dirty = true;
                         _dirty = true;
-                        consume = true;
                         break;
                         break;
                     }
                     }
                     case Keyboard::KEY_RIGHT_ARROW:
                     case Keyboard::KEY_RIGHT_ARROW:
@@ -182,7 +178,6 @@ bool TextBox::keyEvent(Keyboard::KeyEvent evt, int key)
                         font->getLocationAtIndex(_text.c_str(), _textBounds, fontSize, &_caretLocation, textIndex + 1,
                         font->getLocationAtIndex(_text.c_str(), _textBounds, fontSize, &_caretLocation, textIndex + 1,
                             textAlignment, true, rightToLeft);
                             textAlignment, true, rightToLeft);
                         _dirty = true;
                         _dirty = true;
-                        consume = true;
                         break;
                         break;
                     }
                     }
                     case Keyboard::KEY_UP_ARROW:
                     case Keyboard::KEY_UP_ARROW:
@@ -202,7 +197,6 @@ bool TextBox::keyEvent(Keyboard::KeyEvent evt, int key)
                         }
                         }
 
 
                         _dirty = true;
                         _dirty = true;
-                        consume = true;
                         break;
                         break;
                     }
                     }
                     case Keyboard::KEY_DOWN_ARROW:
                     case Keyboard::KEY_DOWN_ARROW:
@@ -222,7 +216,6 @@ bool TextBox::keyEvent(Keyboard::KeyEvent evt, int key)
                         }
                         }
 
 
                         _dirty = true;
                         _dirty = true;
-                        consume = true;
                         break;
                         break;
                     }
                     }
                 }
                 }
@@ -259,7 +252,6 @@ bool TextBox::keyEvent(Keyboard::KeyEvent evt, int key)
 
 
                             _dirty = true;
                             _dirty = true;
                         }
                         }
-                        consume = true;
                         break;
                         break;
                     }
                     }
                     case Keyboard::KEY_RETURN:
                     case Keyboard::KEY_RETURN:
@@ -273,7 +265,6 @@ bool TextBox::keyEvent(Keyboard::KeyEvent evt, int key)
                     {
                     {
                         // Insert character into string.
                         // Insert character into string.
                         _text.insert(textIndex, 1, (char)key);
                         _text.insert(textIndex, 1, (char)key);
-                        consume = true;
 
 
                         // Get new location of caret.
                         // Get new location of caret.
                         font->getLocationAtIndex(_text.c_str(), _textBounds, fontSize, &_caretLocation, textIndex + 1,
                         font->getLocationAtIndex(_text.c_str(), _textBounds, fontSize, &_caretLocation, textIndex + 1,
@@ -325,7 +316,7 @@ bool TextBox::keyEvent(Keyboard::KeyEvent evt, int key)
 
 
     _lastKeypress = key;
     _lastKeypress = key;
 
 
-    return (consume & _consumeInputEvents);
+    return _consumeInputEvents;
 }
 }
 
 
 void TextBox::update(const Control* container, const Vector2& offset)
 void TextBox::update(const Control* container, const Vector2& offset)
@@ -374,7 +365,47 @@ void TextBox::setCaretLocation(int x, int y)
 
 
     if (index == -1)
     if (index == -1)
     {
     {
-        _caretLocation.set(_prevCaretLocation);
+        // Attempt to find the nearest valid caret location.
+        Rectangle textBounds;
+        font->measureText(_text.c_str(), _textBounds, fontSize, &textBounds, textAlignment, true, true);
+
+        if (_caretLocation.x > textBounds.x + textBounds.width &&
+            _caretLocation.y > textBounds.y + textBounds.height)
+        {
+            font->getLocationAtIndex(_text.c_str(), _textBounds, fontSize, &_caretLocation, _text.length(),
+                textAlignment, true, rightToLeft);
+            return;
+        }
+
+        if (_caretLocation.x < textBounds.x)
+        {
+            _caretLocation.x = textBounds.x;
+        }
+        else if (_caretLocation.x > textBounds.x + textBounds.width)
+        {
+            _caretLocation.x = textBounds.x + textBounds.width;
+        }
+
+        if (_caretLocation.y < textBounds.y)
+        {
+            _caretLocation.y = textBounds.y;
+        }
+        else if (_caretLocation.y > textBounds.y + textBounds.height)
+        {
+            Font* font = getFont(_state);
+            GP_ASSERT(font);
+            unsigned int fontSize = getFontSize(_state);
+            _caretLocation.y = textBounds.y + textBounds.height - fontSize;
+        }
+
+        index = font->getIndexAtLocation(_text.c_str(), _textBounds, fontSize, _caretLocation, &_caretLocation,
+            textAlignment, true, rightToLeft);
+
+        if (index == -1)
+        {
+            // We failed to find a valid location; just put the caret back to where it was.
+            _caretLocation.set(_prevCaretLocation);
+        }
     }
     }
 }
 }
 
 

+ 26 - 26
gameplay/src/lua/lua_PhysicsVehicleWheel.cpp

@@ -27,7 +27,7 @@ void luaRegister_PhysicsVehicleWheel()
         {"getNode", lua_PhysicsVehicleWheel_getNode},
         {"getNode", lua_PhysicsVehicleWheel_getNode},
         {"getRollInfluence", lua_PhysicsVehicleWheel_getRollInfluence},
         {"getRollInfluence", lua_PhysicsVehicleWheel_getRollInfluence},
         {"getShapeType", lua_PhysicsVehicleWheel_getShapeType},
         {"getShapeType", lua_PhysicsVehicleWheel_getShapeType},
-        {"getStrutConnectionPoint", lua_PhysicsVehicleWheel_getStrutConnectionPoint},
+        {"getStrutConnectionOffset", lua_PhysicsVehicleWheel_getStrutConnectionOffset},
         {"getStrutDampingCompression", lua_PhysicsVehicleWheel_getStrutDampingCompression},
         {"getStrutDampingCompression", lua_PhysicsVehicleWheel_getStrutDampingCompression},
         {"getStrutDampingRelaxation", lua_PhysicsVehicleWheel_getStrutDampingRelaxation},
         {"getStrutDampingRelaxation", lua_PhysicsVehicleWheel_getStrutDampingRelaxation},
         {"getStrutForceMax", lua_PhysicsVehicleWheel_getStrutForceMax},
         {"getStrutForceMax", lua_PhysicsVehicleWheel_getStrutForceMax},
@@ -40,14 +40,14 @@ void luaRegister_PhysicsVehicleWheel()
         {"getWheelRadius", lua_PhysicsVehicleWheel_getWheelRadius},
         {"getWheelRadius", lua_PhysicsVehicleWheel_getWheelRadius},
         {"isDynamic", lua_PhysicsVehicleWheel_isDynamic},
         {"isDynamic", lua_PhysicsVehicleWheel_isDynamic},
         {"isEnabled", lua_PhysicsVehicleWheel_isEnabled},
         {"isEnabled", lua_PhysicsVehicleWheel_isEnabled},
-        {"isFront", lua_PhysicsVehicleWheel_isFront},
         {"isKinematic", lua_PhysicsVehicleWheel_isKinematic},
         {"isKinematic", lua_PhysicsVehicleWheel_isKinematic},
+        {"isSteerable", lua_PhysicsVehicleWheel_isSteerable},
         {"removeCollisionListener", lua_PhysicsVehicleWheel_removeCollisionListener},
         {"removeCollisionListener", lua_PhysicsVehicleWheel_removeCollisionListener},
         {"setEnabled", lua_PhysicsVehicleWheel_setEnabled},
         {"setEnabled", lua_PhysicsVehicleWheel_setEnabled},
         {"setFrictionBreakout", lua_PhysicsVehicleWheel_setFrictionBreakout},
         {"setFrictionBreakout", lua_PhysicsVehicleWheel_setFrictionBreakout},
-        {"setFront", lua_PhysicsVehicleWheel_setFront},
         {"setRollInfluence", lua_PhysicsVehicleWheel_setRollInfluence},
         {"setRollInfluence", lua_PhysicsVehicleWheel_setRollInfluence},
-        {"setStrutConnectionPoint", lua_PhysicsVehicleWheel_setStrutConnectionPoint},
+        {"setSteerable", lua_PhysicsVehicleWheel_setSteerable},
+        {"setStrutConnectionOffset", lua_PhysicsVehicleWheel_setStrutConnectionOffset},
         {"setStrutDampingCompression", lua_PhysicsVehicleWheel_setStrutDampingCompression},
         {"setStrutDampingCompression", lua_PhysicsVehicleWheel_setStrutDampingCompression},
         {"setStrutDampingRelaxation", lua_PhysicsVehicleWheel_setStrutDampingRelaxation},
         {"setStrutDampingRelaxation", lua_PhysicsVehicleWheel_setStrutDampingRelaxation},
         {"setStrutForceMax", lua_PhysicsVehicleWheel_setStrutForceMax},
         {"setStrutForceMax", lua_PhysicsVehicleWheel_setStrutForceMax},
@@ -405,7 +405,7 @@ int lua_PhysicsVehicleWheel_getShapeType(lua_State* state)
     return 0;
     return 0;
 }
 }
 
 
-int lua_PhysicsVehicleWheel_getStrutConnectionPoint(lua_State* state)
+int lua_PhysicsVehicleWheel_getStrutConnectionOffset(lua_State* state)
 {
 {
     // Get the number of parameters.
     // Get the number of parameters.
     int paramCount = lua_gettop(state);
     int paramCount = lua_gettop(state);
@@ -422,13 +422,13 @@ int lua_PhysicsVehicleWheel_getStrutConnectionPoint(lua_State* state)
                 ScriptUtil::LuaArray<Vector3> param1 = ScriptUtil::getObjectPointer<Vector3>(2, "Vector3", false);
                 ScriptUtil::LuaArray<Vector3> param1 = ScriptUtil::getObjectPointer<Vector3>(2, "Vector3", false);
 
 
                 PhysicsVehicleWheel* instance = getInstance(state);
                 PhysicsVehicleWheel* instance = getInstance(state);
-                instance->getStrutConnectionPoint(param1);
+                instance->getStrutConnectionOffset(param1);
                 
                 
                 return 0;
                 return 0;
             }
             }
             else
             else
             {
             {
-                lua_pushstring(state, "lua_PhysicsVehicleWheel_getStrutConnectionPoint - Failed to match the given parameters to a valid function signature.");
+                lua_pushstring(state, "lua_PhysicsVehicleWheel_getStrutConnectionOffset - Failed to match the given parameters to a valid function signature.");
                 lua_error(state);
                 lua_error(state);
             }
             }
             break;
             break;
@@ -889,7 +889,7 @@ int lua_PhysicsVehicleWheel_isEnabled(lua_State* state)
     return 0;
     return 0;
 }
 }
 
 
-int lua_PhysicsVehicleWheel_isFront(lua_State* state)
+int lua_PhysicsVehicleWheel_isKinematic(lua_State* state)
 {
 {
     // Get the number of parameters.
     // Get the number of parameters.
     int paramCount = lua_gettop(state);
     int paramCount = lua_gettop(state);
@@ -902,7 +902,7 @@ int lua_PhysicsVehicleWheel_isFront(lua_State* state)
             if ((lua_type(state, 1) == LUA_TUSERDATA))
             if ((lua_type(state, 1) == LUA_TUSERDATA))
             {
             {
                 PhysicsVehicleWheel* instance = getInstance(state);
                 PhysicsVehicleWheel* instance = getInstance(state);
-                bool result = instance->isFront();
+                bool result = instance->isKinematic();
 
 
                 // Push the return value onto the stack.
                 // Push the return value onto the stack.
                 lua_pushboolean(state, result);
                 lua_pushboolean(state, result);
@@ -911,7 +911,7 @@ int lua_PhysicsVehicleWheel_isFront(lua_State* state)
             }
             }
             else
             else
             {
             {
-                lua_pushstring(state, "lua_PhysicsVehicleWheel_isFront - Failed to match the given parameters to a valid function signature.");
+                lua_pushstring(state, "lua_PhysicsVehicleWheel_isKinematic - Failed to match the given parameters to a valid function signature.");
                 lua_error(state);
                 lua_error(state);
             }
             }
             break;
             break;
@@ -926,7 +926,7 @@ int lua_PhysicsVehicleWheel_isFront(lua_State* state)
     return 0;
     return 0;
 }
 }
 
 
-int lua_PhysicsVehicleWheel_isKinematic(lua_State* state)
+int lua_PhysicsVehicleWheel_isSteerable(lua_State* state)
 {
 {
     // Get the number of parameters.
     // Get the number of parameters.
     int paramCount = lua_gettop(state);
     int paramCount = lua_gettop(state);
@@ -939,7 +939,7 @@ int lua_PhysicsVehicleWheel_isKinematic(lua_State* state)
             if ((lua_type(state, 1) == LUA_TUSERDATA))
             if ((lua_type(state, 1) == LUA_TUSERDATA))
             {
             {
                 PhysicsVehicleWheel* instance = getInstance(state);
                 PhysicsVehicleWheel* instance = getInstance(state);
-                bool result = instance->isKinematic();
+                bool result = instance->isSteerable();
 
 
                 // Push the return value onto the stack.
                 // Push the return value onto the stack.
                 lua_pushboolean(state, result);
                 lua_pushboolean(state, result);
@@ -948,7 +948,7 @@ int lua_PhysicsVehicleWheel_isKinematic(lua_State* state)
             }
             }
             else
             else
             {
             {
-                lua_pushstring(state, "lua_PhysicsVehicleWheel_isKinematic - Failed to match the given parameters to a valid function signature.");
+                lua_pushstring(state, "lua_PhysicsVehicleWheel_isSteerable - Failed to match the given parameters to a valid function signature.");
                 lua_error(state);
                 lua_error(state);
             }
             }
             break;
             break;
@@ -1127,7 +1127,7 @@ int lua_PhysicsVehicleWheel_setFrictionBreakout(lua_State* state)
     return 0;
     return 0;
 }
 }
 
 
-int lua_PhysicsVehicleWheel_setFront(lua_State* state)
+int lua_PhysicsVehicleWheel_setRollInfluence(lua_State* state)
 {
 {
     // Get the number of parameters.
     // Get the number of parameters.
     int paramCount = lua_gettop(state);
     int paramCount = lua_gettop(state);
@@ -1138,19 +1138,19 @@ int lua_PhysicsVehicleWheel_setFront(lua_State* state)
         case 2:
         case 2:
         {
         {
             if ((lua_type(state, 1) == LUA_TUSERDATA) &&
             if ((lua_type(state, 1) == LUA_TUSERDATA) &&
-                lua_type(state, 2) == LUA_TBOOLEAN)
+                lua_type(state, 2) == LUA_TNUMBER)
             {
             {
                 // Get parameter 1 off the stack.
                 // Get parameter 1 off the stack.
-                bool param1 = ScriptUtil::luaCheckBool(state, 2);
+                float param1 = (float)luaL_checknumber(state, 2);
 
 
                 PhysicsVehicleWheel* instance = getInstance(state);
                 PhysicsVehicleWheel* instance = getInstance(state);
-                instance->setFront(param1);
+                instance->setRollInfluence(param1);
                 
                 
                 return 0;
                 return 0;
             }
             }
             else
             else
             {
             {
-                lua_pushstring(state, "lua_PhysicsVehicleWheel_setFront - Failed to match the given parameters to a valid function signature.");
+                lua_pushstring(state, "lua_PhysicsVehicleWheel_setRollInfluence - Failed to match the given parameters to a valid function signature.");
                 lua_error(state);
                 lua_error(state);
             }
             }
             break;
             break;
@@ -1165,7 +1165,7 @@ int lua_PhysicsVehicleWheel_setFront(lua_State* state)
     return 0;
     return 0;
 }
 }
 
 
-int lua_PhysicsVehicleWheel_setRollInfluence(lua_State* state)
+int lua_PhysicsVehicleWheel_setSteerable(lua_State* state)
 {
 {
     // Get the number of parameters.
     // Get the number of parameters.
     int paramCount = lua_gettop(state);
     int paramCount = lua_gettop(state);
@@ -1176,19 +1176,19 @@ int lua_PhysicsVehicleWheel_setRollInfluence(lua_State* state)
         case 2:
         case 2:
         {
         {
             if ((lua_type(state, 1) == LUA_TUSERDATA) &&
             if ((lua_type(state, 1) == LUA_TUSERDATA) &&
-                lua_type(state, 2) == LUA_TNUMBER)
+                lua_type(state, 2) == LUA_TBOOLEAN)
             {
             {
                 // Get parameter 1 off the stack.
                 // Get parameter 1 off the stack.
-                float param1 = (float)luaL_checknumber(state, 2);
+                bool param1 = ScriptUtil::luaCheckBool(state, 2);
 
 
                 PhysicsVehicleWheel* instance = getInstance(state);
                 PhysicsVehicleWheel* instance = getInstance(state);
-                instance->setRollInfluence(param1);
+                instance->setSteerable(param1);
                 
                 
                 return 0;
                 return 0;
             }
             }
             else
             else
             {
             {
-                lua_pushstring(state, "lua_PhysicsVehicleWheel_setRollInfluence - Failed to match the given parameters to a valid function signature.");
+                lua_pushstring(state, "lua_PhysicsVehicleWheel_setSteerable - Failed to match the given parameters to a valid function signature.");
                 lua_error(state);
                 lua_error(state);
             }
             }
             break;
             break;
@@ -1203,7 +1203,7 @@ int lua_PhysicsVehicleWheel_setRollInfluence(lua_State* state)
     return 0;
     return 0;
 }
 }
 
 
-int lua_PhysicsVehicleWheel_setStrutConnectionPoint(lua_State* state)
+int lua_PhysicsVehicleWheel_setStrutConnectionOffset(lua_State* state)
 {
 {
     // Get the number of parameters.
     // Get the number of parameters.
     int paramCount = lua_gettop(state);
     int paramCount = lua_gettop(state);
@@ -1220,13 +1220,13 @@ int lua_PhysicsVehicleWheel_setStrutConnectionPoint(lua_State* state)
                 ScriptUtil::LuaArray<Vector3> param1 = ScriptUtil::getObjectPointer<Vector3>(2, "Vector3", true);
                 ScriptUtil::LuaArray<Vector3> param1 = ScriptUtil::getObjectPointer<Vector3>(2, "Vector3", true);
 
 
                 PhysicsVehicleWheel* instance = getInstance(state);
                 PhysicsVehicleWheel* instance = getInstance(state);
-                instance->setStrutConnectionPoint(*param1);
+                instance->setStrutConnectionOffset(*param1);
                 
                 
                 return 0;
                 return 0;
             }
             }
             else
             else
             {
             {
-                lua_pushstring(state, "lua_PhysicsVehicleWheel_setStrutConnectionPoint - Failed to match the given parameters to a valid function signature.");
+                lua_pushstring(state, "lua_PhysicsVehicleWheel_setStrutConnectionOffset - Failed to match the given parameters to a valid function signature.");
                 lua_error(state);
                 lua_error(state);
             }
             }
             break;
             break;

+ 4 - 4
gameplay/src/lua/lua_PhysicsVehicleWheel.h

@@ -12,7 +12,7 @@ int lua_PhysicsVehicleWheel_getFrictionBreakout(lua_State* state);
 int lua_PhysicsVehicleWheel_getNode(lua_State* state);
 int lua_PhysicsVehicleWheel_getNode(lua_State* state);
 int lua_PhysicsVehicleWheel_getRollInfluence(lua_State* state);
 int lua_PhysicsVehicleWheel_getRollInfluence(lua_State* state);
 int lua_PhysicsVehicleWheel_getShapeType(lua_State* state);
 int lua_PhysicsVehicleWheel_getShapeType(lua_State* state);
-int lua_PhysicsVehicleWheel_getStrutConnectionPoint(lua_State* state);
+int lua_PhysicsVehicleWheel_getStrutConnectionOffset(lua_State* state);
 int lua_PhysicsVehicleWheel_getStrutDampingCompression(lua_State* state);
 int lua_PhysicsVehicleWheel_getStrutDampingCompression(lua_State* state);
 int lua_PhysicsVehicleWheel_getStrutDampingRelaxation(lua_State* state);
 int lua_PhysicsVehicleWheel_getStrutDampingRelaxation(lua_State* state);
 int lua_PhysicsVehicleWheel_getStrutForceMax(lua_State* state);
 int lua_PhysicsVehicleWheel_getStrutForceMax(lua_State* state);
@@ -25,14 +25,14 @@ int lua_PhysicsVehicleWheel_getWheelDirection(lua_State* state);
 int lua_PhysicsVehicleWheel_getWheelRadius(lua_State* state);
 int lua_PhysicsVehicleWheel_getWheelRadius(lua_State* state);
 int lua_PhysicsVehicleWheel_isDynamic(lua_State* state);
 int lua_PhysicsVehicleWheel_isDynamic(lua_State* state);
 int lua_PhysicsVehicleWheel_isEnabled(lua_State* state);
 int lua_PhysicsVehicleWheel_isEnabled(lua_State* state);
-int lua_PhysicsVehicleWheel_isFront(lua_State* state);
 int lua_PhysicsVehicleWheel_isKinematic(lua_State* state);
 int lua_PhysicsVehicleWheel_isKinematic(lua_State* state);
+int lua_PhysicsVehicleWheel_isSteerable(lua_State* state);
 int lua_PhysicsVehicleWheel_removeCollisionListener(lua_State* state);
 int lua_PhysicsVehicleWheel_removeCollisionListener(lua_State* state);
 int lua_PhysicsVehicleWheel_setEnabled(lua_State* state);
 int lua_PhysicsVehicleWheel_setEnabled(lua_State* state);
 int lua_PhysicsVehicleWheel_setFrictionBreakout(lua_State* state);
 int lua_PhysicsVehicleWheel_setFrictionBreakout(lua_State* state);
-int lua_PhysicsVehicleWheel_setFront(lua_State* state);
 int lua_PhysicsVehicleWheel_setRollInfluence(lua_State* state);
 int lua_PhysicsVehicleWheel_setRollInfluence(lua_State* state);
-int lua_PhysicsVehicleWheel_setStrutConnectionPoint(lua_State* state);
+int lua_PhysicsVehicleWheel_setSteerable(lua_State* state);
+int lua_PhysicsVehicleWheel_setStrutConnectionOffset(lua_State* state);
 int lua_PhysicsVehicleWheel_setStrutDampingCompression(lua_State* state);
 int lua_PhysicsVehicleWheel_setStrutDampingCompression(lua_State* state);
 int lua_PhysicsVehicleWheel_setStrutDampingRelaxation(lua_State* state);
 int lua_PhysicsVehicleWheel_setStrutDampingRelaxation(lua_State* state);
 int lua_PhysicsVehicleWheel_setStrutForceMax(lua_State* state);
 int lua_PhysicsVehicleWheel_setStrutForceMax(lua_State* state);