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