+ {
+ float brightness = p->score*p->score*p->score;
+ v3f p1;
+ v3_lerp( p->log[j], p->log[j+1], brightness, p1 );
+ vg_line( p->log[j], p1, p->colour );
+ }
+
+ vg_line_cross( p->log[p->log_length-1], p->colour, 0.25f );
+
+ v3f p1;
+ v3_add( p->log[p->log_length-1], p->n, p1 );
+ vg_line( p->log[p->log_length-1], p1, 0xffffffff );
+
+ vg_line_pt3( p->apex, 0.02f, 0xffffffff );
+ }
+
+#if 0
+ vg_line_pt3( s->state.apex, 0.030f, 0xff0000ff );
+#endif
+}
+
+/*
+ * truck alignment model at ra(local)
+ * returns 1 if valid surface:
+ * surface_normal will be filled out with an averaged normal vector
+ * axel_dir will be the direction from left to right wheels
+ *
+ * returns 0 if no good surface found
+ */
+VG_STATIC
+int skate_compute_surface_alignment( player_instance *player,
+ v3f ra, u32 colour,
+ v3f surface_normal, v3f axel_dir )
+{
+ struct player_skate *s = &player->_skate;
+
+ v3f truck, left, right;
+ m4x3_mulv( player->rb.to_world, ra, truck );
+
+ v3_muladds( truck, player->rb.to_world[0], -k_board_width, left );
+ v3_muladds( truck, player->rb.to_world[0], k_board_width, right );
+ vg_line( left, right, colour );
+
+ float k_max_truck_flex = VG_PIf * 0.25f;
+
+ ray_hit ray_l, ray_r;
+
+ v3f dir;
+ v3_muls( player->rb.to_world[1], -1.0f, dir );
+
+ int res_l = 0, res_r = 0;
+
+ for( int i=0; i<8; i++ )
+ {
+ float t = 1.0f - (float)i * (1.0f/8.0f);
+ v3_muladds( truck, player->rb.to_world[0], -k_board_radius*t, left );
+ v3_muladds( left, player->rb.to_world[1], k_board_radius, left );
+ ray_l.dist = 2.1f * k_board_radius;
+
+ res_l = ray_world( left, dir, &ray_l );
+
+ if( res_l )
+ break;
+ }
+
+ for( int i=0; i<8; i++ )
+ {
+ float t = 1.0f - (float)i * (1.0f/8.0f);
+ v3_muladds( truck, player->rb.to_world[0], k_board_radius*t, right );
+ v3_muladds( right, player->rb.to_world[1], k_board_radius, right );
+ ray_r.dist = 2.1f * k_board_radius;
+
+ res_r = ray_world( right, dir, &ray_r );
+
+ if( res_r )
+ break;
+ }
+
+ v3f v0;
+ v3f midpoint;
+ v3f tangent_average;
+ v3_muladds( truck, player->rb.to_world[1], -k_board_radius, midpoint );
+ v3_zero( tangent_average );
+
+ if( res_l || res_r )
+ {
+ v3f p0, p1, t;
+ v3_copy( midpoint, p0 );
+ v3_copy( midpoint, p1 );
+
+ if( res_l )
+ {
+ v3_copy( ray_l.pos, p0 );
+ v3_cross( ray_l.normal, player->rb.to_world[0], t );
+ v3_add( t, tangent_average, tangent_average );
+ }
+ if( res_r )
+ {
+ v3_copy( ray_r.pos, p1 );
+ v3_cross( ray_r.normal, player->rb.to_world[0], t );
+ v3_add( t, tangent_average, tangent_average );
+ }
+
+ v3_sub( p1, p0, v0 );
+ v3_normalize( v0 );
+ }
+ else
+ {
+ /* fallback: use the closes point to the trucks */
+ v3f closest;
+ int idx = bh_closest_point( world.geo_bh, midpoint, closest, 0.1f );
+
+ if( idx != -1 )
+ {
+ u32 *tri = &world.scene_geo->arrindices[ idx * 3 ];
+ v3f verts[3];
+
+ for( int j=0; j<3; j++ )
+ v3_copy( world.scene_geo->arrvertices[ tri[j] ].co, verts[j] );
+
+ v3f vert0, vert1, n;
+ v3_sub( verts[1], verts[0], vert0 );
+ v3_sub( verts[2], verts[0], vert1 );
+ v3_cross( vert0, vert1, n );
+ v3_normalize( n );
+
+ if( v3_dot( n, player->rb.to_world[1] ) < 0.3f )
+ return 0;
+
+ v3_cross( n, player->rb.to_world[2], v0 );
+ v3_muladds( v0, player->rb.to_world[2],
+ -v3_dot( player->rb.to_world[2], v0 ), v0 );
+ v3_normalize( v0 );
+
+ v3f t;
+ v3_cross( n, player->rb.to_world[0], t );
+ v3_add( t, tangent_average, tangent_average );
+ }
+ else
+ return 0;
+ }
+
+ v3_muladds( truck, v0, k_board_width, right );
+ v3_muladds( truck, v0, -k_board_width, left );
+
+ vg_line( left, right, VG__WHITE );
+
+ v3_normalize( tangent_average );
+ v3_cross( v0, tangent_average, surface_normal );
+ v3_copy( v0, axel_dir );
+
+ return 1;
+}
+
+VG_STATIC void skate_weight_distribute( player_instance *player )
+{
+ struct player_skate *s = &player->_skate;
+ v3_zero( s->weight_distribution );
+
+ int reverse_dir = v3_dot( player->rb.to_world[2], player->rb.v ) < 0.0f?1:-1;
+
+ if( s->state.manual_direction == 0 )
+ {
+ if( (player->input_js1v->axis.value > 0.7f) &&
+ (s->state.activity == k_skate_activity_ground) &&
+ (s->state.jump_charge <= 0.01f) )
+ s->state.manual_direction = reverse_dir;
+ }
+ else
+ {
+ if( player->input_js1v->axis.value < 0.1f )
+ {
+ s->state.manual_direction = 0;
+ }
+ else
+ {
+ if( reverse_dir != s->state.manual_direction )
+ {
+ return;
+ }
+ }
+ }
+
+ if( s->state.manual_direction )
+ {
+ float amt = vg_minf( player->input_js1v->axis.value * 8.0f, 1.0f );
+ s->weight_distribution[2] = k_board_length * amt *
+ (float)s->state.manual_direction;
+ }
+
+ /* TODO: Fall back on land normal */
+ /* TODO: Lerp weight distribution */
+ if( s->state.manual_direction )
+ {
+ v3f plane_z;
+
+ m3x3_mulv( player->rb.to_world, s->weight_distribution, plane_z );
+ v3_negate( plane_z, plane_z );
+
+ v3_muladds( plane_z, s->surface_picture,
+ -v3_dot( plane_z, s->surface_picture ), plane_z );
+ v3_normalize( plane_z );
+
+ v3_muladds( plane_z, s->surface_picture, 0.3f, plane_z );
+ v3_normalize( plane_z );
+
+ v3f p1;
+ v3_muladds( player->rb.co, plane_z, 1.5f, p1 );
+ vg_line( player->rb.co, p1, VG__GREEN );
+
+ v3f refdir;
+ v3_muls( player->rb.to_world[2], -(float)s->state.manual_direction,
+ refdir );
+
+ rb_effect_spring_target_vector( &player->rb, refdir, plane_z,
+ k_manul_spring, k_manul_dampener,
+ s->substep_delta );
+ }
+}
+
+VG_STATIC void skate_adjust_up_direction( player_instance *player )
+{
+ struct player_skate *s = &player->_skate;
+
+ if( s->state.activity == k_skate_activity_ground )
+ {
+ v3f target;
+ v3_copy( s->surface_picture, target );
+
+ target[1] += 2.0f * s->surface_picture[1];
+ v3_normalize( target );
+
+ v3_lerp( s->state.up_dir, target,
+ 8.0f * s->substep_delta, s->state.up_dir );
+ }
+ else if( s->state.activity == k_skate_activity_air )
+ {
+ v3_lerp( s->state.up_dir, player->rb.to_world[1],
+ 8.0f * s->substep_delta, s->state.up_dir );
+ }
+ else
+ {
+ v3_lerp( s->state.up_dir, player->basis[1],
+ 12.0f * s->substep_delta, s->state.up_dir );
+ }
+}
+
+VG_STATIC int skate_point_visible( v3f origin, v3f target )
+{
+ v3f dir;
+ v3_sub( target, origin, dir );
+
+ ray_hit ray;
+ ray.dist = v3_length( dir );
+ v3_muls( dir, 1.0f/ray.dist, dir );
+ ray.dist -= 0.025f;
+
+ if( ray_world( origin, dir, &ray ) )
+ return 0;
+
+ return 1;
+}
+
+VG_STATIC void skate_grind_orient( struct grind_info *inf, m3x3f mtx )
+{
+ /* TODO: Is N and Dir really orthogonal? */
+ v3_copy( inf->dir, mtx[0] );
+ v3_copy( inf->n, mtx[1] );
+ v3_cross( mtx[0], mtx[1], mtx[2] );
+}
+
+VG_STATIC void skate_grind_friction( player_instance *player,
+ struct grind_info *inf, float strength )
+{
+ v3f v2;
+ v3_muladds( player->rb.to_world[2], inf->n,
+ -v3_dot( player->rb.to_world[2], inf->n ), v2 );
+
+ float a = 1.0f-fabsf( v3_dot( v2, inf->dir ) ),
+ dir = vg_signf( v3_dot( player->rb.v, inf->dir ) ),
+ F = a * -dir * k_grind_max_friction;
+
+ v3_muladds( player->rb.v, inf->dir, F*k_rb_delta*strength, player->rb.v );
+}
+
+VG_STATIC void skate_grind_decay( player_instance *player,
+ struct grind_info *inf, float strength )
+{
+ m3x3f mtx, mtx_inv;
+ skate_grind_orient( inf, mtx );
+ m3x3_transpose( mtx, mtx_inv );
+
+ v3f v_grind;
+ m3x3_mulv( mtx_inv, player->rb.v, v_grind );
+
+ float decay = 1.0f - ( k_rb_delta * k_grind_decayxy * strength );
+ v3_mul( v_grind, (v3f){ 1.0f, decay, decay }, v_grind );
+ m3x3_mulv( mtx, v_grind, player->rb.v );
+}
+
+VG_STATIC void skate_grind_truck_apply( player_instance *player,
+ float sign, struct grind_info *inf,
+ float strength )
+{
+ struct player_skate *s = &player->_skate;
+
+ /* TODO: Trash compactor this */
+ v3f ra = { 0.0f, -k_board_radius, sign * k_board_length };
+ v3f raw, wsp;
+ m3x3_mulv( player->rb.to_world, ra, raw );
+ v3_add( player->rb.co, raw, wsp );
+
+ v3_copy( ra, s->weight_distribution );
+
+ v3f delta;
+ v3_sub( inf->co, wsp, delta );
+
+ /* spring force */
+ v3_muladds( player->rb.v, delta, k_spring_force*strength*k_rb_delta,
+ player->rb.v );
+
+ skate_grind_decay( player, inf, strength );
+ skate_grind_friction( player, inf, strength );
+
+ /* yeah yeah yeah yeah */
+ v3f raw_nplane, axis;
+ v3_muladds( raw, inf->n, -v3_dot( inf->n, raw ), raw_nplane );
+ v3_cross( raw_nplane, inf->n, axis );
+ v3_normalize( axis );
+
+ /* orientation */
+ m3x3f mtx;
+ skate_grind_orient( inf, mtx );
+ v3f target_fwd, fwd, up, target_up;
+ m3x3_mulv( mtx, s->grind_vec, target_fwd );
+ v3_copy( raw_nplane, fwd );
+ v3_copy( player->rb.to_world[1], up );
+ v3_copy( inf->n, target_up );
+
+ v3_muladds( target_fwd, inf->n, -v3_dot(inf->n,target_fwd), target_fwd );
+ v3_muladds( fwd, inf->n, -v3_dot(inf->n,fwd), fwd );
+
+ v3_normalize( target_fwd );
+ v3_normalize( fwd );
+
+
+ float way = player->input_js1v->axis.value *
+ vg_signf( v3_dot( raw_nplane, player->rb.v ) );
+
+ v4f q;
+ q_axis_angle( q, axis, VG_PIf*0.125f * way );
+ q_mulv( q, target_up, target_up );
+ q_mulv( q, target_fwd, target_fwd );
+
+ rb_effect_spring_target_vector( &player->rb, up, target_up,
+ k_grind_spring,
+ k_grind_dampener,
+ k_rb_delta );
+
+ rb_effect_spring_target_vector( &player->rb, fwd, target_fwd,
+ k_grind_spring*strength,
+ k_grind_dampener*strength,
+ k_rb_delta );
+
+ vg_line_arrow( player->rb.co, target_up, 1.0f, VG__GREEN );
+ vg_line_arrow( player->rb.co, fwd, 0.8f, VG__RED );
+ vg_line_arrow( player->rb.co, target_fwd, 1.0f, VG__YELOW );
+
+ s->grind_strength = strength;
+
+ /* Fake contact */
+ struct grind_limit *limit = &s->limits[ s->limit_count ++ ];
+ m4x3_mulv( player->rb.to_local, wsp, limit->ra );
+ m3x3_mulv( player->rb.to_local, inf->n, limit->n );
+ limit->p = 0.0f;
+
+ v3_copy( inf->dir, s->grind_dir );
+}
+
+VG_STATIC void skate_5050_apply( player_instance *player,
+ struct grind_info *inf_front,
+ struct grind_info *inf_back )
+{
+ struct player_skate *s = &player->_skate;
+ struct grind_info inf_avg;
+
+ v3_sub( inf_front->co, inf_back->co, inf_avg.dir );
+ v3_muladds( inf_back->co, inf_avg.dir, 0.5f, inf_avg.co );
+ v3_normalize( inf_avg.dir );
+
+ v3f axis_front, axis_back, axis;
+ v3_cross( inf_front->dir, inf_front->n, axis_front );
+ v3_cross( inf_back->dir, inf_back->n, axis_back );
+ v3_add( axis_front, axis_back, axis );
+ v3_normalize( axis );
+
+ v3_cross( axis, inf_avg.dir, inf_avg.n );
+
+ skate_grind_decay( player, &inf_avg, 1.0f );
+
+
+ float way = player->input_js1v->axis.value *
+ vg_signf( v3_dot( player->rb.to_world[2], player->rb.v ) );
+ v4f q;
+ v3f up, target_up;
+ v3_copy( player->rb.to_world[1], up );
+ v3_copy( inf_avg.n, target_up );
+ q_axis_angle( q, player->rb.to_world[0], VG_PIf*0.25f * -way );
+ q_mulv( q, target_up, target_up );
+
+ v3_zero( s->weight_distribution );
+ s->weight_distribution[2] = k_board_length * -way;
+
+ rb_effect_spring_target_vector( &player->rb, up, target_up,
+ k_grind_spring,
+ k_grind_dampener,
+ k_rb_delta );
+
+ v3f fwd_nplane, dir_nplane;
+ v3_muladds( player->rb.to_world[2], inf_avg.n,
+ -v3_dot( player->rb.to_world[2], inf_avg.n ), fwd_nplane );
+
+ v3f dir;
+ v3_muls( inf_avg.dir, v3_dot( fwd_nplane, inf_avg.dir ), dir );
+ v3_muladds( dir, inf_avg.n, -v3_dot( dir, inf_avg.n ), dir_nplane );
+
+ v3_normalize( fwd_nplane );
+ v3_normalize( dir_nplane );
+
+ rb_effect_spring_target_vector( &player->rb, fwd_nplane, dir_nplane,
+ 1000.0f,
+ k_grind_dampener,
+ k_rb_delta );
+
+ v3f pos_front = { 0.0f, -k_board_radius, -1.0f * k_board_length },
+ pos_back = { 0.0f, -k_board_radius, 1.0f * k_board_length },
+ delta_front, delta_back, delta_total;
+
+ m4x3_mulv( player->rb.to_world, pos_front, pos_front );
+ m4x3_mulv( player->rb.to_world, pos_back, pos_back );
+
+ v3_sub( inf_front->co, pos_front, delta_front );
+ v3_sub( inf_back->co, pos_back, delta_back );
+ v3_add( delta_front, delta_back, delta_total );
+
+ v3_muladds( player->rb.v, delta_total, 50.0f * k_rb_delta, player->rb.v );
+
+ /* Fake contact */
+ struct grind_limit *limit = &s->limits[ s->limit_count ++ ];
+ v3_zero( limit->ra );
+ m3x3_mulv( player->rb.to_local, inf_avg.n, limit->n );
+ limit->p = 0.0f;
+
+ v3_copy( inf_avg.dir, s->grind_dir );
+}
+
+VG_STATIC int skate_grind_truck_renew( player_instance *player, float sign,
+ struct grind_info *inf )
+{
+ struct player_skate *s = &player->_skate;
+
+ v3f wheel_co = { 0.0f, 0.0f, sign * k_board_length },
+ grind_co = { 0.0f, -k_board_radius, sign * k_board_length };
+
+ m4x3_mulv( player->rb.to_world, wheel_co, wheel_co );
+ m4x3_mulv( player->rb.to_world, grind_co, grind_co );
+
+ /* Exit condition: lost grind tracking */
+ if( !skate_grind_scansq( player, grind_co, player->rb.v, 0.3f, inf ) )
+ return 0;
+
+ /* Exit condition: cant see grind target directly */
+ if( !skate_point_visible( wheel_co, inf->co ) )
+ return 0;
+
+ /* Exit condition: minimum velocity not reached, but allow a bit of error */
+ float dv = fabsf(v3_dot( player->rb.v, inf->dir )),
+ minv = k_grind_axel_min_vel*0.8f;
+
+ if( dv < minv )
+ return 0;
+
+ if( fabsf(v3_dot( inf->dir, s->grind_dir )) < k_grind_max_edge_angle )
+ return 0;
+
+ v3_copy( inf->dir, s->grind_dir );
+ return 1;
+}
+
+VG_STATIC int skate_grind_truck_entry( player_instance *player, float sign,
+ struct grind_info *inf )
+{
+ struct player_skate *s = &player->_skate;
+
+ /* TODO: Trash compactor this */
+ v3f ra = { 0.0f, -k_board_radius, sign * k_board_length };
+
+ v3f raw, wsp;
+ m3x3_mulv( player->rb.to_world, ra, raw );
+ v3_add( player->rb.co, raw, wsp );
+
+ if( skate_grind_scansq( player, wsp, player->rb.v, 0.3, inf ) )
+ {
+ if( fabsf(v3_dot( player->rb.v, inf->dir )) < k_grind_axel_min_vel )
+ return 0;
+
+ /* velocity should be at least 60% aligned */
+ v3f pv, axis;
+ v3_cross( inf->n, inf->dir, axis );
+ v3_muladds( player->rb.v, inf->n, -v3_dot( player->rb.v, inf->n ), pv );
+
+ if( v3_length2( pv ) < 0.0001f )
+ return 0;
+ v3_normalize( pv );
+
+ if( fabsf(v3_dot( pv, inf->dir )) < k_grind_axel_max_angle )
+ return 0;
+
+ if( v3_dot( player->rb.v, inf->n ) > 0.5f )
+ return 0;
+
+#if 0
+ /* check for vertical alignment */
+ if( v3_dot( player->rb.to_world[1], inf->n ) < k_grind_axel_max_vangle )
+ return 0;
+#endif
+
+ v3f local_co, local_dir, local_n;
+ m4x3_mulv( player->rb.to_local, inf->co, local_co );
+ m3x3_mulv( player->rb.to_local, inf->dir, local_dir );
+ m3x3_mulv( player->rb.to_local, inf->n, local_n );
+
+ v2f delta = { local_co[0], local_co[2] - k_board_length*sign };
+
+ float truck_height = -(k_board_radius+0.03f);
+
+ v3f rv;
+ v3_cross( player->rb.w, raw, rv );
+ v3_add( player->rb.v, rv, rv );
+
+ if( (local_co[1] >= truck_height) &&
+ (v2_length2( delta ) <= k_board_radius*k_board_radius) )
+ {
+ return 1;
+ }
+ }
+
+ return 0;
+}
+
+VG_STATIC void skate_boardslide_apply( player_instance *player,
+ struct grind_info *inf )
+{
+ struct player_skate *s = &player->_skate;
+
+ v3f local_co, local_dir, local_n;
+ m4x3_mulv( player->rb.to_local, inf->co, local_co );
+ m3x3_mulv( player->rb.to_local, inf->dir, local_dir );
+ m3x3_mulv( player->rb.to_local, inf->n, local_n );
+
+ v3f intersection;
+ v3_muladds( local_co, local_dir, local_co[0]/-local_dir[0],
+ intersection );
+ v3_copy( intersection, s->weight_distribution );
+
+ skate_grind_decay( player, inf, 0.1f );
+ skate_grind_friction( player, inf, 0.25f );
+
+ /* direction alignment */
+ v3f dir, perp;
+ v3_cross( local_dir, local_n, perp );
+ v3_muls( local_dir, vg_signf(local_dir[0]), dir );
+ v3_muls( perp, vg_signf(perp[2]), perp );
+
+ m3x3_mulv( player->rb.to_world, dir, dir );
+ m3x3_mulv( player->rb.to_world, perp, perp );
+
+ rb_effect_spring_target_vector( &player->rb, player->rb.to_world[0],
+ dir,
+ k_grind_spring, k_grind_dampener,
+ k_rb_delta );
+
+ rb_effect_spring_target_vector( &player->rb, player->rb.to_world[2],
+ perp,
+ k_grind_spring, k_grind_dampener,
+ k_rb_delta );
+
+ vg_line_arrow( player->rb.co, dir, 0.5f, VG__GREEN );
+ vg_line_arrow( player->rb.co, perp, 0.5f, VG__BLUE );
+
+ v3_copy( inf->dir, s->grind_dir );
+}
+
+VG_STATIC int skate_boardslide_entry( player_instance *player,
+ struct grind_info *inf )
+{
+ struct player_skate *s = &player->_skate;
+
+ if( skate_grind_scansq( player, player->rb.co,
+ player->rb.to_world[0], k_board_length,
+ inf ) )
+ {
+ v3f local_co, local_dir;
+ m4x3_mulv( player->rb.to_local, inf->co, local_co );
+ m3x3_mulv( player->rb.to_local, inf->dir, local_dir );
+
+ if( (fabsf(local_co[2]) <= k_board_length) && /* within wood area */
+ (local_co[1] >= 0.0f) && /* at deck level */
+ (fabsf(local_dir[0]) >= 0.5f) ) /* perpendicular to us */
+ {
+ if( fabsf(v3_dot( player->rb.v, inf->dir )) < k_grind_axel_min_vel )
+ return 0;
+
+ return 1;
+ }
+ }
+
+ return 0;
+}
+
+VG_STATIC int skate_boardslide_renew( player_instance *player,
+ struct grind_info *inf )
+{
+ struct player_skate *s = &player->_skate;
+
+ if( !skate_grind_scansq( player, player->rb.co,
+ player->rb.to_world[0], k_board_length,
+ inf ) )
+ return 0;
+
+ /* Exit condition: cant see grind target directly */
+ v3f vis;
+ v3_muladds( player->rb.co, player->rb.to_world[1], 0.2f, vis );
+ if( !skate_point_visible( vis, inf->co ) )
+ return 0;
+
+ /* Exit condition: minimum velocity not reached, but allow a bit of error
+ * TODO: trash compactor */
+ float dv = fabsf(v3_dot( player->rb.v, inf->dir )),
+ minv = k_grind_axel_min_vel*0.8f;
+
+ if( dv < minv )
+ return 0;
+
+ if( fabsf(v3_dot( inf->dir, s->grind_dir )) < k_grind_max_edge_angle )
+ return 0;
+
+ return 1;
+}
+
+VG_STATIC void skate_store_grind_vec( player_instance *player,
+ struct grind_info *inf )
+{
+ struct player_skate *s = &player->_skate;
+
+ m3x3f mtx;
+ skate_grind_orient( inf, mtx );
+ m3x3_transpose( mtx, mtx );
+
+ v3f raw;
+ v3_sub( inf->co, player->rb.co, raw );
+
+ m3x3_mulv( mtx, raw, s->grind_vec );
+ v3_normalize( s->grind_vec );
+ v3_copy( inf->dir, s->grind_dir );
+}
+
+VG_STATIC enum skate_activity skate_availible_grind( player_instance *player )
+{
+ struct player_skate *s = &player->_skate;
+
+ /* debounces this state manager a little bit */
+ if( s->frames_since_activity_change < 10 )
+ {
+ s->frames_since_activity_change ++;
+ return k_skate_activity_undefined;
+ }
+
+ struct grind_info inf_back50,
+ inf_front50,
+ inf_slide;
+
+ int res_back50 = 0,
+ res_front50 = 0,
+ res_slide = 0;
+
+ if( s->state.activity == k_skate_activity_grind_boardslide )
+ {
+ res_slide = skate_boardslide_renew( player, &inf_slide );
+ }
+ else if( s->state.activity == k_skate_activity_grind_back50 )
+ {
+ res_back50 = skate_grind_truck_renew( player, 1.0f, &inf_back50 );
+ res_front50 = skate_grind_truck_entry( player, -1.0f, &inf_front50 );
+ }
+ else if( s->state.activity == k_skate_activity_grind_front50 )
+ {
+ res_front50 = skate_grind_truck_renew( player, -1.0f, &inf_front50 );
+ res_back50 = skate_grind_truck_entry( player, 1.0f, &inf_back50 );
+ }
+ else if( s->state.activity == k_skate_activity_grind_5050 )
+ {
+ res_front50 = skate_grind_truck_renew( player, -1.0f, &inf_front50 );
+ res_back50 = skate_grind_truck_entry( player, 1.0f, &inf_back50 );
+ }
+ else
+ {
+ res_slide = skate_boardslide_entry( player, &inf_slide );
+ res_back50 = skate_grind_truck_entry( player, 1.0f, &inf_back50 );
+ res_front50 = skate_grind_truck_entry( player, -1.0f, &inf_front50 );
+
+ if( res_back50 != res_front50 )
+ {
+ int wants_to_do_that = fabsf(player->input_js1v->axis.value) >= 0.25f;
+
+ res_back50 &= wants_to_do_that;
+ res_front50 &= wants_to_do_that;
+ }
+ }
+
+ const enum skate_activity table[] =
+ { /* slide | back | front */
+ k_skate_activity_undefined, /* 0 0 0 */
+ k_skate_activity_grind_front50, /* 0 0 1 */
+ k_skate_activity_grind_back50, /* 0 1 0 */
+ k_skate_activity_grind_5050, /* 0 1 1 */
+
+ /* slide has priority always */
+ k_skate_activity_grind_boardslide, /* 1 0 0 */
+ k_skate_activity_grind_boardslide, /* 1 0 1 */
+ k_skate_activity_grind_boardslide, /* 1 1 0 */
+ k_skate_activity_grind_boardslide, /* 1 1 1 */
+ }
+ , new_activity = table[ res_slide << 2 | res_back50 << 1 | res_front50 ];