]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/menu/anim/animhost.qc
Merge branch 'master' into Mario/ctf_updates
[xonotic/xonotic-data.pk3dir.git] / qcsrc / menu / anim / animhost.qc
1 #include "../menu.qh"
2
3 #ifndef ANIM_ANIMHOST_H
4 #define ANIM_ANIMHOST_H
5 #include "../oo/base.qh"
6 CLASS(AnimHost, Object)
7         METHOD(AnimHost, addAnim, void(entity, entity))
8         METHOD(AnimHost, removeAnim, void(entity, entity))
9         METHOD(AnimHost, removeAllAnim, void(entity))
10         METHOD(AnimHost, removeObjAnim, void(entity, entity))
11         METHOD(AnimHost, stopAllAnim, void(entity))
12         METHOD(AnimHost, stopObjAnim, void(entity, entity))
13         METHOD(AnimHost, resumeAllAnim, void(entity))
14         METHOD(AnimHost, resumeObjAnim, void(entity, entity))
15         METHOD(AnimHost, finishAllAnim, void(entity))
16         METHOD(AnimHost, finishObjAnim, void(entity, entity))
17         METHOD(AnimHost, tickAll, void(entity))
18         ATTRIB(AnimHost, firstChild, entity, NULL)
19         ATTRIB(AnimHost, lastChild, entity, NULL)
20 ENDCLASS(AnimHost)
21 .entity nextSibling;
22 .entity prevSibling;
23 #endif
24
25 #ifdef IMPLEMENTATION
26 void AnimHost_addAnim(entity me, entity other)
27 {
28         if(other.parent)
29                 error("Can't add already added anim!");
30
31         if(other.isFinished(other))
32                 error("Can't add finished anim!");
33
34         other.parent = me;
35
36         entity l;
37         l = me.lastChild;
38
39         if(l)
40                 l.nextSibling = other;
41         else
42                 me.firstChild = other;
43
44         other.prevSibling = l;
45         other.nextSibling = NULL;
46         me.lastChild = other;
47 }
48
49 void AnimHost_removeAnim(entity me, entity other)
50 {
51         if(other.parent != me)
52                 error("Can't remove from wrong AnimHost!");
53
54         other.parent = NULL;
55
56         entity n, p;
57         n = other.nextSibling;
58         p = other.prevSibling;
59
60         if(p)
61                 p.nextSibling = n;
62         else
63                 me.firstChild = n;
64
65         if(n)
66                 n.prevSibling = p;
67         else
68                 me.lastChild = p;
69         remove(other);
70 }
71
72 void AnimHost_removeAllAnim(entity me)
73 {
74         entity e, tmp;
75         for(e = me.firstChild; e; e = e.nextSibling)
76         {
77                 tmp = e;
78                 e = tmp.prevSibling;
79                 me.removeAnim(me, tmp);
80         }
81 }
82
83 void AnimHost_removeObjAnim(entity me, entity obj)
84 {
85         entity e, tmp;
86         for(e = me.firstChild; e; e = e.nextSibling)
87         {
88                 if (e.object == obj)
89                 {
90                         tmp = e;
91                         e = tmp.prevSibling;
92                         me.removeAnim(me, tmp);
93                 }
94         }
95 }
96
97 void AnimHost_stopAllAnim(entity me)
98 {
99         entity e;
100         for(e = me.firstChild; e; e = e.nextSibling)
101         {
102                 e.stopAnim(e);
103         }
104 }
105
106 void AnimHost_stopObjAnim(entity me, entity obj)
107 {
108         entity e;
109         for(e = me.firstChild; e; e = e.nextSibling)
110         {
111                 if (e.object == obj)
112                 {
113                         e.stopAnim(e);
114                 }
115         }
116 }
117
118 void AnimHost_resumeAllAnim(entity me)
119 {
120         entity e;
121         for(e = me.firstChild; e; e = e.nextSibling)
122         {
123                 e.resumeAnim(e);
124         }
125 }
126
127 void AnimHost_resumeObjAnim(entity me, entity obj)
128 {
129         entity e;
130         for(e = me.firstChild; e; e = e.nextSibling)
131         {
132                 if (e.object == obj)
133                 {
134                         e.resumeAnim(e);
135                 }
136         }
137 }
138
139 void AnimHost_finishAllAnim(entity me)
140 {
141         entity e, tmp;
142         for(e = me.firstChild; e; e = e.nextSibling)
143         {
144                 tmp = e;
145                 e = tmp.prevSibling;
146                 tmp.finishAnim(tmp);
147         }
148 }
149
150 void AnimHost_finishObjAnim(entity me, entity obj)
151 {
152         entity e, tmp;
153         for(e = me.firstChild; e; e = e.nextSibling)
154         {
155                 if (e.object == obj)
156                 {
157                         tmp = e;
158                         e = tmp.prevSibling;
159                         tmp.finishAnim(tmp);
160                 }
161         }
162 }
163
164 void AnimHost_tickAll(entity me)
165 {
166         entity e, tmp;
167         for(e = me.firstChild; e; e = e.nextSibling)
168         {
169                 e.tick(e, time);
170                 if (e.isFinished(e))
171                 {
172                         tmp = e;
173                         e = tmp.prevSibling;
174                         me.removeAnim(me, tmp);
175                 }
176         }
177 }
178 #endif