better nametag
authorhgn <hgodden00@gmail.com>
Sun, 12 Nov 2023 20:53:21 +0000 (20:53 +0000)
committerhgn <hgodden00@gmail.com>
Sun, 12 Nov 2023 20:53:21 +0000 (20:53 +0000)
font.h
player_remote.c
player_remote.h
skaterift.c

diff --git a/font.h b/font.h
index c00aece3c9f2f46a59ae2e3f76062284bd93e113..3bda50039a964220b4ff67194568d9f3ce8c39e2 100644 (file)
--- a/font.h
+++ b/font.h
@@ -57,7 +57,12 @@ enum efont_SRglyph{
    k_SRglyph_kbm_space     = 0xa1,
    k_SRglyph_kbm_return    = 0xa2,
    k_SRglyph_kbm_escape    = 0xa3,
-   k_SRglyph_kbm_mousemove = 0xa4
+   k_SRglyph_kbm_mousemove = 0xa4,
+   k_SRglyph_vg_ret        = 0xa5,
+   k_SRglyph_vg_link       = 0xa6,
+   k_SRglyph_vg_square     = 0xa7,
+   k_SRglyph_vg_triangle   = 0xa8,
+   k_SRglyph_vg_circle     = 0xa9
 };
 
 typedef struct font3d font3d;
index 7a85910d2781edd3a03c45bddd0ccaf26aa557e0..3c5614a1a5c0b6e203cdf199b4482e7f87e97278 100644 (file)
@@ -517,7 +517,8 @@ static void animate_remote_player( u32 index ){
    }
 
    struct network_player *player = &netplayers.list[ index ];
-   player->active_world = NULL;
+   if( player->active != 2 )
+      player->active_world = NULL;
    
    if( minframe && maxframe ){
       pose_remote_player( index, minframe, maxframe );
@@ -580,12 +581,17 @@ static int remote_players_randomize( int argc, const char *argv[] ){
    for( int i=0; i<NETWORK_MAX_PLAYERS; i ++ ){
       struct network_player *player = &netplayers.list[i];
 
-      player->active = vg_randu32() & 0x1;
+      player->active = (vg_randu32() & 0x1)? 2: 0;
       player->isfriend = vg_randu32() & vg_randu32() & 0x1;
       player->isblocked = vg_randu32() & vg_randu32() & vg_randu32() & 0x1;
       player->world_match[ 0 ] = vg_randu32() & 0x1;
       player->world_match[ 1 ] = 0;
 
+      if( player->world_match[0] )
+         player->active_world = &world_static.instances[0];
+      else
+         player->active_world = NULL;
+
       for( int i=0; i<sizeof(player->username)-1; i ++ ){
          player->username[i] = 'a' + (vg_randu32() % 30);
          player->username[i+1] = '\0';
@@ -601,8 +607,8 @@ static int remote_players_randomize( int argc, const char *argv[] ){
       v3f pos;
 
       vg_rand_sphere( pos );
-      v3_muls( pos, 100.0f,
-               netplayers.final_mtx[ i*localplayer.skeleton.bone_count][3] );
+      v3_muladds( localplayer.rb.co, pos, 100.0f,
+                  netplayers.final_mtx[ i*localplayer.skeleton.bone_count][3] );
    }
 
    return 0;
@@ -631,6 +637,15 @@ static void remote_sfx_pre_update(void){
    }
 }
 
+/*
+ * animator->root_co of remote player
+ */
+static void remote_player_position( int id, v3f out_co ){
+   struct skeleton *sk = &localplayer.skeleton;
+   m4x3f *final_mtx = &netplayers.final_mtx[ sk->bone_count*id ];
+   v3_copy( final_mtx[0][3], out_co );
+}
+
 enum remote_player_gui_type {
    k_remote_player_gui_type_stranger,
    k_remote_player_gui_type_friend,
@@ -662,7 +677,7 @@ static void remote_player_nametag( m4x4f pv, v3f co, const char *name,
       wr[1] = vg_clampf((1.0f-wpos[1]) * vg.window_y, -32000.0f, 32000.0f );
       wr[3] = 32;
 
-      ui_fill( wr, ui_opacity( ui_colour(k_ui_bg), 0.6f ) );
+      ui_fill( wr, ui_opacity( ui_colour(k_ui_bg), 0.23f ) );
       ui_text( wr, name, 1, k_ui_align_middle_center, 0 );
 
       vg_ui.font = &vg_ui_font_small;
@@ -687,7 +702,7 @@ static void remote_player_nametag( m4x4f pv, v3f co, const char *name,
                                  vg_ui.font->glyph_height };
 
                   vg_strnull( &str, buf, 32 );
-                  vg_strcatch( &str, (char)k_SRglyph_ps4_circle );
+                  vg_strcatch( &str, (char)k_SRglyph_vg_circle );
                   vg_strcati32( &str, medals[i] );
 
                   ui_text( col, buf, 1, k_ui_align_middle_center, 
@@ -765,14 +780,53 @@ static void remote_players_imgui_lobby(void){
 }
 
 static void remote_players_imgui_world( world_instance *world, m4x4f pv,
-                                        f32 max_dist ){
+                                        f32 max_dist, int geo_cull ){
+   ui_flush( k_ui_shader_colour );
+
    for( u32 i=0; i<NETWORK_MAX_PLAYERS; i++ ){
       struct network_player *player = &netplayers.list[i];
       if( player->active ){
+         v3f co;
+         remote_player_position( i, co );
+
+         if( player->active_world != world ){
+            continue;
+         }
+
+         f32 d2 = v3_dist2( co, localplayer.rb.co );
+
+         if( d2 > (max_dist*max_dist) )
+            continue;
+
+         f32 dist = sqrtf(d2);
+         f32 opacity = 0.95f * sqrtf(((max_dist-dist)/max_dist));
+
+         if( geo_cull ){
+            ray_hit hit;
+            hit.dist = dist;
+
+            v3f dir;
+            v3_sub( co, skaterift.cam.pos, dir );
+            v3_normalize( dir );
+
+            if( ray_world( world, skaterift.cam.pos, dir, &hit, 
+                           k_material_flag_ghosts ) ){
+               opacity *= 0.5f;
+            }
+         }
+
+         player->opacity = vg_lerpf( player->opacity, opacity,
+                                     vg.time_frame_delta * 2.0f );
+
          remote_player_nametag( 
                pv, 
                netplayers.final_mtx[localplayer.skeleton.bone_count*i][3], 
                player->username, player->isfriend, player->medals );
+
+         vg_ui.colour[3] = player->opacity;
+         ui_flush( k_ui_shader_colour );
       }
    }
+
+   vg_ui.colour[3] = 1.0f;
 }
index 9ac3186b7eaf5c69d25a32cf5699e8c913bc3842..3e66aff776cc5891227c8b6d884e9c521a21a8ae 100644 (file)
@@ -23,7 +23,9 @@ struct {
       char username[ NETWORK_USERNAME_MAX ];
       char items[k_netmsg_playeritem_max][ADDON_UID_MAX];
 
+      /* ui */
       u32 medals[3];
+      f32 opacity;
 
       u32 down_bytes;
       f32 down_kbs;
index 1fec3c720aa42a9032d327387fa76a8f5fb753d3..b4b5258c5f69b73b73903fdd104c409808954e54 100644 (file)
@@ -670,10 +670,14 @@ static void vg_gui(void){
    remote_player_network_imgui( vg.pv );
 
 
-   remote_players_imgui_world( world_current_instance(), vg.pv, INFINITY );
    if( skaterift.activity == k_skaterift_respawning ){
+      remote_players_imgui_world( world_current_instance(), vg.pv, 
+                                  2000.0f, 0 );
       remote_players_imgui_lobby();
    }
+   else {
+      remote_players_imgui_world( world_current_instance(), vg.pv, 100.0f, 1 );
+   }
 }