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