Skip to content

Commit

Permalink
Added client pause flag to status message for net play.
Browse files Browse the repository at this point in the history
  • Loading branch information
thor2016 committed Feb 25, 2024
1 parent 6832eaa commit 015f6a0
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 23 deletions.
19 changes: 14 additions & 5 deletions src/drivers/Qt/NetPlay.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
#include "../../movie.h"
#include "../../debug.h"
#include "utils/crc32.h"
#include "utils/StringUtils.h"
#include "Qt/main.h"
#include "Qt/dface.h"
#include "Qt/input.h"
Expand Down Expand Up @@ -287,7 +288,7 @@ int NetPlayServer::sendRomLoadReq( NetPlayClient *client )

msg.hdr.msgSize += fileSize;
msg.fileSize = fileSize;
strncpy( msg.fileName, GameInfo->filename, sizeof(msg.fileName) );
Strlcpy( msg.fileName, GameInfo->filename, sizeof(msg.fileName) );

printf("Sending ROM Load Request: %s %lu\n", filepath, fileSize );
FCEUI_SetEmulationPaused(EMULATIONPAUSED_PAUSED);
Expand Down Expand Up @@ -440,6 +441,8 @@ void NetPlayServer::serverProcessMessage( NetPlayClient *client, void *msgBuf, s
client->gpData[2] = msg->ctrlState[2];
client->gpData[3] = msg->ctrlState[3];

client->setPaused( (msg->flags & netPlayClientState::PAUSE_FLAG) ? true : false );

NetPlayFrameData data;
if ( (msg->opsFrame == 0) || netPlayFrameData.find( msg->opsFrame, data ) )
{
Expand Down Expand Up @@ -498,6 +501,7 @@ void NetPlayServer::update(void)
uint32_t lagFrame = 0;
uint8_t localGP[4] = { 0 };
uint8_t gpData[4] = { 0 };
int numClientsPaused = 0;

if (currFrame > maxLead)
{
Expand Down Expand Up @@ -537,6 +541,11 @@ void NetPlayServer::update(void)
{
gpData[client->role] = client->gpData[client->role];
}

if (client->isPaused())
{
numClientsPaused++;
}
}


Expand All @@ -561,7 +570,7 @@ void NetPlayServer::update(void)
shouldRunFrame = (clientMinFrame != 0xFFFFFFFF) &&
(clientMinFrame >= lagFrame ) &&
(clientMaxFrame < leadFrame) &&
(currFrame > lastFrame);
(currFrame > lastFrame) && (numClientsPaused == 0);

//printf("Client Frame: Min:%u Max:%u\n", clientMinFrame, clientMaxFrame);

Expand Down Expand Up @@ -798,7 +807,7 @@ void NetPlayClient::update(void)
statusMsg.flags = 0;
if (FCEUI_EmulationPaused())
{
statusMsg.flags |= 0x0001;
statusMsg.flags |= netPlayClientState::PAUSE_FLAG;
}
statusMsg.frameRdy = inputFrameBack();
statusMsg.frameRun = currFrame;
Expand Down Expand Up @@ -915,8 +924,8 @@ void NetPlayClient::clientProcessMessage( void *msgBuf, size_t msgSize )
{
netPlayAuthResp msg;
msg.playerId = role;
strncpy( msg.userName, userName.toLocal8Bit().constData(), sizeof(msg.userName));
strncpy( msg.pswd, password.toLocal8Bit().constData(), sizeof(msg.pswd) );
Strlcpy( msg.userName, userName.toLocal8Bit().constData(), sizeof(msg.userName));
Strlcpy( msg.pswd, password.toLocal8Bit().constData(), sizeof(msg.pswd) );

printf("Authentication Request Received\n");
msg.toNetworkByteOrder();
Expand Down
3 changes: 3 additions & 0 deletions src/drivers/Qt/NetPlay.h
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,8 @@ class NetPlayClient : public QObject
bool isAuthenticated();
bool isPlayerRole();
bool shouldDestroy(){ return needsDestroy; }
bool isPaused(){ return paused; }
void setPaused(bool value){ paused = value; }

QString userName;
QString password;
Expand All @@ -230,6 +232,7 @@ class NetPlayClient : public QObject
bool disconnectPending = false;
bool needsDestroy = false;
bool _connected = false;
bool paused = false;

std::list <NetPlayFrameInput> input;
FCEU::mutex inputMtx;
Expand Down
2 changes: 2 additions & 0 deletions src/drivers/Qt/NetPlayMsgDef.h
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,8 @@ struct netPlayClientState
uint32_t ramChkSum;
uint8_t ctrlState[4];

static constexpr uint32_t PAUSE_FLAG = 0x0001;

netPlayClientState(void)
: hdr(NETPLAY_CLIENT_STATE, sizeof(netPlayClientState)), flags(0),
frameRdy(0), frameRun(0), opsChkSum(0), ramChkSum(0)
Expand Down
37 changes: 19 additions & 18 deletions src/drivers/Qt/RamWatch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
#include "../../fceu.h"
#include "../../cheat.h"
#include "../../debug.h"
#include "utils/StringUtils.h"

#include "Qt/main.h"
#include "Qt/dface.h"
Expand Down Expand Up @@ -375,7 +376,8 @@ void RamWatchDialog_t::updateRamWatchDisplay(void)
int idx=0;
QTreeWidgetItem *item;
std::list < ramWatch_t * >::iterator it;
char addrStr[32], valStr1[16], valStr2[16];
FCEU::FixedString<32> addrStr;
FCEU::FixedString<16> valStr1, valStr2;
ramWatch_t *rw;

for (it = ramWatchList.ls.begin (); it != ramWatchList.ls.end (); it++)
Expand All @@ -397,64 +399,63 @@ void RamWatchDialog_t::updateRamWatchDisplay(void)
}
if ( rw->isSep || (rw->addr < 0) )
{
strcpy (addrStr, "--------");
addrStr = "--------";
}
else
{
if ( rw->size > 1 )
{
snprintf (addrStr, sizeof(addrStr), "$%04X-$%04X", rw->addr, rw->addr + rw->size - 1);
addrStr.sprintf("$%04X-$%04X", rw->addr, rw->addr + rw->size - 1);
}
else
{
snprintf (addrStr, sizeof(addrStr), "$%04X", rw->addr);
addrStr.sprintf("$%04X", rw->addr);
}
}

rw->updateMem ();

if ( rw->isSep || (rw->addr < 0) )
{
strcpy( valStr1, "--------");
strcpy( valStr2, "--------");
valStr1 = valStr2 = "--------";
}
else
{
if (rw->size == 4)
{
if (rw->type == 's')
{
snprintf (valStr1, sizeof(valStr1), "%i", rw->val.i32);
valStr1.sprintf("%i", rw->val.i32);
}
else
{
snprintf (valStr1, sizeof(valStr1), "%u", rw->val.u32);
valStr1.sprintf("%u", rw->val.u32);
}
snprintf (valStr2, sizeof(valStr2), "0x%08X", rw->val.u32);
valStr2.sprintf("0x%08X", rw->val.u32);
}
else if (rw->size == 2)
{
if (rw->type == 's')
{
snprintf (valStr1, sizeof(valStr1), "%6i", rw->val.i16);
valStr1.sprintf("%6i", rw->val.i16);
}
else
{
snprintf (valStr1, sizeof(valStr1), "%6u", rw->val.u16);
valStr1.sprintf("%6u", rw->val.u16);
}
snprintf (valStr2, sizeof(valStr2), "0x%04X", rw->val.u16);
valStr2.sprintf("0x%04X", rw->val.u16);
}
else
{
if (rw->type == 's')
{
snprintf (valStr1, sizeof(valStr1), "%6i", rw->val.i8);
valStr1.sprintf("%6i", rw->val.i8);
}
else
{
snprintf (valStr1, sizeof(valStr1), "%6u", rw->val.u8);
valStr1.sprintf("%6u", rw->val.u8);
}
snprintf (valStr2, sizeof(valStr2), "0x%02X", rw->val.u8);
valStr2.sprintf("0x%02X", rw->val.u8);
}
}

Expand Down Expand Up @@ -494,9 +495,9 @@ void RamWatchDialog_t::updateRamWatchDisplay(void)
else
{
item->setFirstColumnSpanned(false);
item->setText( 0, tr(addrStr) );
item->setText( 1, tr(valStr1) );
item->setText( 2, tr(valStr2) );
item->setText( 0, tr(addrStr.c_str()) );
item->setText( 1, tr(valStr1.c_str()) );
item->setText( 2, tr(valStr2.c_str()) );
item->setText( 3, tr(rw->name.c_str()) );
}

Expand Down

0 comments on commit 015f6a0

Please sign in to comment.