From 5a0941ff7e68f784871b6076750e7616405c6c61 Mon Sep 17 00:00:00 2001 From: "simon.kagstrom" Date: Thu, 29 Jan 2009 21:11:04 +0000 Subject: [PATCH] Send joystick data over the network as well, games are mostly playable now --- Src/C64_SDL.h | 37 +++++++++++++++++++++++++++++++------ Src/Network.cpp | 13 +++++++++++-- Src/Network.h | 8 ++++---- 3 files changed, 46 insertions(+), 12 deletions(-) diff --git a/Src/C64_SDL.h b/Src/C64_SDL.h index 268937e..36d1c60 100644 --- a/Src/C64_SDL.h +++ b/Src/C64_SDL.h @@ -576,9 +576,14 @@ void C64::network_vblank() Uint8 *master = this->TheDisplay->BitmapBase(); NetworkClient *remote = this->network_server->clients[i]; + /* Has the client sent any data? */ if (remote->ReceiveUpdate() == true) { - if (remote->DecodeUpdate(NULL, true) == false) + uint8 *js = &TheCIA1->Joystick2; + + if (ThePrefs.JoystickSwap) + js = &TheCIA1->Joystick1; + if (remote->DecodeUpdate(NULL, js, true) == false) { /* Disconnect or sending crap, remove this guy! */ this->network_server->RemoveClient(remote); @@ -616,8 +621,13 @@ void C64::network_vblank() this->network_client->Disconnect(); delete this->network_client; this->network_client = NULL; + return; } - else if (this->network_client->ReceiveUpdateBlock()) + + this->network_client->EncodeJoystickUpdate(TheCIA1->Joystick2); + this->network_client->SendUpdate(); + + if (this->network_client->ReceiveUpdateBlock()) { /* Got something? */ if (this->network_client->DecodeUpdate(this->network_client->screen) == true) @@ -645,14 +655,15 @@ void C64::VBlank(bool draw_frame) /* From Acorn port */ static uint64_t lastFrame; static uint32_t now; + uint8 j1, j2; #if defined(GEKKO) WPAD_ScanPads(); #endif // Poll joysticks - TheCIA1->Joystick1 = poll_joystick(0); - TheCIA1->Joystick2 = poll_joystick(1); + j1 = poll_joystick(0); + j2 = poll_joystick(1); // Poll keyboard TheDisplay->PollKeyboard(TheCIA1->KeyMatrix, TheCIA1->RevMatrix, &joykey); @@ -664,11 +675,25 @@ void C64::VBlank(bool draw_frame) #ifndef GEKKO // Joystick keyboard emulation if (TheDisplay->NumLock()) - TheCIA1->Joystick1 &= joykey; + j1 &= joykey; else - TheCIA1->Joystick2 &= joykey; + j2 &= joykey; #endif + if (this->network_server) + { + /* Only poll one joystick for network servers */ + if (ThePrefs.JoystickSwap) + TheCIA1->Joystick2 = j2; + else + TheCIA1->Joystick1 = j2; + } + else + { + TheCIA1->Joystick1 = j1; + TheCIA1->Joystick2 = j2; + } + // Count TOD clocks TheCIA1->CountTOD(); TheCIA2->CountTOD(); diff --git a/Src/Network.cpp b/Src/Network.cpp index 749eaf2..9fb55fe 100644 --- a/Src/Network.cpp +++ b/Src/Network.cpp @@ -350,10 +350,15 @@ size_t Network::EncodeSoundBuffer(struct NetworkUpdate *dst, Uint8 *buf, size_t return dst->size; } -void Network::EncodeJoystickUpdate(struct NetworkUpdate *dst, Uint8 which, Uint8 v) +void Network::EncodeJoystickUpdate(Uint8 v) { + struct NetworkUpdate *dst = this->cur_ud; + dst->type = JOYSTICK_UPDATE; dst->u.joystick.val = v; + dst->size = sizeof(NetworkUpdate); + + this->AddNetworkUpdate(dst); } @@ -568,7 +573,7 @@ bool Network::DeMarshalData(NetworkUpdate *p) return true; } -bool Network::DecodeUpdate(uint8 *screen, bool server) +bool Network::DecodeUpdate(uint8 *screen, uint8 *js, bool server) { NetworkUpdate *p = this->ud; bool out = true; @@ -585,6 +590,10 @@ bool Network::DecodeUpdate(uint8 *screen, bool server) if (this->DecodeDisplayUpdate(screen, p) == false) out = false; break; + case JOYSTICK_UPDATE: + if (js) + *js = p->u.joystick.val; + break; case DISCONNECT: out = false; break; diff --git a/Src/Network.h b/Src/Network.h index ce24d0a..26ce539 100644 --- a/Src/Network.h +++ b/Src/Network.h @@ -53,7 +53,10 @@ public: size_t EncodeDisplay(Uint8 *master, Uint8 *remote); - bool DecodeUpdate(uint8 *screen, bool server = false); + void EncodeJoystickUpdate(Uint8 v); + + + bool DecodeUpdate(uint8 *screen, uint8 *js = NULL, bool server = false); void ResetNetworkUpdate(void); @@ -107,9 +110,6 @@ protected: size_t EncodeSoundBuffer(struct NetworkUpdate *dst, Uint8 *buf, size_t len); - void EncodeJoystickUpdate(struct NetworkUpdate *dst, - Uint8 which, Uint8 v); - /** * Decode a display update message onto @a screen *