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