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