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