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