the luxuries of a modern C compiler
[carveJwlIkooP6JGAAIwe30JlM.git] / entity.h
1 #ifndef ENTITY_H
2 #define ENTITY_H
3
4 #include "model.h"
5
6 typedef struct ent_spawn ent_spawn;
7 typedef struct ent_light ent_light;
8 typedef struct ent_gate ent_gate;
9 typedef struct ent_route_node ent_route_node;
10 typedef struct ent_path_index ent_path_index;
11 typedef struct ent_checkpoint ent_checkpoint;
12 typedef struct ent_route ent_route;
13 typedef struct ent_water ent_water;
14 typedef struct ent_audio_clip ent_audio_clip;
15 typedef struct volume_particles volume_particles;
16 typedef struct volume_trigger volume_trigger;
17 typedef struct ent_volume ent_volume;
18 typedef struct ent_audio ent_audio;
19 typedef struct ent_marker ent_marker;
20 typedef struct ent_traffic ent_traffic;
21 typedef struct ent_font ent_font;
22 typedef struct ent_font_variant ent_font_variant;
23 typedef struct ent_glyph ent_glyph;
24 typedef struct ent_skateshop ent_skateshop;
25 typedef struct ent_camera ent_camera;
26 typedef struct ent_swspreview ent_swspreview;
27 typedef struct ent_worldinfo ent_worldinfo;
28
29 enum entity_alias{
30 k_ent_none = 0,
31 k_ent_gate = 1,
32 k_ent_spawn = 2,
33 k_ent_route_node = 3,
34 k_ent_route = 4,
35 k_ent_water = 5,
36 k_ent_volume = 6,
37 k_ent_audio = 7,
38 k_ent_marker = 8,
39 k_ent_font = 9,
40 k_ent_font_variant= 10,
41 k_ent_traffic = 11,
42 k_ent_skateshop = 12,
43 k_ent_camera = 13,
44 k_ent_swspreview = 14,
45 k_ent_menuitem = 15,
46 k_ent_worldinfo = 16
47 };
48
49 static u32 mdl_entity_id_type( u32 entity_id )
50 {
51 return (entity_id & 0xffff0000) >> 16;
52 }
53
54 static u32 mdl_entity_id_id( u32 entity_id )
55 {
56 return entity_id & 0x0000ffff;
57 }
58
59 static u32 mdl_entity_id( u32 type, u32 index )
60 {
61 return (type & 0xfffff)<<16 | (index & 0xfffff);
62 }
63
64 enum entity_function{
65 k_ent_function_trigger,
66 k_ent_function_particle_spawn
67 };
68
69 struct ent_spawn{
70 mdl_transform transform;
71 u32 pstr_name;
72 };
73
74 enum light_type{
75 k_light_type_point = 0,
76 k_light_type_spot = 1
77 };
78
79 struct ent_light{
80 mdl_transform transform;
81 u32 daytime,
82 type;
83
84 v4f colour;
85 float angle,
86 range;
87
88 m4x3f inverse_world;
89 v2f angle_sin_cos;
90 };
91
92 enum gate_type{
93 k_gate_type_unlinked = 0,
94 k_gate_type_teleport = 1,
95 k_gate_type_nonlocal_unlinked = 2,
96 k_gate_type_nonlocel = 3
97 };
98
99 struct ent_gate{
100 u32 type,
101 target,
102 key;
103
104 v3f dimensions,
105 co[2];
106
107 v4f q[2];
108
109 /* runtime */
110 m4x3f to_world, transport;
111
112 union{
113 u32 timing_version;
114
115 struct{
116 u8 ref_count;
117 };
118 };
119
120 double timing_time;
121 u16 routes[4]; /* routes that pass through this gate */
122 u8 route_count;
123 };
124
125 struct ent_route_node{
126 v3f co;
127 u8 ref_count, ref_total;
128 };
129
130 struct ent_path_index{
131 u16 index;
132 };
133
134 struct ent_checkpoint{
135 u16 gate_index,
136 path_start,
137 path_count;
138 };
139
140 struct ent_route{
141
142 union{
143 mdl_transform transform;
144 u32 official_track_id;
145 };
146
147 u32 pstr_name;
148 u16 checkpoints_start,
149 checkpoints_count;
150
151 v4f colour;
152
153 /* runtime */
154 u16 active_checkpoint,
155 valid_checkpoints;
156
157 float factive;
158 m4x3f board_transform;
159 mdl_submesh sm;
160 double timing_base;
161 };
162
163 struct ent_water{
164 mdl_transform transform;
165 float max_dist;
166 u32 reserved0, reserved1;
167 };
168
169 struct ent_audio_clip{
170 union{
171 mdl_file file;
172 audio_clip clip;
173 };
174
175 float probability;
176 };
177
178 struct volume_particles{
179 u32 blank, blank2;
180 };
181
182 struct volume_trigger{
183 u32 event, blank;
184 };
185
186 enum volume_subtype{
187 k_volume_subtype_trigger,
188 k_volume_subtype_particle
189 };
190
191 struct ent_volume{
192 mdl_transform transform;
193 m4x3f to_world, to_local;
194 u32 type;
195
196 u32 target;
197
198 union{
199 volume_trigger trigger;
200 volume_particles particles;
201 };
202 };
203
204 struct ent_audio{
205 mdl_transform transform;
206 u32 flags,
207 clip_start,
208 clip_count;
209 float volume, crossfade;
210 u32 behaviour,
211 group,
212 probability_curve,
213 max_channels;
214 };
215
216 struct ent_marker{
217 mdl_transform transform;
218 u32 pstr_alias;
219 };
220
221 enum skateshop_type{
222 k_skateshop_type_boardshop,
223 k_skateshop_type_charshop,
224 k_skateshop_type_worldshop
225 };
226
227 struct ent_skateshop{
228 mdl_transform transform;
229 u32 type, id_camera;
230
231 union{
232 struct{
233 u32 id_display,
234 id_info,
235 id_rack;
236 }
237 boards;
238
239 struct{
240 u32 id_display,
241 id_info;
242 }
243 character;
244
245 struct{
246 u32 id_display,
247 id_info;
248 }
249 worlds;
250 };
251 };
252
253 struct ent_swspreview{
254 u32 id_camera, id_display, id_display1;
255 };
256
257 struct ent_traffic{
258 mdl_transform transform;
259 u32 submesh_start,
260 submesh_count,
261 start_node,
262 node_count;
263 float speed,
264 t;
265 u32 index; /* into the path */
266 };
267
268 struct ent_camera{
269 mdl_transform transform;
270 float fov;
271 };
272
273 enum ent_menuitem_type{
274 k_ent_menuitem_type_visual = 0,
275 k_ent_menuitem_type_event_button = 1,
276 k_ent_menuitem_type_page_button = 2,
277 k_ent_menuitem_type_toggle = 3,
278 k_ent_menuitem_type_slider = 4,
279 k_ent_menuitem_type_page = 5
280 };
281
282 typedef struct ent_menuitem ent_menuitem;
283 struct ent_menuitem{
284 u32 type, groups,
285 id_links[4]; /* ent_menuitem */
286 f32 factive, fvisible;
287
288 mdl_transform transform;
289 u32 submesh_start, submesh_count;
290
291 union{ u64 _u64; /* force storage for 64bit pointers */
292 i32 *pi32;
293 f32 *pf32;
294 void *pvoid;
295 };
296
297 union{
298 struct{
299 u32 id_min, /* ent_marker */
300 id_max, /* . */
301 id_handle, /* ent_menuitem */
302 pstr_data;
303 }
304 slider;
305
306 struct{
307 u32 pstr;
308 }
309 button;
310
311 struct{
312 u32 id_check, /* ent_menuitem */
313 pstr_data;
314 v3f offset; /* relative to parent */
315 }
316 checkmark;
317
318 struct{
319 u32 pstr_name,
320 id_entrypoint, /* ent_menuitem */
321 id_viewpoint; /* ent_camera */
322 }
323 page;
324 };
325 };
326
327 struct ent_worldinfo{
328 u32 pstr_name, pstr_author, pstr_desc;
329 f32 timezone;
330 };
331
332 VG_STATIC ent_marker *ent_find_marker( mdl_context *mdl,
333 mdl_array_ptr *arr, const char *alias )
334 {
335 for( u32 i=0; i<mdl_arrcount(arr); i++ ){
336 ent_marker *marker = mdl_arritm( arr, i );
337
338 if( !strcmp( mdl_pstr( mdl, marker->pstr_alias ), alias ) ){
339 return marker;
340 }
341 }
342
343 return NULL;
344 }
345
346 enum channel_behaviour{
347 k_channel_behaviour_unlimited = 0,
348 k_channel_behaviour_discard_if_full = 1,
349 k_channel_behaviour_crossfade_if_full = 2
350 };
351
352 enum probability_curve{
353 k_probability_curve_constant = 0,
354 k_probability_curve_wildlife_day = 1,
355 k_probability_curve_wildlife_night = 2
356 };
357
358 struct ent_font{
359 u32 alias,
360 variant_start,
361 variant_count,
362 glyph_start,
363 glyph_count,
364 glyph_utf32_base;
365 };
366
367 struct ent_font_variant{
368 u32 name,
369 material_id;
370 };
371
372 struct ent_glyph{
373 v2f size;
374 u32 indice_start,
375 indice_count;
376 };
377
378
379 typedef struct ent_call ent_call;
380 struct ent_call{
381 u32 id, function;
382 void *data;
383 };
384
385 #include "world.h"
386 VG_STATIC void entity_call( world_instance *world, ent_call *call );
387
388 #endif /* ENTITY_H */