switch to entity list
[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 enum gate_type{
95 k_gate_type_unlinked = 0,
96 k_gate_type_teleport = 1,
97 k_gate_type_nonlocal_unlinked = 2,
98 k_gate_type_nonlocel = 3
99 };
100
101 struct ent_gate{
102 u32 type,
103 target,
104 key;
105
106 v3f dimensions,
107 co[2];
108
109 v4f q[2];
110
111 /* runtime */
112 m4x3f to_world, transport;
113
114 union{
115 u32 timing_version;
116
117 struct{
118 u8 ref_count;
119 };
120 };
121
122 double timing_time;
123 u16 routes[4]; /* routes that pass through this gate */
124 u8 route_count;
125 };
126
127 struct ent_route_node{
128 v3f co;
129 u8 ref_count, ref_total;
130 };
131
132 struct ent_path_index{
133 u16 index;
134 };
135
136 struct ent_checkpoint{
137 u16 gate_index,
138 path_start,
139 path_count;
140 };
141
142 struct ent_route{
143
144 union{
145 mdl_transform transform;
146 u32 official_track_id;
147 };
148
149 u32 pstr_name;
150 u16 checkpoints_start,
151 checkpoints_count;
152
153 v4f colour;
154
155 /* runtime */
156 u16 active_checkpoint,
157 valid_checkpoints;
158
159 float factive;
160 m4x3f board_transform;
161 mdl_submesh sm;
162 double timing_base;
163 };
164
165 struct ent_water{
166 mdl_transform transform;
167 float max_dist;
168 u32 reserved0, reserved1;
169 };
170
171 struct ent_audio_clip{
172 union{
173 mdl_file file;
174 audio_clip clip;
175 }_;
176
177 float probability;
178 };
179
180 struct volume_particles{
181 u32 blank, blank2;
182 };
183
184 struct volume_trigger{
185 u32 event, blank;
186 };
187
188 enum ent_volume_flag {
189 k_ent_volume_flag_particles = 0x1,
190 k_ent_volume_flag_disabled = 0x2
191 };
192
193 struct ent_volume{
194 mdl_transform transform;
195 m4x3f to_world, to_local;
196 u32 flags;
197
198 u32 target;
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 f32 time_limit;
390 };
391
392 typedef struct ent_call ent_call;
393 struct ent_call{
394 u32 id, function;
395 void *data;
396 };
397
398 #include "world.h"
399 VG_STATIC void entity_call( world_instance *world, ent_call *call );
400
401 #endif /* ENTITY_H */