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