mirror of
https://github.com/Oibaf66/frodo-wii.git
synced 2025-02-16 20:39:15 +01:00
Add screenshot to network connect messages (not tested)
This commit is contained in:
parent
3983fbb7d2
commit
332264abcb
@ -25,6 +25,9 @@
|
|||||||
#include "main.h"
|
#include "main.h"
|
||||||
#include "C64.h"
|
#include "C64.h"
|
||||||
|
|
||||||
|
#include "utils.hh"
|
||||||
|
#include "data_store.hh"
|
||||||
|
|
||||||
#if defined(GEKKO)
|
#if defined(GEKKO)
|
||||||
# include <wiiuse/wpad.h>
|
# include <wiiuse/wpad.h>
|
||||||
#endif
|
#endif
|
||||||
@ -611,7 +614,7 @@ bool Network::SendUpdate()
|
|||||||
|
|
||||||
v = this->SendTo((void*)p, this->sock,
|
v = this->SendTo((void*)p, this->sock,
|
||||||
size_to_send, &this->connection_addr);
|
size_to_send, &this->connection_addr);
|
||||||
if (v < 0 || v != size_to_send)
|
if (v < 0 || (size_t)v != size_to_send)
|
||||||
return false;
|
return false;
|
||||||
cur_sz += size_to_send;
|
cur_sz += size_to_send;
|
||||||
p += size_to_send;
|
p += size_to_send;
|
||||||
@ -715,7 +718,7 @@ bool Network::MarshalData(NetworkUpdate *p)
|
|||||||
snd->flags = htons(snd->flags);
|
snd->flags = htons(snd->flags);
|
||||||
snd->n_items = htons(snd->n_items);
|
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];
|
NetworkUpdateSoundInfo *cur = &info[i];
|
||||||
|
|
||||||
@ -945,10 +948,50 @@ bool Network::DecodeUpdate(C64Display *display, uint8 *js, MOS6581 *dst)
|
|||||||
return out;
|
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()
|
bool Network::ConnectToBroker()
|
||||||
{
|
{
|
||||||
NetworkUpdate *ud = InitNetworkUpdate(this->ud, CONNECT_TO_BROKER,
|
NetworkUpdate *ud = InitNetworkUpdate(this->ud, CONNECT_TO_BROKER,
|
||||||
sizeof(NetworkUpdate) + sizeof(NetworkUpdatePeerInfo));
|
sizeof(NetworkUpdate) + sizeof(NetworkUpdatePeerInfo));
|
||||||
NetworkUpdatePeerInfo *pi = (NetworkUpdatePeerInfo *)ud->data;
|
NetworkUpdatePeerInfo *pi = (NetworkUpdatePeerInfo *)ud->data;
|
||||||
bool out;
|
bool out;
|
||||||
|
|
||||||
@ -956,11 +999,13 @@ bool Network::ConnectToBroker()
|
|||||||
pi->key = ThePrefs.NetworkKey;
|
pi->key = ThePrefs.NetworkKey;
|
||||||
pi->version = FRODO_NETWORK_PROTOCOL_VERSION;
|
pi->version = FRODO_NETWORK_PROTOCOL_VERSION;
|
||||||
pi->avatar = ThePrefs.NetworkAvatar;
|
pi->avatar = ThePrefs.NetworkAvatar;
|
||||||
this->EncodeScreenshot(pi->screenshot, TheC64->TheDisplay->BitmapBase());
|
pi->screenshot_key = 0;
|
||||||
|
|
||||||
strcpy((char*)pi->name, ThePrefs.NetworkName);
|
strcpy((char*)pi->name, ThePrefs.NetworkName);
|
||||||
this->AddNetworkUpdate(ud);
|
this->AddNetworkUpdate(ud);
|
||||||
out = this->SendUpdate();
|
out = this->AppendScreenshot(pi);
|
||||||
|
if (out)
|
||||||
|
out = this->SendUpdate();
|
||||||
this->ResetNetworkUpdate();
|
this->ResetNetworkUpdate();
|
||||||
|
|
||||||
return out;
|
return out;
|
||||||
@ -1059,7 +1104,6 @@ network_connection_error_t Network::WaitForPeerList()
|
|||||||
{
|
{
|
||||||
NetworkUpdateListPeers *pi;
|
NetworkUpdateListPeers *pi;
|
||||||
struct timeval tv;
|
struct timeval tv;
|
||||||
const char **msgs;
|
|
||||||
|
|
||||||
tv.tv_sec = 1;
|
tv.tv_sec = 1;
|
||||||
tv.tv_usec = 0;
|
tv.tv_usec = 0;
|
||||||
|
@ -106,6 +106,14 @@ struct NetworkUpdatePingAck
|
|||||||
uint8 data[]; /* Only used for bandwidth ping/acks */
|
uint8 data[]; /* Only used for bandwidth ping/acks */
|
||||||
};
|
};
|
||||||
|
|
||||||
|
struct NetworkUpdateDataStore
|
||||||
|
{
|
||||||
|
uint32_t key;
|
||||||
|
uint32_t metadata; /* Type etc */
|
||||||
|
uint8_t data[];
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
struct NetworkUpdateSoundInfo
|
struct NetworkUpdateSoundInfo
|
||||||
{
|
{
|
||||||
uint16 delay_cycles;
|
uint16 delay_cycles;
|
||||||
@ -144,8 +152,7 @@ struct NetworkUpdatePeerInfo
|
|||||||
uint32 version; /* Version number */
|
uint32 version; /* Version number */
|
||||||
|
|
||||||
uint32 avatar; /* Hash of the avatar */
|
uint32 avatar; /* Hash of the avatar */
|
||||||
/* RAW-encoded screenshot of how the display looks like */
|
uint32 screenshot_key; /* Key number of the screenshot */
|
||||||
uint8 screenshot[(SCREENSHOT_X * SCREENSHOT_Y) / 2];
|
|
||||||
};
|
};
|
||||||
|
|
||||||
struct NetworkUpdateListPeers
|
struct NetworkUpdateListPeers
|
||||||
@ -323,6 +330,8 @@ protected:
|
|||||||
|
|
||||||
bool ConnectToBroker();
|
bool ConnectToBroker();
|
||||||
|
|
||||||
|
bool AppendScreenshot(NetworkUpdatePeerInfo *pi);
|
||||||
|
|
||||||
bool ConnectToPeer();
|
bool ConnectToPeer();
|
||||||
|
|
||||||
bool WaitForPeerReply();
|
bool WaitForPeerReply();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user