]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/menu/anim/keyframe.qc
Merge branch 'Mirio/credits' into 'master'
[xonotic/xonotic-data.pk3dir.git] / qcsrc / menu / anim / keyframe.qc
1 #ifdef INTERFACE
2 CLASS(Keyframe) EXTENDS(Animation)
3         METHOD(Keyframe, addEasing, entity(entity, float, float, float(float, float, float, float)))
4         METHOD(Keyframe, addAnim, void(entity, entity))
5         METHOD(Keyframe, calcValue, float(entity, float, float, float, float))
6         ATTRIB(Keyframe, currentChild, entity, NULL)
7         ATTRIB(Keyframe, firstChild, entity, NULL)
8         ATTRIB(Keyframe, lastChild, entity, NULL)
9 ENDCLASS(Keyframe)
10 entity makeHostedKeyframe(entity, void(entity, float), float, float, float);
11 entity makeKeyframe(entity, void(entity, float), float, float, float);
12 float getNewChildStart(entity);
13 float getNewChildDuration(entity, float);
14 float getNewChildValue(entity);
15 #endif
16
17 #ifdef IMPLEMENTATION
18 entity makeHostedKeyframe(entity obj, void(entity, float) objSetter, float animDuration, float animStart, float animEnd)
19 {
20         entity me;
21         me = makeKeyframe(obj, objSetter, animDuration, animStart, animEnd);
22         anim.addAnim(anim, me);
23         return me;
24 }
25
26 entity makeKeyframe(entity obj, void(entity, float) objSetter, float animDuration, float animStart, float animEnd)
27 {
28         entity me;
29         me = spawnKeyframe();
30         me.configureAnimation(me, obj, objSetter, time, animDuration, animStart, animEnd);
31         return me;
32 }
33
34 entity Keyframe_addEasing(entity me, float animDurationTime, float animEnd, float(float, float, float, float) func)
35 {
36         entity other;
37         other = makeEasing(me.object, me.setter, func, getNewChildStart(me), getNewChildDuration(me, animDurationTime), getNewChildValue(me), animEnd);
38         me.addAnim(me, other);
39         return other;
40 }
41
42 float getNewChildStart(entity me)
43 {
44         if (me.lastChild)
45                 return (me.lastChild.startTime + me.lastChild.duration);
46         else
47                 return 0;
48 }
49
50 float getNewChildDuration(entity me, float durationTime)
51 {
52         float dura, maxDura;
53         maxDura = me.duration;
54         if (me.lastChild) maxDura = maxDura - (me.lastChild.startTime + me.lastChild.duration);
55         dura = durationTime;
56         if (0 >= dura || dura > maxDura) dura = maxDura;
57         return dura;
58 }
59
60 float getNewChildValue(entity me)
61 {
62         if (me.lastChild)
63                 return (me.lastChild.startValue + me.lastChild.delta);
64         else
65                 return me.startValue;
66 }
67
68 void Keyframe_addAnim(entity me, entity other)
69 {
70         if(other.parent)
71                 error("Can't add already added anim!");
72
73         if(other.isFinished(other))
74                 error("Can't add finished anim!");
75
76         other.parent = me;
77
78         entity l;
79         l = me.lastChild;
80
81         if(l)
82                 l.nextSibling = other;
83         else
84         {
85                 me.currentChild = other;
86                 me.firstChild = other;
87         }
88
89         other.prevSibling = l;
90         other.nextSibling = NULL;
91         me.lastChild = other;
92 }
93
94 float Keyframe_calcValue(entity me, float tickTime, float animDuration, float animStartValue, float animDelta)
95 {
96         if (me.currentChild)
97                 if (me.currentChild.isFinished(me.currentChild))
98                         me.currentChild = me.currentChild.nextSibling;
99
100         if (me.currentChild)
101         {
102                 me.currentChild.tick(me.currentChild, tickTime);
103                 return me.currentChild.value;
104         }
105
106         return animStartValue + animDelta;
107 }
108 #endif