aboutsummaryrefslogtreecommitdiff
path: root/src/types.h
blob: 200a9cc9829a84f9dd554653c73da88f024bbc25 (plain)
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
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
/*
 * types.h
 *
 * All the data types - avoid circular reference silliness
 *
 * (c) 2008 Thomas White <taw27@cam.ac.uk>
 *
 *  thrust3d - a silly game
 *
 */

#ifdef HAVE_CONFIG_H
#include <config.h>
#endif

#ifndef TYPES_H
#define TYPES_H

#include <gl.h>
#include <SDL.h>
#include <pthread.h>

/* Maximum number of individual textures */
#define MAX_TEXTURES 128

/* Maximum number of rooms which can be "seen" at once */
#define MAX_ROOMS 64

/* Maximum number of lights per room */
#define MAX_LIGHTS 4

typedef struct {

	int disable_vbos;
	int disable_fbos;
	int disable_shaders;
	int audio_debug;
	int game_debug;
	int no_music;
	int no_framerate_limit;
	int status_line;

} GameOptions;

typedef enum {
	ATTRIB_NONE	= 0,
	ATTRIB_COLOUR	= 1<<0,		/* Colour specified? */
	ATTRIB_PULSE	= 1<<1,		/* Pulsating colour */
	ATTRIB_RADIUS	= 1<<2,		/* Radius is set */
	ATTRIB_SHINY	= 1<<3,		/* Primitive is shiny */
	ATTRIB_SWIRLY	= 1<<4,		/* Primitive is texture with swirlyness */
} PrimitiveAttrib;

typedef enum {
	PRIMITIVE_QUADS,
	PRIMITIVE_TRIANGLES,
	PRIMITIVE_HEMISPHERE
} PrimitiveType;

typedef struct {

	GLenum type;
	int num_vertices;
	GLfloat *vertices;
	GLfloat *normals;
	GLfloat *texcoords;
	GLuint vertices_buffer;
	GLuint normals_buffer;
	GLuint texcoords_buffer;
	
	PrimitiveAttrib attribs;
	GLfloat col_r;
	GLfloat col_g;
	GLfloat col_b;
	char *texture;
	GLfloat radius;
	GLfloat shininess;
	
} Primitive;

typedef struct {

	char *name;		/* Identifier */
	
	int num_primitives;
	Primitive **primitives;	/* Geometry */
	
	PrimitiveAttrib attrib_total;
	
} Model;

typedef struct {
	int num_models;
	Model **models;
} ModelContext;

typedef enum {
	OBJ_NONE	= 0,
	OBJ_GRAVITY	= 1<<0,		/* Object is subject to gravity */
} ObjectAttrib;

typedef struct {
	
	Model *model;
	
	GLfloat x;
	GLfloat y;
	GLfloat z;

	ObjectAttrib attribs;
	GLfloat vx;
	GLfloat vy;
	GLfloat vz;
	
	float yaw;
	float yawspeed;
	
	int landed;			/* Object has landed */
	int recharging;			/* Object has landed on a platform, so is recharging */
	
} ModelInstance;

typedef struct {
	char *name;
	GLuint *data;
	GLuint texname;
} Texture;

typedef struct {

	int	shaders;
	int	vbos;
	int	fbos;
	
	/* Lighting shaders */
	GLuint	lighting_vert;
	GLuint	lighting_frag;
	GLuint	lighting_program;

	/* Textures */
	Texture		textures[MAX_TEXTURES];
	unsigned int	num_textures;
	
	/* Swirlyness stuff */
	GLuint		swirly_vert;
	GLuint		swirly_frag;
	GLuint		swirly_program;
	GLuint		swirly_fbo;
        GLuint		swirly_texture;
	
	GLfloat         aspect;
	int             width;
	int             height;

	GLfloat		*hemisphere_v;
	GLfloat		*hemisphere_n;
	GLfloat		*hemisphere_t;

} RenderContext;

#define AUDIO_MAX_SOUNDS 16
typedef struct {

	/* There are two mono samples in a stereo sample. */
	struct sound_struct {
		Sint16 *data;
		long dpos;		/* Number of (mono) samples played so far */
		long dlen;		/* Number of (mono) samples in 'data' */
		int inuse;
		int playing;
		int repeat;
		float volume;
		size_t decode_pos;	/* Number of (mono) samples decoded so far */
	} sounds[AUDIO_MAX_SOUNDS];
	
	pthread_mutex_t sounds_mutex;			/* Mutex for the list of sounds being played */
	pthread_t dispatch_threads[AUDIO_MAX_SOUNDS];	/* List of dispatch threads */
	int dispatch_threads_inuse[AUDIO_MAX_SOUNDS];	/* List of 'in use' flags for the dispatch threads */
	
	int debug;
	int startup;
	float startup_volume;
	int paused;
	int shutdown;
	
} AudioContext;

typedef struct {
	AudioContext *audiocontext;
	char *filename;
	float volume;
	int repeat;
	int idx;
} AudioDispatchData;

typedef struct {
	int rx;
	int ry;
	int rz;
} Connection;

typedef struct {
	GLfloat x;
	GLfloat y;
	GLfloat z;
} Light;

typedef struct {

	ModelInstance **objects;
	int num_objects;
	
	int rx;
	int ry;
	int rz;
	
	int needed_this_time;
	int checked_this_time;
	Connection connected[MAX_ROOMS];
	int num_connected;
	
	char *comment;
	
	Light lights[MAX_LIGHTS];
	int num_lights;
	
} Room;

typedef struct {

	int debug;

	unsigned int thrusting;
	unsigned int turn_left;
	unsigned int turn_right;
	unsigned int forward;
	unsigned int reverse;
	
	Uint32 tlast;			/* Time at which the last physics step was performed */
	
	ModelInstance *lander;
	
	ModelContext *models;
	RenderContext *render;
	AudioContext *audio;
	
	int cur_room_x;
	int cur_room_y;
	int cur_room_z;
	
	Room *rooms[MAX_ROOMS];
	int num_rooms;
	
	float view_angle;
	float view_dist;
	int paused;
	int pause_rel;
	
	int		frames;
	Uint32		t_fps;
	int		fps;
	
	GLfloat		radiation;
	GLfloat		fuel;
	
	GLfloat		platform_rel_x;
	GLfloat		platform_rel_y;
	GLfloat		time_of_landing_event;
		
} Game;

typedef struct {

	double nx;
	double ny;
	double nz;	/* Normal of face being collided with */
	
	double cx;
	double cy;
	double cz;	/* Coordinates of object at the moment when it collides */
	
	double ttc;
	
	ModelInstance *obj;	/* The object being collided against */

} CollisionSpec;

#endif	/* TYPES_H */