Bläddra i källkod

Merge pull request #84 from blackberry-gaming/next-kcunney

Next kcunney
Sean Paul Taylor 14 år sedan
förälder
incheckning
7f221aed38

+ 2 - 1
gameplay/gameplay.vcxproj

@@ -173,7 +173,8 @@
     <None Include="res\textures\particle-default.png" />
     <None Include="res\textures\particle-default.png" />
     <None Include="src\BoundingBox.inl" />
     <None Include="src\BoundingBox.inl" />
     <None Include="src\BoundingSphere.inl" />
     <None Include="src\BoundingSphere.inl" />
-    <None Include="src\Game.inl" />
+    <None Include="src\Curve.inl" />
+    <None Include="src\Game.inl" />
     <None Include="src\gameplay-main-macos.mm" />
     <None Include="src\gameplay-main-macos.mm" />
     <None Include="src\Image.inl" />
     <None Include="src\Image.inl" />
     <None Include="src\Matrix.inl" />
     <None Include="src\Matrix.inl" />

+ 3 - 0
gameplay/gameplay.vcxproj.filters

@@ -481,6 +481,9 @@
     <None Include="res\textures\particle-default.png">
     <None Include="res\textures\particle-default.png">
       <Filter>res\textures</Filter>
       <Filter>res\textures</Filter>
     </None>
     </None>
+    <None Include="src\Curve.inl">
+        <Filter>src</Filter>
+    </None>
     <None Include="src\Game.inl">
     <None Include="src\Game.inl">
       <Filter>src</Filter>
       <Filter>src</Filter>
     </None>
     </None>

+ 88 - 93
gameplay/src/Animation.cpp

@@ -7,7 +7,6 @@
 #include "Transform.h"
 #include "Transform.h"
 #include "Properties.h"
 #include "Properties.h"
 
 
-#define ANIMATION_DEFAULT_CLIP_SUFFIX "__default__clip"
 #define ANIMATION_INDEFINITE_STR "INDEFINITE"
 #define ANIMATION_INDEFINITE_STR "INDEFINITE"
 #define ANIMATION_DEFAULT_CLIP 0
 #define ANIMATION_DEFAULT_CLIP 0
 #define ANIMATION_ROTATE_OFFSET 0
 #define ANIMATION_ROTATE_OFFSET 0
@@ -30,7 +29,13 @@ Animation::Animation(const char* id, AnimationTarget* target, int propertyId, un
 
 
 Animation::~Animation()
 Animation::~Animation()
 {
 {
-    if (_clips != NULL)
+    if (_defaultClip)
+    {
+        _defaultClip->stop();
+        SAFE_RELEASE(_defaultClip);
+    }
+
+    if (_clips)
     {
     {
         std::vector<AnimationClip*>::iterator clipIter = _clips->begin();
         std::vector<AnimationClip*>::iterator clipIter = _clips->begin();
     
     
@@ -44,18 +49,6 @@ Animation::~Animation()
         _clips->clear();
         _clips->clear();
     }
     }
     SAFE_DELETE(_clips);
     SAFE_DELETE(_clips);
-
-    SAFE_DELETE(_defaultClip);
-
-    /*vector<Channel*>::iterator channelIter = _channels.begin();
-    while (channelIter != _channels.end())
-    {
-        Animation::Channel* channel = *channelIter;
-        channel->_target->removeChannel(channel);
-        SAFE_RELEASE(channel);
-        channelIter++;
-    }*/
-    _channels.clear();
 }
 }
 
 
 Animation::Channel::Channel(Animation* animation, AnimationTarget* target, int propertyId, Curve* curve, unsigned long duration)
 Animation::Channel::Channel(Animation* animation, AnimationTarget* target, int propertyId, Curve* curve, unsigned long duration)
@@ -71,9 +64,9 @@ Animation::Channel::Channel(Animation* animation, AnimationTarget* target, int p
 
 
 Animation::Channel::~Channel()
 Animation::Channel::~Channel()
 {
 {
+    SAFE_DELETE(_curve);
     _animation->removeChannel(this);
     _animation->removeChannel(this);
     SAFE_RELEASE(_animation);
     SAFE_RELEASE(_animation);
-    SAFE_DELETE(_curve);
 }
 }
 
 
 const char* Animation::getId() const
 const char* Animation::getId() const
@@ -90,60 +83,24 @@ void Animation::createClips(const char* animationFile)
 {
 {
     assert(animationFile);
     assert(animationFile);
 
 
-    Properties* pAnim = Properties::create(animationFile);
-    assert(pAnim);
-
-    Properties* animation = pAnim->getNextNamespace();
-    int frameCount = animation->getInt("frameCount");
-
-    const Properties* pClip = animation->getNextNamespace();
-    while (pClip != NULL)
-    {
-        int begin = pClip->getInt("begin");
-        int end = pClip->getInt("end");
-
-        AnimationClip* clip = createClip(pClip->getId(), ((float) begin / frameCount) * _duration, ((float) end / frameCount) * _duration);
-
-        const char* repeat = pClip->getString("repeatCount");
-        if (repeat)
-        {
-            if (strcmp(repeat, ANIMATION_INDEFINITE_STR) == 0)
-            {
-                clip->setRepeatCount(AnimationClip::REPEAT_INDEFINITE);
-            }
-            else
-            {
-                float value;
-                sscanf(repeat, "%f", &value);
-                clip->setRepeatCount(value);
-            }
-        }
+    Properties* properties = Properties::create(animationFile);
+    assert(properties);
 
 
-        const char* speed = pClip->getString("speed");
-        if (speed)
-        {
-            float value;
-            sscanf(speed, "%f", &value);
-            clip->setSpeed(value);
-        }
+    Properties* pAnimation = properties->getNextNamespace();
+    assert(pAnimation);
+    
+    int frameCount = pAnimation->getInt("frameCount");
+    assert(frameCount > 0);
 
 
-        pClip = animation->getNextNamespace();
-    }
+    createClips(pAnimation, (unsigned int)frameCount);
 
 
-    SAFE_DELETE(pAnim);
+    SAFE_DELETE(properties);
 }
 }
 
 
 AnimationClip* Animation::createClip(const char* id, unsigned long start, unsigned long end)
 AnimationClip* Animation::createClip(const char* id, unsigned long start, unsigned long end)
 {
 {
-    if (_clips != NULL && findClip(id) != NULL)
-    {
-        return NULL;
-    }
-    
     AnimationClip* clip = new AnimationClip(id, this, start, end);
     AnimationClip* clip = new AnimationClip(id, this, start, end);
-
     addClip(clip);
     addClip(clip);
-
     return clip;
     return clip;
 }
 }
 
 
@@ -205,6 +162,77 @@ void Animation::stop(const char* id)
     }
     }
 }
 }
 
 
+void Animation::createDefaultClip()
+{
+    _defaultClip = new AnimationClip("default_clip", this, 0.0f, _duration);
+}
+
+void Animation::createClips(Properties* animationProperties, unsigned int frameCount)
+{   
+    assert(animationProperties);
+    
+    Properties* pClip = animationProperties->getNextNamespace();
+    
+    while (pClip != NULL && std::strcmp(pClip->getNamespace(), "clip") == 0)
+    {
+        int begin = pClip->getInt("begin");
+        int end = pClip->getInt("end");
+
+        AnimationClip* clip = createClip(pClip->getId(), ((float) begin / frameCount) * _duration, ((float) end / frameCount) * _duration);
+
+        const char* repeat = pClip->getString("repeatCount");
+        if (repeat)
+        {
+            if (strcmp(repeat, ANIMATION_INDEFINITE_STR) == 0)
+            {
+                clip->setRepeatCount(AnimationClip::REPEAT_INDEFINITE);
+            }
+            else
+            {
+                float value;
+                sscanf(repeat, "%f", &value);
+                clip->setRepeatCount(value);
+            }
+        }
+
+        const char* speed = pClip->getString("speed");
+        if (speed)
+        {
+            float value;
+            sscanf(speed, "%f", &value);
+            clip->setSpeed(value);
+        }
+
+        pClip = animationProperties->getNextNamespace();
+    }
+}
+
+void Animation::addClip(AnimationClip* clip)
+{
+    if (_clips == NULL)
+        _clips = new std::vector<AnimationClip*>;
+
+    _clips->push_back(clip);
+}
+
+AnimationClip* Animation::findClip(const char* id) const
+{
+    if (_clips)
+    {
+        AnimationClip* clip = NULL;
+        unsigned int clipCount = _clips->size();
+        for (unsigned int i = 0; i < clipCount; i++)
+        {
+            clip = _clips->at(i);
+            if (clip->_id.compare(id) == 0)
+            {
+                return _clips->at(i);
+            }
+        }
+    }
+    return NULL;
+}
+
 Animation::Channel* Animation::createChannel(AnimationTarget* target, int propertyId, unsigned int keyCount, unsigned long* keyTimes, float* keyValues, unsigned int type)
 Animation::Channel* Animation::createChannel(AnimationTarget* target, int propertyId, unsigned int keyCount, unsigned long* keyTimes, float* keyValues, unsigned int type)
 {
 {
     unsigned int propertyComponentCount = target->getAnimationPropertyComponentCount(propertyId);
     unsigned int propertyComponentCount = target->getAnimationPropertyComponentCount(propertyId);
@@ -328,37 +356,4 @@ void Animation::removeChannel(Channel* channel)
         _controller->destroyAnimation(this);
         _controller->destroyAnimation(this);
 }
 }
 
 
-void Animation::createDefaultClip()
-{
-    std::string clipId = _id + ANIMATION_DEFAULT_CLIP_SUFFIX;
-
-    _defaultClip = new AnimationClip(clipId.c_str(), this, 0.0f, _duration);
-}
-
-void Animation::addClip(AnimationClip* clip)
-{
-    if (_clips == NULL)
-        _clips = new std::vector<AnimationClip*>;
-
-    _clips->push_back(clip);
-}
-
-AnimationClip* Animation::findClip(const char* id) const
-{
-    if (_clips)
-    {
-        AnimationClip* clip = NULL;
-        unsigned int clipCount = _clips->size();
-        for (unsigned int i = 0; i < clipCount; i++)
-        {
-            clip = _clips->at(i);
-            if (clip->_id.compare(id) == 0)
-            {
-                return _clips->at(i);
-            }
-        }
-    }
-    return NULL;
-}
-
 }
 }

+ 11 - 5
gameplay/src/Animation.h

@@ -2,6 +2,7 @@
 #define ANIMATION_H_
 #define ANIMATION_H_
 
 
 #include "Ref.h"
 #include "Ref.h"
+#include "Properties.h"
 
 
 namespace gameplay
 namespace gameplay
 {
 {
@@ -133,6 +134,16 @@ private:
      */
      */
     ~Animation();
     ~Animation();
 
 
+    /**
+     * Creates the default clip.
+     */
+    void createDefaultClip();
+
+    /**
+     * Creates AnimationClip's for this Animation from the specified Property object.
+     */
+    void createClips(Properties* animationProperties, unsigned int frameCount);
+
     /**
     /**
      * Adds a clip to this Animation.
      * Adds a clip to this Animation.
      */
      */
@@ -143,11 +154,6 @@ private:
      */
      */
     AnimationClip* findClip(const char* id) const;
     AnimationClip* findClip(const char* id) const;
 
 
-    /**
-     * Creates the default clip.
-     */
-    void createDefaultClip();
-
     /**
     /**
      * Creates a channel within this animation.
      * Creates a channel within this animation.
      */ 
      */ 

+ 2 - 6
gameplay/src/AnimationClip.cpp

@@ -11,18 +11,15 @@ namespace gameplay
 AnimationClip::AnimationClip(const char* id, Animation* animation, unsigned long startTime, unsigned long endTime)
 AnimationClip::AnimationClip(const char* id, Animation* animation, unsigned long startTime, unsigned long endTime)
     : _id(id), _animation(animation), _startTime(startTime), _endTime(endTime), _duration(_endTime - _startTime), _repeatCount(1.0f), 
     : _id(id), _animation(animation), _startTime(startTime), _endTime(endTime), _duration(_endTime - _startTime), _repeatCount(1.0f), 
       _activeDuration(_duration * _repeatCount), _speed(1.0f), _isPlaying(false), _timeStarted(0), _elapsedTime(0), _runningTime(0), 
       _activeDuration(_duration * _repeatCount), _speed(1.0f), _isPlaying(false), _timeStarted(0), _elapsedTime(0), _runningTime(0), 
-      _channelPriority(NULL), _crossFadeToClip(NULL), _crossFadeStart(0), _crossFadeOutElapsed(0), _crossFadeOutDuration(0), _blendWeight(1.0f), 
+      _crossFadeToClip(NULL), _crossFadeStart(0), _crossFadeOutElapsed(0), _crossFadeOutDuration(0), _blendWeight(1.0f), 
       _isFadingOutStarted(false), _isFadingOut(false), _isFadingIn(false), _beginListeners(NULL), _endListeners(NULL)
       _isFadingOutStarted(false), _isFadingOut(false), _isFadingIn(false), _beginListeners(NULL), _endListeners(NULL)
 {
 {
     assert(0 <= startTime && startTime <= animation->_duration && 0 <= endTime && endTime <= animation->_duration);
     assert(0 <= startTime && startTime <= animation->_duration && 0 <= endTime && endTime <= animation->_duration);
     
     
-    unsigned int channelCount = _animation->_channels.size();
-    _channelPriority = new unsigned int[channelCount];
-    
+    unsigned int channelCount = _animation->_channels.size();    
     for (unsigned int i = 0; i < channelCount; i++)
     for (unsigned int i = 0; i < channelCount; i++)
     {
     {
         _values.push_back(new AnimationValue(_animation->_channels[i]->_curve->getComponentCount()));
         _values.push_back(new AnimationValue(_animation->_channels[i]->_curve->getComponentCount()));
-        _channelPriority[i] = 0;
     }
     }
 }
 }
 
 
@@ -37,7 +34,6 @@ AnimationClip::~AnimationClip()
     _values.clear();
     _values.clear();
 
 
     SAFE_RELEASE(_crossFadeToClip);
     SAFE_RELEASE(_crossFadeToClip);
-    SAFE_DELETE(_channelPriority);
     SAFE_DELETE(_beginListeners);
     SAFE_DELETE(_beginListeners);
     SAFE_DELETE(_endListeners);
     SAFE_DELETE(_endListeners);
 }
 }

+ 0 - 1
gameplay/src/AnimationClip.h

@@ -239,7 +239,6 @@ private:
     unsigned long _timeStarted;               // The game time when this clip was actually started.
     unsigned long _timeStarted;               // The game time when this clip was actually started.
     unsigned long _elapsedTime;               // Time elapsed while the clip is running.
     unsigned long _elapsedTime;               // Time elapsed while the clip is running.
     long _runningTime;                        // Keeps track of the Animation's relative time in respect to the active duration.
     long _runningTime;                        // Keeps track of the Animation's relative time in respect to the active duration.
-    unsigned int* _channelPriority;           // Keeps track of each channel's priority.
     AnimationClip* _crossFadeToClip;          // The clip to cross fade to
     AnimationClip* _crossFadeToClip;          // The clip to cross fade to
     unsigned long _crossFadeStart;            // The time at which the cross fade started.
     unsigned long _crossFadeStart;            // The time at which the cross fade started.
     unsigned long _crossFadeOutElapsed;       // The amount of time that has elapsed for the crossfade.
     unsigned long _crossFadeOutElapsed;       // The amount of time that has elapsed for the crossfade.

+ 150 - 29
gameplay/src/AnimationController.cpp

@@ -19,13 +19,9 @@ AnimationController::~AnimationController()
 Animation* AnimationController::createAnimation(const char* id, AnimationTarget* target, int propertyId, unsigned int keyCount, unsigned long* keyTimes, float* keyValues, Curve::InterpolationType type)
 Animation* AnimationController::createAnimation(const char* id, AnimationTarget* target, int propertyId, unsigned int keyCount, unsigned long* keyTimes, float* keyValues, Curve::InterpolationType type)
 {
 {
     assert(type != Curve::BEZIER && type != Curve::HERMITE);
     assert(type != Curve::BEZIER && type != Curve::HERMITE);
-    assert(id && keyCount >= 2 && keyTimes && keyValues);
-    Animation* animation = getAnimation(id);
+    assert(keyCount >= 2 && keyTimes && keyValues && target);
 
 
-    if (animation != NULL)
-        return NULL;
-
-    animation = new Animation(id, target, propertyId, keyCount, keyTimes, keyValues, type);
+    Animation* animation = new Animation(id, target, propertyId, keyCount, keyTimes, keyValues, type);
 
 
     addAnimation(animation);
     addAnimation(animation);
     
     
@@ -34,34 +30,24 @@ Animation* AnimationController::createAnimation(const char* id, AnimationTarget*
 
 
 Animation* AnimationController::createAnimation(const char* id, AnimationTarget* target, int propertyId, unsigned int keyCount, unsigned long* keyTimes, float* keyValues, float* keyInValue, float* keyOutValue, Curve::InterpolationType type)
 Animation* AnimationController::createAnimation(const char* id, AnimationTarget* target, int propertyId, unsigned int keyCount, unsigned long* keyTimes, float* keyValues, float* keyInValue, float* keyOutValue, Curve::InterpolationType type)
 {
 {
-    assert(id && keyCount >= 2 && keyTimes && keyValues && keyInValue && keyOutValue);
-    Animation* animation = getAnimation(id);
-
-    if (animation != NULL)
-        return NULL;
-    
-    animation = new Animation(id, target, propertyId, keyCount, keyTimes, keyValues, keyInValue, keyOutValue, type);
+    assert(target && keyCount >= 2 && keyTimes && keyValues && keyInValue && keyOutValue);
+    Animation* animation = new Animation(id, target, propertyId, keyCount, keyTimes, keyValues, keyInValue, keyOutValue, type);
 
 
     addAnimation(animation);
     addAnimation(animation);
 
 
     return animation;
     return animation;
 }
 }
 
 
-Animation* AnimationController::createAnimation(const char* id, AnimationTarget* target, Properties* p)
+Animation* AnimationController::createAnimation(const char* id, AnimationTarget* target, const char* animationFile)
 {
 {
-    Animation* animation = getAnimation(id);
-
-    if (animation != NULL)
-        return NULL;
+    assert(target && animationFile);
     
     
-    // TODO: Implement loading from a properties object here.
-    /*
-    animation = new Animation(id, target, p);
+    Properties* p = Properties::create(animationFile);
+    assert(p);
 
 
-    addAnimation(animation);
+    Animation* animation = createAnimation(id, target, p->getNextNamespace());
 
 
-    target->addAnimation(animation);
-    */
+    SAFE_DELETE(p);
 
 
     return animation;
     return animation;
 }
 }
@@ -125,7 +111,6 @@ void AnimationController::stopAllAnimations()
         AnimationClip* clip = *clipIter;
         AnimationClip* clip = *clipIter;
         clip->_isPlaying = false;
         clip->_isPlaying = false;
         clip->onEnd();
         clip->onEnd();
-        clipIter = _runningClips.erase(clipIter);
         SAFE_RELEASE(clip);
         SAFE_RELEASE(clip);
     }
     }
     _runningClips.clear();
     _runningClips.clear();
@@ -133,6 +118,144 @@ void AnimationController::stopAllAnimations()
     _state = IDLE;
     _state = IDLE;
 }
 }
 
 
+Animation* AnimationController::createAnimation(const char* id, AnimationTarget* target, Properties* animationProperties)
+{
+    assert(target && animationProperties);
+    assert(std::strcmp(animationProperties->getNamespace(), "animation") == 0);
+    
+    const char* propertyIdStr = animationProperties->getString("property");
+    assert(propertyIdStr);
+    
+    // Get animation target property id
+    int propertyId = AnimationTarget::getPropertyId(target->_targetType, propertyIdStr);
+    assert(propertyId != -1);
+    
+    unsigned int keyCount = animationProperties->getInt("keyCount");
+    assert(keyCount > 0);
+
+    const char* keyTimesStr = animationProperties->getString("keyTimes");
+    assert(keyTimesStr);
+    
+    const char* keyValuesStr = animationProperties->getString("keyValues");
+    assert(keyValuesStr);
+    
+    const char* curveStr = animationProperties->getString("curve");
+    assert(curveStr);
+    
+    char delimeter = ' ';
+    unsigned int startOffset = 0;
+    unsigned int endOffset = std::string::npos;
+    
+    unsigned long* keyTimes = new unsigned long[keyCount];
+    for (unsigned int i = 0; i < keyCount; i++)
+    {
+        endOffset = static_cast<std::string>(keyTimesStr).find_first_of(delimeter, startOffset);
+        if (endOffset != std::string::npos)
+        {
+            keyTimes[i] = std::strtoul(static_cast<std::string>(keyTimesStr).substr(startOffset, endOffset - startOffset).c_str(), NULL, 0);
+        }
+        else
+        {
+            keyTimes[i] = std::strtoul(static_cast<std::string>(keyTimesStr).substr(startOffset, static_cast<std::string>(keyTimesStr).length()).c_str(), NULL, 0);
+        }
+        startOffset = endOffset + 1;
+    }
+
+    startOffset = 0;
+    endOffset = std::string::npos;
+    
+    int componentCount = target->getAnimationPropertyComponentCount(propertyId);
+    assert(componentCount > 0);
+    
+    unsigned int components = keyCount * componentCount;
+    
+    float* keyValues = new float[components];
+    for (unsigned int i = 0; i < components; i++)
+    {
+        endOffset = static_cast<std::string>(keyValuesStr).find_first_of(delimeter, startOffset);
+        if (endOffset != std::string::npos)
+        {   
+            keyValues[i] = std::atof(static_cast<std::string>(keyValuesStr).substr(startOffset, endOffset - startOffset).c_str());
+        }
+        else
+        {
+            keyValues[i] = std::atof(static_cast<std::string>(keyValuesStr).substr(startOffset, static_cast<std::string>(keyValuesStr).length()).c_str());
+        }
+        startOffset = endOffset + 1;
+    }
+
+    const char* keyInStr = animationProperties->getString("keyIn");
+    float* keyIn = NULL;
+    if (keyInStr)
+    {
+        keyIn = new float[components];
+        startOffset = 0;
+        endOffset = std::string::npos;
+        for (unsigned int i = 0; i < components; i++)
+        {
+            endOffset = static_cast<std::string>(keyInStr).find_first_of(delimeter, startOffset);
+            if (endOffset != std::string::npos)
+            {   
+                keyIn[i] = std::atof(static_cast<std::string>(keyInStr).substr(startOffset, endOffset - startOffset).c_str());
+            }
+            else
+            {
+                keyIn[i] = std::atof(static_cast<std::string>(keyInStr).substr(startOffset, static_cast<std::string>(keyInStr).length()).c_str());
+            }
+            startOffset = endOffset + 1;
+        }
+    }
+    
+    const char* keyOutStr = animationProperties->getString("keyOut");
+    float* keyOut = NULL;
+    if(keyOutStr)
+    {   
+        keyOut = new float[components];
+        startOffset = 0;
+        endOffset = std::string::npos;
+        for (unsigned int i = 0; i < components; i++)
+        {
+            endOffset = static_cast<std::string>(keyOutStr).find_first_of(delimeter, startOffset);
+            if (endOffset != std::string::npos)
+            {   
+                keyOut[i] = std::atof(static_cast<std::string>(keyOutStr).substr(startOffset, endOffset - startOffset).c_str());
+            }
+            else
+            {
+                keyOut[i] = std::atof(static_cast<std::string>(keyOutStr).substr(startOffset, static_cast<std::string>(keyOutStr).length()).c_str());
+            }
+            startOffset = endOffset + 1;
+        }
+    }
+
+    int curve = Curve::getInterpolationType(curveStr);
+
+    Animation* animation = NULL;
+    if (keyIn && keyOut)
+    {
+        animation = createAnimation(id, target, propertyId, keyCount, keyTimes, keyValues, keyIn, keyOut, (Curve::InterpolationType)curve);
+    }
+    else
+    {
+        animation = createAnimation(id, target, propertyId, keyCount, keyTimes, keyValues, (Curve::InterpolationType) curve);
+    }
+
+    SAFE_DELETE(keyOut);
+    SAFE_DELETE(keyIn);
+    SAFE_DELETE(keyValues);
+    SAFE_DELETE(keyTimes);
+
+    Properties* pClip = animationProperties->getNextNamespace();
+    if (pClip && std::strcmp(pClip->getNamespace(), "clip") == 0)
+    {
+        int frameCount = animationProperties->getInt("frameCount");
+        assert(frameCount > 0);
+        animation->createClips(animationProperties, (unsigned int) frameCount);
+    }
+
+    return animation;
+}
+
 AnimationController::State AnimationController::getState() const
 AnimationController::State AnimationController::getState() const
 {
 {
     return _state;
     return _state;
@@ -201,20 +324,18 @@ void AnimationController::update(long elapsedTime)
         return;
         return;
 
 
     std::list<AnimationClip*>::iterator clipIter = _runningClips.begin();
     std::list<AnimationClip*>::iterator clipIter = _runningClips.begin();
-    unsigned int clipCount = 0;
     while (clipIter != _runningClips.end())
     while (clipIter != _runningClips.end())
     {
     {
         AnimationClip* clip = (*clipIter);
         AnimationClip* clip = (*clipIter);
         if (clip->update(elapsedTime))
         if (clip->update(elapsedTime))
         {
         {
-            clipIter = _runningClips.erase(clipIter);
             SAFE_RELEASE(clip);
             SAFE_RELEASE(clip);
+            clipIter = _runningClips.erase(clipIter);
         }
         }
         else
         else
         {
         {
             clipIter++;
             clipIter++;
         }
         }
-        clipCount++;
     }
     }
     
     
     if (_runningClips.empty())
     if (_runningClips.empty())
@@ -235,8 +356,8 @@ void AnimationController::destroyAnimation(Animation* animation)
         if (animation == *itr)
         if (animation == *itr)
         {
         {
             Animation* animation = *itr;
             Animation* animation = *itr;
-            SAFE_RELEASE(animation);
             _animations.erase(itr);
             _animations.erase(itr);
+            SAFE_RELEASE(animation);
             return;
             return;
         }
         }
         itr++;
         itr++;

+ 20 - 8
gameplay/src/AnimationController.h

@@ -17,6 +17,7 @@ class AnimationController
     friend class Game;
     friend class Game;
     friend class Animation;
     friend class Animation;
     friend class AnimationClip;
     friend class AnimationClip;
+    friend class SceneLoader;
 
 
 public:
 public:
 
 
@@ -32,7 +33,7 @@ public:
      * @param keyValues The list of key values for the animation.
      * @param keyValues The list of key values for the animation.
      * @param type The curve interpolation type.
      * @param type The curve interpolation type.
      *
      *
-     * @return The newly created animation, or NULL if an animation with the given ID already exists.
+     * @return The newly created animation.
      */
      */
     Animation* createAnimation(const char* id, AnimationTarget* target, int propertyId, unsigned int keyCount, unsigned long* keyTimes, float* keyValues, Curve::InterpolationType type);
     Animation* createAnimation(const char* id, AnimationTarget* target, int propertyId, unsigned int keyCount, unsigned long* keyTimes, float* keyValues, Curve::InterpolationType type);
 
 
@@ -49,7 +50,7 @@ public:
      * @param keyOutValue The list of key out values for the animation.
      * @param keyOutValue The list of key out values for the animation.
      * @param type The curve interpolation type.
      * @param type The curve interpolation type.
      *
      *
-     * @return The newly created animation, or NULL if an animation with the given ID already exists.
+     * @return The newly created animation.
      */
      */
     Animation* createAnimation(const char* id, AnimationTarget* target, int propertyId, unsigned int keyCount, unsigned long* keyTimes, float* keyValues, float* keyInValue, float* keyOutValue, Curve::InterpolationType type);
     Animation* createAnimation(const char* id, AnimationTarget* target, int propertyId, unsigned int keyCount, unsigned long* keyTimes, float* keyValues, float* keyInValue, float* keyOutValue, Curve::InterpolationType type);
 
 
@@ -58,11 +59,11 @@ public:
      * 
      * 
      * @param id The ID of the animation.
      * @param id The ID of the animation.
      * @param target The animation target.
      * @param target The animation target.
-     * @param properties The properties object defining the animation data.
+     * @param animationFile The animation file defining the animation data.
      *
      *
-     * @return The newly created animation, or NULL if an animation with the given ID already exists.
+     * @return The newly created animation.
      */
      */
-    Animation* createAnimation(const char* id, AnimationTarget* target, Properties* p);
+    Animation* createAnimation(const char* id, AnimationTarget* target, const char* animationFile);
 
 
     /**
     /**
      * Creates a simple two keyframe from-to animation.
      * Creates a simple two keyframe from-to animation.
@@ -76,7 +77,7 @@ public:
      * @param type The curve interpolation type.
      * @param type The curve interpolation type.
      * @param duration The duration of the animation (in milliseconds).
      * @param duration The duration of the animation (in milliseconds).
      *
      *
-     * @return The newly created animation, or NULL if an animation with the given ID already exists.
+     * @return The newly created animation.
      */
      */
     Animation* createAnimationFromTo(const char* id, AnimationTarget* target, int propertyId, float* from, float* to, Curve::InterpolationType type, unsigned long duration);
     Animation* createAnimationFromTo(const char* id, AnimationTarget* target, int propertyId, float* from, float* to, Curve::InterpolationType type, unsigned long duration);
 
 
@@ -92,7 +93,7 @@ public:
      * @param type The curve interpolation type.
      * @param type The curve interpolation type.
      * @param duration The duration of the animation (in milliseconds).
      * @param duration The duration of the animation (in milliseconds).
      *
      *
-     * @return The newly created animation, or NULL if an animation with the given ID already exists.
+     * @return The newly created animation.
      */
      */
     Animation* createAnimationFromBy(const char* id, AnimationTarget* target, int propertyId, float* from, float* by, Curve::InterpolationType type, unsigned long duration);
     Animation* createAnimationFromBy(const char* id, AnimationTarget* target, int propertyId, float* from, float* by, Curve::InterpolationType type, unsigned long duration);
 
 
@@ -134,6 +135,17 @@ private:
      */
      */
     ~AnimationController();
     ~AnimationController();
     
     
+    /**
+     * Creates an animation on this target using the data from the given properties object. 
+     * 
+     * @param id The ID of the animation.
+     * @param target The animation target.
+     * @param properties The properties object defining the animation data.
+     *
+     * @return The newly created animation.
+     */
+    Animation* createAnimation(const char* id, AnimationTarget* target, Properties* animationProperties);
+
     /**
     /**
      * Gets the controller's state.
      * Gets the controller's state.
      *
      *
@@ -175,7 +187,7 @@ private:
      * Callback for when the controller receives a frame update event.
      * Callback for when the controller receives a frame update event.
      */
      */
     void update(long elapsedTime);
     void update(long elapsedTime);
-    
+
     /**
     /**
      * Adds an animation on this AnimationTarget.
      * Adds an animation on this AnimationTarget.
      */ 
      */ 

+ 87 - 1
gameplay/src/AnimationTarget.cpp

@@ -19,9 +19,11 @@ AnimationTarget::~AnimationTarget()
         std::vector<Animation::Channel*>::iterator itr = _animationChannels->begin();
         std::vector<Animation::Channel*>::iterator itr = _animationChannels->begin();
         while (itr != _animationChannels->end())
         while (itr != _animationChannels->end())
         {
         {
-            SAFE_DELETE((*itr));
+            Animation::Channel* channel = (*itr);
+            SAFE_DELETE(channel);
             itr++;
             itr++;
         }
         }
+        _animationChannels->clear();
         SAFE_DELETE(_animationChannels);
         SAFE_DELETE(_animationChannels);
     }
     }
 }
 }
@@ -34,6 +36,90 @@ void AnimationTarget::addChannel(Animation::Channel* channel)
     _animationChannels->push_back(channel);
     _animationChannels->push_back(channel);
 }
 }
 
 
+int AnimationTarget::getPropertyId(TargetType type, const char* propertyIdStr)
+{
+    if (type == AnimationTarget::TRANSFORM)
+    {
+        if (strcmp(propertyIdStr, "ANIMATE_SCALE") == 0)
+        {
+            return Transform::ANIMATE_SCALE;
+        }
+        else if (strcmp(propertyIdStr, "ANIMATE_SCALE_X") == 0)
+        {
+            return Transform::ANIMATE_SCALE_X;
+        }
+        else if (strcmp(propertyIdStr, "ANIMATE_SCALE_Y") == 0)
+        {
+            return Transform::ANIMATE_SCALE_Y;
+        }
+        else if (strcmp(propertyIdStr, "ANIMATE_SCALE_Z") == 0)
+        {
+            return Transform::ANIMATE_SCALE_Z;
+        }
+        else if (strcmp(propertyIdStr, "ANIMATE_SCALE_XY") == 0)
+        {
+            return Transform::ANIMATE_SCALE_XY;
+        }
+        else if (strcmp(propertyIdStr, "ANIMATE_SCALE_XZ") == 0)
+        {
+            return Transform::ANIMATE_SCALE_XZ;
+        }
+        else if (strcmp(propertyIdStr, "ANIMATE_SCALE_YZ") == 0)
+        {
+            return Transform::ANIMATE_SCALE_YZ;
+        }
+        else if (strcmp(propertyIdStr, "ANIMATE_ROTATE") == 0)
+        {
+            return Transform::ANIMATE_ROTATE;
+        }
+        else if (strcmp(propertyIdStr, "ANIMATE_TRANSLATE") == 0)
+        {
+            return Transform::ANIMATE_TRANSLATE;
+        }
+        else if (strcmp(propertyIdStr, "ANIMATE_TRANSLATE_X") == 0)
+        {
+            return Transform::ANIMATE_TRANSLATE_X;
+        }
+        else if (strcmp(propertyIdStr, "ANIMATE_TRANSLATE_Y") == 0)
+        {
+            return Transform::ANIMATE_TRANSLATE_Y;
+        }
+        else if (strcmp(propertyIdStr, "ANIMATE_TRANSLATE_Z") == 0)
+        {
+            return Transform::ANIMATE_TRANSLATE_Z;
+        }
+        else if (strcmp(propertyIdStr, "ANIMATE_TRANSLATE_XY") == 0)
+        {
+            return Transform::ANIMATE_TRANSLATE_XY;
+        }
+        else if (strcmp(propertyIdStr, "ANIMATE_TRANSLATE_XZ") == 0)
+        {
+            return Transform::ANIMATE_TRANSLATE_XZ;
+        }
+        else if (strcmp(propertyIdStr, "ANIMATE_TRANSLATE_YZ") == 0)
+        {
+            return Transform::ANIMATE_TRANSLATE_YZ;
+        }
+        else if (strcmp(propertyIdStr, "ANIMATE_ROTATE_TRANSLATE") == 0)
+        {
+            return Transform::ANIMATE_ROTATE_TRANSLATE;
+        }
+        else if (strcmp(propertyIdStr, "ANIMATE_SCALE_ROTATE_TRANSLATE") == 0)
+        {
+            return Transform::ANIMATE_SCALE_ROTATE_TRANSLATE;
+        }
+    }
+    else
+    {
+        if (strcmp(propertyIdStr, "ANIMATE_UNIFORM") == 0)
+        {
+            return MaterialParameter::ANIMATE_UNIFORM;
+        }
+    }
+
+    return -1;
+}
+
 }
 }
 
 
 
 

+ 10 - 0
gameplay/src/AnimationTarget.h

@@ -76,6 +76,16 @@ private:
      */
      */
     AnimationTarget(const AnimationTarget& copy);
     AnimationTarget(const AnimationTarget& copy);
 
 
+    /**
+     * Gets the TargetType's property ID value for the specified property ID string.
+     * 
+     * @param type The TargetType of the AnimationTarget.
+     * @param propertyIdStr The property ID string.
+     * @return The property ID value for teh property ID string; -1 if the propertyIdStr does not exist
+     *    for the TargetType.
+     */
+    static int getPropertyId(TargetType type, const char* propertyIdStr);
+
     Animation::Channel* _highestPriority;
     Animation::Channel* _highestPriority;
     std::vector<Animation::Channel*>* _animationChannels;   // Collection of all animation channels that target the AnimationTarget
     std::vector<Animation::Channel*>* _animationChannels;   // Collection of all animation channels that target the AnimationTarget
 
 

Filskillnaden har hållts tillbaka eftersom den är för stor
+ 650 - 175
gameplay/src/Curve.cpp


+ 246 - 10
gameplay/src/Curve.h

@@ -11,53 +11,267 @@ class Curve
 {
 {
     friend class Animation;
     friend class Animation;
     friend class AnimationClip;
     friend class AnimationClip;
+    friend class AnimationController;
 
 
 public:
 public:
 
 
     /**
     /**
-     * Defines the type of interpolation.
+     * Types of interpolation.
+     *
+     * Defines how the points in the curve are connected.
      *
      *
      * Note: InterpolationType::BEZIER requires control points and InterpolationType::HERMITE requires tangents.
      * Note: InterpolationType::BEZIER requires control points and InterpolationType::HERMITE requires tangents.
      */
      */
     enum InterpolationType
     enum InterpolationType
     {
     {
         /**
         /**
-         * Bezier interpolation. Requires that two control points are set for each segment.
+         * Bezier Interpolation. 
+         *
+         * Requires that two control points are set for each segment.
          */
          */
         BEZIER,
         BEZIER,
 
 
         /**
         /**
-         * B-Spline interpolation. Uses the points as control points, and the curve is guaranteed to only pass through the
+         * B-Spline Interpolation. 
+         *
+         * Uses the points as control points, and the curve is guaranteed to only pass through the
          * first and last point.
          * first and last point.
          */
          */
         BSPLINE,
         BSPLINE,
 
 
         /**
         /**
-         * Flat. A form of Hermite interpolation that generates flat tangents for you. The tangents have a value equal to 0.
+         * Flat Interpolation. 
+         * 
+         * A form of Hermite interpolation that generates flat tangents for you. The tangents have a value equal to 0.
          */
          */
         FLAT,
         FLAT,
 
 
         /**
         /**
-         * Hermite interpolation. Requires that two tangents for each segment.
+         * Hermite Interpolation. 
+         *
+         * Requires that two tangents for each segment.
          */
          */
         HERMITE,
         HERMITE,
 
 
         /**
         /**
-         * Linear interpolation.
+         * Linear Interpolation.
          */
          */
         LINEAR,
         LINEAR,
 
 
         /** 
         /** 
-         * Smooth. A form of Hermite interpolation that generates tangents for each segment based on the points prior to and after the segment.
+         * Smooth Interpolation. 
+         *
+         * A form of Hermite interpolation that generates tangents for each segment based on the points prior to and after the segment.
          */
          */
         SMOOTH,
         SMOOTH,
 
 
         /**
         /**
-         * Discrete interpolation.
+         * Discrete Interpolation.
          */ 
          */ 
-        STEP
+        STEP,
+
+        /**
+         * Quadratic-In Interpolation.
+         */
+        QUADRATIC_IN, 
+        
+        /**
+         * Quadratic-Out Interpolation.
+         */
+        QUADRATIC_OUT,
+
+        /**
+         * Quadratic-In-Out Interpolation.
+         */
+        QUADRATIC_IN_OUT,
+
+        /**
+         * Quadratic-Out-In Interpolation.
+         */
+        QUADRATIC_OUT_IN,
+
+        /**
+         * Cubic-In Interpolation.
+         */
+        CUBIC_IN,
+        
+        /**
+         * Cubic-Out Interpolation.
+         */
+        CUBIC_OUT,
+        
+        /**
+         * Cubic-In-Out Interpolation.
+         */
+        CUBIC_IN_OUT,
+        
+        /**
+         * Cubic-Out-In Interpolation.
+         */
+        CUBIC_OUT_IN,
+
+        /**
+         * Quartic-In Interpolation.
+         */
+        QUARTIC_IN,
+
+        /**
+         * Quartic-Out Interpolation.
+         */
+        QUARTIC_OUT,
+
+        /**
+         * Quartic-In-Out Interpolation.
+         */
+        QUARTIC_IN_OUT,
+
+        /**
+         * Quartic-Out-In Interpolation.
+         */
+        QUARTIC_OUT_IN,
+
+        /**
+         * Quintic-In Interpolation.
+         */
+        QUINTIC_IN,
+        
+        /**
+         * Quintic-Out Interpolation.
+         */
+        QUINTIC_OUT,
+        
+        /**
+         * Quintic-In-Out Interpolation.
+         */
+        QUINTIC_IN_OUT,
+        
+        /**
+         * Quintic-Out-In Interpolation.
+         */
+        QUINTIC_OUT_IN,
+        
+        /**
+         * Sine-In Interpolation.
+         */
+        SINE_IN,
+        
+        /**
+         * Sine-Out Interpolation.
+         */
+        SINE_OUT,
+        
+        /**
+         * Sine-In-Out Interpolation.
+         */
+        SINE_IN_OUT,
+        
+        /**
+         * Sine-Out-In Interpolation.
+         */
+        SINE_OUT_IN,
+
+        /**
+         * Exponential-In Interpolation.
+         */
+        EXPONENTIAL_IN,
+
+        /**
+         * Exponential-Out Interpolation.
+         */
+        EXPONENTIAL_OUT,
+
+        /**
+         * Exponential-In-Out Interpolation.
+         */
+        EXPONENTIAL_IN_OUT,
+
+        /**
+         * Exponential-Out-In Interpolation.
+         */
+        EXPONENTIAL_OUT_IN,
+
+        /**
+         * Circular-In Interpolation.
+         */
+        CIRCULAR_IN,
+
+        /**
+         * Circular-Out Interpolation.
+         */
+        CIRCULAR_OUT,
+
+        /**
+         * Circular-In-Out Interpolation.
+         */
+        CIRCULAR_IN_OUT,
+
+        /**
+         * Circular-Out-In Interpolation.
+         */
+        CIRCULAR_OUT_IN,
+
+        /**
+         * Elastic-In Interpolation.
+         */
+        ELASTIC_IN,
+
+        /**
+         * Elastic-Out Interpolation.
+         */
+        ELASTIC_OUT,
+
+        /**
+         * Elastic-In-Out Interpolation.
+         */
+        ELASTIC_IN_OUT,
+
+        /**
+         * Elastic-Out-In Interpolation.
+         */
+        ELASTIC_OUT_IN,
+
+        /**
+         * Overshoot-In Interpolation.
+         */
+        OVERSHOOT_IN,
+
+        /**
+         * Overshoot-Out Interpolation.
+         */
+        OVERSHOOT_OUT,
+
+        /**
+         * Overshoot-In-Out Interpolation.
+         */
+        OVERSHOOT_IN_OUT,
+
+        /**
+         * Overshoot-Out-In Interpolation.
+         */
+        OVERSHOOT_OUT_IN,
+
+        /**
+         * Bounce-In Interpolation.
+         */
+        BOUNCE_IN,
+
+        /**
+         * Bounce-Out Interpolation.
+         */
+        BOUNCE_OUT,
+
+        /**
+         * Bounce-In-Out Interpolation.
+         */
+        BOUNCE_IN_OUT,
+
+        /**
+         * Bounce-Out-In Interpolation.
+         */
+        BOUNCE_OUT_IN
     };
     };
 
 
+
     /**
     /**
      * Constructs a new curve and the specified parameters.
      * Constructs a new curve and the specified parameters.
      *
      *
@@ -226,12 +440,20 @@ private:
      * Quaternion interpolation function.
      * Quaternion interpolation function.
      */
      */
     void interpolateQuaternion(float s, float* from, float* to, float* dst) const;
     void interpolateQuaternion(float s, float* from, float* to, float* dst) const;
-
+    
     /**
     /**
      * Determines the current keyframe to interpolate from based on the specified time.
      * Determines the current keyframe to interpolate from based on the specified time.
      */ 
      */ 
     int determineIndex(float time) const;
     int determineIndex(float time) const;
 
 
+    /**
+     * Gets the InterpolationType value for the given string ID
+     *
+     * @param interpolationId The string representation of the InterpolationType
+     * @return the InterpolationType value; -1 if the string does not represent an InterpolationType.
+     */
+    static int getInterpolationType(const char* interpolationId);
+
     unsigned int _pointCount;           // Number of points on the curve.
     unsigned int _pointCount;           // Number of points on the curve.
     unsigned int _componentCount;       // Number of components on the curve.
     unsigned int _componentCount;       // Number of components on the curve.
     unsigned int _componentSize;        // The component size (in bytes).
     unsigned int _componentSize;        // The component size (in bytes).
@@ -240,6 +462,20 @@ private:
     Point* _points;                     // The points on the curve.
     Point* _points;                     // The points on the curve.
 };
 };
 
 
+inline float bezier(float eq0, float eq1, float eq2, float eq3, float from, float out, float to, float in);
+
+inline float bspline(float eq0, float eq1, float eq2, float eq3, float c0, float c1, float c2, float c3);
+
+inline float hermite(float h00, float h01, float h10, float h11, float from, float out, float to, float in);
+
+inline float hermiteFlat(float h00, float h01, float from, float to);
+
+inline float hermiteSmooth(float h00, float h01, float h10, float h11, float from, float out, float to, float in);
+
+inline float lerp(float s, float from, float to);
+
 }
 }
 
 
+#include "Curve.inl"
+
 #endif
 #endif

+ 36 - 0
gameplay/src/Curve.inl

@@ -0,0 +1,36 @@
+#include "Curve.h"
+
+namespace gameplay
+{
+
+inline float bezier(float eq0, float eq1, float eq2, float eq3, float from, float out, float to, float in)
+{
+    return from * eq0 + out * eq1 + in * eq2 + to * eq3;
+}
+
+inline float bspline(float eq0, float eq1, float eq2, float eq3, float c0, float c1, float c2, float c3)
+{
+    return c0 * eq0 + c1 * eq1 + c2 * eq2 + c3 * eq3;
+}
+
+inline float hermite(float h00, float h01, float h10, float h11, float from, float out, float to, float in)
+{
+    return h00 * from + h01 * to + h10 * out + h11 * in;
+}
+
+inline float hermiteFlat(float h00, float h01, float from, float to)
+{
+    return h00 * from + h01 * to;
+}
+
+inline float hermiteSmooth(float h00, float h01, float h10, float h11, float from, float out, float to, float in)
+{
+    return h00 * from + h01 * to + h10 * out + h11 * in;
+}
+
+inline float lerp(float s, float from, float to)
+{
+    return from + (to - from) * s;
+}
+
+}

+ 3 - 1
gameplay/src/Game.cpp

@@ -161,8 +161,10 @@ void Game::frame()
     else
     else
     {
     {
         if (!_initialized)
         if (!_initialized)
+        {
             initialize();
             initialize();
-        _initialized = true;
+            _initialized = true;
+        }
     }
     }
 
 
     // Update Time.
     // Update Time.

Vissa filer visades inte eftersom för många filer har ändrats