From e6c4db94d81306fda59b8fb32ae07fb3f0c8bf08 Mon Sep 17 00:00:00 2001 From: Magnus Auvinen Date: Sun, 29 Jul 2007 13:21:33 +0000 Subject: fixed some problems with the snapshot handling. added fps meter. fixed error when connecting to several servers --- src/engine/client/client.cpp | 49 ++++++++++++++++++++++++++++---------------- 1 file changed, 31 insertions(+), 18 deletions(-) (limited to 'src/engine/client/client.cpp') diff --git a/src/engine/client/client.cpp b/src/engine/client/client.cpp index af537e62..d4c7f2db 100644 --- a/src/engine/client/client.cpp +++ b/src/engine/client/client.cpp @@ -398,7 +398,7 @@ bool client::load_data() debug_font = gfx_load_texture("data/debug_font.png"); return true; } - +extern int memory_alloced; void client::debug_render() { if(!config.debug) @@ -417,12 +417,14 @@ void client::debug_render() net.stats(¤t); } + static float frametime_avg = 0; + frametime_avg = frametime_avg*0.9f + frametime*0.1f; char buffer[512]; - sprintf(buffer, "send: %8d recv: %8d latency: %4.0f %c", + sprintf(buffer, "send: %6d recv: %6d latency: %4.0f %c fps: %d", (current.send_bytes-prev.send_bytes)*10, (current.recv_bytes-prev.recv_bytes)*10, - latency*1000.0f, extra_polating?'E':' '); - gfx_quads_text(10, 10, 16, buffer); + latency*1000.0f, extra_polating?'E':' ', (int)(1.0f/frametime_avg)); + gfx_quads_text(2, 2, 16, buffer); } @@ -538,25 +540,36 @@ void client::run(const char *direct_connect_server) // switch snapshot if(recived_snapshots >= 3) { - snapshot_info *cur = snapshots[SNAP_CURRENT]; - int64 t = game_start_time + (cur->tick+1)*time_freq()/50; - if(latency > 0) - t += (int64)(time_freq()*(latency*1.1f)); - - if(t < time_get()) + int64 now = time_get(); + while(1) { - snapshot_info *next = snapshots[SNAP_CURRENT]->next; - if(next) + snapshot_info *cur = snapshots[SNAP_CURRENT]; + int64 tickstart = game_start_time + (cur->tick+1)*time_freq()/50; + int64 t = tickstart; + if(latency > 0) + t += (int64)(time_freq()*(latency*1.1f)); + + if(t < now) { - snapshots[SNAP_PREV] = snapshots[SNAP_CURRENT]; - snapshots[SNAP_CURRENT] = next; - snapshot_start_time = t; + snapshot_info *next = snapshots[SNAP_CURRENT]->next; + if(next) + { + snapshots[SNAP_PREV] = snapshots[SNAP_CURRENT]; + snapshots[SNAP_CURRENT] = next; + snapshot_start_time = t; + } + else + { + extra_polating = 1; + break; + } } else - extra_polating = 1; + { + extra_polating = 0; + break; + } } - else - extra_polating = 0; } // send input -- cgit 1.4.1