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