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