Send joystick data over the network as well, games are mostly playable now

This commit is contained in:
simon.kagstrom 2009-01-29 21:11:04 +00:00
parent 3c3d364190
commit 5a0941ff7e
3 changed files with 46 additions and 12 deletions

View File

@ -576,9 +576,14 @@ void C64::network_vblank()
Uint8 *master = this->TheDisplay->BitmapBase(); Uint8 *master = this->TheDisplay->BitmapBase();
NetworkClient *remote = this->network_server->clients[i]; NetworkClient *remote = this->network_server->clients[i];
/* Has the client sent any data? */
if (remote->ReceiveUpdate() == true) 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! */ /* Disconnect or sending crap, remove this guy! */
this->network_server->RemoveClient(remote); this->network_server->RemoveClient(remote);
@ -616,8 +621,13 @@ void C64::network_vblank()
this->network_client->Disconnect(); this->network_client->Disconnect();
delete this->network_client; delete this->network_client;
this->network_client = NULL; 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? */ /* Got something? */
if (this->network_client->DecodeUpdate(this->network_client->screen) == true) if (this->network_client->DecodeUpdate(this->network_client->screen) == true)
@ -645,14 +655,15 @@ void C64::VBlank(bool draw_frame)
/* From Acorn port */ /* From Acorn port */
static uint64_t lastFrame; static uint64_t lastFrame;
static uint32_t now; static uint32_t now;
uint8 j1, j2;
#if defined(GEKKO) #if defined(GEKKO)
WPAD_ScanPads(); WPAD_ScanPads();
#endif #endif
// Poll joysticks // Poll joysticks
TheCIA1->Joystick1 = poll_joystick(0); j1 = poll_joystick(0);
TheCIA1->Joystick2 = poll_joystick(1); j2 = poll_joystick(1);
// Poll keyboard // Poll keyboard
TheDisplay->PollKeyboard(TheCIA1->KeyMatrix, TheCIA1->RevMatrix, &joykey); TheDisplay->PollKeyboard(TheCIA1->KeyMatrix, TheCIA1->RevMatrix, &joykey);
@ -664,11 +675,25 @@ void C64::VBlank(bool draw_frame)
#ifndef GEKKO #ifndef GEKKO
// Joystick keyboard emulation // Joystick keyboard emulation
if (TheDisplay->NumLock()) if (TheDisplay->NumLock())
TheCIA1->Joystick1 &= joykey; j1 &= joykey;
else else
TheCIA1->Joystick2 &= joykey; j2 &= joykey;
#endif #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 // Count TOD clocks
TheCIA1->CountTOD(); TheCIA1->CountTOD();
TheCIA2->CountTOD(); TheCIA2->CountTOD();

View File

@ -350,10 +350,15 @@ size_t Network::EncodeSoundBuffer(struct NetworkUpdate *dst, Uint8 *buf, size_t
return dst->size; 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->type = JOYSTICK_UPDATE;
dst->u.joystick.val = v; dst->u.joystick.val = v;
dst->size = sizeof(NetworkUpdate);
this->AddNetworkUpdate(dst);
} }
@ -568,7 +573,7 @@ bool Network::DeMarshalData(NetworkUpdate *p)
return true; return true;
} }
bool Network::DecodeUpdate(uint8 *screen, bool server) bool Network::DecodeUpdate(uint8 *screen, uint8 *js, bool server)
{ {
NetworkUpdate *p = this->ud; NetworkUpdate *p = this->ud;
bool out = true; bool out = true;
@ -585,6 +590,10 @@ bool Network::DecodeUpdate(uint8 *screen, bool server)
if (this->DecodeDisplayUpdate(screen, p) == false) if (this->DecodeDisplayUpdate(screen, p) == false)
out = false; out = false;
break; break;
case JOYSTICK_UPDATE:
if (js)
*js = p->u.joystick.val;
break;
case DISCONNECT: case DISCONNECT:
out = false; out = false;
break; break;

View File

@ -53,7 +53,10 @@ public:
size_t EncodeDisplay(Uint8 *master, Uint8 *remote); 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); void ResetNetworkUpdate(void);
@ -107,9 +110,6 @@ protected:
size_t EncodeSoundBuffer(struct NetworkUpdate *dst, size_t EncodeSoundBuffer(struct NetworkUpdate *dst,
Uint8 *buf, size_t len); Uint8 *buf, size_t len);
void EncodeJoystickUpdate(struct NetworkUpdate *dst,
Uint8 which, Uint8 v);
/** /**
* Decode a display update message onto @a screen * Decode a display update message onto @a screen
* *