From e6c4db94d81306fda59b8fb32ae07fb3f0c8bf08 Mon Sep 17 00:00:00 2001 From: Magnus Auvinen Date: Sun, 29 Jul 2007 13:21:33 +0000 Subject: [PATCH] fixed some problems with the snapshot handling. added fps meter. fixed error when connecting to several servers --- src/engine/client/client.cpp | 49 +++++++++++++++++++----------- src/engine/client/gfx.cpp | 8 +++++ src/engine/interface.h | 1 + src/game/client/game_client.cpp | 1 + src/game/client/mapres_tilemap.cpp | 8 +++-- src/game/server/game_server.cpp | 2 ++ 6 files changed, 49 insertions(+), 20 deletions(-) diff --git a/src/engine/client/client.cpp b/src/engine/client/client.cpp index af537e62c..d4c7f2db7 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 diff --git a/src/engine/client/gfx.cpp b/src/engine/client/gfx.cpp index 7b0b421e2..763264875 100644 --- a/src/engine/client/gfx.cpp +++ b/src/engine/client/gfx.cpp @@ -111,6 +111,13 @@ struct batch int num; }; +void gfx_destoy_batch(void *in_b) +{ + batch *b = (batch*)in_b; + delete b; + +} + void gfx_quads_draw_batch(void *in_b) { batch *b = (batch*)in_b; @@ -152,6 +159,7 @@ void *gfx_quads_create_batch() batch *b = new batch; b->num = num_vertices; b->vb.data(vertices, num_vertices*sizeof(custom_vertex), GL_STATIC_DRAW); + dbg_msg("gfx", "created batch. num=%d size=%d", num_vertices, num_vertices*sizeof(custom_vertex)); num_vertices = 0; gfx_quads_end(); return b; diff --git a/src/engine/interface.h b/src/engine/interface.h index ba8dacceb..d51cedc4e 100644 --- a/src/engine/interface.h +++ b/src/engine/interface.h @@ -756,6 +756,7 @@ void gfx_getscreen(float *tl_x, float *tl_y, float *br_x, float *br_y); void gfx_quads_draw_batch(void *batch); void *gfx_quads_create_batch(); +void gfx_destoy_batch(void *batch); void mods_message(int msg, int client_id); void modc_message(int msg); diff --git a/src/game/client/game_client.cpp b/src/game/client/game_client.cpp index eef3e692d..365205a49 100644 --- a/src/game/client/game_client.cpp +++ b/src/game/client/game_client.cpp @@ -1205,6 +1205,7 @@ void modc_render() { menu_active = !menu_active; } + if (!menu_active) { if(inp_key_down(input::enter)) diff --git a/src/game/client/mapres_tilemap.cpp b/src/game/client/mapres_tilemap.cpp index f1f29d8ff..3b2a5006b 100644 --- a/src/game/client/mapres_tilemap.cpp +++ b/src/game/client/mapres_tilemap.cpp @@ -5,12 +5,16 @@ #include -bool must_init = true; void *batches[32] = {0}; int tilemap_init() { - must_init = true; + for(int i = 0; i < 32; i++) + if(batches[i]) + { + gfx_destoy_batch(batches[i]); + batches[i] = 0; + } return 0; } diff --git a/src/game/server/game_server.cpp b/src/game/server/game_server.cpp index d1b3c44bf..fa7493bf1 100644 --- a/src/game/server/game_server.cpp +++ b/src/game/server/game_server.cpp @@ -1826,6 +1826,8 @@ void mods_init() if(type != -1) { + // LOL, the only new in the entire game code + // perhaps we can get rid of it. seams like a stupid thing to have powerup *ppower = new powerup(type, subtype); ppower->pos = vec2(it->x, it->y); }