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