small compression
[carveJwlIkooP6JGAAIwe30JlM.git] / player_skate.c
index 1ea632a7ce1d87c78a69b6ef850f134708178787..4688702a68385f01c8d95b68bbc9dffcab278cdf 100644 (file)
@@ -974,11 +974,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 );
    }
 }
 
@@ -1104,7 +1102,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 +1499,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], localplayer.basis[1], avg );
+      v3_normalize( avg );
+
+      v3_lerp( state->up_dir, avg,
+               6.0f * player_skate.substep_delta, state->up_dir );
    }
 }
 
@@ -2039,7 +2047,11 @@ 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 );
+#if 0
+         player__networked_sfx( k_player_subsystem_walk, 32, 
+                                k_player_walk_soundeffect_splash,
+                                localplayer.rb.co, 1.0f );
+#endif
          player__skate_kill_audio();
          player__dead_transition();
          return;
@@ -2160,15 +2172,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 ){
@@ -2524,10 +2536,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 +2556,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 +2570,30 @@ 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 */
    }
 }
 
@@ -2667,7 +2682,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 );
@@ -3115,7 +3132,8 @@ static void player__skate_post_animate(void){
    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[ av->id_head ], 
+              head, state->head_position );
    m4x3_mulv( localplayer.rb.to_local, 
               state->head_position, state->head_position );
 }
@@ -3183,4 +3201,80 @@ static void player__skate_reset( ent_spawn *rp ){
    state->head_position[1] = 1.8f;
 }
 
+#include "network_compression.h"
+
+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 );
+}
+
+static void player__skate_sfx_oneshot( u8 id, v3f pos, f32 volume ){
+   audio_lock();
+
+   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 */