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