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 22:09:15 +0000
committerMagnus Auvinen <magnus.auvinen@gmail.com>2007-07-29 22:09:15 +0000
commit8233a44b605f53b9e852a51efb4dca8f15635198 (patch)
treec55d5ef893b98916d38a0be2beefc12bc35fa73d /src/engine
parent0dd86dd084d22dc766bb4231285d2ac18e3dfa65 (diff)
downloadzcatch-8233a44b605f53b9e852a51efb4dca8f15635198.tar.gz
zcatch-8233a44b605f53b9e852a51efb4dca8f15635198.zip
an update :D
Diffstat (limited to 'src/engine')
-rw-r--r--src/engine/client/client.cpp40
-rw-r--r--src/engine/client/gfx.cpp3
-rw-r--r--src/engine/packet.h2
-rw-r--r--src/engine/server/server.cpp12
-rw-r--r--src/engine/snapshot.cpp15
-rw-r--r--src/engine/snapshot.h1
6 files changed, 60 insertions, 13 deletions
diff --git a/src/engine/client/client.cpp b/src/engine/client/client.cpp
index 55646b35..ac41350e 100644
--- a/src/engine/client/client.cpp
+++ b/src/engine/client/client.cpp
@@ -601,6 +601,15 @@ void client::run(const char *direct_connect_server)
 		// panic button
 		if(input::pressed(input::lctrl) && input::pressed('Q'))
 			break;
+
+		if(input::pressed(input::f5))
+		{
+			// ack snapshot
+			msg_pack_start_system(NETMSG_SNAPACK, 0);
+			msg_pack_int(-1);
+			msg_pack_end();
+			client_send_msg();
+		}
 			
 		// pump the network
 		pump_network();
@@ -794,7 +803,7 @@ void client::process_packet(NETPACKET *packet)
 					error("failure to load map");
 				}
 			}
-			else if(msg == NETMSG_SNAP || msg == NETMSG_SNAPSMALL || msg == NETMSG_SNAPEMPTY)
+			else if(msg == NETMSG_SNAP || msg == NETMSG_SNAPEMPTY) //|| msg == NETMSG_SNAPSMALL || msg == NETMSG_SNAPEMPTY)
 			{
 				//dbg_msg("client/network", "got snapshot");
 				int game_tick = msg_unpack_int();
@@ -802,15 +811,19 @@ void client::process_packet(NETPACKET *packet)
 				int num_parts = 1;
 				int part = 0;
 				int part_size = 0;
+				int crc = 0;
 				
-				if(msg == NETMSG_SNAP)
+				//if(msg == NETMSG_SNAP)
 				{
-					num_parts = msg_unpack_int();
-					part = msg_unpack_int();
+					//num_parts = msg_unpack_int();
+					//part = msg_unpack_int();
 				}
 				
 				if(msg != NETMSG_SNAPEMPTY)
+				{
 					part_size = msg_unpack_int();
+					crc = msg_unpack_int();
+				}
 				
 				if(snapshot_part == part)
 				{
@@ -831,6 +844,8 @@ void client::process_packet(NETPACKET *packet)
 						unsigned char tmpbuffer2[MAX_SNAPSHOT_SIZE];
 						if(part_size)
 						{
+							if(msg == NETMSG_SNAPEMPTY)
+								dbg_msg("client", "FAILURE!");
 							int compsize = zerobit_decompress(snapshot_incomming_data, part_size, tmpbuffer);
 							int intsize = intpack_decompress(tmpbuffer, compsize, tmpbuffer2);
 							deltadata = tmpbuffer2;
@@ -857,6 +872,8 @@ void client::process_packet(NETPACKET *packet)
 								dbg_msg("client", "error, couldn't find the delta snapshot");
 							}
 						}
+
+						//dbg_msg("UNPACK", "%d unpacked with %d", game_tick, delta_tick);
 						
 						unsigned char tmpbuffer3[MAX_SNAPSHOT_SIZE];
 						int snapsize = snapshot_unpack_delta(deltashot, (snapshot*)tmpbuffer3, deltadata, deltasize);
@@ -873,6 +890,10 @@ void client::process_packet(NETPACKET *packet)
 						// add new
 						snapshot_info *snap = client_snapshot_add(game_tick, time_get(), tmpbuffer3, snapsize);
 						
+						//int ncrc = snapshot_crc((snapshot*)tmpbuffer3);
+						//if(crc != ncrc)
+							//dbg_msg("client", "client snapshot crc failure %d %d", crc, ncrc);
+						
 						// apply snapshot, cycle pointers
 						recived_snapshots++;
 						
@@ -908,10 +929,13 @@ void client::process_packet(NETPACKET *packet)
 						snapshot_part = 0;
 						
 						// ack snapshot
-						msg_pack_start_system(NETMSG_SNAPACK, 0);
-						msg_pack_int(game_tick);
-						msg_pack_end();
-						client_send_msg();
+						//if((rand()%10)==0)
+						{
+							msg_pack_start_system(NETMSG_SNAPACK, 0);
+							msg_pack_int(game_tick);
+							msg_pack_end();
+							client_send_msg();
+						}
 					}
 				}
 				else
diff --git a/src/engine/client/gfx.cpp b/src/engine/client/gfx.cpp
index 819061ba..61369106 100644
--- a/src/engine/client/gfx.cpp
+++ b/src/engine/client/gfx.cpp
@@ -175,7 +175,8 @@ bool gfx_init()
 		indecies[i*6 + 5] = i+2;
 	}*/
 	
-	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
+	//glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
+	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
 	
 	// create null texture, will get id=0
 	gfx_load_texture_raw(4,4,IMG_RGBA,null_texture_data);
diff --git a/src/engine/packet.h b/src/engine/packet.h
index 9c3bb422..1700665d 100644
--- a/src/engine/packet.h
+++ b/src/engine/packet.h
@@ -164,10 +164,12 @@ public:
 	void *new_item(int type, int id, int size)
 	{
 		snapshot::item *obj = (snapshot::item *)(data+data_size);
+		mem_zero(obj, sizeof(snapshot::item) + size);
 		obj->type_and_id = (type<<16)|id;
 		offsets[num_items] = data_size;
 		data_size += sizeof(snapshot::item) + size;
 		num_items++;
+		
 		dbg_assert(data_size < MAX_SNAPSHOT_SIZE, "too much data");
 		dbg_assert(num_items < MAX_ITEMS, "too many items");
 
diff --git a/src/engine/server/server.cpp b/src/engine/server/server.cpp
index 86806c2a..dd5caf7b 100644
--- a/src/engine/server/server.cpp
+++ b/src/engine/server/server.cpp
@@ -300,10 +300,13 @@ public:
 						delta_tick = clients[i].last_acked_snapshot;
 						deltashot = (snapshot *)delta_data;
 					}
+					else
+						dbg_msg("server", "no delta, sending full snapshot");
 				}
 				
 				// create delta
 				int deltasize = snapshot_create_delta(deltashot, (snapshot*)data, deltadata);
+				//dbg_msg("PACK", "%d unpacked with %d", current_tick, delta_tick);
 				
 				if(deltasize)
 				{
@@ -327,13 +330,14 @@ public:
 						int chunk = left < max_size ? left : max_size;
 						left -= chunk;
 
-						if(numpackets == 1)
-							msg_pack_start_system(NETMSG_SNAPSMALL, 0);
-						else
-							msg_pack_start_system(NETMSG_SNAP, 0);
+						//if(numpackets == 1)
+						//	msg_pack_start_system(NETMSG_SNAPSMALL, 0);
+						//else
+						msg_pack_start_system(NETMSG_SNAP, 0);
 						msg_pack_int(current_tick);
 						msg_pack_int(current_tick-delta_tick); // compressed with
 						msg_pack_int(chunk);
+						msg_pack_int(snapshot_crc((snapshot*)data));
 						msg_pack_raw(&compdata[n*max_size], chunk);
 						msg_pack_end();
 						//const msg_info *info = msg_get_info();
diff --git a/src/engine/snapshot.cpp b/src/engine/snapshot.cpp
index 2f6f1f36..2e68df72 100644
--- a/src/engine/snapshot.cpp
+++ b/src/engine/snapshot.cpp
@@ -27,6 +27,21 @@ void *snapshot_empty_delta()
 	return &empty;
 }
 
+int snapshot_crc(snapshot *snap)
+{
+	int crc = 0;
+	
+	for(int i = 0; i < snap->num_items; i++)
+	{
+		snapshot::item *item = snap->get_item(i);
+		int size = snap->get_item_datasize(i);
+		
+		for(int b = 0; b < size/4; b++)
+			crc += item->data()[b];
+	}
+	return crc;
+}
+
 static int diff_item(int *past, int *current, int *out, int size)
 {
 	/*
diff --git a/src/engine/snapshot.h b/src/engine/snapshot.h
index 9af94a3b..b0ffc768 100644
--- a/src/engine/snapshot.h
+++ b/src/engine/snapshot.h
@@ -41,6 +41,7 @@ struct snapshot
 };
 
 void *snapshot_empty_delta();
+int snapshot_crc(snapshot *snap);
 int snapshot_create_delta(snapshot *from, snapshot *to, void *data);
 int snapshot_unpack_delta(snapshot *from, snapshot *to, void *data, int data_size);