update helpers/location to 'frosted' ui
[carveJwlIkooP6JGAAIwe30JlM.git] / player_remote.c
index ba07abea312a44ebcae783bb00c9c16d792a05d6..43c56079cd436123f39f638e8f4706aa7e6581f4 100644 (file)
@@ -1,6 +1,7 @@
 #include "player_remote.h"
 #include "skeleton.h"
 #include "player_render.h"
+#include "player_api.h"
 #include "network_common.h"
 #include "addon.h"
 #include "font.h"
@@ -8,10 +9,14 @@
 #include "ent_miniworld.h"
 #include "ent_region.h"
 #include "shaders/model_entity.h"
+#include "vg/vg_steam_friends.h"
+
+struct global_netplayers netplayers;
 
 static i32 k_show_own_name = 0;
 
-static void player_remote_clear( struct network_player *player ){
+static void player_remote_clear( struct network_player *player )
+{
    addon_cache_unwatch( k_addon_type_player, player->playermodel_view_slot );
    addon_cache_unwatch( k_addon_type_board, player->board_view_slot );
 
@@ -53,7 +58,8 @@ static void relink_remote_player_worlds( u32 client_id ){
  *
  * Run if local worlds change
  */
-static void relink_all_remote_player_worlds(void){
+void relink_all_remote_player_worlds(void)
+{
    for( u32 i=0; i<vg_list_size(netplayers.list); i++ ){
       struct network_player *player = &netplayers.list[i];
       if( player->active )
@@ -61,7 +67,8 @@ static void relink_all_remote_player_worlds(void){
    }
 }
 
-static void player_remote_update_friendflags( struct network_player *remote ){
+void player_remote_update_friendflags( struct network_player *remote )
+{
    ISteamFriends *hSteamFriends = SteamAPI_SteamFriends();
    remote->isfriend = SteamAPI_ISteamFriends_HasFriend( hSteamFriends,
                         remote->steamid, k_EFriendFlagImmediate );
@@ -69,7 +76,8 @@ static void player_remote_update_friendflags( struct network_player *remote ){
                         remote->steamid, k_EFriendFlagBlocked );
 }
 
-static void player_remote_rx_200_300( SteamNetworkingMessage_t *msg ){
+void player_remote_rx_200_300( SteamNetworkingMessage_t *msg )
+{
    netmsg_blank *tmp = msg->m_pData;
 
    if( tmp->inetmsg_id == k_inetmsg_playerjoin ){
@@ -140,6 +148,7 @@ static void player_remote_rx_200_300( SteamNetworkingMessage_t *msg ){
       }
       
       netmsg_playerframe *frame = msg->m_pData;
+
       if( frame->client >= vg_list_size(netplayers.list) ){
          vg_error( "inetmsg_playerframe: player index out of range\n" );
          return;
@@ -313,7 +322,8 @@ static void player_remote_rx_200_300( SteamNetworkingMessage_t *msg ){
 /*
  * Write localplayer pose to network
  */
-static void remote_player_send_playerframe(void){
+void remote_player_send_playerframe(void)
+{
    u8 sysid = localplayer.subsystem;
    if( sysid >= k_player_subsystem_max ) return;
 
@@ -386,7 +396,8 @@ static void remote_player_send_playerframe(void){
 /*
  * Updates network traffic stats
  */
-static void remote_player_debug_update(void){
+void remote_player_debug_update(void)
+{
    if( (vg.time_real - netplayers.last_data_measurement) > 1.0 ){
       netplayers.last_data_measurement = vg.time_real;
       u32 total_down = 0;
@@ -409,7 +420,8 @@ static void remote_player_debug_update(void){
 /*
  * Debugging information
  */
-static void remote_player_network_imgui( m4x4f pv ){
+void remote_player_network_imgui( m4x4f pv )
+{
    if( network_client.user_intent == k_server_intent_online ){
       if( !(steam_ready &&
          (network_client.state == k_ESteamNetworkingConnectionState_Connected)))
@@ -430,6 +442,12 @@ static void remote_player_network_imgui( m4x4f pv ){
    ui_rect panel = { (vg.window_x / 2) - 200, 0, 400, 600 };
    ui_fill( panel, (ui_colour(k_ui_bg)&0x00ffffff)|0x50000000 );
 
+   ui_font_face( &vgf_default_title );
+   ui_info( panel, "Network" );
+   ui_font_face( &vgf_default_large );
+   ui_info( panel, "Status" );
+   ui_font_face( &vgf_default_small );
+
    char buf[512];
    const char *netstatus = "PROGRAMMING ERROR";
 
@@ -596,8 +614,8 @@ static void pose_remote_player( u32 index,
 /* 
  * animate remote player and store in final_mtx
  */
-static void animate_remote_player( u32 index ){
-
+void animate_remote_player( u32 index )
+{
    /*
     * Trys to keep the cursor inside the buffer
     */
@@ -652,7 +670,8 @@ static void animate_remote_player( u32 index ){
 /*
  * Update full final_mtx for all remote players
  */
-static void animate_remote_players(void){
+void animate_remote_players(void)
+{
    for( u32 i=0; i<vg_list_size(netplayers.list); i ++ ){
       struct network_player *player = &netplayers.list[i];
       if( !player->active ) continue;
@@ -664,7 +683,8 @@ static void animate_remote_players(void){
 /*
  * Draw remote players
  */
-static void render_remote_players( world_instance *world, camera *cam ){
+void render_remote_players( world_instance *world, vg_camera *cam )
+{
    u32 draw_list[ NETWORK_MAX_PLAYERS ],
        draw_list_count = 0,
        gliders = 0;
@@ -673,8 +693,11 @@ static void render_remote_players( world_instance *world, camera *cam ){
       struct network_player *player = &netplayers.list[i];
       if( !player->active || player->isblocked ) continue;
       if( player->active_world != world ) continue;
+
+#if 0
       if( !player->isfriend && 
             (world-world_static.instances == k_world_purpose_hub)) continue;
+#endif
 
       draw_list[draw_list_count ++] = i;
 
@@ -774,7 +797,8 @@ static int remote_players_randomize( int argc, const char *argv[] ){
    return 0;
 }
 
-static void remote_players_init(void){
+void remote_players_init(void)
+{
    vg_console_reg_cmd( "add_test_players", remote_players_randomize, NULL );
    vg_console_reg_var( "k_show_own_name", &k_show_own_name, 
                        k_var_dtype_i32, 0 );
@@ -783,7 +807,8 @@ static void remote_players_init(void){
    }
 }
 
-static void remote_sfx_pre_update(void){
+void remote_sfx_pre_update(void)
+{
    for( u32 i=0; i<NETWORK_SFX_QUEUE_LENGTH; i ++ ){
       struct net_sfx *si = &netplayers.sfx_queue[i];
 
@@ -840,13 +865,14 @@ static int player_tag_position( m4x4f pv, v3f root_co, ui_point out_point ){
 /*
  * Draw chat box relative to the root tag position on the screen
  */
-static void chat_box( ui_point tag_root, f64 time, const char *message ){
+static void chat_box( ui_point tag_root, f64 time, const char *message )
+{
    if( (vg.time_real - time) > 15.0 ) 
       return;
 
    ui_rect wr;
    wr[2] = ui_text_line_width( message ) + 8;
-   wr[3] = vg_ui.font->glyph_height + 2;
+   wr[3] = vg_ui.font->ch + 2;
    wr[0] = tag_root[0]-(wr[2]/2);
    wr[1] = tag_root[1] - wr[3] - 8;
 
@@ -858,8 +884,9 @@ static void chat_box( ui_point tag_root, f64 time, const char *message ){
  * Draw full imgui for remote player
  */
 static void remote_player_nametag( ui_point tag_root, 
-                                   struct network_player *player ){
-   vg_ui.font = &vg_ui_font_big;
+                                   struct network_player *player )
+{
+   ui_font_face( &vgf_default_large );
 
    ui_rect wr;
    wr[2] = VG_MAX( ui_text_line_width( player->username ), 140 ) + 8;
@@ -870,7 +897,7 @@ static void remote_player_nametag( ui_point tag_root,
    ui_fill( wr, ui_opacity( ui_colour(k_ui_bg), 0.23f ) );
    ui_text( wr, player->username, 1, k_ui_align_middle_center, 0 );
 
-   vg_ui.font = &vg_ui_font_small;
+   ui_font_face( &vgf_default_small );
 
    /* medals */
    int cols = 0;
@@ -888,10 +915,12 @@ static void remote_player_nametag( ui_point tag_root,
       for( int i=0; i<3; i ++ ){
          if( player->medals[i] ){
             ui_rect col = { wr[0] + (f32)cols*w, wr[1] + wr[3], w, 
-                           vg_ui.font->glyph_height };
+                           vg_ui.font->ch };
 
             vg_strnull( &str, buf, 32 );
+#if 0
             vg_strcatch( &str, (char)k_SRglyph_vg_circle );
+#endif
             vg_strcati32( &str, player->medals[i] );
 
             ui_text( col, buf, 1, k_ui_align_middle_center, 
@@ -948,14 +977,15 @@ static void remote_player_gui_info( ui_rect box,
    else
       fg = ui_colour( in_world? k_ui_fg: k_ui_fg+4 );
 
-   vg_ui.font = &vg_ui_font_big;
+   ui_font_face( &vgf_default_large );
    ui_text( top, username, 1, k_ui_align_middle_center, fg );
-   vg_ui.font = &vg_ui_font_small;
+   ui_font_face( &vgf_default_small );
 
    ui_text( bottom, activity, 1, k_ui_align_middle_center, fg );
 }
 
-static void remote_players_imgui_lobby(void){
+void remote_players_imgui_lobby(void)
+{
    if( network_client.user_intent == k_server_intent_online ){
       if( !(steam_ready &&
          (network_client.state == k_ESteamNetworkingConnectionState_Connected)))
@@ -967,10 +997,10 @@ static void remote_players_imgui_lobby(void){
    ui_px y = 50, width = 200, height = 42, gap = 2,
          x = vg.window_x - width;
 
-   vg_ui.font = &vg_ui_font_big;
+   ui_font_face( &vgf_default_large );
    ui_text( (ui_rect){ x, 0, width, height }, 
             "In World", 1, k_ui_align_middle_center, 0 );
-   vg_ui.font = &vg_ui_font_small;
+   ui_font_face( &vgf_default_small );
 
 
    ui_rect us = { x, y, width, height };
@@ -999,8 +1029,9 @@ static void remote_players_imgui_lobby(void){
    }
 }
 
-static void remote_players_imgui_world( world_instance *world, m4x4f pv,
-                                        f32 max_dist, int geo_cull ){
+void remote_players_imgui_world( world_instance *world, m4x4f pv,
+                                 f32 max_dist, int geo_cull )
+{
    ui_flush( k_ui_shader_colour, vg.window_x, vg.window_y );
 
    for( u32 i=0; i<NETWORK_MAX_PLAYERS; i++ ){
@@ -1070,7 +1101,8 @@ static void chat_enter( char *buf, u32 len ){
    chat_send_message( buf );
 }
 
-static void remote_players_chat_imgui(void){
+void remote_players_chat_imgui(void)
+{
    if( netplayers.chatting == 1 ){
       ui_rect box = { 0, 0, 400, 40 },
               window = { 0, 0, vg.window_x, vg.window_y };