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