X-Git-Url: https://harrygodden.com/git/?a=blobdiff_plain;f=player_skate.c;h=6b5bdfb993b4dc0f16cab22400407dec183f311c;hb=73adac381b2c72f08293416a960942dc40db3c7f;hp=e208a49b6cf99aef08e6518060e3842e5e6a5b72;hpb=63b5ac44f74599b21c4b9b18398c29b797337bea;p=carveJwlIkooP6JGAAIwe30JlM.git diff --git a/player_skate.c b/player_skate.c index e208a49..6b5bdfb 100644 --- a/player_skate.c +++ b/player_skate.c @@ -6,6 +6,7 @@ #include "vg/vg_perlin.h" #include "menu.h" #include "ent_skateshop.h" +#include "addon.h" VG_STATIC void player__skate_bind( player_instance *player ) { @@ -55,7 +56,7 @@ VG_STATIC int skate_collide_smooth( player_instance *player, m4x3f mtx, rb_sphere *sphere, rb_ct *man ) { - world_instance *world = get_active_world(); + world_instance *world = world_current_instance(); int len = 0; len = rb_sphere__scene( mtx, sphere, NULL, &world->rb_geo.inf.scene, man ); @@ -92,7 +93,7 @@ VG_STATIC int skate_grind_scansq( player_instance *player, v3f pos, v3f dir, float r, struct grind_info *inf ) { - world_instance *world = get_active_world(); + world_instance *world = world_current_instance(); v4f plane; v3_copy( dir, plane ); @@ -103,8 +104,7 @@ VG_STATIC int skate_grind_scansq( player_instance *player, v3_add( pos, (v3f){ r, r, r }, box[1] ); v3_sub( pos, (v3f){ r, r, r }, box[0] ); - struct grind_sample - { + struct grind_sample{ v2f co; v2f normal; v3f normal3, @@ -234,10 +234,8 @@ too_many_samples: float yi = v3_dot( player->basis[1], si->normal3 ), yj = v3_dot( player->basis[1], sj->normal3 ); - if( yi > yj ) - v3_add( si->normal3, average_normal, average_normal ); - else - v3_add( sj->normal3, average_normal, average_normal ); + if( yi > yj ) v3_add( si->normal3, average_normal, average_normal ); + else v3_add( sj->normal3, average_normal, average_normal ); passed_samples ++; } @@ -264,7 +262,7 @@ too_many_samples: v3_copy( average_normal, inf->n ); v3_copy( average_direction, inf->dir ); - vg_line_pt3( inf->co, 0.02f, VG__GREEN ); + vg_line_point( inf->co, 0.02f, VG__GREEN ); vg_line_arrow( inf->co, average_direction, 0.3f, VG__GREEN ); vg_line_arrow( inf->co, inf->n, 0.2f, VG__CYAN ); @@ -348,7 +346,7 @@ VG_STATIC int create_jumps_to_hit_target( player_instance *player, VG_STATIC void player__approximate_best_trajectory( player_instance *player ) { - world_instance *world0 = get_active_world(); + world_instance *world0 = world_current_instance(); struct player_skate *s = &player->_skate; float k_trace_delta = k_rb_delta * 10.0f; @@ -502,7 +500,7 @@ void player__approximate_best_trajectory( player_instance *player ) m3x3_mul( gate->transport, basis, basis ); if( gate->type == k_gate_type_nonlocel ){ - trace_world = &world_global.worlds[ gate->target ]; + trace_world = &world_static.worlds[ gate->target ]; } } } @@ -853,6 +851,10 @@ VG_STATIC void skate_apply_steering_model( player_instance *player ) rate = 35.0f; top = 1.5f; } + + if( grab < 0.5f ){ + top *= 1.0f+v3_length( s->state.throw_v )*k_mmthrow_steer; + } } float current = v3_dot( player->rb.to_world[1], player->rb.w ), @@ -980,7 +982,7 @@ VG_STATIC void skate_apply_jump_model( player_instance *player ) s->state.jump_time = vg.time; audio_lock(); - audio_oneshot_3d( &audio_jumps[vg_randu32()%2], player->rb.co, 40.0f, 1.0f ); + audio_oneshot_3d( &audio_jumps[vg_randu32()%2], player->rb.co,40.0f,1.0f); audio_unlock(); } } @@ -1178,7 +1180,7 @@ VG_STATIC void player__skate_post_update( player_instance *player ) v3_add( jump->log[jump->log_length-1], jump->n, p1 ); vg_line( jump->log[jump->log_length-1], p1, 0xffffffff ); - vg_line_pt3( jump->apex, 0.02f, 0xffffffff ); + vg_line_point( jump->apex, 0.02f, 0xffffffff ); } audio_lock(); @@ -1320,7 +1322,7 @@ int skate_compute_surface_alignment( player_instance *player, v3f surface_normal, v3f axel_dir ) { struct player_skate *s = &player->_skate; - world_instance *world = get_active_world(); + world_instance *world = world_current_instance(); v3f truck, left, right; m4x3_mulv( player->rb.to_world, ra, truck ); @@ -1533,7 +1535,7 @@ VG_STATIC int skate_point_visible( v3f origin, v3f target ) v3_muls( dir, 1.0f/ray.dist, dir ); ray.dist -= 0.025f; - if( ray_world( get_active_world(), origin, dir, &ray ) ) + if( ray_world( world_current_instance(), origin, dir, &ray ) ) return 0; return 1; @@ -1666,6 +1668,10 @@ VG_STATIC void skate_5050_apply( player_instance *player, v3_muladds( inf_back->co, inf_avg.dir, 0.5f, inf_avg.co ); v3_normalize( inf_avg.dir ); + /* dont ask */ + v3_muls( inf_avg.dir, vg_signf(v3_dot(inf_avg.dir,player->rb.v)), + 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 ); @@ -1694,6 +1700,8 @@ VG_STATIC void skate_5050_apply( player_instance *player, k_grind_spring, k_grind_dampener, k_rb_delta ); + vg_line_arrow( player->rb.co, up, 1.0f, VG__GREEN ); + vg_line_arrow( player->rb.co, target_up, 1.0f, VG__GREEN ); v3f fwd_nplane, dir_nplane; v3_muladds( player->rb.to_world[2], inf_avg.n, @@ -1710,6 +1718,8 @@ VG_STATIC void skate_5050_apply( player_instance *player, 1000.0f, k_grind_dampener, k_rb_delta ); + vg_line_arrow( player->rb.co, fwd_nplane, 0.8f, VG__RED ); + vg_line_arrow( player->rb.co, dir_nplane, 0.8f, VG__RED ); 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 }, @@ -2075,10 +2085,21 @@ VG_STATIC enum skate_activity skate_availible_grind( player_instance *player ) VG_STATIC void player__skate_update( player_instance *player ) { struct player_skate *s = &player->_skate; - world_instance *world = get_active_world(); + world_instance *world = world_current_instance(); + + if( world->water.enabled ){ + if( player->rb.co[1]+0.25f < world->water.height ){ + audio_oneshot_3d( &audio_splash, player->rb.co, 40.0f, 1.0f ); + player__skate_kill_audio( player ); + player__dead_transition( player ); + return; + } + } v3_copy( player->rb.co, s->state.prev_pos ); s->state.activity_prev = s->state.activity; + v3f normal_total; + v3_zero( normal_total ); struct board_collider { @@ -2112,7 +2133,6 @@ VG_STATIC void player__skate_update( player_instance *player ) float slap = 0.0f; if( s->state.activity <= k_skate_activity_air_to_grind ){ - float min_dist = 0.6f; for( int i=0; i<2; i++ ){ v3f wpos, closest; @@ -2134,9 +2154,6 @@ VG_STATIC void player__skate_update( player_instance *player ) wheels[1].pos[1] = s->state.slap; - - - const int k_wheel_count = 2; s->substep = k_rb_delta; @@ -2330,8 +2347,7 @@ begin_collision:; s->substep -= s->substep_delta; rb_ct manifold[128]; - int manifold_len = 0; - + int manifold_len = 0; /* * Phase -1: head detection * -------------------------------------------------------------------------- @@ -2399,7 +2415,7 @@ begin_collision:; manifold_len += l; if( vg_lines.draw ) - debug_capsule( mtx, capsule.radius, capsule.height, VG__WHITE ); + vg_line_capsule( mtx, capsule.radius, capsule.height, VG__WHITE ); /* add limits */ if( s->state.activity >= k_skate_activity_grind_any ){ @@ -2421,7 +2437,7 @@ begin_collision:; v3f world_cog; m4x3_mulv( player->rb.to_world, s->weight_distribution, world_cog ); - vg_line_pt3( world_cog, 0.02f, VG__BLACK ); + vg_line_point( world_cog, 0.02f, VG__BLACK ); for( int i=0; isubstep_delta ); @@ -2483,6 +2499,7 @@ begin_collision:; v3f impulse; v3_muls( ct->n, lambda, impulse ); + v3_muladds( normal_total, impulse, inv_mass, normal_total ); v3_muladds( player->rb.v, impulse, inv_mass, player->rb.v ); v3_cross( delta, impulse, impulse ); m3x3_mulv( iIw, impulse, impulse ); @@ -2509,6 +2526,24 @@ begin_collision:; * -------------------------------------------------------------------------- */ + f32 nforce = v3_length(normal_total); + if( nforce > 4.0f ){ + if( nforce > 17.6f ){ + v3_muladds( player->rb.v, normal_total, -1.0f, player->rb.v ); + player__dead_transition(player); + player__skate_kill_audio(player); + return; + } + + f32 amt = k_cam_punch; + if( player->camera_mode == k_cam_firstperson ){ + amt *= 0.25f; + } + + v3_muladds( player->cam_land_punch_v, normal_total, amt, + player->cam_land_punch_v ); + } + s->surface = k_surface_prop_concrete; for( int i=0; irb.to_world, mtx ); m4x3_mulv( player->rb.to_world, wheels[i].pos, mtx[3] ); - debug_sphere( mtx, wheels[i].radius, - (u32[]){ VG__WHITE, VG__BLACK, + vg_line_sphere( mtx, wheels[i].radius, + (u32[]){ VG__WHITE, VG__BLACK, wheels[i].colour }[ wheels[i].state ]); } skate_integrate( player ); - vg_line_pt3( s->state.cog, 0.02f, VG__WHITE ); + vg_line_point( s->state.cog, 0.02f, VG__WHITE ); ent_gate *gate = world_intersect_gates(world, player->rb.co, s->state.prev_pos ); @@ -2591,8 +2626,7 @@ begin_collision:; } } -VG_STATIC void player__skate_im_gui( player_instance *player ) -{ +VG_STATIC void player__skate_im_gui( player_instance *player ){ struct player_skate *s = &player->_skate; player__debugtext( 1, "V: %5.2f %5.2f %5.2f",player->rb.v[0], player->rb.v[1], @@ -2964,7 +2998,9 @@ VG_STATIC void player__skate_animate( player_instance *player, q_mul( kf_board->q, qtrick, kf_board->q ); q_normalize( kf_board->q ); - struct player_board *board = player_get_player_board( player ); + struct player_board *board = + addon_cache_item_if_loaded( k_addon_type_board, + player->board_view_slot ); if( board ){ /* foot weight distribution */