about summary refs log tree commit diff
path: root/src/engine
diff options
context:
space:
mode:
authorMagnus Auvinen <magnus.auvinen@gmail.com>2007-07-29 13:21:33 +0000
committerMagnus Auvinen <magnus.auvinen@gmail.com>2007-07-29 13:21:33 +0000
commite6c4db94d81306fda59b8fb32ae07fb3f0c8bf08 (patch)
treed5f713cb83ea7e56223460df06531269d1a26684 /src/engine
parent25c0ffb4f4b34758a4dddb7ff4a1cada1bb07136 (diff)
downloadzcatch-e6c4db94d81306fda59b8fb32ae07fb3f0c8bf08.tar.gz
zcatch-e6c4db94d81306fda59b8fb32ae07fb3f0c8bf08.zip
fixed some problems with the snapshot handling. added fps meter. fixed error when connecting to several servers
Diffstat (limited to 'src/engine')
-rw-r--r--src/engine/client/client.cpp49
-rw-r--r--src/engine/client/gfx.cpp8
-rw-r--r--src/engine/interface.h1
3 files changed, 40 insertions, 18 deletions
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(&current);
 	}
 	
+	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 7b0b421e..76326487 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 ba8dacce..d51cedc4 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);