-
Notifications
You must be signed in to change notification settings - Fork 0
/
object.c
204 lines (164 loc) · 4.83 KB
/
object.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
/*------------------------------------------------------------------
object.c:
XINVADERS 3D - 3d Shoot'em up
Copyright (C) 2000 Don Llopis
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
------------------------------------------------------------------*/
#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include "mat4x4.h"
#include "vec4x1.h"
#include "defines.h"
#include "object.h"
/*================================================================*/
void Objlist_clear ( OBJLIST *lst )
{
lst->obj_count = 0;
lst->head = NULL;
lst->tail = NULL;
}
/*================================================================*/
void Objlist_add ( OBJLIST *lst, OBJECT *obj )
{
OBJECT *tmp;
if ( lst->head )
{
tmp = lst->tail;
lst->tail->next = obj;
/* move tail forward */
lst->tail = lst->tail->next;
lst->tail->prev = tmp;
lst->tail->next = NULL;
}
/* empty list so initialize head and tail */
else
{
lst->head = lst->tail = obj;
lst->head->prev = lst->tail->prev = NULL;
lst->head->next = lst->tail->next = NULL;
}
lst->obj_count++;
}
/*================================================================*/
void Objlist_del ( OBJLIST *lst, OBJECT *obj )
{
if ( lst->head )
{
/* is the object at the head of the list */
if ( obj->prev == NULL )
{
/* is object both at head and tail */
if ( obj->next == NULL )
{
lst->head = lst->tail = NULL;
obj->next = obj->prev = NULL;
}
else
{
lst->head = obj->next;
lst->head->prev = NULL;
}
}
/* is the object at the end of the list */
else if ( obj->next == NULL )
{
lst->tail = obj->prev;
lst->tail->next = NULL;
}
/* otherwise object somewhere in the list */
else
{
obj->prev->next = obj->next;
obj->next->prev = obj->prev;
}
obj->next = obj->prev = NULL;
lst->obj_count--;
}
}
/*================================================================*/
int Objlist_count ( OBJLIST *lst )
{
return lst->obj_count;
}
/*================================================================*/
OBJECT * Object_new ( void )
{
OBJECT *obj;
obj = ( OBJECT * ) malloc ( sizeof ( OBJECT ) );
return obj;
}
/*================================================================*/
void Object_delete ( OBJECT *obj )
{
free ( obj );
obj = NULL;
}
/*================================================================*/
void Object_init ( OBJECT *obj )
{
obj->active = FALSE;
obj->frame = 0L;
obj->delay = 0L;
obj->max_frame = 0L;
obj->zone = 0L;
obj->zheight = 0L;
Vector_init ( obj->pos );
Vector_init ( obj->old_pos );
Vector_init ( obj->dir );
Vector_init ( obj->thrust );
obj->actionfn = NULL;
obj->drawfn = NULL;
obj->next = NULL;
obj->prev = NULL;
}
/*================================================================*/
void Object_set_actionfn ( OBJECT *obj, PFV1 actionfn )
{
obj->actionfn = actionfn;
}
/*================================================================*/
void Object_set_drawfn ( OBJECT *obj, PFV2 drawfn )
{
obj->drawfn = drawfn;
}
/*================================================================*/
void Object_set_model ( OBJECT *obj, MODEL *model )
{
obj->model = model;
}
/*================================================================*/
void Object_set_pos ( OBJECT *obj, VECTOR4 pos )
{
Vector_copy ( pos, obj->pos );
}
/*================================================================*/
void Object_get_pos ( OBJECT *obj, VECTOR4 pos )
{
Vector_copy ( obj->pos, pos );
}
/*================================================================*/
void Object_set_dir ( OBJECT *obj, VECTOR4 dir )
{
Vector_copy ( dir, obj->dir );
}
/*================================================================*/
void Object_get_dir ( OBJECT *obj, VECTOR4 dir )
{
Vector_copy ( obj->dir, dir );
}
/*================================================================*/
void Object_draw ( OBJECT *obj )
{
}
/*================================================================*/