]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/menu/anim/animation.qc
Header police
[xonotic/xonotic-data.pk3dir.git] / qcsrc / menu / anim / animation.qc
1 #include "animation.qh"
2 #ifndef ANIM_ANIMATION_H
3         #define ANIM_ANIMATION_H
4         CLASS(Animation, Object)
5                 METHOD(Animation, configureAnimation, void(entity, entity, void(entity, float), float, float, float, float));
6                 METHOD(Animation, update, void(entity, float, float, float));
7                 METHOD(Animation, setTimeStartEnd, void(entity, float, float));
8                 METHOD(Animation, setTimeStartDuration, void(entity, float, float));
9                 METHOD(Animation, setValueStartEnd, void(entity, float, float));
10                 METHOD(Animation, setValueStartDelta, void(entity, float, float));
11                 METHOD(Animation, setObjectSetter, void(entity, entity, void(entity, float)));
12                 METHOD(Animation, tick, void(entity, float));
13                 METHOD(Animation, calcValue, float(entity, float, float, float, float));
14                 METHOD(Animation, isStopped, float(entity));
15                 METHOD(Animation, stopAnim, void(entity));
16                 METHOD(Animation, resumeAnim, void(entity));
17                 METHOD(Animation, isFinished, float(entity));
18                 METHOD(Animation, finishAnim, void(entity));
19                 ATTRIB(Animation, object, entity, NULL)
20                 void setterDummy(entity, float) {}
21                 ATTRIB(Animation, setter, void(entity, float), setterDummy)
22                 ATTRIB(Animation, value, float, 0)
23                 ATTRIB(Animation, startTime, float, 0)
24                 ATTRIB(Animation, duration, float, 0)
25                 ATTRIB(Animation, startValue, float, 0)
26                 ATTRIB(Animation, delta, float, 0)
27                 ATTRIB(Animation, stopped, float, false)
28                 ATTRIB(Animation, finished, float, false)
29         ENDCLASS(Animation)
30 #endif
31
32 #ifdef IMPLEMENTATION
33         METHOD(Animation, configureAnimation, void(entity this, entity obj, void(entity, float) objSetter, float animStartTime, float animDuration, float animStartValue, float animEndValue))
34         {
35                 this.setObjectSetter(this, obj, objSetter);
36                 this.setTimeStartDuration(this, animStartTime, animDuration);
37                 this.setValueStartEnd(this, animStartValue, animEndValue);
38         }
39
40         METHOD(Animation, update, void(entity this, float animDuration, float animStartValue, float animEndValue))
41         {
42                 this.setTimeStartDuration(this, time, animDuration);
43                 this.setValueStartEnd(this, animStartValue, animEndValue);
44         }
45
46         METHOD(Animation, setTimeStartEnd, void(entity this, float s, float e))
47         {
48                 this.startTime = s;
49                 this.duration = e - s;
50         }
51
52         METHOD(Animation, setTimeStartDuration, void(entity this, float s, float d))
53         {
54                 this.startTime = s;
55                 this.duration = d;
56         }
57
58         METHOD(Animation, setValueStartEnd, void(entity this, float s, float e))
59         {
60                 this.startValue = s;
61                 this.delta = e - s;
62         }
63
64         METHOD(Animation, setValueStartDelta, void(entity this, float s, float d))
65         {
66                 this.startValue = s;
67                 this.delta = d;
68         }
69
70         METHOD(Animation, setObjectSetter, void(entity this, entity o, void(entity, float) s))
71         {
72                 this.object = o;
73                 this.setter = s;
74         }
75
76         METHOD(Animation, tick, void(entity this, float tickTime))
77         {
78                 if (this.isStopped(this) || this.isFinished(this) || (tickTime < this.startTime)) return;
79
80                 if (tickTime >= (this.startTime + this.duration)) this.finishAnim(this);
81                 else this.value = this.calcValue(this, (tickTime - this.startTime), this.duration, this.startValue, this.delta);
82
83                 this.setter(this.object, this.value);
84         }
85
86         METHOD(Animation, calcValue, float(entity this, float tickTime, float animDuration, float animStartValue, float animDelta))
87         {
88                 return animStartValue;
89         }
90
91         METHOD(Animation, isStopped, bool(entity this))
92         {
93                 return this.stopped;
94         }
95
96         METHOD(Animation, stopAnim, void(entity this))
97         {
98                 this.stopped = true;
99         }
100
101         METHOD(Animation, resumeAnim, void(entity this))
102         {
103                 this.stopped = false;
104         }
105
106         METHOD(Animation, isFinished, bool(entity this))
107         {
108                 return this.finished;
109         }
110
111         METHOD(Animation, finishAnim, void(entity this))
112         {
113                 this.value = this.delta + this.startValue;
114                 this.finished = true;
115                 this.setter(this.object, this.value);
116         }
117
118 #endif