reduced shader bind code dupe & adjust skate uprighter strenght
[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 float factive;
181 m4x3f board_transform;
182 mdl_submesh sm;
183 double timing_base;
184 };
185
186 struct ent_water{
187 mdl_transform transform;
188 float max_dist;
189 u32 reserved0, reserved1;
190 };
191
192 struct ent_audio_clip{
193 union{
194 mdl_file file;
195 audio_clip clip;
196 }_;
197
198 float probability;
199 };
200
201 struct volume_particles{
202 u32 blank, blank2;
203 };
204
205 struct volume_trigger{
206 u32 event, blank;
207 };
208
209 enum ent_volume_flag {
210 k_ent_volume_flag_particles = 0x1,
211 k_ent_volume_flag_disabled = 0x2
212 };
213
214 struct ent_volume{
215 mdl_transform transform;
216 m4x3f to_world, to_local;
217 u32 flags;
218
219 u32 target;
220 union{
221 volume_trigger trigger;
222 volume_particles particles;
223 };
224 };
225
226 struct ent_audio{
227 mdl_transform transform;
228 u32 flags,
229 clip_start,
230 clip_count;
231 float volume, crossfade;
232 u32 behaviour,
233 group,
234 probability_curve,
235 max_channels;
236 };
237
238 struct ent_marker{
239 mdl_transform transform;
240 u32 pstr_alias;
241 };
242
243 enum skateshop_type{
244 k_skateshop_type_boardshop,
245 k_skateshop_type_charshop,
246 k_skateshop_type_worldshop,
247 };
248
249 struct ent_skateshop{
250 mdl_transform transform;
251 u32 type, id_camera;
252
253 union{
254 struct{
255 u32 id_display,
256 id_info,
257 id_rack;
258 }
259 boards;
260
261 struct{
262 u32 id_display,
263 id_info;
264 }
265 character;
266
267 struct{
268 u32 id_display,
269 id_info;
270 }
271 worlds;
272 };
273 };
274
275 struct ent_swspreview{
276 u32 id_camera, id_display, id_display1;
277 };
278
279 struct ent_traffic{
280 mdl_transform transform;
281 u32 submesh_start,
282 submesh_count,
283 start_node,
284 node_count;
285 float speed,
286 t;
287 u32 index; /* into the path */
288 };
289
290 struct ent_camera{
291 mdl_transform transform;
292 float fov;
293 };
294
295 enum ent_menuitem_type{
296 k_ent_menuitem_type_visual = 0,
297 k_ent_menuitem_type_event_button = 1,
298 k_ent_menuitem_type_page_button = 2,
299 k_ent_menuitem_type_toggle = 3,
300 k_ent_menuitem_type_slider = 4,
301 k_ent_menuitem_type_page = 5,
302 k_ent_menuitem_type_binding = 6,
303 k_ent_menuitem_type_disabled = 90
304 };
305
306 enum ent_menuitem_stack_behaviour{
307 k_ent_menuitem_stack_append = 0,
308 k_ent_menuitem_stack_replace = 1
309 };
310
311 typedef struct ent_menuitem ent_menuitem;
312 struct ent_menuitem{
313 u32 type, groups,
314 id_links[4]; /* ent_menuitem */
315 f32 factive, fvisible;
316
317 mdl_transform transform;
318 u32 submesh_start, submesh_count;
319
320 union{ u64 _u64; /* force storage for 64bit pointers */
321 i32 *pi32;
322 f32 *pf32;
323 void *pvoid;
324 };
325
326 union{
327 struct{
328 u32 pstr_name;
329 }
330 visual;
331
332 struct{
333 u32 id_min, /* ent_marker */
334 id_max, /* . */
335 id_handle, /* ent_menuitem */
336 pstr_data;
337 }
338 slider;
339
340 struct{
341 u32 pstr,
342 stack_behaviour;
343 }
344 button;
345
346 struct{
347 u32 id_check, /* ent_menuitem */
348 pstr_data;
349 v3f offset; /* relative to parent */
350 }
351 checkmark;
352
353 struct{
354 u32 pstr_name,
355 id_entrypoint, /* ent_menuitem */
356 id_viewpoint; /* ent_camera */
357 }
358 page;
359
360 struct{
361 u32 pstr_bind,
362 font_variant;
363 }
364 binding;
365 };
366 };
367
368 struct ent_worldinfo{
369 u32 pstr_name, pstr_author, pstr_desc;
370 f32 timezone;
371 };
372
373 static ent_marker *ent_find_marker( mdl_context *mdl,
374 mdl_array_ptr *arr, const char *alias )
375 {
376 for( u32 i=0; i<mdl_arrcount(arr); i++ ){
377 ent_marker *marker = mdl_arritm( arr, i );
378
379 if( !strcmp( mdl_pstr( mdl, marker->pstr_alias ), alias ) ){
380 return marker;
381 }
382 }
383
384 return NULL;
385 }
386
387 enum channel_behaviour{
388 k_channel_behaviour_unlimited = 0,
389 k_channel_behaviour_discard_if_full = 1,
390 k_channel_behaviour_crossfade_if_full = 2
391 };
392
393 enum probability_curve{
394 k_probability_curve_constant = 0,
395 k_probability_curve_wildlife_day = 1,
396 k_probability_curve_wildlife_night = 2
397 };
398
399 struct ent_font{
400 u32 alias,
401 variant_start,
402 variant_count,
403 glyph_start,
404 glyph_count,
405 glyph_utf32_base;
406 };
407
408 struct ent_font_variant{
409 u32 name,
410 material_id;
411 };
412
413 struct ent_glyph{
414 v2f size;
415 u32 indice_start,
416 indice_count;
417 };
418
419 struct ent_ccmd{
420 u32 pstr_command;
421 };
422
423 enum ent_objective_filter{
424 k_ent_objective_filter_none = 0x00000000,
425 k_ent_objective_filter_trick_shuvit = 0x00000001,
426 k_ent_objective_filter_trick_kickflip = 0x00000002,
427 k_ent_objective_filter_trick_treflip = 0x00000004,
428 k_ent_objective_filter_trick_any =
429 k_ent_objective_filter_trick_shuvit|
430 k_ent_objective_filter_trick_treflip|
431 k_ent_objective_filter_trick_kickflip,
432 k_ent_objective_filter_flip_back = 0x00000008,
433 k_ent_objective_filter_flip_front = 0x00000010,
434 k_ent_objective_filter_flip_any =
435 k_ent_objective_filter_flip_back|
436 k_ent_objective_filter_flip_front,
437 k_ent_objective_filter_grind_truck_any = 0x00000020,
438 k_ent_objective_filter_grind_board_any = 0x00000040,
439 k_ent_objective_filter_grind_any =
440 k_ent_objective_filter_grind_truck_any|
441 k_ent_objective_filter_grind_board_any,
442 k_ent_objective_filter_footplant = 0x00000080,
443 k_ent_objective_filter_passthrough = 0x00000100
444 };
445
446 enum ent_objective_flag {
447 k_ent_objective_hidden = 0x1,
448 k_ent_objective_passed = 0x2
449 };
450
451 struct ent_objective{
452 mdl_transform transform;
453 u32 submesh_start,
454 submesh_count,
455 flags,
456 id_next,
457 filter,filter2,
458 id_win,
459 win_event;
460 f32 time_limit;
461 };
462
463 enum ent_challenge_flag {
464 k_ent_challenge_timelimit = 0x1
465 };
466
467 struct ent_challenge{
468 mdl_transform transform;
469 u32 pstr_alias,
470 flags,
471 target,
472 target_event,
473 reset,
474 reset_event,
475 first,
476 camera,
477 status;
478 };
479
480 struct ent_relay {
481 u32 targets[4][2];
482 };
483
484 struct ent_cubemap {
485 v3f co;
486 u32 resolution, live, texture_id,
487 framebuffer_id, renderbuffer_id, placeholder[2];
488 };
489
490 typedef struct ent_call ent_call;
491 struct ent_call{
492 u32 id, function;
493 void *data;
494 };
495
496 #include "world.h"
497 static void entity_call( world_instance *world, ent_call *call );
498
499 #endif /* ENTITY_H */