d56d70271d043a7b239b64df174f2fc6b29a33b3
[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
27 enum entity_alias{
28 k_ent_none = 0,
29 k_ent_gate = 1,
30 k_ent_spawn = 2,
31 k_ent_route_node = 3,
32 k_ent_route = 4,
33 k_ent_water = 5,
34 k_ent_volume = 6,
35 k_ent_audio = 7,
36 k_ent_marker = 8,
37 k_ent_font = 9,
38 k_ent_font_variant= 10,
39 k_ent_traffic = 11,
40 k_ent_skateshop = 12,
41 k_ent_camera = 13
42 };
43
44 static u32 mdl_entity_id_type( u32 entity_id )
45 {
46 return (entity_id & 0xffff0000) >> 16;
47 }
48
49 static u32 mdl_entity_id_id( u32 entity_id )
50 {
51 return entity_id & 0x0000ffff;
52 }
53
54 static u32 mdl_entity_id( u32 type, u32 index )
55 {
56 return (type & 0xfffff)<<16 | (index & 0xfffff);
57 }
58
59 enum entity_function{
60 k_ent_function_trigger,
61 k_ent_function_particle_spawn
62 };
63
64 struct ent_spawn{
65 mdl_transform transform;
66 u32 pstr_name;
67 };
68
69 enum light_type{
70 k_light_type_point = 0,
71 k_light_type_spot = 1
72 };
73
74 struct ent_light{
75 mdl_transform transform;
76 u32 daytime,
77 type;
78
79 v4f colour;
80 float angle,
81 range;
82
83 m4x3f inverse_world;
84 v2f angle_sin_cos;
85 };
86
87 enum gate_type{
88 k_gate_type_unlinked = 0,
89 k_gate_type_teleport = 1,
90 k_gate_type_nonlocal_unlinked = 2,
91 k_gate_type_nonlocel = 3
92 };
93
94 struct ent_gate{
95 u32 type,
96 target;
97
98 v3f dimensions,
99 co[2];
100
101 v4f q[2];
102
103 /* runtime */
104 m4x3f to_world, transport;
105
106 union{
107 u32 timing_version;
108
109 struct{
110 u8 ref_count;
111 };
112 };
113
114 double timing_time;
115 u16 routes[4]; /* routes that pass through this gate */
116 u8 route_count;
117 };
118
119 struct ent_route_node{
120 v3f co;
121 u8 ref_count, ref_total;
122 };
123
124 struct ent_path_index{
125 u16 index;
126 };
127
128 struct ent_checkpoint{
129 u16 gate_index,
130 path_start,
131 path_count;
132 };
133
134 struct ent_route{
135
136 union{
137 mdl_transform transform;
138 u32 official_track_id;
139 };
140
141 u32 pstr_name;
142 u16 checkpoints_start,
143 checkpoints_count;
144
145 v4f colour;
146
147 /* runtime */
148 u16 active_checkpoint,
149 valid_checkpoints;
150
151 float factive;
152 m4x3f board_transform;
153 mdl_submesh sm;
154 double timing_base;
155 };
156
157 struct ent_water{
158 mdl_transform transform;
159 float max_dist;
160 u32 reserved0, reserved1;
161 };
162
163 struct ent_audio_clip{
164 union{
165 mdl_file file;
166 audio_clip clip;
167 };
168
169 float probability;
170 };
171
172 struct volume_particles{
173 u32 blank, blank2;
174 };
175
176 struct volume_trigger{
177 u32 event, blank;
178 };
179
180 enum volume_subtype{
181 k_volume_subtype_trigger,
182 k_volume_subtype_particle
183 };
184
185 struct ent_volume{
186 mdl_transform transform;
187 m4x3f to_world, to_local;
188 u32 type;
189
190 u32 target;
191
192 union{
193 volume_trigger trigger;
194 volume_particles particles;
195 };
196 };
197
198 struct ent_audio{
199 mdl_transform transform;
200 u32 flags,
201 clip_start,
202 clip_count;
203 float volume, crossfade;
204 u32 behaviour,
205 group,
206 probability_curve,
207 max_channels;
208 };
209
210 struct ent_marker{
211 mdl_transform transform;
212 u32 pstr_alias;
213 };
214
215 struct ent_skateshop{
216 mdl_transform transform;
217 u32 id_display,
218 id_info,
219 id_rack,
220 id_camera;
221 };
222
223 struct ent_traffic{
224 mdl_transform transform;
225 u32 submesh_start,
226 submesh_count,
227 start_node,
228 node_count;
229 float speed,
230 t;
231 u32 index; /* into the path */
232 };
233
234 struct ent_camera{
235 mdl_transform transform;
236 float fov;
237 };
238
239 VG_STATIC ent_marker *ent_find_marker( mdl_context *mdl,
240 mdl_array_ptr *arr, const char *alias )
241 {
242 for( u32 i=0; i<mdl_arrcount(arr); i++ ){
243 ent_marker *marker = mdl_arritm( arr, i );
244
245 if( !strcmp( mdl_pstr( mdl, marker->pstr_alias ), alias ) ){
246 return marker;
247 }
248 }
249
250 return NULL;
251 }
252
253 enum channel_behaviour{
254 k_channel_behaviour_unlimited = 0,
255 k_channel_behaviour_discard_if_full = 1,
256 k_channel_behaviour_crossfade_if_full = 2
257 };
258
259 enum probability_curve{
260 k_probability_curve_constant = 0,
261 k_probability_curve_wildlife_day = 1,
262 k_probability_curve_wildlife_night = 2
263 };
264
265 struct ent_font{
266 u32 alias,
267 variant_start,
268 variant_count,
269 glyph_start,
270 glyph_count,
271 glyph_utf32_base;
272 };
273
274 struct ent_font_variant{
275 u32 name,
276 material_id;
277 };
278
279 struct ent_glyph{
280 v2f size;
281 u32 indice_start,
282 indice_count;
283 };
284
285
286 typedef struct ent_call ent_call;
287 struct ent_call{
288 u32 id, function;
289 void *data;
290 };
291
292 #include "world.h"
293
294 VG_STATIC void entity_call( world_instance *world, ent_call *call );
295
296 #endif /* ENTITY_H */