]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blobdiff - qcsrc/menu/anim/keyframe.c
Merge branch 'master' into TimePath/issue-1170
[xonotic/xonotic-data.pk3dir.git] / qcsrc / menu / anim / keyframe.c
index 39e1fd8b423f9c0ba15a53a47b0199724af885d8..3bcda94e692939b733c668cf09e46b27e59364c6 100644 (file)
@@ -1,33 +1,71 @@
 #ifdef INTERFACE
 CLASS(Keyframe) EXTENDS(Animation)
+       METHOD(Keyframe, addEasing, entity(entity, float, float, float(float, float, float, float)))
        METHOD(Keyframe, addAnim, void(entity, entity))
        METHOD(Keyframe, calcValue, float(entity, float, float, float, float))
        ATTRIB(Keyframe, currentChild, entity, NULL)
        ATTRIB(Keyframe, firstChild, entity, NULL)
        ATTRIB(Keyframe, lastChild, entity, NULL)
-ENDCLASS(Animation)
+ENDCLASS(Keyframe)
 entity makeHostedKeyframe(entity, void(entity, float), float, float, float);
 entity makeKeyframe(entity, void(entity, float), float, float, float);
+float getNewChildStart(entity);
+float getNewChildDuration(entity, float);
+float getNewChildValue(entity);
 #endif
 
 #ifdef IMPLEMENTATION
-entity makeHostedKeyframe(entity obj, void(entity, float) setter, float duration, float start, float end)
+entity makeHostedKeyframe(entity obj, void(entity, float) objSetter, float animDuration, float animStart, float animEnd)
 {
        entity me;
-       me = makeKeyframe(obj, setter, duration, start, end);
+       me = makeKeyframe(obj, objSetter, animDuration, animStart, animEnd);
        anim.addAnim(anim, me);
        return me;
 }
 
-entity makeKeyframe(entity obj, void(entity, float) setter, float duration, float start, float end)
+entity makeKeyframe(entity obj, void(entity, float) objSetter, float animDuration, float animStart, float animEnd)
 {
        entity me;
        me = spawnKeyframe();
-       me.configureAnimation(me, obj, setter, time, duration, start, end);
+       me.configureAnimation(me, obj, objSetter, time, animDuration, animStart, animEnd);
        return me;
 }
 
-void addAnimKeyframe(entity me, entity other)
+entity Keyframe_addEasing(entity me, float animDurationTime, float animEnd, float(float, float, float, float) func)
+{
+       entity other;
+       other = makeEasing(me.object, me.setter, func, getNewChildStart(me), getNewChildDuration(me, animDurationTime), getNewChildValue(me), animEnd);
+       me.addAnim(me, other);
+       return other;
+}
+
+float getNewChildStart(entity me)
+{
+       if (me.lastChild)
+               return (me.lastChild.startTime + me.lastChild.duration);
+       else
+               return 0;
+}
+
+float getNewChildDuration(entity me, float durationTime)
+{
+       float dura, maxDura;
+       maxDura = me.duration;
+       if (me.lastChild) maxDura = maxDura - (me.lastChild.startTime + me.lastChild.duration);
+       dura = durationTime;
+       if (0 >= dura || dura > maxDura) dura = maxDura;
+       return dura;
+}
+
+float getNewChildValue(entity me)
+{
+       if (me.lastChild)
+               return (me.lastChild.startValue + me.lastChild.delta);
+       else
+               return me.startValue;
+}
+
+void Keyframe_addAnim(entity me, entity other)
 {
        if(other.parent)
                error("Can't add already added anim!");
@@ -37,8 +75,7 @@ void addAnimKeyframe(entity me, entity other)
 
        other.parent = me;
 
-       entity f, l;
-       f = me.firstChild;
+       entity l;
        l = me.lastChild;
 
        if(l)
@@ -54,7 +91,7 @@ void addAnimKeyframe(entity me, entity other)
        me.lastChild = other;
 }
 
-float calcValueKeyframe(entity me, float time, float duration, float startValue, float delta)
+float Keyframe_calcValue(entity me, float tickTime, float animDuration, float animStartValue, float animDelta)
 {
        if (me.currentChild)
                if (me.currentChild.isFinished(me.currentChild))
@@ -62,10 +99,10 @@ float calcValueKeyframe(entity me, float time, float duration, float startValue,
 
        if (me.currentChild)
        {
-               me.currentChild.tick(me.currentChild, time);
+               me.currentChild.tick(me.currentChild, tickTime);
                return me.currentChild.value;
        }
 
-       return startValue + delta;
+       return animStartValue + animDelta;
 }
 #endif