about summary refs log tree commit diff
path: root/src/engine
diff options
context:
space:
mode:
authorMagnus Auvinen <magnus.auvinen@gmail.com>2007-10-28 11:30:25 +0000
committerMagnus Auvinen <magnus.auvinen@gmail.com>2007-10-28 11:30:25 +0000
commita3ce2eb90cd26fe87042344175e5c9669adb7dcd (patch)
treed936a8ffafe366caea08c5bb384794034c590322 /src/engine
parenteba83b7e194cc6b4ba76fd5e048d81279becfc35 (diff)
downloadzcatch-a3ce2eb90cd26fe87042344175e5c9669adb7dcd.tar.gz
zcatch-a3ce2eb90cd26fe87042344175e5c9669adb7dcd.zip
major update. splitted the player information into two diffrent network items
Diffstat (limited to 'src/engine')
-rw-r--r--src/engine/client/client.c8
-rw-r--r--src/engine/client/gfx.c7
-rw-r--r--src/engine/client/snd.c13
-rw-r--r--src/engine/config_variables.h2
-rw-r--r--src/engine/network.c16
-rw-r--r--src/engine/protocol.h2
-rw-r--r--src/engine/server/server.c15
-rw-r--r--src/engine/snapshot.c17
-rw-r--r--src/engine/system.c1
9 files changed, 56 insertions, 25 deletions
diff --git a/src/engine/client/client.c b/src/engine/client/client.c
index f8ccf6e5..c6a9252f 100644
--- a/src/engine/client/client.c
+++ b/src/engine/client/client.c
@@ -1007,6 +1007,14 @@ static void client_run(const char *direct_connect_server)
 int editor_main(int argc, char **argv);
 
 /*client main_client; */
+/*
+const char *user_directory()
+{
+	static char path[512] = {0};
+	
+}*/
+
+
 
 int main(int argc, char **argv)
 {
diff --git a/src/engine/client/gfx.c b/src/engine/client/gfx.c
index 13c35a39..fe72f4c7 100644
--- a/src/engine/client/gfx.c
+++ b/src/engine/client/gfx.c
@@ -531,9 +531,14 @@ int gfx_load_texture_raw(int w, int h, int format, const void *data)
 	unsigned char *texdata = (unsigned char *)data;
 	unsigned char *tmpdata = 0;
 	int oglformat = 0;
+	int tex = 0;
+	
+	/* don't waste memory on texture if we are stress testing */
+	if(config.stress)
+		return -1;
 	
 	/* grab texture */
-	int tex = first_free_texture;
+	tex = first_free_texture;
 	first_free_texture = textures[tex].next;
 	textures[tex].next = -1;
 	
diff --git a/src/engine/client/snd.c b/src/engine/client/snd.c
index 79121584..725bc569 100644
--- a/src/engine/client/snd.c
+++ b/src/engine/client/snd.c
@@ -334,14 +334,23 @@ int snd_load_wv(const char *filename)
 	int sid = -1;
 	char error[100];
 	WavpackContext *context;
+	
+	/* don't waste memory on sound when we are stress testing */
+	if(config.stress)
+		return -1;
+
+	file = fopen(filename, "rb"); /* TODO: use system.h stuff for this */
+	if(!file)
+	{
+		dbg_msg("sound/wv", "failed to open %s", filename);
+		return -1;
+	}
 
 	sid = snd_alloc_id();
 	if(sid < 0)
 		return -1;
 	snd = &samples[sid];
 
-	file = fopen(filename, "rb"); /* TODO: use system.h stuff for this */
-
 	context = WavpackOpenFileInput(read_data, error);
 	if (context)
 	{
diff --git a/src/engine/config_variables.h b/src/engine/config_variables.h
index dfe638d0..4ef8958e 100644
--- a/src/engine/config_variables.h
+++ b/src/engine/config_variables.h
@@ -46,3 +46,5 @@ MACRO_CONFIG_STR(sv_map, 128, "dm1")
 
 MACRO_CONFIG_INT(sv_max_clients, 8, 1, 16)
 
+MACRO_CONFIG_INT(sv_bandwidth_mode, 0, 0, 2)
+
diff --git a/src/engine/network.c b/src/engine/network.c
index 05779831..1005bbf2 100644
--- a/src/engine/network.c
+++ b/src/engine/network.c
@@ -17,7 +17,8 @@ enum
 	NETWORK_VERSION = 1,
 	
 	NETWORK_HEADER_SIZE = 6,
-	NETWORK_MAX_PACKET_SIZE = 1024,
+	NETWORK_MAX_PAYLOAD = 1024,
+	NETWORK_MAX_PACKET_SIZE = NETWORK_HEADER_SIZE+NETWORK_MAX_PAYLOAD,
 	NETWORK_MAX_CLIENTS = 16,
 	
 	NETWORK_CONNSTATE_OFFLINE=0,
@@ -738,6 +739,8 @@ int netserver_recv(NETSERVER *s, NETPACKET *packet)
 
 int netserver_send(NETSERVER *s, NETPACKET *packet)
 {
+	dbg_assert(packet->data_size < NETWORK_MAX_PAYLOAD, "packet payload too big");
+	
 	if(packet->flags&PACKETFLAG_CONNLESS)
 	{
 		/* send connectionless packet */
@@ -775,9 +778,12 @@ void netserver_stats(NETSERVER *s, NETSTATS *stats)
 	
 	for(c = 0; c < s->max_clients; c++)
 	{
-		int *sstats = (int *)(&(s->slots[c].conn.stats));
-		for(i = 0; i < num_stats; i++)
-			istats[i] += sstats[i];
+		if(s->slots[c].conn.state != NETWORK_CONNSTATE_OFFLINE)
+		{
+			int *sstats = (int *)(&(s->slots[c].conn.stats));
+			for(i = 0; i < num_stats; i++)
+				istats[i] += sstats[i];
+		}
 	}
 }
 
@@ -869,6 +875,8 @@ int netclient_recv(NETCLIENT *c, NETPACKET *packet)
 
 int netclient_send(NETCLIENT *c, NETPACKET *packet)
 {
+	dbg_assert(packet->data_size < NETWORK_MAX_PAYLOAD, "packet payload too big");
+	
 	if(packet->flags&PACKETFLAG_CONNLESS)
 	{
 		/* send connectionless packet */
diff --git a/src/engine/protocol.h b/src/engine/protocol.h
index b9aba258..96ad1e6b 100644
--- a/src/engine/protocol.h
+++ b/src/engine/protocol.h
@@ -30,5 +30,5 @@ enum
 	MAX_NAME_LENGTH=32,
 	MAX_CLANNAME_LENGTH=32,
 	MAX_INPUT_SIZE=128,
-	MAX_SNAPSHOT_PACKSIZE=1200
+	MAX_SNAPSHOT_PACKSIZE=900
 };
diff --git a/src/engine/server/server.c b/src/engine/server/server.c
index afbcc0dd..0262c65f 100644
--- a/src/engine/server/server.c
+++ b/src/engine/server/server.c
@@ -739,6 +739,10 @@ static int server_run()
 				}
 	
 				/* snap game */
+				if(config.sv_bandwidth_mode == 0 ||
+					(config.sv_bandwidth_mode == 1 && current_tick%2) ||
+					(config.sv_bandwidth_mode == 2 && (current_tick%3) == 0 ))
+				/* if(current_tick&1) */
 				{
 					int64 start = time_get();
 					server_do_snap();
@@ -765,12 +769,21 @@ static int server_run()
 			{
 				if(config.debug)
 				{
-					dbg_msg("server", "sim=%.02fms snap=%.02fms net=%.02fms total=%.02fms load=%.02f%%",
+					static NETSTATS prev_stats;
+					NETSTATS stats;
+					netserver_stats(net, &stats);
+					dbg_msg("server", "sim=%.02fms snap=%.02fms net=%.02fms tot=%.02fms load=%.02f%%",
 						(simulationtime/reportinterval)/(double)time_freq()*1000,
 						(snaptime/reportinterval)/(double)time_freq()*1000,
 						(networktime/reportinterval)/(double)time_freq()*1000,
 						(totaltime/reportinterval)/(double)time_freq()*1000,
 						(totaltime)/reportinterval/(double)time_freq()*100.0f);
+
+					dbg_msg("server", "send=%8d recv=%8d",
+						(stats.send_bytes - prev_stats.send_bytes)/reportinterval,
+						(stats.recv_bytes - prev_stats.recv_bytes)/reportinterval);
+						
+					prev_stats = stats;
 				}
 	
 				simulationtime = 0;
diff --git a/src/engine/snapshot.c b/src/engine/snapshot.c
index 84f0416b..40bad21e 100644
--- a/src/engine/snapshot.c
+++ b/src/engine/snapshot.c
@@ -94,26 +94,11 @@ void snapshot_debug_dump(SNAPSHOT *snap)
 
 static int diff_item(int *past, int *current, int *out, int size)
 {
-	/*
 	int needed = 0;
 	while(size)
 	{
 		*out = *current-*past;
-		if(*out)
-			needed = 1;
-		out++;
-		current++;
-		past++;
-		size--;
-	}*/
-
-	int needed = 0;
-	while(size)
-	{
-		*out = *current-*past;
-		if(*out)
-			needed = 1;
-		
+		needed |= *out;
 		out++;
 		past++;
 		current++;
diff --git a/src/engine/system.c b/src/engine/system.c
index 67e84b74..71f5b545 100644
--- a/src/engine/system.c
+++ b/src/engine/system.c
@@ -81,6 +81,7 @@ void dbg_msg(const char *sys, const char *fmt, ...)
 	vprintf(fmt, args);
 	va_end(args);
 	printf("\n");
+	fflush(stdout);
 }
 
 int memory_alloced = 0;