about summary refs log tree commit diff
path: root/src/game/client/components/controls.cpp
diff options
context:
space:
mode:
authorMagnus Auvinen <magnus.auvinen@gmail.com>2009-01-10 13:34:01 +0000
committerMagnus Auvinen <magnus.auvinen@gmail.com>2009-01-10 13:34:01 +0000
commit1dc158bb789b3c7f287e55036ec22764af1c835d (patch)
tree40ab111b9c0cf36e42807f0f7c711c6c9a11f940 /src/game/client/components/controls.cpp
parent39370635cc0e776630a08263028a2f5edcfd37d9 (diff)
downloadzcatch-1dc158bb789b3c7f287e55036ec22764af1c835d.tar.gz
zcatch-1dc158bb789b3c7f287e55036ec22764af1c835d.zip
fixed so when you are in not in playing mode, the input snapping drops to 1hz to save even more bandwidth
Diffstat (limited to 'src/game/client/components/controls.cpp')
-rw-r--r--src/game/client/components/controls.cpp96
1 files changed, 54 insertions, 42 deletions
diff --git a/src/game/client/components/controls.cpp b/src/game/client/components/controls.cpp
index 63a081eb..675b748b 100644
--- a/src/game/client/components/controls.cpp
+++ b/src/game/client/components/controls.cpp
@@ -79,6 +79,7 @@ int CONTROLS::snapinput(int *data)
 {
 	static NETOBJ_PLAYER_INPUT last_data = {0};
 	static int64 last_send_time = 0;
+	bool send = false;
 	
 	// update player state
 	if(gameclient.chat->is_active())
@@ -87,6 +88,10 @@ int CONTROLS::snapinput(int *data)
 		input_data.player_state = PLAYERSTATE_IN_MENU;
 	else
 		input_data.player_state = PLAYERSTATE_PLAYING;
+	
+	if(last_data.player_state != input_data.player_state)
+		send = true;
+		
 	last_data.player_state = input_data.player_state;
 	
 	// we freeze the input if chat or menu is activated
@@ -101,55 +106,62 @@ int CONTROLS::snapinput(int *data)
 		input_direction_right = 0;
 			
 		mem_copy(data, &input_data, sizeof(input_data));
-		return sizeof(input_data);
+
+		// send once a second just to be sure
+		if(time_get() > last_send_time + time_freq())
+			send = true;
 	}
-	
-	input_data.target_x = (int)mouse_pos.x;
-	input_data.target_y = (int)mouse_pos.y;
-	if(!input_data.target_x && !input_data.target_y)
-		input_data.target_y = 1;
-		
-	// set direction
-	input_data.direction = 0;
-	if(input_direction_left && !input_direction_right)
-		input_data.direction = -1;
-	if(!input_direction_left && input_direction_right)
-		input_data.direction = 1;
-
-	// stress testing
-	if(config.dbg_stress)
+	else
 	{
-		float t = client_localtime();
-		mem_zero(&input_data, sizeof(input_data));
-
-		input_data.direction = ((int)t/2)&1;
-		input_data.jump = ((int)t);
-		input_data.fire = ((int)(t*10));
-		input_data.hook = ((int)(t*2))&1;
-		input_data.wanted_weapon = ((int)t)%NUM_WEAPONS;
-		input_data.target_x = (int)(sinf(t*3)*100.0f);
-		input_data.target_y = (int)(cosf(t*3)*100.0f);
-	}
-
-	// check if we need to send input
-	bool send = false;
-	if(input_data.direction != last_data.direction) send = true;
-	else if(input_data.jump != last_data.jump) send = true;
-	else if(input_data.fire != last_data.fire) send = true;
-	else if(input_data.hook != last_data.hook) send = true;
-	else if(input_data.player_state != last_data.player_state) send = true;
-	else if(input_data.wanted_weapon != last_data.wanted_weapon) send = true;
-	else if(input_data.next_weapon != last_data.next_weapon) send = true;
-	else if(input_data.prev_weapon != last_data.prev_weapon) send = true;
-
-	if(time_get() > last_send_time + time_freq()/10)
-		send = true;
+		
+		input_data.target_x = (int)mouse_pos.x;
+		input_data.target_y = (int)mouse_pos.y;
+		if(!input_data.target_x && !input_data.target_y)
+			input_data.target_y = 1;
+			
+		// set direction
+		input_data.direction = 0;
+		if(input_direction_left && !input_direction_right)
+			input_data.direction = -1;
+		if(!input_direction_left && input_direction_right)
+			input_data.direction = 1;
+
+		// stress testing
+		if(config.dbg_stress)
+		{
+			float t = client_localtime();
+			mem_zero(&input_data, sizeof(input_data));
+
+			input_data.direction = ((int)t/2)&1;
+			input_data.jump = ((int)t);
+			input_data.fire = ((int)(t*10));
+			input_data.hook = ((int)(t*2))&1;
+			input_data.wanted_weapon = ((int)t)%NUM_WEAPONS;
+			input_data.target_x = (int)(sinf(t*3)*100.0f);
+			input_data.target_y = (int)(cosf(t*3)*100.0f);
+		}
 
+		// check if we need to send input
+		if(input_data.direction != last_data.direction) send = true;
+		else if(input_data.jump != last_data.jump) send = true;
+		else if(input_data.fire != last_data.fire) send = true;
+		else if(input_data.hook != last_data.hook) send = true;
+		else if(input_data.player_state != last_data.player_state) send = true;
+		else if(input_data.wanted_weapon != last_data.wanted_weapon) send = true;
+		else if(input_data.next_weapon != last_data.next_weapon) send = true;
+		else if(input_data.prev_weapon != last_data.prev_weapon) send = true;
+
+		// send at at least 10hz
+		if(time_get() > last_send_time + time_freq()/10)
+			send = true;
+	}
+	
+	// copy and return size	
 	last_data = input_data;
+	
 	if(!send)
 		return 0;
 		
-	// copy and return size	
 	last_send_time = time_get();
 	mem_copy(data, &input_data, sizeof(input_data));
 	return sizeof(input_data);