#include "player_render.h"
#include "network_common.h"
#include "addon.h"
+#include "font.h"
+#include "gui.h"
static void player_remote_clear( struct network_player *player ){
addon_cache_unwatch( k_addon_type_player, player->playermodel_view_slot );
static void relink_remote_player_worlds( u32 client_id ){
struct network_player *player = &netplayers.list[client_id];
- player->hub_match = 0;
- player->client_match = 0;
-
- addon_alias q0,q1;
- addon_uid_to_alias( player->items[k_netmsg_playeritem_world0], &q0 );
- addon_uid_to_alias( player->items[k_netmsg_playeritem_world1], &q1 );
+ addon_alias q[2];
+ addon_uid_to_alias( player->items[k_netmsg_playeritem_world0], &q[0] );
+ addon_uid_to_alias( player->items[k_netmsg_playeritem_world1], &q[1] );
/*
* currently in 10.23, the hub world will always be the same.
* this might but probably wont change in the future
*/
- if( world_static.addon_hub )
- if( addon_alias_eq( &q0, &world_static.addon_hub->alias ) )
- player->hub_match = 1;
+ for( u32 i=0; i<k_world_max; i++ ){
+ addon_reg *reg = world_static.instance_addons[ i ];
+
+ player->world_match[i] = 0;
- if( world_static.addon_client )
- if( addon_alias_eq( &q1, &world_static.addon_client->alias ) )
- player->client_match = 1;
+ if( reg ){
+ if( addon_alias_eq( &q[i], &world_static.instance_addons[i]->alias ) )
+ player->world_match[i] = 1;
+ }
+ }
}
/*
* -------------------------------------------------------------*/
for( u32 i=0; i<frame->sound_effects; i ++ ){
- /* CHEATING for now */
struct net_sfx sfx;
net_sfx_exchange( &ctx, &sfx );
- net_sfx_play( &sfx );
+
+ f64 t = (frame->timestamp - NETWORK_FRAMERATE) +
+ (sfx.subframe*NETWORK_FRAMERATE);
+
+ f32 remaining = t - ib->t;
+
+ if( remaining <= 0.0f )
+ net_sfx_play( &sfx );
+ else{
+ struct net_sfx *dst = NULL;
+
+ for( u32 j=0; j<NETWORK_SFX_QUEUE_LENGTH; j ++ ){
+ struct net_sfx *sj = &netplayers.sfx_queue[j];
+ if( sj->system == k_player_subsystem_invalid ){
+ dst = sj;
+ break;
+ }
+
+ if( sj->priority < sfx.priority )
+ dst = sj;
+ }
+
+ *dst = sfx;
+ dst->subframe = remaining;
+ }
}
/* animation
}
}
+static void remote_player_nametag( m4x4f pv, v3f co, const char *name ){
+ return;
+ vg_ui.font = &vg_ui_font_big;
+ v4f wpos;
+ v3_copy( co, wpos );
+ wpos[1] += 2.0f;
+ wpos[3] = 1.0f;
+
+ m4x4_mulv( pv, wpos, wpos );
+
+ if( wpos[3] > 0.0f ){
+ v2_muls( wpos, (1.0f/wpos[3]) * 0.5f, wpos );
+ v2_add( wpos, (v2f){ 0.5f, 0.5f }, wpos );
+
+ ui_rect wr;
+ wr[0] = vg_clampf(wpos[0] * vg.window_x, -32000.0f,32000.0f)-150;
+ wr[1] = vg_clampf((1.0f-wpos[1]) * vg.window_y,
+ -32000.0f,32000.0f);
+ wr[2] = 300;
+ wr[3] = 32;
+ ui_fill( wr, (ui_colour(k_ui_bg)&0x00ffffff)|0x50000000 );
+ ui_text( wr, name, 1, k_ui_align_middle_center, 0 );
+ }
+ vg_ui.font = &vg_ui_font_small;
+}
+
/*
* Debugging information
*/
i, player->username, sysname, player->down_kbs );
ui_info( panel, buf );
- v4f wpos = { 0.0f, 2.0f, 0.0f, 1.0f };
struct player_avatar *av = localplayer.playeravatar;
- m4x3_mulv( netplayers.final_mtx[av->sk.bone_count*i], wpos, wpos );
- m4x4_mulv( pv, wpos, wpos );
-
- if( wpos[3] > 0.0f ){
- v2_muls( wpos, (1.0f/wpos[3]) * 0.5f, wpos );
- v2_add( wpos, (v2f){ 0.5f, 0.5f }, wpos );
-
- ui_rect wr;
- wr[0] = vg_clampf(wpos[0] * vg.window_x, -32000.0f,32000.0f)-150;
- wr[1] = vg_clampf((1.0f-wpos[1]) * vg.window_y,
- -32000.0f,32000.0f);
- wr[2] = 300;
- wr[3] = 17;
- ui_fill( wr, (ui_colour(k_ui_bg)&0x00ffffff)|0x50000000 );
- ui_text( wr, buf, 1, k_ui_align_middle_center, 0 );
- }
+ remote_player_nametag(
+ pv,
+ netplayers.final_mtx[av->sk.bone_count*i][3],
+ player->username );
}
}
}
else {
ui_info( panel, "offline" );
}
+
+ struct player_avatar *av = localplayer.playeravatar;
+ remote_player_nametag(
+ pv,
+ localplayer.final_mtx[0][3],
+ "Localplayer" );
}
/*
memcpy( board_pose, &pose0.board, sizeof(*board_pose) );
}
- if( instance_id ){
- if( player->client_match ){
- player->active_world = &world_static.instances[ instance_id ];
- }
- }
- else{
- if( player->hub_match ){
- player->active_world = &world_static.instances[ instance_id ];
- }
- }
+ if( player->world_match[ instance_id ] )
+ player->active_world = &world_static.instances[ instance_id ];
}
/*
* Draw remote players
*/
static void render_remote_players( world_instance *world, camera *cam ){
-
SDL_AtomicLock( &addon_system.sl_cache_using_resources );
for( u32 i=0; i<NETWORK_MAX_PLAYERS; i ++ ){
SDL_AtomicUnlock( &addon_system.sl_cache_using_resources );
}
-/* TODO: Which world is the player in
- * nametags with occlusion
- */
+static void render_remote_player_nametag( v3f co, const char *name ){
+ m4x3f mlocal;
+ m4x3_identity( mlocal );
+ mlocal[3][0] -= font3d_string_width( 2, name ) * 0.5f;
+
+ m4x3f mmdl;
+ m3x3_identity( mmdl );
+ for( int i=0; i<3; i++ )
+ v3_muls( skaterift.cam.mtx.v[i], 0.2f, mmdl[i] );
+ m3x3_transpose( mmdl, mmdl );
+ v3_add( co, (v3f){0.0f,2.0f,0.0f}, mmdl[3] );
+
+ m4x3_mul( mmdl, mlocal, mmdl );
+ font3d_simple_draw( 2, name, &skaterift.cam, mmdl );
+}
+
+static void render_remote_players_tags( world_instance *world, camera *cam ){
+ glEnable(GL_BLEND);
+ glEnable(GL_DEPTH_TEST);
+ glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA );
+ glBlendEquation(GL_FUNC_ADD);
+
+ font3d_bind( &gui.font, k_font_shader_default, 1, NULL, &skaterift.cam );
+ font3d_setcolour( (v4f){1.0f,1.0f,1.0f,1.0f} );
+
+ render_remote_player_nametag(
+ localplayer.final_mtx[0][3],
+ steam_username_at_startup );
+
+ for( u32 i=0; i<NETWORK_MAX_PLAYERS; i ++ ){
+ struct network_player *player = &netplayers.list[i];
+ if( !player->active ) continue;
+ if( player->active_world != world ) continue;
+
+ struct player_avatar *av = localplayer.playeravatar;
+ render_remote_player_nametag(
+ netplayers.final_mtx[av->sk.bone_count*i][3],
+ player->username );
+ }
+
+ glDisable(GL_BLEND);
+}
+
+static void remote_players_init(void){
+ for( u32 i=0; i<NETWORK_SFX_QUEUE_LENGTH; i ++ ){
+ netplayers.sfx_queue[i].system = k_player_subsystem_invalid;
+ }
+}
+
+static void remote_sfx_pre_update(void){
+ for( u32 i=0; i<NETWORK_SFX_QUEUE_LENGTH; i ++ ){
+ struct net_sfx *si = &netplayers.sfx_queue[i];
+
+ if( si->system != k_player_subsystem_invalid ){
+ si->subframe -= vg.time_frame_delta;
+ if( si->subframe <= 0.0f ){
+ net_sfx_play( si );
+ si->system = k_player_subsystem_invalid;
+ }
+ }
+ }
+}