From 332264abcb70f263bc528704d7c04db941468ab8 Mon Sep 17 00:00:00 2001 From: "simon.kagstrom" Date: Sat, 6 Feb 2010 14:00:12 +0000 Subject: [PATCH] Add screenshot to network connect messages (not tested) --- Src/Network.cpp | 56 +++++++++++++++++++++++++++++++++++++++++++------ Src/Network.h | 13 ++++++++++-- 2 files changed, 61 insertions(+), 8 deletions(-) diff --git a/Src/Network.cpp b/Src/Network.cpp index 827a400..0b9dc57 100644 --- a/Src/Network.cpp +++ b/Src/Network.cpp @@ -25,6 +25,9 @@ #include "main.h" #include "C64.h" +#include "utils.hh" +#include "data_store.hh" + #if defined(GEKKO) # include #endif @@ -611,7 +614,7 @@ bool Network::SendUpdate() v = this->SendTo((void*)p, this->sock, size_to_send, &this->connection_addr); - if (v < 0 || v != size_to_send) + if (v < 0 || (size_t)v != size_to_send) return false; cur_sz += size_to_send; p += size_to_send; @@ -715,7 +718,7 @@ bool Network::MarshalData(NetworkUpdate *p) snd->flags = htons(snd->flags); snd->n_items = htons(snd->n_items); - for (unsigned int i = 0; i < items; i++) + for (int i = 0; i < items; i++) { NetworkUpdateSoundInfo *cur = &info[i]; @@ -945,10 +948,50 @@ bool Network::DecodeUpdate(C64Display *display, uint8 *js, MOS6581 *dst) return out; } +bool Network::AppendScreenshot(NetworkUpdatePeerInfo *pi) +{ + NetworkUpdateDataStore *dsu; + NetworkUpdate *ud; + SDL_Surface *scr; + struct ds_data *data; + void *png; + size_t sz; + bool out = NULL; + + scr = TheC64->TheDisplay->SurfaceFromC64Display(); + if (!scr) + goto out_none; + + png = sdl_surface_to_png(scr, &sz); + if (!png) + goto out_scr; + + data = DataStore::ds->embedData(png, sz); + if (!data) + goto out_png; + ud = InitNetworkUpdate(this->ud, 0, sizeof(NetworkUpdate) + + sizeof(NetworkUpdateDataStore) + sz); + dsu = (NetworkUpdateDataStore *)ud->data; + dsu->key = data->key; + dsu->metadata = data->metadata; + memcpy(dsu->data, data->data, sz); + this->AddNetworkUpdate(ud); + + out = true; + free(data); +out_png: + free(png); +out_scr: + SDL_FreeSurface(scr); +out_none: + + return out; +} + bool Network::ConnectToBroker() { NetworkUpdate *ud = InitNetworkUpdate(this->ud, CONNECT_TO_BROKER, - sizeof(NetworkUpdate) + sizeof(NetworkUpdatePeerInfo)); + sizeof(NetworkUpdate) + sizeof(NetworkUpdatePeerInfo)); NetworkUpdatePeerInfo *pi = (NetworkUpdatePeerInfo *)ud->data; bool out; @@ -956,11 +999,13 @@ bool Network::ConnectToBroker() pi->key = ThePrefs.NetworkKey; pi->version = FRODO_NETWORK_PROTOCOL_VERSION; pi->avatar = ThePrefs.NetworkAvatar; - this->EncodeScreenshot(pi->screenshot, TheC64->TheDisplay->BitmapBase()); + pi->screenshot_key = 0; strcpy((char*)pi->name, ThePrefs.NetworkName); this->AddNetworkUpdate(ud); - out = this->SendUpdate(); + out = this->AppendScreenshot(pi); + if (out) + out = this->SendUpdate(); this->ResetNetworkUpdate(); return out; @@ -1059,7 +1104,6 @@ network_connection_error_t Network::WaitForPeerList() { NetworkUpdateListPeers *pi; struct timeval tv; - const char **msgs; tv.tv_sec = 1; tv.tv_usec = 0; diff --git a/Src/Network.h b/Src/Network.h index 000ead0..351ef7a 100644 --- a/Src/Network.h +++ b/Src/Network.h @@ -106,6 +106,14 @@ struct NetworkUpdatePingAck uint8 data[]; /* Only used for bandwidth ping/acks */ }; +struct NetworkUpdateDataStore +{ + uint32_t key; + uint32_t metadata; /* Type etc */ + uint8_t data[]; +}; + + struct NetworkUpdateSoundInfo { uint16 delay_cycles; @@ -144,8 +152,7 @@ struct NetworkUpdatePeerInfo uint32 version; /* Version number */ uint32 avatar; /* Hash of the avatar */ - /* RAW-encoded screenshot of how the display looks like */ - uint8 screenshot[(SCREENSHOT_X * SCREENSHOT_Y) / 2]; + uint32 screenshot_key; /* Key number of the screenshot */ }; struct NetworkUpdateListPeers @@ -323,6 +330,8 @@ protected: bool ConnectToBroker(); + bool AppendScreenshot(NetworkUpdatePeerInfo *pi); + bool ConnectToPeer(); bool WaitForPeerReply();