Преглед изворни кода

Merge pull request #509 from blackberry-gaming/next-dgough

Next dgough
Sean Paul Taylor пре 13 година
родитељ
комит
99b0626c5d

+ 7 - 2
CHANGES.md

@@ -3,7 +3,12 @@
 - Pre-built versions gameplay-encoder added to bin folder with TTF, DAE and FBX support built-in.
 - Improved modular shader library with support for #include in shaders.
 - Fixes to FrameBuffer, RenderTarget and DepthStencilTarget.
-- TODO
+- Fixes node cloning.
+- Adds the ability to clone the boy in sample03-character by pressing 'c'.
+- Improvements to gameplay-encoder.
+  - Prompts user for font size if not specified.
+  - Fixes output file path when encoding fonts.
+  - Adds "-g" argument for grouping animations.
 
 ## v1.3.0
 
@@ -12,7 +17,7 @@
 - User Interface support for scrolling with scrollbars on Container.
 - PVRTC, ATC and DXT texture compression support.
 - Performance improvements in user interface forms and text.
-- Performance improvements in animations on transforms.
+- Performance improvements in animations on transforms.
 - Performance improvements using NEON math for BlackBerry and iOS.
 - Fixes for improvements in error handling throughout all systems.
 - Fixes supporting built-in Maya COLLADA exporter via DAE_FBX export.

+ 10 - 0
gameplay/src/Animation.cpp

@@ -450,6 +450,16 @@ Animation* Animation::clone(Channel* channel, AnimationTarget* target)
     // Release the animation because a newly created animation has a ref count of 1 and the channels hold the ref to animation.
     animation->release();
     GP_ASSERT(animation->getRefCount() == 1);
+
+    // Clone the clips
+    if (_clips)
+    {
+        for (std::vector<AnimationClip*>::iterator it = _clips->begin(); it != _clips->end(); ++it)
+        {
+            AnimationClip* newClip = (*it)->clone(animation);
+            animation->addClip(newClip);
+        }
+    }
     return animation;
 }
 

+ 25 - 0
gameplay/src/AnimationClip.cpp

@@ -550,4 +550,29 @@ void AnimationClip::resetClipStateBit(unsigned char bit)
     _stateBits &= ~bit;
 }
 
+AnimationClip* AnimationClip::clone(Animation* animation) const
+{
+    // Don't clone the elapsed time, listeners or crossfade information.
+    AnimationClip* newClip = new AnimationClip(getID(), animation, getStartTime(), getEndTime());
+    newClip->setRepeatCount(getRepeatCount());
+    newClip->setSpeed(getSpeed());
+    newClip->setRepeatCount(getRepeatCount());
+    newClip->setBlendWeight(getBlendWeight());
+    
+    size_t size = _values.size();
+    newClip->_values.resize(size, NULL);
+    for (size_t i = 0; i < size; ++i)
+    {
+        if (newClip->_values[i] == NULL)
+        {
+            newClip->_values[i] = new AnimationValue(*_values[i]);
+        }
+        else
+        {
+            *newClip->_values[i] = *_values[i];
+        }
+    }
+    return newClip;
 }
+
+}

+ 9 - 0
gameplay/src/AnimationClip.h

@@ -310,6 +310,15 @@ private:
      */
     void resetClipStateBit(unsigned char bit);
 
+    /**
+     * Clones the animation clip.
+     * 
+     * @param animation The animation that the new clip belongs to.
+     * 
+     * @return The newly created animation clip.
+     */
+    AnimationClip* clone(Animation* animation) const;
+
     std::string _id;                                    // AnimationClip ID.
     Animation* _animation;                              // The Animation this clip is created from.
     unsigned long _startTime;                           // Start time of the clip.

+ 24 - 0
gameplay/src/AnimationValue.cpp

@@ -11,11 +11,35 @@ AnimationValue::AnimationValue(unsigned int componentCount)
     _value = new float[_componentCount];
 }
 
+AnimationValue::AnimationValue(const AnimationValue& copy)
+{
+    _value = new float[copy._componentCount];
+    _componentSize = copy._componentSize;
+    _componentCount = copy._componentCount;
+    memcpy(_value, copy._value, _componentSize);
+}
+
 AnimationValue::~AnimationValue()
 {
     SAFE_DELETE_ARRAY(_value);
 }
 
+AnimationValue& AnimationValue::operator=(const AnimationValue& v)
+{
+    if (this != &v)
+    {
+        if (_value == NULL || _componentSize != v._componentSize || _componentCount != v._componentCount)
+        {
+            _componentSize = v._componentSize;
+            _componentCount = v._componentCount;
+            SAFE_DELETE_ARRAY(_value);
+            _value = new float[v._componentCount];
+        }
+        memcpy(_value, v._value, _componentSize);
+    }
+    return *this;
+}
+
 float AnimationValue::getFloat(unsigned int index) const
 {
     GP_ASSERT(index < _componentCount);

+ 5 - 0
gameplay/src/AnimationValue.h

@@ -72,6 +72,11 @@ private:
      */
     ~AnimationValue();
 
+    /**
+     * Hidden copy assignment operator.
+     */
+    AnimationValue& operator=(const AnimationValue& v);
+
     unsigned int _componentCount;   // The number of float values for the property.
     unsigned int _componentSize;    // The number of bytes of memory the property is.
     float* _value;                  // The current value of the property.

+ 9 - 1
gameplay/src/MeshSkin.cpp

@@ -79,7 +79,15 @@ MeshSkin* MeshSkin::clone(NodeCloneContext &context) const
             skin->_rootNode = _rootNode->cloneRecursive(context);
         }
         
-        Node* node = skin->_rootNode->findNode(_rootJoint->getId());
+        Node* node = NULL;
+        if (strcmp(skin->_rootNode->getId(), _rootJoint->getId()) == 0)
+        {
+            node = skin->_rootNode;
+        }
+        else
+        {
+            node = skin->_rootNode->findNode(_rootJoint->getId());
+        }
         GP_ASSERT(node);
         skin->_rootJoint = static_cast<Joint*>(node);
         for (unsigned int i = 0; i < jointCount; ++i)

+ 1 - 0
gameplay/src/Scene.cpp

@@ -32,6 +32,7 @@ Scene::~Scene()
 
     // Remove all nodes from the scene
     removeAllNodes();
+    SAFE_DELETE(_debugBatch);
 }
 
 Scene* Scene::createScene()

+ 1 - 0
gameplay/src/Transform.cpp

@@ -853,6 +853,7 @@ void Transform::cloneInto(Transform* transform, NodeCloneContext &context) const
     transform->_scale.set(_scale);
     transform->_rotation.set(_rotation);
     transform->_translation.set(_translation);
+    transform->dirty(DIRTY_TRANSLATION | DIRTY_ROTATION | DIRTY_SCALE);
 }
 
 void Transform::applyAnimationValueRotation(AnimationValue* value, unsigned int index, float blendWeight)