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)
22 entity this = makeKeyframe(obj, objSetter, animDuration, animStart, animEnd);
23 anim.addAnim(anim, this);
27 entity makeKeyframe(entity obj, void(entity, float) objSetter, float animDuration, float animStart, float animEnd)
29 entity this = NEW(Keyframe);
30 this.configureAnimation(this, obj, objSetter, time, animDuration, animStart, animEnd);
34 METHOD(Keyframe, addEasing, entity(entity this, float animDurationTime, float animEnd, float(float, float, float, float) func))
36 entity other = makeEasing(this.object, this.setter, func, getNewChildStart(this), getNewChildDuration(this, animDurationTime), getNewChildValue(this), animEnd);
37 this.addAnim(this, other);
41 float getNewChildStart(entity this)
43 if (this.lastChild) return this.lastChild.startTime + this.lastChild.duration;
47 float getNewChildDuration(entity this, float durationTime)
49 float maxDura = this.duration;
50 if (this.lastChild) maxDura = maxDura - (this.lastChild.startTime + this.lastChild.duration);
51 float dura = durationTime;
52 if (0 >= dura || dura > maxDura) dura = maxDura;
56 float getNewChildValue(entity this)
58 if (this.lastChild) return this.lastChild.startValue + this.lastChild.delta;
59 else return this.startValue;
62 METHOD(Keyframe, addAnim, void(entity this, entity other))
64 if (other.parent) error("Can't add already added anim!");
66 if (other.isFinished(other)) error("Can't add finished anim!");
70 entity l = this.lastChild;
74 l.nextSibling = other;
78 this.currentChild = other;
79 this.firstChild = other;
82 other.prevSibling = l;
83 other.nextSibling = NULL;
84 this.lastChild = other;
87 METHOD(Keyframe, calcValue, float(entity this, float tickTime, float animDuration, float animStartValue, float animDelta))
89 if (this.currentChild)
90 if (this.currentChild.isFinished(this.currentChild)) this.currentChild = this.currentChild.nextSibling;
92 if (this.currentChild)
94 this.currentChild.tick(this.currentChild, tickTime);
95 return this.currentChild.value;
98 return animStartValue + animDelta;