diff --git a/src/game/client/game_client.cpp b/src/game/client/game_client.cpp index d29c6b7d1..c49b45c9b 100644 --- a/src/game/client/game_client.cpp +++ b/src/game/client/game_client.cpp @@ -1541,9 +1541,14 @@ void modc_render() sprintf(buf, "%4d", player->score); gfx_pretty_text(x+60-gfx_pretty_text_width(48,buf), y, 48, buf); gfx_pretty_text(x+128, y, 48, client_datas[player->clientid].name); + sprintf(buf, "%4d", player->latency); float tw = gfx_pretty_text_width(48.0f, buf); gfx_pretty_text(x+w-tw-20, y, 48, buf); + + /*sprintf(buf, "%4d", player->latency_flux); + tw = gfx_pretty_text_width(24.0f, buf); + gfx_pretty_text(x+w-tw-20, y+20, 24, buf);*/ render_tee(&idlestate, player->clientid, vec2(1,0), vec2(x+90, y+24)); y += 58.0f; diff --git a/src/game/game.h b/src/game/game.h index 1c5243478..3331d6f52 100644 --- a/src/game/game.h +++ b/src/game/game.h @@ -149,6 +149,7 @@ struct obj_player int score; int latency; + int latency_flux; int emote; int hook_active; diff --git a/src/game/server/game_server.cpp b/src/game/server/game_server.cpp index 31052aa57..3dfa07737 100644 --- a/src/game/server/game_server.cpp +++ b/src/game/server/game_server.cpp @@ -1006,6 +1006,27 @@ int player::handle_weapons() void player::tick() { + // do latency stuff + { + client_info info; + if(server_getclientinfo(client_id, &info)) + { + latency_accum += info.latency; + latency_accum_max = max(latency_accum_max, info.latency); + latency_accum_min = min(latency_accum_min, info.latency); + } + + if(server_tick()%server_tickspeed() == 0) + { + latency_avg = latency_accum/server_tickspeed(); + latency_max = latency_accum_max; + latency_min = latency_accum_min; + latency_accum = 0; + latency_accum_min = 1000; + latency_accum_max = 0; + } + } + // TODO: rework the input to be more robust // TODO: remove this tick count, it feels weird if(dead) @@ -1287,11 +1308,8 @@ void player::snap(int snaping_client) player->vy = (int)vel.y; player->emote = EMOTE_NORMAL; - player->latency = 0; - client_info info; - if(server_getclientinfo(client_id, &info)) - player->latency = info.latency; - + player->latency = latency_avg; + player->latency_flux = latency_max-latency_min; player->ammocount = weapons[active_weapon].ammo; player->health = 0; @@ -1637,8 +1655,8 @@ void mods_client_enter(int client_id) void mods_client_drop(int client_id) { dbg_msg("mods", "client drop %d", client_id); - players[client_id].client_id = -1; world.remove_entity(&players[client_id]); + players[client_id].client_id = -1; } void mods_message(int msg, int client_id) diff --git a/src/game/server/game_server.h b/src/game/server/game_server.h index e8690669e..c285c4d5e 100644 --- a/src/game/server/game_server.h +++ b/src/game/server/game_server.h @@ -246,6 +246,13 @@ public: bool dead; int die_tick; + + int latency_accum; + int latency_accum_min; + int latency_accum_max; + int latency_avg; + int latency_min; + int latency_max; // hooking stuff enum