From 1b889e55df5f9c0a8a26daba03ffa21754d78230 Mon Sep 17 00:00:00 2001 From: hgn Date: Sun, 12 Nov 2023 20:53:21 +0000 Subject: [PATCH] better nametag --- font.h | 7 ++++- player_remote.c | 68 ++++++++++++++++++++++++++++++++++++++++++++----- player_remote.h | 2 ++ skaterift.c | 6 ++++- 4 files changed, 74 insertions(+), 9 deletions(-) diff --git a/font.h b/font.h index c00aece..3bda500 100644 --- 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; diff --git a/player_remote.c b/player_remote.c index 7a85910..3c5614a 100644 --- a/player_remote.c +++ b/player_remote.c @@ -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; iactive = 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; iusername)-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; iactive ){ + 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; } diff --git a/player_remote.h b/player_remote.h index 9ac3186..3e66aff 100644 --- a/player_remote.h +++ b/player_remote.h @@ -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; diff --git a/skaterift.c b/skaterift.c index 1fec3c7..b4b5258 100644 --- a/skaterift.c +++ b/skaterift.c @@ -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 ); + } } -- 2.25.1