]> icculus.org git repositories - divverent/nexuiz.git/blob - data/qcsrc/menu/anim/animation.c
little renaming and an extra check
[divverent/nexuiz.git] / data / qcsrc / menu / anim / animation.c
1 #ifdef INTERFACE
2 CLASS(Animation) EXTENDS(Object)
3         METHOD(Animation, setTimeStartEnd, void(entity, float, float))
4         METHOD(Animation, setTimeStartDuration, void(entity, float, float))
5         METHOD(Animation, setValueStartEnd, void(entity, float, float))
6         METHOD(Animation, setValueStartDelta, void(entity, float, float))
7         METHOD(Animation, setObjectSetter, void(entity, entity, void(entity, float)))
8         METHOD(Animation, tick, void(entity, float))
9         METHOD(Animation, isFinished, float(entity))
10         METHOD(Animation, stopAnim, void(entity))
11         METHOD(Animation, finishAnim, void(entity))
12         ATTRIB(Animation, object, entity, NULL)
13         ATTRIB(Animation, setter, void(entity, float), setterDummy)
14         ATTRIB(Animation, math, float(float, float, float, float), animLinear)
15         ATTRIB(Animation, value, float, 0)
16         ATTRIB(Animation, startTime, float, 0)
17         ATTRIB(Animation, duration, float, 0)
18         ATTRIB(Animation, startValue, float, 0)
19         ATTRIB(Animation, delta, float, 0)
20         ATTRIB(Animation, finished, float, FALSE)
21 ENDCLASS(Animation)
22 entity makeHostedAnimation(entity, void(entity, float), float, float, float);
23 entity makeAnimation(entity, void(entity, float), float, float, float);
24 float animLinear(float, float, float, float);
25 void setterDummy(entity, float);
26 #endif
27
28 #ifdef IMPLEMENTATION
29 entity makeHostedAnimation(entity obj, void(entity, float) setter, float duration, float start, float end)
30 {
31         entity me;
32         me = makeAnimation(obj, setter, duration, start, end);
33         anim.addAnim(anim, me);
34         return me;
35 }
36
37 entity makeAnimation(entity obj, void(entity, float) setter, float duration, float start, float end)
38 {
39         entity me;
40         me = spawnAnimation();
41         me.setObjectSetter(me, obj, setter);
42         me.setTimeStartDuration(me, time, duration);
43         me.setValueStartEnd(me, start, end);
44         return me;
45 }
46
47 void setTimeStartEndAnimation(entity me, float s, float e)
48 {
49         me.startTime = s;
50         me.duration = e - s;
51 }
52
53 void setTimeStartDurationAnimation(entity me, float s, float d)
54 {
55         me.startTime = s;
56         me.duration = d;
57 }
58
59 void setValueStartEndAnimation(entity me, float s, float e)
60 {
61         me.startValue = s;
62         me.delta = e - s;
63 }
64
65 void setValueStartDeltaAnimation(entity me, float s, float d)
66 {
67         me.startValue = s;
68         me.delta = d;
69 }
70
71 void setObjectSetterAnimation(entity me, entity o, void(entity, float) s)
72 {
73         me.object = o;
74         me.setter = s;
75 }
76
77 void tickAnimation(entity me, float time)
78 {
79         if (me.isFinished(me))
80                 return;
81
82         me.value = me.math((time - me.startTime), me.duration, me.startValue, me.delta);
83         me.setter(me.object, me.value);
84
85         if (time > (me.startTime + me.duration))
86                 me.finishAnim(me);
87 }
88
89 float isFinishedAnimation(entity me)
90 {
91         return me.finished;
92 }
93
94 void stopAnimAnimation(entity me)
95 {
96 }
97
98 void finishAnimAnimation(entity me)
99 {
100         me.finished = TRUE;
101 }
102
103 float animLinear(float time, float duration, float start, float delta)
104 {
105         if (time > duration)
106                 return delta + start;
107         return (delta * (time / duration)) + start;
108 }
109
110 void setterDummy(entity object, float value)
111 {
112 }
113
114 #endif