breakup walk system and add new exit animation
[carveJwlIkooP6JGAAIwe30JlM.git] / player_skate.h
1 #ifndef PLAYER_SKATE_H
2 #define PLAYER_SKATE_H
3
4 #include "player.h"
5 #include "player_api.h"
6
7 typedef struct jump_info jump_info;
8
9 struct player_skate{
10 struct player_skate_state{
11 enum skate_activity{
12 k_skate_activity_air,
13 k_skate_activity_air_to_grind,
14 k_skate_activity_ground,
15 k_skate_activity_handplant,
16 k_skate_activity_undefined,
17 k_skate_activity_grind_any,
18 k_skate_activity_grind_boardslide,
19 k_skate_activity_grind_metallic,
20 k_skate_activity_grind_back50,
21 k_skate_activity_grind_front50,
22 k_skate_activity_grind_5050
23 }
24 activity,
25 activity_prev;
26
27 u32 grind_cooldown,
28 surface_cooldown;
29
30 f32 reverse, slip, delayed_slip_dir;
31 int manual_direction;
32
33 /* tricks */
34 v3f flip_axis;
35 float flip_time,
36 flip_rate;
37
38 v3f trick_vel, /* measured in units of TAU/s */
39 trick_euler; /* measured in units of TAU */
40 v3f trick_residualv, /* spring */
41 trick_residuald;
42
43 float trick_time;
44 enum trick_type{
45 k_trick_type_none,
46 k_trick_type_kickflip,
47 k_trick_type_shuvit,
48 k_trick_type_treflip,
49 }
50 trick_type;
51 float gravity_bias;
52
53 f32 trick_input_collect;
54
55 v3f up_dir;
56 v3f head_position;
57
58 v3f throw_v;
59 v3f cog_v, cog;
60
61 float grabbing;
62 v2f grab_mouse_delta;
63
64 int charging_jump, jump_dir;
65 float jump_charge,
66 slap;
67
68 double jump_time;
69 double start_push,
70 cur_push;
71
72 v3f prev_pos;
73
74 /* initial launch conditions */
75 double air_start;
76 v3f air_init_v,
77 air_init_co;
78
79 float land_dist;
80 v3f land_normal;
81 v4f smoothed_rotation;
82
83 f32 velocity_limit, grind_y_start, skid;
84 f32 handplant_t;
85
86 v3f store_cog_v, store_cog, store_co;
87 v4f store_smoothed, store_q;
88 }
89 state;
90
91 struct player_skate_animator {
92 v3f root_co;
93 v4f root_q;
94 v3f root_v;
95
96 v3f offset,
97 local_cog;
98
99 f32 slide,
100 skid,
101 z,
102 x,
103 fly,
104 grind,
105 grind_balance,
106 stand,
107 push,
108 jump,
109 airdir,
110 weight,
111 trick_foot,
112 slap,
113 subslap,
114 reverse,
115 delayed_slip_dir,
116 grabbing;
117
118 v2f wobble;
119 f32 foot_offset[2];
120
121 v4f qfixuptotal;
122 v4f qflip;
123
124 v3f board_euler;
125 f32 board_lean;
126 v2f steer, grab;
127
128 f32 jump_charge;
129
130 /* linear anims. TODO: we can union a bunch of variables here depending
131 * on activity. */
132 f32 push_time, jump_time, handplant_t;
133 u8 jump_dir;
134 u8 trick_type;
135 u8 activity;
136 }
137 animator;
138
139 /* animation /audio
140 * --------------------------------------------------------------*/
141 struct skeleton_anim *anim_stand, *anim_highg, *anim_slide,
142 *anim_air, *anim_grind, *anim_grind_jump,
143 *anim_push, *anim_push_reverse,
144 *anim_ollie, *anim_ollie_reverse,
145 *anim_grabs, *anim_stop,
146 *anim_handplant;
147
148 /* vectors representing the direction of the axels in localspace */
149 v3f truckv0[2];
150
151 audio_channel *aud_main, *aud_slide, *aud_air;
152 enum mdl_surface_prop surface, audio_surface;
153
154 int wheel_contacts[2];
155 float sample_change_cooldown;
156
157 enum {
158 k_skate_sample_concrete,
159 k_skate_sample_wood,
160 k_skate_sample_concrete_scrape_metal,
161 k_skate_sample_concrete_scrape_wood,
162 k_skate_sample_metal_scrape_generic
163 }
164 main_sample_type;
165
166 /*
167 * Physics
168 * ----------------------------------------------------
169 */
170
171 float substep, substep_delta;
172
173 struct jump_info{
174 v3f log[50];
175 v3f n;
176 v3f apex;
177 v3f v;
178
179 float gravity;
180
181 int log_length;
182 float score,
183 land_dist;
184
185 enum prediction_type{
186 k_prediction_none,
187 k_prediction_unset,
188 k_prediction_land,
189 k_prediction_grind
190 }
191 type;
192
193 u32 colour;
194 }
195 possible_jumps[36];
196 u32 possible_jump_count;
197
198 v3f surface_picture,
199 weight_distribution,
200 grind_vec,
201 grind_dir;
202
203 float grind_strength;
204 struct grind_limit{
205 v3f ra, n;
206 float p;
207 }
208 limits[3];
209 u32 limit_count;
210 }
211 static player_skate;
212
213 enum player_skate_soundeffect {
214 k_player_skate_soundeffect_jump,
215 k_player_skate_soundeffect_tap,
216 k_player_skate_soundeffect_land_good,
217 k_player_skate_soundeffect_land_bad,
218 k_player_skate_soundeffect_grind_metal,
219 k_player_skate_soundeffect_grind_wood,
220 };
221
222 static float
223 k_friction_lat = 12.0f,
224 k_friction_resistance = 0.01f,
225
226 k_max_push_speed = 16.0f,
227 k_push_accel = 10.0f,
228 k_push_cycle_rate = 8.0f,
229
230 k_steer_ground = 2.5f,
231 k_steer_air = 3.6f,
232
233 k_jump_charge_speed = (1.0f/0.4f),
234 k_jump_force = 5.0f,
235
236 k_cog_spring = 0.2f,
237 k_cog_damp = 0.02f,
238 k_cog_mass_ratio = 0.9f,
239
240 k_mmthrow_steer = 1.0f,
241 k_mmthrow_scale = 6.0f,
242 k_mmcollect_lat = 2.0f,
243 k_mmcollect_vert = 0.0f,
244 k_mmdecay = 12.0f,
245 k_spring_angular = 1.0f,
246
247 k_spring_force = 300.0f,
248 k_spring_dampener = 5.0f,
249
250 k_grind_spring = 50.0f,
251 k_grind_aligment = 10.0f,
252 k_grind_dampener = 5.0f,
253
254 k_surface_spring = 100.0f,
255 k_surface_dampener = 40.0f,
256 k_manul_spring = 200.0f,
257 k_manul_dampener = 30.0f,
258 k_board_interia = 8.0f,
259
260 k_grind_decayxy = 30.0f,
261 k_grind_axel_min_vel = 1.0f,
262 k_grind_axel_max_angle = 0.95f, /* cosine(|a|) */
263 k_grind_axel_max_vangle = 0.4f,
264 k_grind_max_friction = 3.0f,
265 k_grind_max_edge_angle = 0.97f,
266
267 k_board_length = 0.45f,
268 k_board_width = 0.13f,
269 k_board_end_radius = 0.1f,
270 k_board_radius = 0.14f, /* 0.07 */
271
272 k_grind_balance = -40.0f,
273 k_anim_transition = 0.12f;
274
275 static void player__skate_register(void){
276 VG_VAR_F32( k_grind_dampener, flags=VG_VAR_CHEAT );
277 VG_VAR_F32( k_grind_spring, flags=VG_VAR_CHEAT );
278 VG_VAR_F32( k_grind_aligment, flags=VG_VAR_CHEAT );
279 VG_VAR_F32( k_surface_spring, flags=VG_VAR_CHEAT );
280 VG_VAR_F32( k_surface_dampener, flags=VG_VAR_CHEAT );
281 VG_VAR_F32( k_board_interia, flags=VG_VAR_CHEAT );
282 VG_VAR_F32( k_grind_decayxy, flags=VG_VAR_CHEAT );
283 VG_VAR_F32( k_grind_axel_min_vel, flags=VG_VAR_CHEAT );
284 VG_VAR_F32( k_grind_axel_max_angle, flags=VG_VAR_CHEAT );
285 VG_VAR_F32( k_grind_max_friction, flags=VG_VAR_CHEAT );
286 VG_VAR_F32( k_grind_balance, flags=VG_VAR_CHEAT );
287 VG_VAR_F32( k_friction_lat, flags=VG_VAR_CHEAT );
288
289 VG_VAR_F32( k_cog_spring, flags=VG_VAR_CHEAT );
290 VG_VAR_F32( k_cog_damp, flags=VG_VAR_CHEAT );
291 VG_VAR_F32( k_cog_mass_ratio, flags=VG_VAR_CHEAT );
292
293 VG_VAR_F32( k_spring_force, flags=VG_VAR_CHEAT );
294 VG_VAR_F32( k_spring_dampener, flags=VG_VAR_CHEAT );
295 VG_VAR_F32( k_spring_angular, flags=VG_VAR_CHEAT );
296
297 VG_VAR_F32( k_mmthrow_scale, flags=VG_VAR_CHEAT );
298 VG_VAR_F32( k_mmcollect_lat, flags=VG_VAR_CHEAT );
299 VG_VAR_F32( k_mmcollect_vert, flags=VG_VAR_CHEAT );
300 VG_VAR_F32( k_mmdecay, flags=VG_VAR_CHEAT );
301 VG_VAR_F32( k_mmthrow_steer, flags=VG_VAR_CHEAT );
302 VG_VAR_F32( k_anim_transition, flags=VG_VAR_CHEAT );
303 }
304
305 static void player__skate_bind (void);
306 static void player__skate_pre_update (void);
307 static void player__skate_update (void);
308 static void player__skate_post_update (void);
309 static void player__skate_im_gui (void);
310 static void player__skate_animate (void);
311 static void player__skate_pose (void *animator, player_pose *pose);
312 static void player__skate_effects( void *_animator, m4x3f *final_mtx,
313 struct player_board *board,
314 struct player_effects_data *effect_data );
315 static void player__skate_post_animate (void);
316 static void player__skate_animator_exchange( bitpack_ctx *ctx, void *data );
317 static void player__skate_sfx_oneshot ( u8 id, v3f pos, f32 volume );
318
319 static void player__skate_clear_mechanics(void);
320 static void player__skate_reset_animator(void);
321 static void player__approximate_best_trajectory(void);
322
323 struct player_subsystem_interface static player_subsystem_skate = {
324 .system_register = player__skate_register,
325 .bind = player__skate_bind,
326 .pre_update = player__skate_pre_update,
327 .update = player__skate_update,
328 .post_update = player__skate_post_update,
329 .im_gui = player__skate_im_gui,
330 .animate = player__skate_animate,
331 .pose = player__skate_pose,
332 .effects = player__skate_effects,
333 .post_animate = player__skate_post_animate,
334 .network_animator_exchange = player__skate_animator_exchange,
335 .sfx_oneshot = player__skate_sfx_oneshot,
336
337 .animator_data = &player_skate.animator,
338 .animator_size = sizeof(player_skate.animator),
339 .name = "Skate"
340 };
341
342 #endif /* PLAYER_SKATE_H */