add engine settings
[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 /* EXTENSION */
173 f32 best_time;
174 };
175
176 enum ent_route_flag {
177 k_ent_route_flag_achieve_silver = 0x1,
178 k_ent_route_flag_achieve_gold = 0x2,
179
180 k_ent_route_flag_out_of_zone = 0x10,
181 k_ent_region_flag_hasname = 0x20
182 };
183
184 struct ent_route{
185 union{
186 mdl_transform transform;
187 u32 official_track_id; /* TODO: remove this */
188 }
189 anon;
190
191 u32 pstr_name;
192 u16 checkpoints_start,
193 checkpoints_count;
194
195 v4f colour;
196
197 /* runtime */
198 u16 active_checkpoint,
199 valid_checkpoints;
200
201 f32 factive;
202 m4x3f board_transform;
203 mdl_submesh sm;
204 f64 timing_base;
205
206 u32 id_camera; /* v103+ */
207
208 /* v104+, but always accessible */
209 u32 flags;
210 f64 best_laptime;
211 f32 ui_stopper, ui_residual;
212
213 ui_px ui_first_block_width, ui_residual_block_w;
214 };
215
216 struct ent_water{
217 mdl_transform transform;
218 float max_dist;
219 u32 reserved0, reserved1;
220 };
221
222 struct ent_audio_clip{
223 union{
224 mdl_file file;
225 audio_clip clip;
226 }_;
227
228 float probability;
229 };
230
231 struct volume_particles{
232 u32 blank, blank2;
233 };
234
235 struct volume_trigger{
236 u32 event, event_leave;
237 };
238
239 enum ent_volume_flag {
240 k_ent_volume_flag_particles = 0x1,
241 k_ent_volume_flag_disabled = 0x2
242 };
243
244 struct ent_volume{
245 mdl_transform transform;
246 m4x3f to_world, to_local;
247 u32 flags;
248
249 u32 target;
250 union{
251 volume_trigger trigger;
252 volume_particles particles;
253 };
254 };
255
256 struct ent_audio{
257 mdl_transform transform;
258 u32 flags,
259 clip_start,
260 clip_count;
261 float volume, crossfade;
262 u32 behaviour,
263 group,
264 probability_curve,
265 max_channels;
266 };
267
268 struct ent_marker{
269 mdl_transform transform;
270 u32 pstr_alias;
271 };
272
273 enum skateshop_type{
274 k_skateshop_type_boardshop = 0,
275 k_skateshop_type_charshop = 1,
276 k_skateshop_type_worldshop = 2,
277 k_skateshop_type_DELETED = 3,
278 k_skateshop_type_server = 4
279 };
280
281 struct ent_skateshop{
282 mdl_transform transform;
283 u32 type, id_camera;
284
285 union{
286 struct{
287 u32 id_display,
288 id_info,
289 id_rack;
290 }
291 boards;
292
293 struct{
294 u32 id_display,
295 id_info;
296 }
297 character;
298
299 struct{
300 u32 id_display,
301 id_info;
302 }
303 worlds;
304
305 struct{
306 u32 id_lever;
307 }
308 server;
309 };
310 };
311
312 struct ent_swspreview{
313 u32 id_camera, id_display, id_display1;
314 };
315
316 struct ent_traffic{
317 mdl_transform transform;
318 u32 submesh_start,
319 submesh_count,
320 start_node,
321 node_count;
322 float speed,
323 t;
324 u32 index; /* into the path */
325 };
326
327 struct ent_camera{
328 mdl_transform transform;
329 float fov;
330 };
331
332 enum ent_menuitem_type{
333 k_ent_menuitem_type_visual = 0,
334 k_ent_menuitem_type_event_button = 1,
335 k_ent_menuitem_type_page_button = 2,
336 k_ent_menuitem_type_toggle = 3,
337 k_ent_menuitem_type_slider = 4,
338 k_ent_menuitem_type_page = 5,
339 k_ent_menuitem_type_binding = 6,
340 k_ent_menuitem_type_visual_nocol = 7,
341 k_ent_menuitem_type_disabled = 90
342 };
343
344 enum ent_menuitem_stack_behaviour{
345 k_ent_menuitem_stack_append = 0,
346 k_ent_menuitem_stack_replace = 1
347 };
348
349 typedef struct ent_menuitem ent_menuitem;
350 struct ent_menuitem{
351 u32 type, groups,
352 id_links[4]; /* ent_menuitem */
353 f32 factive, fvisible;
354
355 mdl_transform transform;
356 u32 submesh_start, submesh_count;
357
358 union{ u64 _u64; /* force storage for 64bit pointers */
359 i32 *pi32;
360 f32 *pf32;
361 void *pvoid;
362 };
363
364 union{
365 struct{
366 u32 pstr_name;
367 }
368 visual;
369
370 struct{
371 u32 id_min, /* ent_marker */
372 id_max, /* . */
373 id_handle, /* ent_menuitem */
374 pstr_data;
375 }
376 slider;
377
378 struct{
379 u32 pstr,
380 stack_behaviour;
381 }
382 button;
383
384 struct{
385 u32 id_check, /* ent_menuitem */
386 pstr_data;
387 v3f offset; /* relative to parent */
388 }
389 checkmark;
390
391 struct{
392 u32 pstr_name,
393 id_entrypoint, /* ent_menuitem */
394 id_viewpoint; /* ent_camera */
395 }
396 page;
397
398 struct{
399 u32 pstr_bind,
400 font_variant;
401 }
402 binding;
403 };
404 };
405
406 struct ent_worldinfo{
407 u32 pstr_name, pstr_author, pstr_desc;
408 f32 timezone;
409 u32 pstr_skybox;
410 u32 flags;
411 };
412
413 static ent_marker *ent_find_marker( mdl_context *mdl,
414 mdl_array_ptr *arr, const char *alias )
415 {
416 for( u32 i=0; i<mdl_arrcount(arr); i++ ){
417 ent_marker *marker = mdl_arritm( arr, i );
418
419 if( !strcmp( mdl_pstr( mdl, marker->pstr_alias ), alias ) ){
420 return marker;
421 }
422 }
423
424 return NULL;
425 }
426
427 enum channel_behaviour{
428 k_channel_behaviour_unlimited = 0,
429 k_channel_behaviour_discard_if_full = 1,
430 k_channel_behaviour_crossfade_if_full = 2
431 };
432
433 enum probability_curve{
434 k_probability_curve_constant = 0,
435 k_probability_curve_wildlife_day = 1,
436 k_probability_curve_wildlife_night = 2
437 };
438
439 struct ent_font{
440 u32 alias,
441 variant_start,
442 variant_count,
443 glyph_start,
444 glyph_count,
445 glyph_utf32_base;
446 };
447
448 struct ent_font_variant{
449 u32 name,
450 material_id;
451 };
452
453 struct ent_glyph{
454 v2f size;
455 u32 indice_start,
456 indice_count;
457 };
458
459 struct ent_ccmd{
460 u32 pstr_command;
461 };
462
463 enum ent_objective_filter{
464 k_ent_objective_filter_none = 0x00000000,
465 k_ent_objective_filter_trick_shuvit = 0x00000001,
466 k_ent_objective_filter_trick_kickflip = 0x00000002,
467 k_ent_objective_filter_trick_treflip = 0x00000004,
468 k_ent_objective_filter_trick_any =
469 k_ent_objective_filter_trick_shuvit|
470 k_ent_objective_filter_trick_treflip|
471 k_ent_objective_filter_trick_kickflip,
472 k_ent_objective_filter_flip_back = 0x00000008,
473 k_ent_objective_filter_flip_front = 0x00000010,
474 k_ent_objective_filter_flip_any =
475 k_ent_objective_filter_flip_back|
476 k_ent_objective_filter_flip_front,
477 k_ent_objective_filter_grind_truck_any = 0x00000020,
478 k_ent_objective_filter_grind_board_any = 0x00000040,
479 k_ent_objective_filter_grind_any =
480 k_ent_objective_filter_grind_truck_any|
481 k_ent_objective_filter_grind_board_any,
482 k_ent_objective_filter_footplant = 0x00000080,
483 k_ent_objective_filter_passthrough = 0x00000100
484 };
485
486 enum ent_objective_flag {
487 k_ent_objective_hidden = 0x1,
488 k_ent_objective_passed = 0x2
489 };
490
491 struct ent_objective{
492 mdl_transform transform;
493 u32 submesh_start,
494 submesh_count,
495 flags,
496 id_next,
497 filter,filter2,
498 id_win,
499 win_event;
500 f32 time_limit;
501 };
502
503 enum ent_challenge_flag {
504 k_ent_challenge_timelimit = 0x1
505 };
506
507 struct ent_challenge{
508 mdl_transform transform;
509 u32 pstr_alias,
510 flags,
511 target,
512 target_event,
513 reset,
514 reset_event,
515 first,
516 camera,
517 status;
518 };
519
520 struct ent_relay {
521 u32 targets[4][2];
522 u32 targets_events[4];
523 };
524
525 struct ent_cubemap {
526 v3f co;
527 u32 resolution, live, texture_id,
528 framebuffer_id, renderbuffer_id, placeholder[2];
529 };
530
531 typedef struct ent_call ent_call;
532 struct ent_call{
533 u32 id, function;
534 void *data;
535 };
536
537 struct ent_miniworld {
538 mdl_transform transform;
539 u32 pstr_world;
540 u32 camera;
541 u32 proxy;
542 };
543
544 struct ent_prop {
545 mdl_transform transform;
546 u32 submesh_start, submesh_count, flags, pstr_alias;
547 };
548
549 struct ent_region {
550 mdl_transform transform;
551 u32 submesh_start, submesh_count, pstr_title, flags, zone_volume;
552 };
553
554 #include "world.h"
555 static void entity_call( world_instance *world, ent_call *call );
556
557 #endif /* ENTITY_H */