achievements
[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
30 enum entity_alias{
31 k_ent_none = 0,
32 k_ent_gate = 1,
33 k_ent_spawn = 2,
34 k_ent_route_node = 3,
35 k_ent_route = 4,
36 k_ent_water = 5,
37 k_ent_volume = 6,
38 k_ent_audio = 7,
39 k_ent_marker = 8,
40 k_ent_font = 9,
41 k_ent_font_variant= 10,
42 k_ent_traffic = 11,
43 k_ent_skateshop = 12,
44 k_ent_camera = 13,
45 k_ent_swspreview = 14,
46 k_ent_menuitem = 15,
47 k_ent_worldinfo = 16,
48 k_ent_ccmd = 17
49 };
50
51 static u32 mdl_entity_id_type( u32 entity_id ){
52 return (entity_id & 0xffff0000) >> 16;
53 }
54
55 static u32 mdl_entity_id_id( u32 entity_id ){
56 return entity_id & 0x0000ffff;
57 }
58
59 static u32 mdl_entity_id( u32 type, u32 index ){
60 return (type & 0xfffff)<<16 | (index & 0xfffff);
61 }
62
63 enum entity_function{
64 k_ent_function_trigger,
65 k_ent_function_particle_spawn
66 };
67
68 struct ent_spawn{
69 mdl_transform transform;
70 u32 pstr_name;
71 };
72
73 enum light_type{
74 k_light_type_point = 0,
75 k_light_type_spot = 1
76 };
77
78 struct ent_light{
79 mdl_transform transform;
80 u32 daytime,
81 type;
82
83 v4f colour;
84 float angle,
85 range;
86
87 m4x3f inverse_world;
88 v2f angle_sin_cos;
89 };
90
91 enum gate_type{
92 k_gate_type_unlinked = 0,
93 k_gate_type_teleport = 1,
94 k_gate_type_nonlocal_unlinked = 2,
95 k_gate_type_nonlocel = 3
96 };
97
98 struct ent_gate{
99 u32 type,
100 target,
101 key;
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 k_skateshop_type_worldshop
224 };
225
226 struct ent_skateshop{
227 mdl_transform transform;
228 u32 type, id_camera;
229
230 union{
231 struct{
232 u32 id_display,
233 id_info,
234 id_rack;
235 }
236 boards;
237
238 struct{
239 u32 id_display,
240 id_info;
241 }
242 character;
243
244 struct{
245 u32 id_display,
246 id_info;
247 }
248 worlds;
249 };
250 };
251
252 struct ent_swspreview{
253 u32 id_camera, id_display, id_display1;
254 };
255
256 struct ent_traffic{
257 mdl_transform transform;
258 u32 submesh_start,
259 submesh_count,
260 start_node,
261 node_count;
262 float speed,
263 t;
264 u32 index; /* into the path */
265 };
266
267 struct ent_camera{
268 mdl_transform transform;
269 float fov;
270 };
271
272 enum ent_menuitem_type{
273 k_ent_menuitem_type_visual = 0,
274 k_ent_menuitem_type_event_button = 1,
275 k_ent_menuitem_type_page_button = 2,
276 k_ent_menuitem_type_toggle = 3,
277 k_ent_menuitem_type_slider = 4,
278 k_ent_menuitem_type_page = 5
279 };
280
281 typedef struct ent_menuitem ent_menuitem;
282 struct ent_menuitem{
283 u32 type, groups,
284 id_links[4]; /* ent_menuitem */
285 f32 factive, fvisible;
286
287 mdl_transform transform;
288 u32 submesh_start, submesh_count;
289
290 union{ u64 _u64; /* force storage for 64bit pointers */
291 i32 *pi32;
292 f32 *pf32;
293 void *pvoid;
294 };
295
296 union{
297 struct{
298 u32 id_min, /* ent_marker */
299 id_max, /* . */
300 id_handle, /* ent_menuitem */
301 pstr_data;
302 }
303 slider;
304
305 struct{
306 u32 pstr;
307 }
308 button;
309
310 struct{
311 u32 id_check, /* ent_menuitem */
312 pstr_data;
313 v3f offset; /* relative to parent */
314 }
315 checkmark;
316
317 struct{
318 u32 pstr_name,
319 id_entrypoint, /* ent_menuitem */
320 id_viewpoint; /* ent_camera */
321 }
322 page;
323 };
324 };
325
326 struct ent_worldinfo{
327 u32 pstr_name, pstr_author, pstr_desc;
328 f32 timezone;
329 };
330
331 VG_STATIC ent_marker *ent_find_marker( mdl_context *mdl,
332 mdl_array_ptr *arr, const char *alias )
333 {
334 for( u32 i=0; i<mdl_arrcount(arr); i++ ){
335 ent_marker *marker = mdl_arritm( arr, i );
336
337 if( !strcmp( mdl_pstr( mdl, marker->pstr_alias ), alias ) ){
338 return marker;
339 }
340 }
341
342 return NULL;
343 }
344
345 enum channel_behaviour{
346 k_channel_behaviour_unlimited = 0,
347 k_channel_behaviour_discard_if_full = 1,
348 k_channel_behaviour_crossfade_if_full = 2
349 };
350
351 enum probability_curve{
352 k_probability_curve_constant = 0,
353 k_probability_curve_wildlife_day = 1,
354 k_probability_curve_wildlife_night = 2
355 };
356
357 struct ent_font{
358 u32 alias,
359 variant_start,
360 variant_count,
361 glyph_start,
362 glyph_count,
363 glyph_utf32_base;
364 };
365
366 struct ent_font_variant{
367 u32 name,
368 material_id;
369 };
370
371 struct ent_glyph{
372 v2f size;
373 u32 indice_start,
374 indice_count;
375 };
376
377 struct ent_ccmd{
378 u32 pstr_command;
379 };
380
381 typedef struct ent_call ent_call;
382 struct ent_call{
383 u32 id, function;
384 void *data;
385 };
386
387 #include "world.h"
388 VG_STATIC void entity_call( world_instance *world, ent_call *call );
389
390 #endif /* ENTITY_H */