]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/menu/anim/keyframe.c
Merge remote branch 'refs/remotes/origin/terencehill/bot_vs_human_fix'
[xonotic/xonotic-data.pk3dir.git] / qcsrc / menu / anim / keyframe.c
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(Animation)
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 addEasingKeyframe(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 addAnimKeyframe(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 f, l;
79         f = me.firstChild;
80         l = me.lastChild;
81
82         if(l)
83                 l.nextSibling = other;
84         else
85         {
86                 me.currentChild = other;
87                 me.firstChild = other;
88         }
89
90         other.prevSibling = l;
91         other.nextSibling = NULL;
92         me.lastChild = other;
93 }
94
95 float calcValueKeyframe(entity me, float tickTime, float animDuration, float animStartValue, float animDelta)
96 {
97         if (me.currentChild)
98                 if (me.currentChild.isFinished(me.currentChild))
99                         me.currentChild = me.currentChild.nextSibling;
100
101         if (me.currentChild)
102         {
103                 me.currentChild.tick(me.currentChild, tickTime);
104                 return me.currentChild.value;
105         }
106
107         return animStartValue + animDelta;
108 }
109 #endif