Indentation cleanup.
[AROS-Contrib.git] / Games / XInvaders3D / object.c
blob84a70d273efc8636a095cadec0011c2e0f257d97
1 /*------------------------------------------------------------------
2 object.c:
4 XINVADERS 3D - 3d Shoot'em up
5 Copyright (C) 2000 Don Llopis
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 ------------------------------------------------------------------*/
22 #include <stdio.h>
23 #include <stdlib.h>
24 #include <sys/types.h>
25 #include "mat4x4.h"
26 #include "vec4x1.h"
27 #include "defines.h"
28 #include "object.h"
30 /*================================================================*/
32 void Objlist_clear ( OBJLIST *lst )
34 lst->obj_count = 0;
35 lst->head = NULL;
36 lst->tail = NULL;
39 /*================================================================*/
41 void Objlist_add ( OBJLIST *lst, OBJECT *obj )
43 OBJECT *tmp;
45 if ( lst->head )
47 tmp = lst->tail;
48 lst->tail->next = obj;
49 /* move tail forward */
50 lst->tail = lst->tail->next;
51 lst->tail->prev = tmp;
52 lst->tail->next = NULL;
54 /* empty list so initialize head and tail */
55 else
57 lst->head = lst->tail = obj;
58 lst->head->prev = lst->tail->prev = NULL;
59 lst->head->next = lst->tail->next = NULL;
62 lst->obj_count++;
65 /*================================================================*/
67 void Objlist_del ( OBJLIST *lst, OBJECT *obj )
69 if ( lst->head )
71 /* is the object at the head of the list */
72 if ( obj->prev == NULL )
74 /* is object both at head and tail */
75 if ( obj->next == NULL )
77 lst->head = lst->tail = NULL;
78 obj->next = obj->prev = NULL;
80 else
82 lst->head = obj->next;
83 lst->head->prev = NULL;
86 /* is the object at the end of the list */
87 else if ( obj->next == NULL )
89 lst->tail = obj->prev;
90 lst->tail->next = NULL;
92 /* otherwise object somewhere in the list */
93 else
95 obj->prev->next = obj->next;
96 obj->next->prev = obj->prev;
99 obj->next = obj->prev = NULL;
100 lst->obj_count--;
104 /*================================================================*/
106 int Objlist_count ( OBJLIST *lst )
108 return lst->obj_count;
111 /*================================================================*/
112 OBJECT * Object_new ( void )
114 OBJECT *obj;
116 obj = ( OBJECT * ) malloc ( sizeof ( OBJECT ) );
118 return obj;
120 /*================================================================*/
122 void Object_delete ( OBJECT *obj )
124 free ( obj );
125 obj = NULL;
128 /*================================================================*/
130 void Object_init ( OBJECT *obj )
132 obj->active = FALSE;
133 obj->frame = 0L;
134 obj->delay = 0L;
135 obj->max_frame = 0L;
137 obj->zone = 0L;
138 obj->zheight = 0L;
140 Vector_init ( obj->pos );
141 Vector_init ( obj->old_pos );
142 Vector_init ( obj->dir );
143 Vector_init ( obj->thrust );
145 obj->actionfn = NULL;
146 obj->drawfn = NULL;
148 obj->next = NULL;
149 obj->prev = NULL;
152 /*================================================================*/
154 void Object_set_actionfn ( OBJECT *obj, PFV1 actionfn )
156 obj->actionfn = actionfn;
159 /*================================================================*/
161 void Object_set_drawfn ( OBJECT *obj, PFV2 drawfn )
163 obj->drawfn = drawfn;
166 /*================================================================*/
168 void Object_set_model ( OBJECT *obj, MODEL *model )
170 obj->model = model;
173 /*================================================================*/
175 void Object_set_pos ( OBJECT *obj, VECTOR4 pos )
177 Vector_copy ( pos, obj->pos );
180 /*================================================================*/
181 void Object_get_pos ( OBJECT *obj, VECTOR4 pos )
183 Vector_copy ( obj->pos, pos );
186 /*================================================================*/
187 void Object_set_dir ( OBJECT *obj, VECTOR4 dir )
189 Vector_copy ( dir, obj->dir );
192 /*================================================================*/
193 void Object_get_dir ( OBJECT *obj, VECTOR4 dir )
195 Vector_copy ( obj->dir, dir );
198 /*================================================================*/
200 void Object_draw ( OBJECT *obj )
204 /*================================================================*/