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