Exemple #1
0
void LocalClient::KeystateTaskThread::task() {
	
	#define KEYSTATE_GRANULARITY_MS 46.66	// aiming for as low a rate as possible
	static TIMER keystate_timer;
	keystate_timer.begin();
	while (LocalClient::KeystateTaskThread::is_running() && LocalClient::is_connected()) {
		if (keystate_timer.get_ms() > KEYSTATE_GRANULARITY_MS) {
			update_keystate(keys);
			post_keystate();
			keystate_timer.begin();
			long wait_ms = KEYSTATE_GRANULARITY_MS - keystate_timer.get_ms();
			if (wait_ms > 1) { SLEEP_MS(wait_ms); }
		}
	}
}
Exemple #2
0
void LocalClient::ListenTaskThread::task() {
	
	struct sockaddr_in from;

	static TIMER ping_timer;	// seems like a waste to actually create another thread for this
	ping_timer.begin();

#define PING_GRANULARITY_MS 2000
	
	while (LocalClient::ListenTaskThread::is_running() && LocalClient::is_connected()) {
		int bytes = socket.receive_data(buffer, &from);
		if (bytes > 0) { handle_current_packet(); }
	}

	post_quit_message();

}