X-Git-Url: https://harrygodden.com/git/?a=blobdiff_plain;f=player_skate.c;h=1ad7231609e2f0dcc2b5abd1a2a94d9e03ce63b8;hb=e311bbe2fa903a7e2a922f202f389b799193195d;hp=1ea632a7ce1d87c78a69b6ef850f134708178787;hpb=22f62f001f21d1b91fefd9fc495c122d9ddf205a;p=carveJwlIkooP6JGAAIwe30JlM.git diff --git a/player_skate.c b/player_skate.c index 1ea632a..1ad7231 100644 --- a/player_skate.c +++ b/player_skate.c @@ -9,9 +9,7 @@ #include "addon.h" static void player__skate_bind(void){ - struct player_avatar *av = localplayer.playeravatar; - struct skeleton *sk = &av->sk; - + struct skeleton *sk = &localplayer.skeleton; rb_update_transform( &localplayer.rb ); struct { struct skeleton_anim **anim; const char *name; } @@ -119,7 +117,7 @@ static int skate_grind_scansq( v3f pos, v3f dir, float r, support_max; v3f support_axis; - v3_cross( plane, localplayer.basis[1], support_axis ); + v3_cross( plane, (v3f){0,1,0}, support_axis ); v3_normalize( support_axis ); bh_iter it; @@ -156,9 +154,9 @@ static int skate_grind_scansq( v3f pos, v3f dir, float r, v3_cross( va, vb, normal ); sample->normal[0] = v3_dot( support_axis, normal ); - sample->normal[1] = v3_dot( localplayer.basis[1], normal ); + sample->normal[1] = normal[1]; sample->co[0] = v3_dot( support_axis, d ); - sample->co[1] = v3_dot( localplayer.basis[1], d ); + sample->co[1] = d[1]; v3_copy( normal, sample->normal3 ); /* normalize later if we want to us it */ @@ -181,8 +179,7 @@ too_many_samples: if( sample_count < 2 ) return 0; - v3f - average_direction, + v3f average_direction, average_normal; v2f min_co, max_co; @@ -227,14 +224,18 @@ too_many_samples: v3_copy( si->normal3, n0 ); v3_copy( sj->normal3, n1 ); v3_cross( n0, n1, dir ); + + if( v3_length2( dir ) <= 0.000001f ) + continue; + v3_normalize( dir ); /* make sure the directions all face a common hemisphere */ v3_muls( dir, vg_signf(v3_dot(dir,plane)), dir ); v3_add( average_direction, dir, average_direction ); - float yi = v3_dot( localplayer.basis[1], si->normal3 ), - yj = v3_dot( localplayer.basis[1], sj->normal3 ); + float yi = si->normal3[1], + yj = sj->normal3[1]; if( yi > yj ) v3_add( si->normal3, average_normal, average_normal ); else v3_add( sj->normal3, average_normal, average_normal ); @@ -286,18 +287,14 @@ static int create_jumps_to_hit_target( jump_info *jumps, v3f v0; v3_sub( target, localplayer.rb.co, v0 ); - m3x3_mulv( localplayer.invbasis, v0, v0 ); v3f ax; v3_copy( v0, ax ); ax[1] = 0.0f; v3_normalize( ax ); - v3f v_local; - m3x3_mulv( localplayer.invbasis, localplayer.rb.v, v_local ); - - v2f d = { v3_dot( ax, v0 ), v0[1] }, - v = { v3_dot( ax, v_local ), v_local[1] }; + v2f d = { v3_dot( ax, v0 ), v0[1] }, + v = { v3_dot( ax, localplayer.rb.v ), localplayer.rb.v[1] }; float a = atan2f( v[1], v[0] ), m = v2_length( v ), @@ -316,7 +313,6 @@ static int create_jumps_to_hit_target( jump_info *jumps, v3_muls( ax, cosf( a0 ) * m, inf->v ); inf->v[1] += sinf( a0 ) * m; - m3x3_mulv( localplayer.basis, inf->v, inf->v ); inf->land_dist = d[0] / (cosf(a0)*m); inf->gravity = gravity; @@ -329,7 +325,6 @@ static int create_jumps_to_hit_target( jump_info *jumps, v3_muls( ax, cosf( a1 ) * m, inf->v ); inf->v[1] += sinf( a1 ) * m; - m3x3_mulv( localplayer.basis, inf->v, inf->v ); inf->land_dist = d[0] / (cosf(a1)*m); inf->gravity = gravity; @@ -357,7 +352,7 @@ static void player__approximate_best_trajectory(void){ v3_normalize( axis ); /* at high slopes, Y component is low */ - float upness = v3_dot( localplayer.rb.to_world[1], localplayer.basis[1] ), + float upness = localplayer.rb.to_world[1][1], angle_begin = -(1.0f-fabsf( upness )), angle_end = 1.0f; @@ -407,17 +402,14 @@ static void player__approximate_best_trajectory(void){ inf->gravity = gravity; v3_copy( launch_v, inf->v ); - m3x3f basis; - m3x3_copy( localplayer.basis, basis ); - for( int i=1; i<=50; i++ ){ float t = (float)i * k_trace_delta; v3_muls( launch_v, t, co1 ); - v3_muladds( co1, basis[1], -0.5f * gravity * t*t, co1 ); + co1[1] += -0.5f * gravity * t*t; v3_add( launch_co, co1, co1 ); - float launch_vy = v3_dot( launch_v,basis[1] ); + float launch_vy = launch_v[1]; int search_for_grind = 1; if( grind_located ) search_for_grind = 0; @@ -438,7 +430,7 @@ static void player__approximate_best_trajectory(void){ for( int j=0; j<2; j++ ){ v3_muls( launch_v_bounds[j], t, bound[j] ); - v3_muladds( bound[j], basis[1], -0.5f*gravity*t*t, bound[j] ); + bound[j][1] += -0.5f*gravity*t*t; v3_add( launch_co, bound[j], bound[j] ); } @@ -457,14 +449,12 @@ static void player__approximate_best_trajectory(void){ if( search_for_grind ){ v3f ve; v3_copy( launch_v, ve ); - v3_muladds( ve, basis[1], -gravity * t, ve ); + ve[1] += -gravity * t; if( skate_grind_scansq( closest, ve, 0.5f, &grind ) ){ /* check alignment */ - v2f v0 = { v3_dot( ve, basis[0] ), - v3_dot( ve, basis[2] ) }, - v1 = { v3_dot( grind.dir, basis[0] ), - v3_dot( grind.dir, basis[2] ) }; + v2f v0 = { ve[0], ve[2] }, + v1 = { grind.dir[0], grind.dir[2] }; v2_normalize( v0 ); v2_normalize( v1 ); @@ -493,11 +483,9 @@ static void player__approximate_best_trajectory(void){ m4x3_mulv( gate->transport, co1, co1 ); m3x3_mulv( gate->transport, launch_v, launch_v); m4x3_mulv( gate->transport, launch_co, launch_co ); - m3x3_mul( gate->transport, basis, basis ); - if( gate->flags & k_ent_gate_nonlocal ){ + if( gate->flags & k_ent_gate_nonlocal ) trace_world = &world_static.instances[ gate->target ]; - } } } @@ -523,7 +511,7 @@ static void player__approximate_best_trajectory(void){ v3f ve; v3_copy( launch_v, ve ); - v3_muladds( ve, localplayer.basis[1], -gravity * t, ve ); + ve[1] += -gravity * t; inf->score = -v3_dot( ve, inf->n ); inf->land_dist = t + k_trace_delta * t1; @@ -570,13 +558,10 @@ static void player__approximate_best_trajectory(void){ v3_copy( jump->v, launch_v ); v3_copy( localplayer.rb.co, launch_co ); - - m3x3f basis; - m3x3_copy( localplayer.basis, basis ); float t = 0.05f * jump->land_dist; v3_muls( launch_v, t, co0 ); - v3_muladds( co0, basis[1], -0.5f * jump->gravity * t*t, co0 ); + co0[1] += -0.5f * jump->gravity * t*t; v3_add( launch_co, co0, co0 ); /* rough scan to make sure we dont collide with anything */ @@ -587,7 +572,7 @@ static void player__approximate_best_trajectory(void){ t *= jump->land_dist; v3_muls( launch_v, t, co1 ); - v3_muladds( co1, basis[1], -0.5f * jump->gravity * t*t, co1 ); + co1[1] += -0.5f * jump->gravity * t*t; v3_add( launch_co, co1, co1 ); float t1; @@ -608,8 +593,7 @@ static void player__approximate_best_trajectory(void){ /* determine score */ v3f ve; v3_copy( jump->v, ve ); - v3_muladds( ve, localplayer.basis[1], - -jump->gravity*jump->land_dist, ve ); + ve[1] += -jump->gravity*jump->land_dist; jump->score = -v3_dot( ve, grind.n ) * 0.9f; player_skate.possible_jumps[ player_skate.possible_jump_count ++ ] = @@ -680,9 +664,8 @@ invalidated_grind:; v3_zero( state->flip_axis ); } } - else{ - v3_copy( localplayer.basis[1], state->land_normal ); - } + else + v3_copy( (v3f){0,1,0}, state->land_normal ); } /* @@ -942,7 +925,7 @@ static void skate_apply_jump_model(void){ v3f jumpdir; /* Launch more up if alignment is up else improve velocity */ - float aup = v3_dot( localplayer.basis[1], localplayer.rb.to_world[1] ), + float aup = localplayer.rb.to_world[1][1], mod = 0.5f, dir = mod + fabsf(aup)*(1.0f-mod); @@ -974,11 +957,9 @@ static void skate_apply_jump_model(void){ v3_muladds( localplayer.rb.v, jumpdir, force, localplayer.rb.v ); state->jump_charge = 0.0f; state->jump_time = vg.time; - - audio_lock(); - audio_oneshot_3d( &audio_jumps[vg_randu32()%2], - localplayer.rb.co,40.0f,1.0f); - audio_unlock(); + player__networked_sfx( k_player_subsystem_skate, 32, + k_player_skate_soundeffect_jump, + localplayer.rb.co, 1.0f ); } } @@ -1054,9 +1035,7 @@ static void skate_apply_cog_model(void){ /* Apply forces & intergrate */ v3_muladds( state->cog_v, F, -rb, state->cog_v ); - v3_muladds( state->cog_v, localplayer.basis[1], -9.8f * k_rb_delta, - state->cog_v ); - + state->cog_v[1] += -9.8f * k_rb_delta; v3_muladds( state->cog, state->cog_v, k_rb_delta, state->cog ); } @@ -1104,7 +1083,13 @@ static void player__skate_pre_update(void){ v3_copy( localplayer.cam.angles, localplayer.angles ); localplayer.angles[2] = 0.0f; - player__begin_holdout(); + v3f newpos, offset; + m4x3_mulv( localplayer.rb.to_world, (v3f){0.0f,1.0f,0.0f}, newpos ); + v3_add( newpos, (v3f){0.0f,-1.0f,0.0f}, newpos ); + v3_sub( localplayer.rb.co, newpos, offset ); + v3_copy( newpos, localplayer.rb.co ); + + player__begin_holdout( offset ); player__skate_kill_audio(); player__walk_transition(); return; @@ -1495,8 +1480,12 @@ static void skate_adjust_up_direction(void){ 8.0f * player_skate.substep_delta, state->up_dir ); } else{ - v3_lerp( state->up_dir, localplayer.basis[1], - 12.0f * player_skate.substep_delta, state->up_dir ); + v3f avg; + v3_add( localplayer.rb.to_world[1], (v3f){0,1,0}, avg ); + v3_normalize( avg ); + + v3_lerp( state->up_dir, avg, + 6.0f * player_skate.substep_delta, state->up_dir ); } } @@ -1551,7 +1540,6 @@ static void skate_grind_decay( struct grind_info *inf, float strength ){ static void skate_grind_truck_apply( float sign, struct grind_info *inf, float strength ){ struct player_skate_state *state = &player_skate.state; - /* REFACTOR */ v3f ra = { 0.0f, -k_board_radius, sign * k_board_length }; v3f raw, wsp; @@ -2039,7 +2027,9 @@ static void player__skate_update(void){ if( world->water.enabled ){ if( localplayer.rb.co[1]+0.25f < world->water.height ){ - audio_oneshot_3d( &audio_splash, localplayer.rb.co, 40.0f, 1.0f ); + player__networked_sfx( k_player_subsystem_walk, 32, + k_player_walk_soundeffect_splash, + localplayer.rb.co, 1.0f ); player__skate_kill_audio(); player__dead_transition(); return; @@ -2093,9 +2083,7 @@ static void player__skate_update(void){ } } min_dist -= 0.2f; - float vy = v3_dot( localplayer.basis[1], localplayer.rb.v ); - vy = vg_maxf( 0.0f, vy ); - + float vy = vg_maxf( 0.0f, localplayer.rb.v[1] ); slap = vg_clampf( (min_dist/0.5f) + vy, 0.0f, 1.0f )*0.3f; } state->slap = vg_lerpf( state->slap, slap, 10.0f*k_rb_delta ); @@ -2160,15 +2148,15 @@ static void player__skate_update(void){ } if( (prev_contacts[0]+prev_contacts[1] == 1) && (contact_count == 2) ){ - audio_lock(); for( int i=0; i<2; i++ ){ if( !prev_contacts[i] ){ v3f co; m4x3_mulv( localplayer.rb.to_world, wheels[i].pos, co ); - audio_oneshot_3d( &audio_taps[vg_randu32()%4], co, 40.0f, 0.75f ); + player__networked_sfx( k_player_subsystem_skate, 32, + k_player_skate_soundeffect_tap, + localplayer.rb.co, 0.75f ); } } - audio_unlock(); } if( contact_count ){ @@ -2296,9 +2284,7 @@ begin_collision:; } rb_update_transform( &localplayer.rb ); - v3_muladds( localplayer.rb.v, localplayer.basis[1], - -state->gravity_bias * player_skate.substep_delta, - localplayer.rb.v ); + localplayer.rb.v[1] += -state->gravity_bias * player_skate.substep_delta; player_skate.substep -= player_skate.substep_delta; @@ -2403,7 +2389,7 @@ begin_collision:; } /* yes, we are currently rebuilding mass matrices every frame. too bad! */ - v3f extent = { k_board_width, 0.1f, k_board_length }; + v3f extent = { k_board_width*10.0f, 0.1f, k_board_length }; float ex2 = k_board_interia*extent[0]*extent[0], ey2 = k_board_interia*extent[1]*extent[1], ez2 = k_board_interia*extent[2]*extent[2]; @@ -2524,10 +2510,11 @@ begin_collision:; skate_integrate(); vg_line_point( state->cog, 0.02f, VG__WHITE ); - ent_gate *gate = - world_intersect_gates(world, localplayer.rb.co, state->prev_pos ); + u32 id = world_intersect_gates( world, localplayer.rb.co, state->prev_pos ); + + if( id ){ + ent_gate *gate = mdl_arritm( &world->ent_gate, mdl_entity_id_id(id) ); - if( gate ){ m4x3_mulv( gate->transport, localplayer.rb.co, localplayer.rb.co ); m3x3_mulv( gate->transport, localplayer.rb.v, localplayer.rb.v ); m4x3_mulv( gate->transport, state->cog, state->cog ); @@ -2543,7 +2530,7 @@ begin_collision:; q_mul( transport_rotation, state->smoothed_rotation, state->smoothed_rotation ); rb_update_transform( &localplayer.rb ); - player__pass_gate( gate ); + player__pass_gate( id ); } /* FIXME: Rate limit */ @@ -2557,28 +2544,51 @@ begin_collision:; if( stick_frames > 5 ) stick_frames = 5; if( stick_frames == 4 ){ - audio_lock(); - if( state->activity == k_skate_activity_ground ){ if( (fabsf(state->slip) > 0.75f) ){ - audio_oneshot_3d( &audio_lands[vg_randu32()%2+3], localplayer.rb.co, - 40.0f, 1.0f ); + player__networked_sfx( k_player_subsystem_skate, 128, + k_player_skate_soundeffect_land_bad, + localplayer.rb.co, 0.6f ); } else{ - audio_oneshot_3d( &audio_lands[vg_randu32()%3], localplayer.rb.co, - 40.0f, 1.0f ); + player__networked_sfx( k_player_subsystem_skate, 128, + k_player_skate_soundeffect_land_good, + localplayer.rb.co, 1.0f ); } } else if( player_skate.surface == k_surface_prop_metal ){ - audio_oneshot_3d( &audio_board[3], localplayer.rb.co, 40.0f, 1.0f ); + player__networked_sfx( k_player_subsystem_skate, 128, + k_player_skate_soundeffect_grind_metal, + localplayer.rb.co, 1.0f ); } else{ - audio_oneshot_3d( &audio_board[8], localplayer.rb.co, 40.0f, 1.0f ); + player__networked_sfx( k_player_subsystem_skate, 128, + k_player_skate_soundeffect_grind_wood, + localplayer.rb.co, 1.0f ); } - - audio_unlock(); } else if( stick_frames == 0 ){ - + /* TODO: EXIT SOUNDS */ + } + + if( (state->activity_prev < k_skate_activity_grind_any) && + (state->activity >= k_skate_activity_grind_any) ){ + state->velocity_limit = v3_length( localplayer.rb.v )*1.0f; + state->grind_y_start = localplayer.rb.co[1]; + } + + if( state->activity >= k_skate_activity_grind_any ){ + f32 dy = localplayer.rb.co[1] - state->grind_y_start; + if( dy < 0.0f ){ + state->velocity_limit += -dy*0.2f; + } + state->grind_y_start = localplayer.rb.co[1]; + + + f32 speed_end = v3_length( localplayer.rb.v ); + if( speed_end > state->velocity_limit ){ + v3_muls( localplayer.rb.v, state->velocity_limit/speed_end, + localplayer.rb.v ); + } } } @@ -2667,7 +2677,9 @@ static void player__skate_animate(void){ (1.0f-fabsf(animator->slide)*0.9f); animator->offset[1]=vg_clampf(animator->offset[1],-0.5f,0.0f); - v3_muls( animator->offset, 0.3f, localplayer.cam_control.tpv_offset_extra ); + v3f cam_offset; + v3_mul( animator->offset, (v3f){1.0f,0.3f,1.0f}, cam_offset ); + v3_copy( cam_offset, localplayer.cam_control.tpv_offset_extra ); /* localized vectors */ m4x3_mulv( localplayer.rb.to_local, state->cog, animator->local_cog ); @@ -2724,6 +2736,7 @@ static void player__skate_animate(void){ animator->grind_balance = vg_lerpf( animator->grind_balance, grind_frame, 5.0f*vg.time_delta ); + animator->activity = state->activity; /* pushing */ animator->push_time = vg.time - state->start_push; @@ -2880,11 +2893,11 @@ static void player__skate_animate(void){ } else q_identity( animator->qfixuptotal ); rb_extrapolate( &localplayer.rb, animator->root_co, animator->root_q ); + v3_copy( localplayer.rb.v, animator->root_v ); } static void player__skate_pose( void *_animator, player_pose *pose ){ - struct player_avatar *av = localplayer.playeravatar; - struct skeleton *sk = &av->sk; + struct skeleton *sk = &localplayer.skeleton; struct player_skate_animator *animator = _animator; pose->type = k_player_pose_type_ik; @@ -2966,14 +2979,14 @@ static void player__skate_pose( void *_animator, player_pose *pose ){ skeleton_lerp_pose( sk, ground_pose, air_pose, animator->fly, pose->keyframes ); - mdl_keyframe *kf_board = &pose->keyframes[av->id_board-1], - *kf_foot_l = &pose->keyframes[av->id_ik_foot_l-1], - *kf_foot_r = &pose->keyframes[av->id_ik_foot_r-1], - *kf_knee_l = &pose->keyframes[av->id_ik_knee_l-1], - *kf_knee_r = &pose->keyframes[av->id_ik_knee_r-1], - *kf_hip = &pose->keyframes[av->id_hip-1], - *kf_wheels[] = { &pose->keyframes[av->id_wheel_r-1], - &pose->keyframes[av->id_wheel_l-1] }; + mdl_keyframe *kf_board = &pose->keyframes[localplayer.id_board-1], + *kf_foot_l = &pose->keyframes[localplayer.id_ik_foot_l-1], + *kf_foot_r = &pose->keyframes[localplayer.id_ik_foot_r-1], + *kf_knee_l = &pose->keyframes[localplayer.id_ik_knee_l-1], + *kf_knee_r = &pose->keyframes[localplayer.id_ik_knee_r-1], + *kf_hip = &pose->keyframes[localplayer.id_hip-1], + *kf_wheels[] = { &pose->keyframes[localplayer.id_wheel_r-1], + &pose->keyframes[localplayer.id_wheel_l-1] }; mdl_keyframe grind_pose[32]; @@ -2989,11 +3002,11 @@ static void player__skate_pose( void *_animator, player_pose *pose ){ float add_grab_mod = 1.0f - animator->fly; /* additive effects */ - u32 apply_to[] = { av->id_hip, - av->id_ik_hand_l, - av->id_ik_hand_r, - av->id_ik_elbow_l, - av->id_ik_elbow_r }; + u32 apply_to[] = { localplayer.id_hip, + localplayer.id_ik_hand_l, + localplayer.id_ik_hand_r, + localplayer.id_ik_elbow_l, + localplayer.id_ik_elbow_r }; float apply_rates[] = { 1.0f, 0.75f, @@ -3008,11 +3021,11 @@ static void player__skate_pose( void *_animator, player_pose *pose ){ /* angle 'correction' */ v3f origin; - v3_add( av->sk.bones[av->id_hip].co, kf_hip->co, origin ); + v3_add( sk->bones[localplayer.id_hip].co, kf_hip->co, origin ); for( int i=0; ikeyframes[apply_to[i]-1]; - keyframe_rotate_around( kf, origin, av->sk.bones[apply_to[i]].co, + keyframe_rotate_around( kf, origin, sk->bones[apply_to[i]].co, animator->qfixuptotal ); } @@ -3074,14 +3087,13 @@ static void player__skate_pose( void *_animator, player_pose *pose ){ q_normalize( kf_wheels[i]->q ); } -#if 0 { mdl_keyframe - *kf_head = &pose->keyframes[av->id_head-1], - *kf_elbow_l = &pose->keyframes[av->id_ik_elbow_l-1], - *kf_elbow_r = &pose->keyframes[av->id_ik_elbow_r-1], - *kf_hand_l = &pose->keyframes[av->id_ik_hand_l-1], - *kf_hand_r = &pose->keyframes[av->id_ik_hand_r-1]; + *kf_head = &pose->keyframes[localplayer.id_head-1], + *kf_elbow_l = &pose->keyframes[localplayer.id_ik_elbow_l-1], + *kf_elbow_r = &pose->keyframes[localplayer.id_ik_elbow_r-1], + *kf_hand_l = &pose->keyframes[localplayer.id_ik_hand_l-1], + *kf_hand_r = &pose->keyframes[localplayer.id_ik_hand_r-1]; float warble = perlin1d( vg.time, 2.0f, 2, 300 ); warble *= vg_maxf(animator->grind, fabsf(animator->weight)) * 0.3f; @@ -3091,31 +3103,86 @@ static void player__skate_pose( void *_animator, player_pose *pose ){ v3f origin = {0.0f,0.2f,0.0f}; keyframe_rotate_around( kf_hand_l, origin, - av->sk.bones[av->id_ik_hand_l].co, qrot ); + sk->bones[localplayer.id_ik_hand_l].co, qrot ); keyframe_rotate_around( kf_hand_r, origin, - av->sk.bones[av->id_ik_hand_r].co, qrot ); + sk->bones[localplayer.id_ik_hand_r].co, qrot ); keyframe_rotate_around( kf_hip, origin, - av->sk.bones[av->id_hip].co, qrot ); + sk->bones[localplayer.id_hip].co, qrot ); keyframe_rotate_around( kf_elbow_r, origin, - av->sk.bones[av->id_ik_elbow_r].co, qrot ); + sk->bones[localplayer.id_ik_elbow_r].co, qrot ); keyframe_rotate_around( kf_elbow_l, origin, - av->sk.bones[av->id_ik_elbow_l].co, qrot ); + sk->bones[localplayer.id_ik_elbow_l].co, qrot ); q_inv( qrot, qrot ); q_mul( qrot, kf_head->q, kf_head->q ); q_normalize( kf_head->q ); } -#endif +} + +static void player__skate_effects( void *_animator, m4x3f *final_mtx, + struct player_board *board, + struct player_effects_data *effect_data ){ + + struct skeleton *sk = &localplayer.skeleton; + struct player_skate_animator *animator = _animator; + + if( animator->grind > 0.5f ){ + v3f vp0, vp1, vpc; + if( board ){ + v3_copy((v3f){0.0f,0.02f, board->truck_positions[0][2]}, vp1 ); + v3_copy((v3f){0.0f,0.02f, board->truck_positions[1][2]}, vp0 ); + } + else{ + v3_zero( vp0 ); + v3_zero( vp1 ); + } + + v3f *board_mtx = final_mtx[ localplayer.id_board ]; + m4x3_mulv( board_mtx, vp0, vp0 ); + m4x3_mulv( board_mtx, vp1, vp1 ); + v3_add( vp0, vp1, vpc ); + v3_muls( vpc, 0.5f, vpc ); + + int back = 0, front = 0, mid = 0; + + if( animator->activity == k_skate_activity_grind_5050 ){ + back = 1; + front = 1; + } + else if( animator->activity == k_skate_activity_grind_back50 ){ + back = 1; + } + else if( animator->activity == k_skate_activity_grind_front50 ){ + front = 1; + } + else if( animator->activity == k_skate_activity_grind_boardslide ){ + mid = 1; + } + + if( back ){ + effect_spark_apply( &effect_data->spark, vp0, + animator->root_v, vg.time_delta ); + } + + if( front ){ + effect_spark_apply( &effect_data->spark, vp1, + animator->root_v, vg.time_delta ); + } + + if( mid ){ + effect_spark_apply( &effect_data->spark, vpc, + animator->root_v, vg.time_delta ); + } + } } static void player__skate_post_animate(void){ - struct player_avatar *av = localplayer.playeravatar; struct player_skate_state *state = &player_skate.state; - localplayer.cam_velocity_influence = 1.0f; v3f head = { 0.0f, 1.8f, 0.0f }; - m4x3_mulv( av->sk.final_mtx[ av->id_head ], head, state->head_position ); + m4x3_mulv( localplayer.final_mtx[ localplayer.id_head ], + head, state->head_position ); m4x3_mulv( localplayer.rb.to_local, state->head_position, state->head_position ); } @@ -3168,19 +3235,82 @@ static void player__skate_clear_mechanics(void){ v3_zero( player_skate.weight_distribution ); } -static void player__skate_reset( ent_spawn *rp ){ - struct player_skate_state *state = &player_skate.state; - v3_zero( localplayer.rb.v ); - v4_copy( rp->transform.q, localplayer.rb.q ); +#include "network_compression.h" - state->activity = k_skate_activity_air; - state->activity_prev = k_skate_activity_air; +static void player__skate_animator_exchange( bitpack_ctx *ctx, void *data ){ + struct player_skate_animator *animator = data; + + bitpack_qv3f( ctx, 24, -1024.0f, 1024.0f, animator->root_co ); + bitpack_qquat( ctx, animator->root_q ); + + bitpack_qv3f( ctx, 8, -1.0f, 1.0f, animator->offset ); + bitpack_qv3f( ctx, 8, -1.0f, 1.0f, animator->local_cog ); + bitpack_qf32( ctx, 8, 0.0f, 1.0f, &animator->slide ); + bitpack_qf32( ctx, 8, -1.0f, 1.0f, &animator->z ); + bitpack_qf32( ctx, 8, -1.0f, 1.0f, &animator->x ); + + /* these could likely be pressed down into single bits if needed */ + bitpack_qf32( ctx, 8, 0.0f, 1.0f, &animator->fly ); + bitpack_qf32( ctx, 8, 0.0f, 1.0f, &animator->grind ); + bitpack_qf32( ctx, 8, 0.0f, 1.0f, &animator->stand ); + bitpack_qf32( ctx, 8, 0.0f, 1.0f, &animator->push ); + bitpack_qf32( ctx, 8, 0.0f, 1.0f, &animator->jump ); /*??*/ + bitpack_qf32( ctx, 8, 0.0f, 1.0f, &animator->jump_charge ); /*??*/ + + /* just the sign bit? */ + bitpack_qf32( ctx, 8, -1.0f, 1.0f, &animator->reverse ); + bitpack_qf32( ctx, 8, -1.0f, 1.0f, &animator->delayed_slip_dir ); + bitpack_bytes( ctx, 1, &animator->jump_dir ); + bitpack_bytes( ctx, 1, &animator->trick_type ); + + bitpack_qf32( ctx, 8, 0.0f, 1.0f, &animator->grind_balance ); + bitpack_qf32( ctx, 8, -1.0f, 1.0f, &animator->airdir ); + bitpack_qf32( ctx, 8, -1.0f, 1.0f, &animator->weight ); + bitpack_qf32( ctx, 8, 0.0f, 1.0f, &animator->trick_foot ); + bitpack_qf32( ctx, 8, 0.0f, 1.0f, &animator->slap ); + bitpack_qf32( ctx, 8, 0.0f, 1.0f, &animator->subslap ); + bitpack_qf32( ctx, 8, 0.0f, 1.0f, &animator->grabbing ); + + /* animator->wobble is ommited */ + + bitpack_qv2f( ctx, 8, -1.0f, 1.0f, animator->foot_offset ); + bitpack_qquat( ctx, animator->qfixuptotal ); + bitpack_qquat( ctx, animator->qflip ); + + bitpack_qv3f( ctx, 16, -100.0f, 100.0f, animator->board_euler ); + bitpack_qf32( ctx, 8, -1.0f, 1.0f, &animator->board_lean ); + bitpack_qv2f( ctx, 8, -1.0f, 1.0f, animator->steer ); + bitpack_qv2f( ctx, 8, -1.0f, 1.0f, animator->grab ); + + bitpack_qf32( ctx, 16, 0.0f, 120.0f, &animator->push_time ); + bitpack_qf32( ctx, 16, 0.0f, 120.0f, &animator->jump_time ); + bitpack_qv3f( ctx, 16, -100.0f, 100.0f, animator->root_v ); + bitpack_bytes( ctx, 1, &animator->activity ); +} - player__skate_clear_mechanics(); - player__skate_reset_animator(); +static void player__skate_sfx_oneshot( u8 id, v3f pos, f32 volume ){ + audio_lock(); - v3_zero( state->head_position ); - state->head_position[1] = 1.8f; + if( id == k_player_skate_soundeffect_jump ){ + audio_oneshot_3d( &audio_jumps[vg_randu32()%2], pos, 40.0f, volume ); + } + else if( id == k_player_skate_soundeffect_tap ){ + audio_oneshot_3d( &audio_taps[vg_randu32()%4], pos, 40.0f, volume ); + } + else if( id == k_player_skate_soundeffect_land_good ){ + audio_oneshot_3d( &audio_lands[vg_randu32()%3], pos, 40.0f, volume ); + } + else if( id == k_player_skate_soundeffect_land_bad ){ + audio_oneshot_3d( &audio_lands[vg_randu32()%2+3], pos, 40.0f, volume ); + } + else if( id == k_player_skate_soundeffect_grind_metal ){ + audio_oneshot_3d( &audio_board[3], pos, 40.0f, volume ); + } + else if( id == k_player_skate_soundeffect_grind_wood ){ + audio_oneshot_3d( &audio_board[8], pos, 40.0f, volume ); + } + + audio_unlock(); } #endif /* PLAYER_SKATE_C */