]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/menu/anim/animhost.c
Merge remote-tracking branch 'origin/samual/serverlist'
[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 l;
33         l = me.lastChild;
34
35         if(l)
36                 l.nextSibling = other;
37         else
38                 me.firstChild = other;
39
40         other.prevSibling = l;
41         other.nextSibling = NULL;
42         me.lastChild = other;
43 }
44
45 void AnimHost_removeAnim(entity me, entity other)
46 {
47         if(other.parent != me)
48                 error("Can't remove from wrong AnimHost!");
49
50         other.parent = NULL;
51
52         entity n, p;
53         n = other.nextSibling;
54         p = other.prevSibling;
55
56         if(p)
57                 p.nextSibling = n;
58         else
59                 me.firstChild = n;
60
61         if(n)
62                 n.prevSibling = p;
63         else
64                 me.lastChild = p;
65         remove(other);
66 }
67
68 void AnimHost_removeAllAnim(entity me)
69 {
70         entity e, tmp;
71         for(e = me.firstChild; e; e = e.nextSibling)
72         {
73                 tmp = e;
74                 e = tmp.prevSibling;
75                 me.removeAnim(me, tmp);
76         }
77 }
78
79 void AnimHost_removeObjAnim(entity me, entity obj)
80 {
81         entity e, tmp;
82         for(e = me.firstChild; e; e = e.nextSibling)
83         {
84                 if (e.object == obj)
85                 {
86                         tmp = e;
87                         e = tmp.prevSibling;
88                         me.removeAnim(me, tmp);
89                 }
90         }
91 }
92
93 void AnimHost_stopAllAnim(entity me)
94 {
95         entity e;
96         for(e = me.firstChild; e; e = e.nextSibling)
97         {
98                 e.stopAnim(e);
99         }
100 }
101
102 void AnimHost_stopObjAnim(entity me, entity obj)
103 {
104         entity e;
105         for(e = me.firstChild; e; e = e.nextSibling)
106         {
107                 if (e.object == obj)
108                 {
109                         e.stopAnim(e);
110                 }
111         }
112 }
113
114 void AnimHost_resumeAllAnim(entity me)
115 {
116         entity e;
117         for(e = me.firstChild; e; e = e.nextSibling)
118         {
119                 e.resumeAnim(e);
120         }
121 }
122
123 void AnimHost_resumeObjAnim(entity me, entity obj)
124 {
125         entity e;
126         for(e = me.firstChild; e; e = e.nextSibling)
127         {
128                 if (e.object == obj)
129                 {
130                         e.resumeAnim(e);
131                 }
132         }
133 }
134
135 void AnimHost_finishAllAnim(entity me)
136 {
137         entity e, tmp;
138         for(e = me.firstChild; e; e = e.nextSibling)
139         {
140                 tmp = e;
141                 e = tmp.prevSibling;
142                 tmp.finishAnim(tmp);
143         }
144 }
145
146 void AnimHost_finishObjAnim(entity me, entity obj)
147 {
148         entity e, tmp;
149         for(e = me.firstChild; e; e = e.nextSibling)
150         {
151                 if (e.object == obj)
152                 {
153                         tmp = e;
154                         e = tmp.prevSibling;
155                         tmp.finishAnim(tmp);
156                 }
157         }
158 }
159
160 void AnimHost_tickAll(entity me)
161 {
162         entity e, tmp;
163         for(e = me.firstChild; e; e = e.nextSibling)
164         {
165                 e.tick(e, time);
166                 if (e.isFinished(e))
167                 {
168                         tmp = e;
169                         e = tmp.prevSibling;
170                         me.removeAnim(me, tmp);
171                 }
172         }
173 }
174 #endif