From 47f73f2b831325909a91910271303dc17118f061 Mon Sep 17 00:00:00 2001 From: "simon.kagstrom" Date: Fri, 30 Jan 2009 15:37:15 +0000 Subject: [PATCH] Minor refactoring, only send joystick data on changes --- Src/C64_SDL.h | 13 ++++++++++--- Src/Network.cpp | 11 ++++++++--- Src/Network.h | 3 +++ Src/NetworkUnix.h | 8 ++------ 4 files changed, 23 insertions(+), 12 deletions(-) diff --git a/Src/C64_SDL.h b/Src/C64_SDL.h index 36d1c60..a0216a5 100644 --- a/Src/C64_SDL.h +++ b/Src/C64_SDL.h @@ -616,6 +616,8 @@ void C64::network_vblank() } } else if (this->network_client) { + Uint8 js = TheCIA1->Joystick2; + if (this->quit_thyself) { this->network_client->Disconnect(); @@ -624,10 +626,15 @@ void C64::network_vblank() return; } - this->network_client->EncodeJoystickUpdate(TheCIA1->Joystick2); - this->network_client->SendUpdate(); + /* Perhaps send joystick data */ + if (this->network_client->cur_joystick_data != js) + { + this->network_client->EncodeJoystickUpdate(js); + this->network_client->SendUpdate(); + this->network_client->cur_joystick_data = js; + } - if (this->network_client->ReceiveUpdateBlock()) + if (this->network_client->ReceiveUpdate()) { /* Got something? */ if (this->network_client->DecodeUpdate(this->network_client->screen) == true) diff --git a/Src/Network.cpp b/Src/Network.cpp index 9fb55fe..6fae160 100644 --- a/Src/Network.cpp +++ b/Src/Network.cpp @@ -633,10 +633,8 @@ void NetworkServer::RemoveClient(NetworkClient *client) /* Not found */ } -NetworkClient::NetworkClient(int sock) : Network() +void NetworkClient::Init() { - this->sock = sock; - this->screen = (Uint8 *)malloc(DISPLAY_X * DISPLAY_Y); assert(this->screen); @@ -644,6 +642,13 @@ NetworkClient::NetworkClient(int sock) : Network() memset(this->screen, 0, DISPLAY_X * DISPLAY_Y); } + +NetworkClient::NetworkClient(int sock) +{ + this->Init(); + this->sock = sock; +} + NetworkClient::~NetworkClient() { free(this->screen); diff --git a/Src/Network.h b/Src/Network.h index 26ce539..7c76add 100644 --- a/Src/Network.h +++ b/Src/Network.h @@ -210,7 +210,10 @@ public: Uint8 *screen; int joystick_port; + Uint8 cur_joystick_data; private: + void Init(); + int sock; }; diff --git a/Src/NetworkUnix.h b/Src/NetworkUnix.h index 7faee28..48b4623 100644 --- a/Src/NetworkUnix.h +++ b/Src/NetworkUnix.h @@ -124,6 +124,8 @@ NetworkClient::NetworkClient(const char *hostname, int port) /* Again from glibc docs */ struct sockaddr_in servername; + this->Init(); + /* Create the socket. */ this->sock = socket (PF_INET, SOCK_STREAM, 0); if (this->sock < 0) @@ -142,12 +144,6 @@ NetworkClient::NetworkClient(const char *hostname, int port) perror ("connect (client)"); 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)