mirror of
https://github.com/Oibaf66/frodo-wii.git
synced 2025-02-21 22:57:10 +01:00
Implemented traffic throttling (skipping frames if needed). There is
probably some work to do to get a steady transfer state working well.
This commit is contained in:
parent
47f73f2b83
commit
f317afd4e8
@ -556,19 +556,14 @@ void C64::Run(void)
|
|||||||
|
|
||||||
void C64::network_vblank()
|
void C64::network_vblank()
|
||||||
{
|
{
|
||||||
|
static uint32_t last_time_update;
|
||||||
#if defined(GEKKO)
|
#if defined(GEKKO)
|
||||||
Uint32 now = ticks_to_millisecs(gettime());
|
Uint32 now = ticks_to_millisecs(gettime());
|
||||||
#else
|
#else
|
||||||
Uint32 now = SDL_GetTicks();
|
Uint32 now = SDL_GetTicks();
|
||||||
#endif
|
#endif
|
||||||
static int frms = 1;
|
|
||||||
frms--;
|
|
||||||
|
|
||||||
if (this->network_server && frms == 0) {
|
if (this->network_server) {
|
||||||
static uint32_t last_time_update;
|
|
||||||
static size_t bytes_sent;
|
|
||||||
|
|
||||||
frms = 6;
|
|
||||||
/* Perhaps accept a new connection */
|
/* Perhaps accept a new connection */
|
||||||
this->network_server->CheckNewConnection();
|
this->network_server->CheckNewConnection();
|
||||||
|
|
||||||
@ -576,6 +571,7 @@ 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];
|
||||||
|
|
||||||
|
remote->Tick( now - last_time_update );
|
||||||
/* Has the client sent any data? */
|
/* Has the client sent any data? */
|
||||||
if (remote->ReceiveUpdate() == true)
|
if (remote->ReceiveUpdate() == true)
|
||||||
{
|
{
|
||||||
@ -589,7 +585,11 @@ void C64::network_vblank()
|
|||||||
this->network_server->RemoveClient(remote);
|
this->network_server->RemoveClient(remote);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
remote->ResetNetworkUpdate();
|
||||||
|
}
|
||||||
|
if (remote->ThrottleTraffic()) {
|
||||||
|
/* Skip this frame if the data rate is too high */
|
||||||
|
continue;
|
||||||
}
|
}
|
||||||
remote->EncodeDisplay(master, remote->screen);
|
remote->EncodeDisplay(master, remote->screen);
|
||||||
if (remote->SendUpdate() == false)
|
if (remote->SendUpdate() == false)
|
||||||
@ -598,22 +598,19 @@ void C64::network_vblank()
|
|||||||
printf("Could not send update\n");
|
printf("Could not send update\n");
|
||||||
this->network_server->RemoveClient(remote);
|
this->network_server->RemoveClient(remote);
|
||||||
}
|
}
|
||||||
else
|
remote->ResetNetworkUpdate();
|
||||||
{
|
|
||||||
remote->ResetNetworkUpdate();
|
|
||||||
|
|
||||||
bytes_sent += remote->GetBytesSent();
|
if (1)
|
||||||
|
{
|
||||||
|
static uint32_t last_traffic_update;
|
||||||
|
|
||||||
|
if (last_time_update - last_traffic_update > 300)
|
||||||
|
{
|
||||||
|
TheDisplay->NetworkTrafficMeter(remote->GetKbps() / (8 * 1024.0));
|
||||||
|
last_traffic_update = now;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (now - last_time_update > 300)
|
|
||||||
{
|
|
||||||
TheDisplay->NetworkTrafficMeter(((bytes_sent * 1000.0) /
|
|
||||||
((float)now - last_time_update)) / 1024.0);
|
|
||||||
for (int i = 0; i < this->network_server->n_clients; i++)
|
|
||||||
this->network_server->clients[i]->ResetBytesSent();
|
|
||||||
bytes_sent = 0;
|
|
||||||
last_time_update = now;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else if (this->network_client) {
|
else if (this->network_client) {
|
||||||
Uint8 js = TheCIA1->Joystick2;
|
Uint8 js = TheCIA1->Joystick2;
|
||||||
@ -632,6 +629,7 @@ void C64::network_vblank()
|
|||||||
this->network_client->EncodeJoystickUpdate(js);
|
this->network_client->EncodeJoystickUpdate(js);
|
||||||
this->network_client->SendUpdate();
|
this->network_client->SendUpdate();
|
||||||
this->network_client->cur_joystick_data = js;
|
this->network_client->cur_joystick_data = js;
|
||||||
|
this->network_client->ResetNetworkUpdate();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this->network_client->ReceiveUpdate())
|
if (this->network_client->ReceiveUpdate())
|
||||||
@ -651,6 +649,7 @@ void C64::network_vblank()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
last_time_update = now;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -660,8 +659,8 @@ void C64::network_vblank()
|
|||||||
void C64::VBlank(bool draw_frame)
|
void C64::VBlank(bool draw_frame)
|
||||||
{
|
{
|
||||||
/* From Acorn port */
|
/* From Acorn port */
|
||||||
static uint64_t lastFrame;
|
static uint32_t lastFrame;
|
||||||
static uint32_t now;
|
uint32_t now;
|
||||||
uint8 j1, j2;
|
uint8 j1, j2;
|
||||||
|
|
||||||
#if defined(GEKKO)
|
#if defined(GEKKO)
|
||||||
|
@ -46,7 +46,10 @@ Network::Network()
|
|||||||
assert(this->ud && this->tmp_ud);
|
assert(this->ud && this->tmp_ud);
|
||||||
|
|
||||||
this->ResetNetworkUpdate();
|
this->ResetNetworkUpdate();
|
||||||
this->bytes_sent = 0;
|
this->traffic = 0;
|
||||||
|
this->last_traffic = 0;
|
||||||
|
this->target_kbps = 120000; /* kilobit per seconds */
|
||||||
|
this->kbps = 0;
|
||||||
|
|
||||||
this->raw_buf = (Uint8*)malloc(RAW_SIZE);
|
this->raw_buf = (Uint8*)malloc(RAW_SIZE);
|
||||||
this->rle_buf = (Uint8*)malloc(RLE_SIZE);
|
this->rle_buf = (Uint8*)malloc(RLE_SIZE);
|
||||||
@ -68,6 +71,15 @@ Network::~Network()
|
|||||||
free(this->diff_buf);
|
free(this->diff_buf);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Network::Tick(int ms)
|
||||||
|
{
|
||||||
|
int last_kbps = ((this->traffic - this->last_traffic) * 8) * (1000 / ms);
|
||||||
|
|
||||||
|
/* 1/3 of the new value, 2/3 of the old */
|
||||||
|
this->kbps = 2 * (this->kbps / 3) + (last_kbps / 3);
|
||||||
|
this->last_traffic = this->traffic;
|
||||||
|
}
|
||||||
|
|
||||||
size_t Network::EncodeSoundRLE(struct NetworkUpdate *dst,
|
size_t Network::EncodeSoundRLE(struct NetworkUpdate *dst,
|
||||||
Uint8 *buffer, size_t buf_len)
|
Uint8 *buffer, size_t buf_len)
|
||||||
{
|
{
|
||||||
@ -493,7 +505,7 @@ bool Network::SendUpdate(int sock)
|
|||||||
return false;
|
return false;
|
||||||
if (this->SendData((void*)src, sock, sz) == false)
|
if (this->SendData((void*)src, sock, sz) == false)
|
||||||
return false;
|
return false;
|
||||||
this->bytes_sent += sz;
|
this->traffic += sz;
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -62,14 +62,20 @@ public:
|
|||||||
|
|
||||||
void DrawTransferredBlocks(SDL_Surface *screen);
|
void DrawTransferredBlocks(SDL_Surface *screen);
|
||||||
|
|
||||||
size_t GetBytesSent() {
|
size_t GetKbps() {
|
||||||
return this->bytes_sent;
|
return this->kbps;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool ThrottleTraffic() {
|
||||||
|
return this->kbps > this->target_kbps;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ResetBytesSent() {
|
void ResetBytesSent() {
|
||||||
this->bytes_sent = 0;
|
this->traffic = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Tick(int ms);
|
||||||
|
|
||||||
void CloseSocket(int sock);
|
void CloseSocket(int sock);
|
||||||
|
|
||||||
bool SendUpdate(int sock);
|
bool SendUpdate(int sock);
|
||||||
@ -167,8 +173,12 @@ protected:
|
|||||||
Uint8 *raw_buf;
|
Uint8 *raw_buf;
|
||||||
Uint8 *rle_buf;
|
Uint8 *rle_buf;
|
||||||
Uint8 *diff_buf;
|
Uint8 *diff_buf;
|
||||||
size_t bytes_sent;
|
|
||||||
Uint32 *square_updated;
|
Uint32 *square_updated;
|
||||||
|
|
||||||
|
size_t traffic, last_traffic;
|
||||||
|
int time_since_last_reset;
|
||||||
|
int target_kbps;
|
||||||
|
int kbps;
|
||||||
};
|
};
|
||||||
|
|
||||||
class NetworkClient : public Network
|
class NetworkClient : public Network
|
||||||
|
@ -158,6 +158,7 @@ bool Network::ReceiveData(void *dst, int sock, size_t sz)
|
|||||||
return false;
|
return false;
|
||||||
received_sz += v;
|
received_sz += v;
|
||||||
}
|
}
|
||||||
|
this->traffic += received_sz;
|
||||||
|
|
||||||
return sz > 0;
|
return sz > 0;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user