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