world regions
[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 typedef struct ent_ccmd ent_ccmd;
29 typedef struct ent_objective ent_objective;
30 typedef struct ent_challenge ent_challenge;
31 typedef struct ent_relay ent_relay;
32 typedef struct ent_cubemap ent_cubemap;
33 typedef struct ent_miniworld ent_miniworld;
34 typedef struct ent_prop ent_prop;
35 typedef struct ent_region ent_region;
36
37 enum entity_alias{
38 k_ent_none = 0,
39 k_ent_gate = 1,
40 k_ent_spawn = 2,
41 k_ent_route_node = 3,
42 k_ent_route = 4,
43 k_ent_water = 5,
44 k_ent_volume = 6,
45 k_ent_audio = 7,
46 k_ent_marker = 8,
47 k_ent_font = 9,
48 k_ent_font_variant= 10,
49 k_ent_traffic = 11,
50 k_ent_skateshop = 12,
51 k_ent_camera = 13,
52 k_ent_swspreview = 14,
53 k_ent_menuitem = 15,
54 k_ent_worldinfo = 16,
55 k_ent_ccmd = 17,
56 k_ent_objective = 18,
57 k_ent_challenge = 19,
58 k_ent_relay = 20,
59 k_ent_cubemap = 21,
60 k_ent_miniworld = 22,
61 k_ent_prop = 23,
62 k_ent_list = 24,
63 k_ent_region = 25
64 };
65
66 static u32 mdl_entity_id_type( u32 entity_id ){
67 return (entity_id & 0x0fff0000) >> 16;
68 }
69
70 static u32 mdl_entity_id_id( u32 entity_id ){
71 return entity_id & 0x0000ffff;
72 }
73
74 static u32 mdl_entity_id( u32 type, u32 index ){
75 return (type & 0xfffff)<<16 | (index & 0xfffff);
76 }
77
78 enum entity_function{
79 k_ent_function_trigger,
80 k_ent_function_particle_spawn,
81 k_ent_function_trigger_leave
82 };
83
84 struct ent_spawn{
85 mdl_transform transform;
86 u32 pstr_name;
87 };
88
89 enum light_type{
90 k_light_type_point = 0,
91 k_light_type_spot = 1
92 };
93
94 struct ent_light{
95 mdl_transform transform;
96 u32 daytime,
97 type;
98
99 v4f colour;
100 float angle,
101 range;
102
103 m4x3f inverse_world;
104 v2f angle_sin_cos;
105 };
106
107 /* v101 */
108 #if 0
109 enum gate_type{
110 k_gate_type_unlinked = 0,
111 k_gate_type_teleport = 1,
112 k_gate_type_nonlocal_unlinked = 2,
113 k_gate_type_nonlocel = 3
114 };
115 #endif
116
117 /* v102+ */
118 enum ent_gate_flag{
119 k_ent_gate_linked = 0x1, /* this is a working portal */
120 k_ent_gate_nonlocal = 0x2, /* use the key string to link this portal.
121 NOTE: if set, it adds the flip flag. */
122 k_ent_gate_flip = 0x4, /* flip direction 180* for exiting portal */
123 k_ent_gate_custom_mesh = 0x8, /* use a custom submesh instead of default */
124 k_ent_gate_locked = 0x10,/* has to be unlocked to be useful */
125
126 k_ent_gate_clean_pass = 0x20,/* player didn't rewind while getting here */
127 };
128
129 struct ent_gate{
130 u32 flags,
131 target,
132 key;
133
134 v3f dimensions,
135 co[2];
136
137 v4f q[2];
138
139 /* runtime */
140 m4x3f to_world, transport;
141
142 union{
143 u32 timing_version;
144
145 struct{
146 u8 ref_count;
147 };
148 };
149
150 double timing_time;
151 u16 routes[4]; /* routes that pass through this gate */
152 u8 route_count;
153
154 /* v102+ */
155 u32 submesh_start, submesh_count;
156 };
157
158 struct ent_route_node{
159 v3f co;
160 u8 ref_count, ref_total;
161 };
162
163 struct ent_path_index{
164 u16 index;
165 };
166
167 struct ent_checkpoint{
168 u16 gate_index,
169 path_start,
170 path_count;
171 };
172
173 enum ent_route_flag {
174 k_ent_route_flag_achieve_silver = 0x1,
175 k_ent_route_flag_achieve_gold = 0x2,
176
177 k_ent_route_flag_out_of_zone = 0x10
178 };
179
180 struct ent_route{
181 union{
182 mdl_transform transform;
183 u32 official_track_id; /* TODO: remove this */
184 }
185 anon;
186
187 u32 pstr_name;
188 u16 checkpoints_start,
189 checkpoints_count;
190
191 v4f colour;
192
193 /* runtime */
194 u16 active_checkpoint,
195 valid_checkpoints;
196
197 f32 factive;
198 m4x3f board_transform;
199 mdl_submesh sm;
200 f64 timing_base;
201
202 u32 id_camera; /* v103+ */
203
204 /* v104+, but always accessible */
205 u32 flags;
206 f64 best_laptime;
207 };
208
209 struct ent_water{
210 mdl_transform transform;
211 float max_dist;
212 u32 reserved0, reserved1;
213 };
214
215 struct ent_audio_clip{
216 union{
217 mdl_file file;
218 audio_clip clip;
219 }_;
220
221 float probability;
222 };
223
224 struct volume_particles{
225 u32 blank, blank2;
226 };
227
228 struct volume_trigger{
229 u32 event, event_leave;
230 };
231
232 enum ent_volume_flag {
233 k_ent_volume_flag_particles = 0x1,
234 k_ent_volume_flag_disabled = 0x2
235 };
236
237 struct ent_volume{
238 mdl_transform transform;
239 m4x3f to_world, to_local;
240 u32 flags;
241
242 u32 target;
243 union{
244 volume_trigger trigger;
245 volume_particles particles;
246 };
247 };
248
249 struct ent_audio{
250 mdl_transform transform;
251 u32 flags,
252 clip_start,
253 clip_count;
254 float volume, crossfade;
255 u32 behaviour,
256 group,
257 probability_curve,
258 max_channels;
259 };
260
261 struct ent_marker{
262 mdl_transform transform;
263 u32 pstr_alias;
264 };
265
266 enum skateshop_type{
267 k_skateshop_type_boardshop = 0,
268 k_skateshop_type_charshop = 1,
269 k_skateshop_type_worldshop = 2,
270 k_skateshop_type_DELETED = 3,
271 k_skateshop_type_server = 4
272 };
273
274 struct ent_skateshop{
275 mdl_transform transform;
276 u32 type, id_camera;
277
278 union{
279 struct{
280 u32 id_display,
281 id_info,
282 id_rack;
283 }
284 boards;
285
286 struct{
287 u32 id_display,
288 id_info;
289 }
290 character;
291
292 struct{
293 u32 id_display,
294 id_info;
295 }
296 worlds;
297
298 struct{
299 u32 id_lever;
300 }
301 server;
302 };
303 };
304
305 struct ent_swspreview{
306 u32 id_camera, id_display, id_display1;
307 };
308
309 struct ent_traffic{
310 mdl_transform transform;
311 u32 submesh_start,
312 submesh_count,
313 start_node,
314 node_count;
315 float speed,
316 t;
317 u32 index; /* into the path */
318 };
319
320 struct ent_camera{
321 mdl_transform transform;
322 float fov;
323 };
324
325 enum ent_menuitem_type{
326 k_ent_menuitem_type_visual = 0,
327 k_ent_menuitem_type_event_button = 1,
328 k_ent_menuitem_type_page_button = 2,
329 k_ent_menuitem_type_toggle = 3,
330 k_ent_menuitem_type_slider = 4,
331 k_ent_menuitem_type_page = 5,
332 k_ent_menuitem_type_binding = 6,
333 k_ent_menuitem_type_visual_nocol = 7,
334 k_ent_menuitem_type_disabled = 90
335 };
336
337 enum ent_menuitem_stack_behaviour{
338 k_ent_menuitem_stack_append = 0,
339 k_ent_menuitem_stack_replace = 1
340 };
341
342 typedef struct ent_menuitem ent_menuitem;
343 struct ent_menuitem{
344 u32 type, groups,
345 id_links[4]; /* ent_menuitem */
346 f32 factive, fvisible;
347
348 mdl_transform transform;
349 u32 submesh_start, submesh_count;
350
351 union{ u64 _u64; /* force storage for 64bit pointers */
352 i32 *pi32;
353 f32 *pf32;
354 void *pvoid;
355 };
356
357 union{
358 struct{
359 u32 pstr_name;
360 }
361 visual;
362
363 struct{
364 u32 id_min, /* ent_marker */
365 id_max, /* . */
366 id_handle, /* ent_menuitem */
367 pstr_data;
368 }
369 slider;
370
371 struct{
372 u32 pstr,
373 stack_behaviour;
374 }
375 button;
376
377 struct{
378 u32 id_check, /* ent_menuitem */
379 pstr_data;
380 v3f offset; /* relative to parent */
381 }
382 checkmark;
383
384 struct{
385 u32 pstr_name,
386 id_entrypoint, /* ent_menuitem */
387 id_viewpoint; /* ent_camera */
388 }
389 page;
390
391 struct{
392 u32 pstr_bind,
393 font_variant;
394 }
395 binding;
396 };
397 };
398
399 struct ent_worldinfo{
400 u32 pstr_name, pstr_author, pstr_desc;
401 f32 timezone;
402 u32 pstr_skybox;
403 };
404
405 static ent_marker *ent_find_marker( mdl_context *mdl,
406 mdl_array_ptr *arr, const char *alias )
407 {
408 for( u32 i=0; i<mdl_arrcount(arr); i++ ){
409 ent_marker *marker = mdl_arritm( arr, i );
410
411 if( !strcmp( mdl_pstr( mdl, marker->pstr_alias ), alias ) ){
412 return marker;
413 }
414 }
415
416 return NULL;
417 }
418
419 enum channel_behaviour{
420 k_channel_behaviour_unlimited = 0,
421 k_channel_behaviour_discard_if_full = 1,
422 k_channel_behaviour_crossfade_if_full = 2
423 };
424
425 enum probability_curve{
426 k_probability_curve_constant = 0,
427 k_probability_curve_wildlife_day = 1,
428 k_probability_curve_wildlife_night = 2
429 };
430
431 struct ent_font{
432 u32 alias,
433 variant_start,
434 variant_count,
435 glyph_start,
436 glyph_count,
437 glyph_utf32_base;
438 };
439
440 struct ent_font_variant{
441 u32 name,
442 material_id;
443 };
444
445 struct ent_glyph{
446 v2f size;
447 u32 indice_start,
448 indice_count;
449 };
450
451 struct ent_ccmd{
452 u32 pstr_command;
453 };
454
455 enum ent_objective_filter{
456 k_ent_objective_filter_none = 0x00000000,
457 k_ent_objective_filter_trick_shuvit = 0x00000001,
458 k_ent_objective_filter_trick_kickflip = 0x00000002,
459 k_ent_objective_filter_trick_treflip = 0x00000004,
460 k_ent_objective_filter_trick_any =
461 k_ent_objective_filter_trick_shuvit|
462 k_ent_objective_filter_trick_treflip|
463 k_ent_objective_filter_trick_kickflip,
464 k_ent_objective_filter_flip_back = 0x00000008,
465 k_ent_objective_filter_flip_front = 0x00000010,
466 k_ent_objective_filter_flip_any =
467 k_ent_objective_filter_flip_back|
468 k_ent_objective_filter_flip_front,
469 k_ent_objective_filter_grind_truck_any = 0x00000020,
470 k_ent_objective_filter_grind_board_any = 0x00000040,
471 k_ent_objective_filter_grind_any =
472 k_ent_objective_filter_grind_truck_any|
473 k_ent_objective_filter_grind_board_any,
474 k_ent_objective_filter_footplant = 0x00000080,
475 k_ent_objective_filter_passthrough = 0x00000100
476 };
477
478 enum ent_objective_flag {
479 k_ent_objective_hidden = 0x1,
480 k_ent_objective_passed = 0x2
481 };
482
483 struct ent_objective{
484 mdl_transform transform;
485 u32 submesh_start,
486 submesh_count,
487 flags,
488 id_next,
489 filter,filter2,
490 id_win,
491 win_event;
492 f32 time_limit;
493 };
494
495 enum ent_challenge_flag {
496 k_ent_challenge_timelimit = 0x1
497 };
498
499 struct ent_challenge{
500 mdl_transform transform;
501 u32 pstr_alias,
502 flags,
503 target,
504 target_event,
505 reset,
506 reset_event,
507 first,
508 camera,
509 status;
510 };
511
512 struct ent_relay {
513 u32 targets[4][2];
514 };
515
516 struct ent_cubemap {
517 v3f co;
518 u32 resolution, live, texture_id,
519 framebuffer_id, renderbuffer_id, placeholder[2];
520 };
521
522 typedef struct ent_call ent_call;
523 struct ent_call{
524 u32 id, function;
525 void *data;
526 };
527
528 struct ent_miniworld {
529 mdl_transform transform;
530 u32 pstr_world;
531 u32 camera;
532 u32 proxy;
533 };
534
535 struct ent_prop {
536 mdl_transform transform;
537 u32 submesh_start, submesh_count, flags;
538 };
539
540 struct ent_region {
541 mdl_transform transform;
542 u32 submesh_start, submesh_count, pstr_title, flags, zone_volume;
543 };
544
545 #include "world.h"
546 static void entity_call( world_instance *world, ent_call *call );
547
548 #endif /* ENTITY_H */