]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/menu/anim/keyframe.c
initial checkin from nexuiz svn r8756
[xonotic/xonotic-data.pk3dir.git] / qcsrc / menu / anim / keyframe.c
1 #ifdef INTERFACE
2 CLASS(Keyframe) EXTENDS(Animation)
3         METHOD(Keyframe, addAnim, void(entity, entity))
4         METHOD(Keyframe, calcValue, float(entity, float, float, float, float))
5         ATTRIB(Keyframe, currentChild, entity, NULL)
6         ATTRIB(Keyframe, firstChild, entity, NULL)
7         ATTRIB(Keyframe, lastChild, entity, NULL)
8 ENDCLASS(Animation)
9 entity makeHostedKeyframe(entity, void(entity, float), float, float, float);
10 entity makeKeyframe(entity, void(entity, float), float, float, float);
11 #endif
12
13 #ifdef IMPLEMENTATION
14 entity makeHostedKeyframe(entity obj, void(entity, float) setter, float duration, float start, float end)
15 {
16         entity me;
17         me = makeKeyframe(obj, setter, duration, start, end);
18         anim.addAnim(anim, me);
19         return me;
20 }
21
22 entity makeKeyframe(entity obj, void(entity, float) setter, float duration, float start, float end)
23 {
24         entity me;
25         me = spawnKeyframe();
26         me.configureAnimation(me, obj, setter, time, duration, start, end);
27         return me;
28 }
29
30 void addAnimKeyframe(entity me, entity other)
31 {
32         if(other.parent)
33                 error("Can't add already added anim!");
34
35         if(other.isFinished(other))
36                 error("Can't add finished anim!");
37
38         other.parent = me;
39
40         entity f, l;
41         f = me.firstChild;
42         l = me.lastChild;
43
44         if(l)
45                 l.nextSibling = other;
46         else
47         {
48                 me.currentChild = other;
49                 me.firstChild = other;
50         }
51
52         other.prevSibling = l;
53         other.nextSibling = NULL;
54         me.lastChild = other;
55 }
56
57 float calcValueKeyframe(entity me, float time, float duration, float startValue, float delta)
58 {
59         if (me.currentChild)
60                 if (me.currentChild.isFinished(me.currentChild))
61                         me.currentChild = me.currentChild.nextSibling;
62
63         if (me.currentChild)
64         {
65                 me.currentChild.tick(me.currentChild, time);
66                 return me.currentChild.value;
67         }
68
69         return startValue + delta;
70 }
71 #endif