]> git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/menu/anim/keyframe.qc
take3: format 903 files
[xonotic/xonotic-data.pk3dir.git] / qcsrc / menu / anim / keyframe.qc
1 #include "keyframe.qh"
2
3 #include "../menu.qh"
4 #include "easing.qh"
5
6 #include "../item/container.qh"
7
8 .entity parent;
9
10 entity makeHostedKeyframe(entity obj, void(entity, float) objSetter, float animDuration, float animStart, float animEnd)
11 {
12         entity this = makeKeyframe(obj, objSetter, animDuration, animStart, animEnd);
13         anim.addAnim(anim, this);
14         return this;
15 }
16
17 entity makeKeyframe(entity obj, void(entity, float) objSetter, float animDuration, float animStart, float animEnd)
18 {
19         entity this = NEW(Keyframe);
20         this.configureAnimation(this, obj, objSetter, time, animDuration, animStart, animEnd);
21         return this;
22 }
23
24 METHOD(Keyframe, addEasing, entity(entity this, float animDurationTime, float animEnd, float(float, float, float, float) func))
25 {
26         entity other = makeEasing(this.object, this.setter, func, getNewChildStart(this), getNewChildDuration(this, animDurationTime), getNewChildValue(this), animEnd);
27         this.addAnim(this, other);
28         return other;
29 }
30
31 float getNewChildStart(entity this)
32 {
33         if (this.lastChild) { return this.lastChild.startTime + this.lastChild.duration; } else { return 0; }
34 }
35
36 float getNewChildDuration(entity this, float durationTime)
37 {
38         float maxDura = this.duration;
39         if (this.lastChild) { maxDura = maxDura - (this.lastChild.startTime + this.lastChild.duration); }
40         float dura = durationTime;
41         if (0 >= dura || dura > maxDura) { dura = maxDura; }
42         return dura;
43 }
44
45 float getNewChildValue(entity this)
46 {
47         if (this.lastChild) { return this.lastChild.startValue + this.lastChild.delta; } else { return this.startValue; }
48 }
49
50 METHOD(Keyframe, addAnim, void(entity this, entity other))
51 {
52         if (other.parent) { error("Can't add already added anim!"); }
53
54         if (other.isFinished(other)) { error("Can't add finished anim!"); }
55
56         other.parent = this;
57
58         entity l = this.lastChild;
59
60         if (l) {
61                 l.nextSibling = other;
62         } else {
63                 this.currentChild = other;
64                 this.firstChild = other;
65         }
66
67         other.prevSibling = l;
68         other.nextSibling = NULL;
69         this.lastChild = other;
70 }
71
72 METHOD(Keyframe, calcValue, float(entity this, float tickTime, float animDuration, float animStartValue, float animDelta))
73 {
74         if (this.currentChild) {
75                 if (this.currentChild.isFinished(this.currentChild)) { this.currentChild = this.currentChild.nextSibling; } }
76
77         if (this.currentChild) {
78                 this.currentChild.tick(this.currentChild, tickTime);
79                 return this.currentChild.value;
80         }
81
82         return animStartValue + animDelta;
83 }