2 #ifndef ANIM_KEYFRAME_H
3 #define ANIM_KEYFRAME_H
4 #include "animation.qc"
5 CLASS(Keyframe, Animation)
6 METHOD(Keyframe, addEasing, entity(entity, float, float, float(float, float, float, float)));
7 METHOD(Keyframe, addAnim, void(entity, entity));
8 METHOD(Keyframe, calcValue, float(entity, float, float, float, float));
9 ATTRIB(Keyframe, currentChild, entity, NULL)
10 ATTRIB(Keyframe, firstChild, entity, NULL)
11 ATTRIB(Keyframe, lastChild, entity, NULL)
13 entity makeHostedKeyframe(entity, void(entity, float), float, float, float);
14 entity makeKeyframe(entity, void(entity, float), float, float, float);
15 float getNewChildStart(entity);
16 float getNewChildDuration(entity, float);
17 float getNewChildValue(entity);
21 entity makeHostedKeyframe(entity obj, void(entity, float) objSetter, float animDuration, float animStart, float animEnd)
23 entity this = makeKeyframe(obj, objSetter, animDuration, animStart, animEnd);
24 anim.addAnim(anim, this);
28 entity makeKeyframe(entity obj, void(entity, float) objSetter, float animDuration, float animStart, float animEnd)
30 entity this = NEW(Keyframe);
31 this.configureAnimation(this, obj, objSetter, time, animDuration, animStart, animEnd);
35 METHOD(Keyframe, addEasing, entity(entity this, float animDurationTime, float animEnd, float(float, float, float, float) func))
37 entity other = makeEasing(this.object, this.setter, func, getNewChildStart(this), getNewChildDuration(this, animDurationTime), getNewChildValue(this), animEnd);
38 this.addAnim(this, other);
42 float getNewChildStart(entity this)
44 if (this.lastChild) return this.lastChild.startTime + this.lastChild.duration;
48 float getNewChildDuration(entity this, float durationTime)
50 float maxDura = this.duration;
51 if (this.lastChild) maxDura = maxDura - (this.lastChild.startTime + this.lastChild.duration);
52 float dura = durationTime;
53 if (0 >= dura || dura > maxDura) dura = maxDura;
57 float getNewChildValue(entity this)
59 if (this.lastChild) return this.lastChild.startValue + this.lastChild.delta;
60 else return this.startValue;
63 METHOD(Keyframe, addAnim, void(entity this, entity other))
65 if (other.parent) error("Can't add already added anim!");
67 if (other.isFinished(other)) error("Can't add finished anim!");
71 entity l = this.lastChild;
75 l.nextSibling = other;
79 this.currentChild = other;
80 this.firstChild = other;
83 other.prevSibling = l;
84 other.nextSibling = NULL;
85 this.lastChild = other;
88 METHOD(Keyframe, calcValue, float(entity this, float tickTime, float animDuration, float animStartValue, float animDelta))
90 if (this.currentChild)
91 if (this.currentChild.isFinished(this.currentChild)) this.currentChild = this.currentChild.nextSibling;
93 if (this.currentChild)
95 this.currentChild.tick(this.currentChild, tickTime);
96 return this.currentChild.value;
99 return animStartValue + animDelta;