1 #ifndef ANIM_KEYFRAME_H
2 #define ANIM_KEYFRAME_H
3 #include "animation.qc"
4 CLASS(Keyframe, Animation)
5 METHOD(Keyframe, addEasing, entity(entity, float, float, float(float, float, float, float)))
6 METHOD(Keyframe, addAnim, void(entity, entity))
7 METHOD(Keyframe, calcValue, float(entity, float, float, float, float))
8 ATTRIB(Keyframe, currentChild, entity, NULL)
9 ATTRIB(Keyframe, firstChild, entity, NULL)
10 ATTRIB(Keyframe, lastChild, entity, NULL)
12 entity makeHostedKeyframe(entity, void(entity, float), float, float, float);
13 entity makeKeyframe(entity, void(entity, float), float, float, float);
14 float getNewChildStart(entity);
15 float getNewChildDuration(entity, float);
16 float getNewChildValue(entity);
20 entity makeHostedKeyframe(entity obj, void(entity, float) objSetter, float animDuration, float animStart, float animEnd)
23 me = makeKeyframe(obj, objSetter, animDuration, animStart, animEnd);
24 anim.addAnim(anim, me);
28 entity makeKeyframe(entity obj, void(entity, float) objSetter, float animDuration, float animStart, float animEnd)
32 me.configureAnimation(me, obj, objSetter, time, animDuration, animStart, animEnd);
36 entity Keyframe_addEasing(entity me, float animDurationTime, float animEnd, float(float, float, float, float) func)
39 other = makeEasing(me.object, me.setter, func, getNewChildStart(me), getNewChildDuration(me, animDurationTime), getNewChildValue(me), animEnd);
40 me.addAnim(me, other);
44 float getNewChildStart(entity me)
47 return (me.lastChild.startTime + me.lastChild.duration);
52 float getNewChildDuration(entity me, float durationTime)
55 maxDura = me.duration;
56 if (me.lastChild) maxDura = maxDura - (me.lastChild.startTime + me.lastChild.duration);
58 if (0 >= dura || dura > maxDura) dura = maxDura;
62 float getNewChildValue(entity me)
65 return (me.lastChild.startValue + me.lastChild.delta);
70 void Keyframe_addAnim(entity me, entity other)
73 error("Can't add already added anim!");
75 if(other.isFinished(other))
76 error("Can't add finished anim!");
84 l.nextSibling = other;
87 me.currentChild = other;
88 me.firstChild = other;
91 other.prevSibling = l;
92 other.nextSibling = NULL;
96 float Keyframe_calcValue(entity me, float tickTime, float animDuration, float animStartValue, float animDelta)
99 if (me.currentChild.isFinished(me.currentChild))
100 me.currentChild = me.currentChild.nextSibling;
104 me.currentChild.tick(me.currentChild, tickTime);
105 return me.currentChild.value;
108 return animStartValue + animDelta;