semantics and world reloading
[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 key;
103
104 v3f dimensions,
105 co[2];
106
107 v4f q[2];
108
109 /* runtime */
110 m4x3f to_world, transport;
111
112 union{
113 u32 timing_version;
114
115 struct{
116 u8 ref_count;
117 };
118 };
119
120 double timing_time;
121 u16 routes[4]; /* routes that pass through this gate */
122 u8 route_count;
123 };
124
125 struct ent_route_node{
126 v3f co;
127 u8 ref_count, ref_total;
128 };
129
130 struct ent_path_index{
131 u16 index;
132 };
133
134 struct ent_checkpoint{
135 u16 gate_index,
136 path_start,
137 path_count;
138 };
139
140 struct ent_route{
141
142 union{
143 mdl_transform transform;
144 u32 official_track_id;
145 };
146
147 u32 pstr_name;
148 u16 checkpoints_start,
149 checkpoints_count;
150
151 v4f colour;
152
153 /* runtime */
154 u16 active_checkpoint,
155 valid_checkpoints;
156
157 float factive;
158 m4x3f board_transform;
159 mdl_submesh sm;
160 double timing_base;
161 };
162
163 struct ent_water{
164 mdl_transform transform;
165 float max_dist;
166 u32 reserved0, reserved1;
167 };
168
169 struct ent_audio_clip{
170 union{
171 mdl_file file;
172 audio_clip clip;
173 };
174
175 float probability;
176 };
177
178 struct volume_particles{
179 u32 blank, blank2;
180 };
181
182 struct volume_trigger{
183 u32 event, blank;
184 };
185
186 enum volume_subtype{
187 k_volume_subtype_trigger,
188 k_volume_subtype_particle
189 };
190
191 struct ent_volume{
192 mdl_transform transform;
193 m4x3f to_world, to_local;
194 u32 type;
195
196 u32 target;
197
198 union{
199 volume_trigger trigger;
200 volume_particles particles;
201 };
202 };
203
204 struct ent_audio{
205 mdl_transform transform;
206 u32 flags,
207 clip_start,
208 clip_count;
209 float volume, crossfade;
210 u32 behaviour,
211 group,
212 probability_curve,
213 max_channels;
214 };
215
216 struct ent_marker{
217 mdl_transform transform;
218 u32 pstr_alias;
219 };
220
221 enum skateshop_type{
222 k_skateshop_type_boardshop,
223 k_skateshop_type_charshop
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 };
245
246 struct ent_swspreview{
247 u32 id_camera, id_display, id_display1;
248 };
249
250 struct ent_traffic{
251 mdl_transform transform;
252 u32 submesh_start,
253 submesh_count,
254 start_node,
255 node_count;
256 float speed,
257 t;
258 u32 index; /* into the path */
259 };
260
261 struct ent_camera{
262 mdl_transform transform;
263 float fov;
264 };
265
266 enum ent_menuitem_type{
267 k_ent_menuitem_type_visual = 0,
268 k_ent_menuitem_type_event_button = 1,
269 k_ent_menuitem_type_page_button = 2,
270 k_ent_menuitem_type_toggle = 3,
271 k_ent_menuitem_type_slider = 4,
272 k_ent_menuitem_type_page = 5
273 };
274
275 typedef struct ent_menuitem ent_menuitem;
276 struct ent_menuitem{
277 u32 type, groups,
278 id_links[4]; /* ent_menuitem */
279 f32 factive, fvisible;
280
281 mdl_transform transform;
282 u32 submesh_start, submesh_count;
283
284 union{ u64 _u64; /* force storage for 64bit pointers */
285 i32 *pi32;
286 f32 *pf32;
287 void *pvoid;
288 };
289
290 union{
291 struct{
292 u32 id_min, /* ent_marker */
293 id_max, /* . */
294 id_handle, /* ent_menuitem */
295 pstr_data;
296 }
297 slider;
298
299 struct{
300 u32 pstr;
301 }
302 button;
303
304 struct{
305 u32 id_check, /* ent_menuitem */
306 pstr_data;
307 v3f offset; /* relative to parent */
308 }
309 checkmark;
310
311 struct{
312 u32 pstr_name,
313 id_entrypoint, /* ent_menuitem */
314 id_viewpoint; /* ent_camera */
315 }
316 page;
317 };
318 };
319
320 struct ent_worldinfo{
321 u32 pstr_name, pstr_author, pstr_desc;
322 f32 timezone;
323 };
324
325 VG_STATIC ent_marker *ent_find_marker( mdl_context *mdl,
326 mdl_array_ptr *arr, const char *alias )
327 {
328 for( u32 i=0; i<mdl_arrcount(arr); i++ ){
329 ent_marker *marker = mdl_arritm( arr, i );
330
331 if( !strcmp( mdl_pstr( mdl, marker->pstr_alias ), alias ) ){
332 return marker;
333 }
334 }
335
336 return NULL;
337 }
338
339 enum channel_behaviour{
340 k_channel_behaviour_unlimited = 0,
341 k_channel_behaviour_discard_if_full = 1,
342 k_channel_behaviour_crossfade_if_full = 2
343 };
344
345 enum probability_curve{
346 k_probability_curve_constant = 0,
347 k_probability_curve_wildlife_day = 1,
348 k_probability_curve_wildlife_night = 2
349 };
350
351 struct ent_font{
352 u32 alias,
353 variant_start,
354 variant_count,
355 glyph_start,
356 glyph_count,
357 glyph_utf32_base;
358 };
359
360 struct ent_font_variant{
361 u32 name,
362 material_id;
363 };
364
365 struct ent_glyph{
366 v2f size;
367 u32 indice_start,
368 indice_count;
369 };
370
371
372 typedef struct ent_call ent_call;
373 struct ent_call{
374 u32 id, function;
375 void *data;
376 };
377
378 #include "world.h"
379
380 #endif /* ENTITY_H */