small compression
authorhgn <hgodden00@gmail.com>
Sat, 4 Nov 2023 16:31:33 +0000 (16:31 +0000)
committerhgn <hgodden00@gmail.com>
Sat, 4 Nov 2023 16:31:33 +0000 (16:31 +0000)
network_compression.h
player_walk.c
player_walk.h

index 6ef08f93f69cb7c9de0bc3b9825a0472a4b5ff50..2c000b7e85122bb679f42ed71eec783bc02f75f6 100644 (file)
@@ -34,18 +34,20 @@ static void bitpack_bytes( bitpack_ctx *ctx, u32 bytes, void *data ){
    ctx->bytes += bytes;
 }
 
-static void bitpack_qf32( bitpack_ctx *ctx, u32 bits, 
-                          f32 min, f32 max, f32 *v ){
+static u32 bitpack_qf32( bitpack_ctx *ctx, u32 bits, 
+                         f32 min, f32 max, f32 *v ){
    u32 mask = (0x1 << bits) - 1;
 
    if( ctx->mode == k_bitpack_compress ){
       u32 a = vg_quantf( *v, bits, min, max );
       bitpack_bytes( ctx, bits/8, &a );
+      return a;
    }
    else {
       u32 a = 0;
       bitpack_bytes( ctx, bits/8, &a );
       *v = vg_dequantf( a, bits, min, max );
+      return a;
    }
 }
 
index 7d3093d0aafb7ae7f703f8e68ff3712f47522a3c..7d09f15e7095708b0b9287b651067da4256856fd 100644 (file)
@@ -228,6 +228,9 @@ static int player_walk_scan_for_drop_in(void){
 static struct skeleton_anim *player_walk_outro_anim( enum walk_outro type ){
    struct player_walk *w = &player_walk;
 
+   if( type >= k_walk_outro_max )
+      return NULL;
+
    return (struct skeleton_anim *[]){ 
             [k_walk_outro_none]        = NULL,
             [k_walk_outro_jump_to_air] = w->anim_jump_to_air,
@@ -911,6 +914,11 @@ static void player__walk_pose( void *_animator, player_pose *pose ){
 
    if( animator->outro_type ){
       struct skeleton_anim *anim = player_walk_outro_anim(animator->outro_type);
+
+      if( !anim ){
+         skeleton_copy_pose( sk, apose, pose->keyframes );
+         return;
+      }
       
       f32 outro_length = (f32)anim->length / anim->rate,
           outro_time = animator->outro_t*outro_length;
@@ -1044,9 +1052,6 @@ static void player__walk_animator_exchange( bitpack_ctx *ctx, void *data ){
    bitpack_qf32( ctx, 8, 0.0f, 1.0f, &animator->run );
    bitpack_qf32( ctx, 8, 0.0f, 1.0f, &animator->walk );
    bitpack_qf32( ctx, 16, 0.0f, 120.0f, &animator->walk_timer );
-   bitpack_qf32( ctx, 8, -k_sit_yaw_limit, k_sit_yaw_limit, &animator->yaw );
-   bitpack_qf32( ctx, 8, -k_sit_pitch_limit, k_sit_pitch_limit, 
-                  &animator->pitch );
 
    for( int i=0; i<1; i++ ){ /* without this you get a warning from gcc. lol */
       bitpack_bytes( ctx, 8, &animator->outro_type );
@@ -1058,6 +1063,11 @@ static void player__walk_animator_exchange( bitpack_ctx *ctx, void *data ){
       }
    }
 
-   bitpack_qf32( ctx, 8, 0.0f, 1.0f, &animator->sit_t );
+   u32 code = bitpack_qf32( ctx, 8, 0.0f, 1.0f, &animator->sit_t );
+   if( code ){
+      bitpack_qf32( ctx, 8, -k_sit_yaw_limit, k_sit_yaw_limit, &animator->yaw );
+      bitpack_qf32( ctx, 8, -k_sit_pitch_limit, k_sit_pitch_limit, 
+                     &animator->pitch );
+   }
 }
 #endif /* PLAYER_DEVICE_WALK_H */
index 48be2ac6118f296e4e3b4dcb2f2703eba41118f9..a8dd9facd0dc526d2fecf94e1adac836fe37de11 100644 (file)
@@ -34,7 +34,8 @@ struct player_walk{
          k_walk_outro_none,
          k_walk_outro_jump_to_air,
          k_walk_outro_drop_in,
-         k_walk_outro_regular
+         k_walk_outro_regular,
+         k_walk_outro_max
       }
       outro_type;
       double outro_start_time;