Nilorea Library

- Main Page
- Data Structures
- Files

- File List
- Globals

All Data Structures Files Functions Variables Typedefs Macros
n_object.c
Go to the documentation of this file.
1
15 #include "nilorea.h"
16
17
18
19 #ifndef NO_ISO_ENGINE
20
21
32 int init_object_list( OBJECT_LIST **objlst , int max )
33 {
34 if( (*objlst) )
35 return TRUE;
36
37 Malloc( (*objlst) , OBJECT_LIST , 1 );
38
39 (*objlst) -> start = NULL ;
40 (*objlst) -> end = NULL ;
41
42 (*objlst) -> nb_items = 0 ;
43
44 if( max < 1 )
45 max = -1 ;
46
47 (*objlst) -> nb_max_items = max ;
48
49 return TRUE;
50
51 } /* init_object_list( ... ) */
52
53
54
64 int destroy_object_list( OBJECT_LIST **objlist )
65 {
66 OBJECT *ptr = NULL ;
67
68 if( !(*objlist) )
69 return TRUE;
70
71 if( (*objlist) -> end )
72 {
73 while( ptr )
74 {
75 ptr = (*objlist) -> end -> prev;
76 Free( (*objlist) -> end );
77 (*objlist) -> end = ptr ;
78 }
79 }
80 Free( (*objlist) );
81
82 return TRUE;
83 } /* destroy_object_list( ... ) */
84
85
106 int add_object( OBJECT_LIST **objlist , int type , int action , int id , double X , double Y , double speed_x , double speed_y , double acc_x , double acc_y , int time_stamp , int timeout ) {
107 OBJECT *objptr = NULL ;
108
109 if( !(*objlist) )
110 return FALSE;
111
112 if( !(*objlist) -> start )
113 {
114 Malloc( (*objlist) -> start , OBJECT , 1 );
115
116 (*objlist) -> start -> type = type ;
117 (*objlist) -> start -> action = action ;
118 (*objlist) -> start -> id = id ;
119 (*objlist) -> start -> cur_pos . X = X ;
120 (*objlist) -> start -> cur_pos . Y = Y ;
121 (*objlist) -> start -> cur_pos . spd_x = speed_x ;
122 (*objlist) -> start -> cur_pos . spd_y = speed_y ;
123 (*objlist) -> start -> cur_pos . acc_x = acc_x ;
124 (*objlist) -> start -> cur_pos . acc_y = acc_y ;
125 (*objlist) -> start -> aim_pos . X = X ;
126 (*objlist) -> start -> aim_pos . Y = Y ;
127 (*objlist) -> start -> aim_pos . spd_x = speed_x ;
128 (*objlist) -> start -> aim_pos . spd_y = speed_y ;
129 (*objlist) -> start -> aim_pos . acc_x = acc_x ;
130 (*objlist) -> start -> aim_pos . acc_y = acc_y ;
131 (*objlist) -> start -> time_stamp = time_stamp ;
132 (*objlist) -> start -> timeout = timeout ;
133 (*objlist) -> start -> curr_time = time_stamp ;
134
135 (*objlist) -> nb_items = 1 ;
136 (*objlist) -> start -> next = NULL ;
137 (*objlist) -> start -> prev = NULL ;
138 (*objlist) -> end = (*objlist) -> start ;
139
140 return TRUE ;
141 }
142
143 /* searching for an update */
144
145 objptr = (*objlist) -> end ;
146
147 if( objptr )
148 {
149 while( objptr && objptr -> id != id )
150 {
151 objptr = objptr -> prev ;
152 }
153 }
154
155 if( objptr != NULL )
156 {
157 objptr -> type = type ;
158 objptr -> action = action ;
159 objptr -> id = id ;
160 objptr -> aim_pos . X = X ;
161 objptr -> aim_pos . Y = Y ;
162 objptr -> aim_pos . spd_x = speed_x ;
163 objptr -> aim_pos . spd_y = speed_y ;
164 objptr -> aim_pos . acc_x = acc_x ;
165 objptr -> aim_pos . acc_y = acc_y ;
166 objptr -> time_stamp = time_stamp ;
167 objptr -> timeout = timeout ;
168 objptr -> curr_time = time_stamp ;
169
170 return TRUE ;
171 }
172
173 Malloc( (*objlist) -> end -> next , OBJECT , 1 );
174
175 (*objlist) -> end -> next -> prev = (*objlist) -> end ;
176 (*objlist) -> end = (*objlist) -> end -> next ;
177 (*objlist) -> end -> next = NULL ;
178
179 (*objlist) -> end -> type = type ;
180 (*objlist) -> end -> action = action ;
181 (*objlist) -> end -> id = id ;
182 (*objlist) -> end -> cur_pos . X = X ;
183 (*objlist) -> end -> cur_pos . Y = Y ;
184 (*objlist) -> end -> cur_pos . spd_x = speed_x ;
185 (*objlist) -> end -> cur_pos . spd_y = speed_y ;
186 (*objlist) -> end -> cur_pos . acc_x = acc_x ;
187 (*objlist) -> end -> cur_pos . acc_y = acc_y ;
188 (*objlist) -> end -> aim_pos . X = X ;
189 (*objlist) -> end -> aim_pos . Y = Y ;
190 (*objlist) -> end -> aim_pos . spd_x = speed_x ;
191 (*objlist) -> end -> aim_pos . spd_y = speed_y ;
192 (*objlist) -> end -> aim_pos . acc_x = acc_x ;
193 (*objlist) -> end -> aim_pos . acc_y = acc_y ;
194 (*objlist) -> end -> time_stamp = time_stamp ;
195 (*objlist) -> end -> timeout = timeout ;
196 (*objlist) -> end -> curr_time = time_stamp ;
197
198 (*objlist) -> nb_items ++ ;
199
200 return TRUE;
201
202 } /* add_object( ... ) */
203
204
205
216 int rem_object( OBJECT_LIST *objlist , int id )
217 {
218 int DONE = 0 ;
219
220 OBJECT *ptr = NULL ;
221
222 if( !objlist )
223 return FALSE ;
224
225 if( objlist -> nb_items == 0 )
226 return FALSE;
227
228 ptr = objlist -> end ;
229
230 while( ptr && !DONE )
231 {
232 if( ptr -> id == id )
233 {
234 ptr -> prev -> next = ptr -> next ;
235 ptr -> next -> prev = ptr -> prev ;
236 Free( ptr );
237
238 objlist -> nb_items-- ;
239
240 DONE = TRUE ;
241 }
242
243 ptr = ptr -> prev ;
244
245 }
246
247 if( !DONE )
248 return FALSE ;
249
250 return TRUE;
251 } /* rem_object( ... ) */
252
253
254
264 int refresh_list_of_object( OBJECT_LIST **objlst )
265 {
266 static N_TIME obj_timer;
267 static int first_launch = TRUE ;
268
269 time_t elapsed = 0 ;
270
271 OBJECT *ptr = NULL ,
272 *objptr = NULL ;
273
274 if( first_launch == TRUE )
275 {
276 start_HiTimer( &obj_timer );
277 first_launch = FALSE ;
278 }
279
280 elapsed = get_usec( &obj_timer );
281
282 ptr = (*objlst) -> end ;
283
284 while( ptr )
285 {
286 if( ptr -> timeout != -1 && ptr -> curr_time > ptr -> timeout )
287 {
288
289 ptr -> curr_time += elapsed ;
290
291 if( !ptr -> next )
292 {
293 if( ptr -> prev )
294 {
295 ptr = ptr -> prev ;
296
297 Free( ptr -> next );
298
299 (*objlst) -> nb_items-- ;
300 (*objlst) -> end = ptr ;
301 }
302 else
303 {
304 Free( ptr );
305 (*objlst) -> nb_items=0 ;
306 (*objlst) -> start = (*objlst) -> end = NULL ;
307 }
308 }
309 else
310 {
311 if( ptr -> prev )
312 {
313 objptr = ptr -> prev;
314
315 ptr -> prev -> next = ptr -> next ;
316 ptr -> next -> prev = ptr -> prev ;
317
318 Free( ptr );
319
320 ptr = objptr ;
321
322 (*objlst) -> nb_items-- ;
323 }
324 else
325 {
326 objptr = ptr -> next ;
327
328 Free( ptr );
329
330 ptr = objptr ;
331 ptr -> prev = NULL ;
332
333 (*objlst) -> nb_items-- ;
334 (*objlst) -> start = ptr ;
335 }
336 }
337 }
338 else
339 {
340 if( ptr )
341 ptr = ptr -> prev ;
342 }
343 }
344
345 return TRUE;
346
347 } /* refresh_list_of_object( ... ) */
348
349
350
360 int sort_list_of_object( OBJECT_LIST *list )
361 {
362
363 if( !list )
364 return FALSE ;
365
366 return TRUE;
367 }
368
369 #endif /* #ifndef NO_ISO_ENGINE */
370
371