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