Minor refactoring, only send joystick data on changes

This commit is contained in:
simon.kagstrom 2009-01-30 15:37:15 +00:00
parent 5a0941ff7e
commit 47f73f2b83
4 changed files with 23 additions and 12 deletions

View File

@ -616,6 +616,8 @@ void C64::network_vblank()
} }
} }
else if (this->network_client) { else if (this->network_client) {
Uint8 js = TheCIA1->Joystick2;
if (this->quit_thyself) if (this->quit_thyself)
{ {
this->network_client->Disconnect(); this->network_client->Disconnect();
@ -624,10 +626,15 @@ void C64::network_vblank()
return; return;
} }
this->network_client->EncodeJoystickUpdate(TheCIA1->Joystick2); /* Perhaps send joystick data */
if (this->network_client->cur_joystick_data != js)
{
this->network_client->EncodeJoystickUpdate(js);
this->network_client->SendUpdate(); this->network_client->SendUpdate();
this->network_client->cur_joystick_data = js;
}
if (this->network_client->ReceiveUpdateBlock()) if (this->network_client->ReceiveUpdate())
{ {
/* Got something? */ /* Got something? */
if (this->network_client->DecodeUpdate(this->network_client->screen) == true) if (this->network_client->DecodeUpdate(this->network_client->screen) == true)

View File

@ -633,10 +633,8 @@ void NetworkServer::RemoveClient(NetworkClient *client)
/* Not found */ /* Not found */
} }
NetworkClient::NetworkClient(int sock) : Network() void NetworkClient::Init()
{ {
this->sock = sock;
this->screen = (Uint8 *)malloc(DISPLAY_X * DISPLAY_Y); this->screen = (Uint8 *)malloc(DISPLAY_X * DISPLAY_Y);
assert(this->screen); assert(this->screen);
@ -644,6 +642,13 @@ NetworkClient::NetworkClient(int sock) : Network()
memset(this->screen, 0, DISPLAY_X * DISPLAY_Y); memset(this->screen, 0, DISPLAY_X * DISPLAY_Y);
} }
NetworkClient::NetworkClient(int sock)
{
this->Init();
this->sock = sock;
}
NetworkClient::~NetworkClient() NetworkClient::~NetworkClient()
{ {
free(this->screen); free(this->screen);

View File

@ -210,7 +210,10 @@ public:
Uint8 *screen; Uint8 *screen;
int joystick_port; int joystick_port;
Uint8 cur_joystick_data;
private: private:
void Init();
int sock; int sock;
}; };

View File

@ -124,6 +124,8 @@ NetworkClient::NetworkClient(const char *hostname, int port)
/* Again from glibc docs */ /* Again from glibc docs */
struct sockaddr_in servername; struct sockaddr_in servername;
this->Init();
/* Create the socket. */ /* Create the socket. */
this->sock = socket (PF_INET, SOCK_STREAM, 0); this->sock = socket (PF_INET, SOCK_STREAM, 0);
if (this->sock < 0) if (this->sock < 0)
@ -142,12 +144,6 @@ NetworkClient::NetworkClient(const char *hostname, int port)
perror ("connect (client)"); perror ("connect (client)");
return; return;
} }
this->screen = (Uint8 *)malloc(DISPLAY_X * DISPLAY_Y);
assert(this->screen);
/* Assume black screen */
memset(this->screen, 0, DISPLAY_X * DISPLAY_Y);
} }
bool Network::ReceiveData(void *dst, int sock, size_t sz) bool Network::ReceiveData(void *dst, int sock, size_t sz)