Added client pause flag to status message for net play.

This commit is contained in:
harry 2024-02-25 16:22:18 -05:00
parent 6832eaa964
commit 015f6a0acd
4 changed files with 38 additions and 23 deletions

View File

@ -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"
@ -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);
@ -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 ) )
{
@ -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)
{
@ -537,6 +541,11 @@ void NetPlayServer::update(void)
{
gpData[client->role] = client->gpData[client->role];
}
if (client->isPaused())
{
numClientsPaused++;
}
}
@ -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);
@ -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;
@ -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();

View File

@ -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;
@ -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;

View File

@ -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)

View File

@ -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"
@ -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++)
@ -397,17 +399,17 @@ 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);
}
}
@ -415,8 +417,7 @@ void RamWatchDialog_t::updateRamWatchDisplay(void)
if ( rw->isSep || (rw->addr < 0) )
{
strcpy( valStr1, "--------");
strcpy( valStr2, "--------");
valStr1 = valStr2 = "--------";
}
else
{
@ -424,37 +425,37 @@ void RamWatchDialog_t::updateRamWatchDisplay(void)
{
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);
}
}
@ -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()) );
}