Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

constant frame_delay changed to variable, set default frame_delay in ConfigManager to 1 ... #58

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions Source/Core/Core/Brawlback/TimeSync.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@

#include "TimeSync.h"
#include "VideoCommon/OnScreenDisplay.h"
#include "Core/ConfigManager.h"

// pretty much all of this time sync stuff was taken from slippi
// Huge thanks to them <3
Expand All @@ -20,6 +21,9 @@ bool TimeSync::shouldStallFrame(s32 currentFrame, s32 latestRemoteFrame, u8 numP

s32 frameDiff = currentFrame - latestRemoteFrame;

const SConfig& settings = SConfig::GetInstance();
int frame_delay = settings.m_delayFrames;

std::stringstream dispStr;
dispStr << "| Frame diff: " << frameDiff << " |\n";
//OSD::AddTypedMessage(OSD::MessageType::NetPlayBuffer, dispStr.str(), OSD::Duration::NORMAL, OSD::Color::CYAN);
Expand All @@ -34,7 +38,7 @@ bool TimeSync::shouldStallFrame(s32 currentFrame, s32 latestRemoteFrame, u8 numP
else
{
INFO_LOG_FMT(BRAWLBACK, "ROLLBACK IS NOT ENABLED! FRAMEDIFF: {}", dispStr.str());
frameDiffCheck = frameDiff > FRAME_DELAY;
frameDiffCheck = frameDiff > frame_delay;
}

if (frameDiffCheck)
Expand Down Expand Up @@ -171,6 +175,9 @@ void TimeSync::ProcessFrameAck(FrameAck* frameAck) {
u8 localPlayerIdx = frameAck->playerIdx; // local player idx
int frame = frameAck->frame; // this is with frame delay

const SConfig& settings = SConfig::GetInstance();
int frame_delay = settings.m_delayFrames;

// SLIPPI LOGIC

// if this current acked frame is more recent than the last acked frame, set it
Expand Down Expand Up @@ -204,13 +211,13 @@ void TimeSync::ProcessFrameAck(FrameAck* frameAck) {
double rtt_ms = (double)rtt / 1000.0;

INFO_LOG_FMT(BRAWLBACK, "Received ack for frame {} (w/o delay: {}) [pIdx {} rtt {} ms]\n",
frame, frame - FRAME_DELAY, (unsigned int)localPlayerIdx, rtt_ms);
frame, frame - frame_delay, (unsigned int)localPlayerIdx, rtt_ms);

if (frame % PING_DISPLAY_INTERVAL == 0) {
std::stringstream dispStr;
dispStr << "Ping (rtt): " << (int)rtt_ms << " ms\n";
//dispStr << "Time offset: " << (double)this->calcTimeOffsetUs(2) / 1000 << " ms\n";
dispStr << "Frame delay: " << FRAME_DELAY << "\n";
dispStr << "Frame delay: " << frame_delay << "\n";
OSD::AddTypedMessage(OSD::MessageType::NetPlayPing, dispStr.str(), OSD::Duration::NORMAL, OSD::Color::GREEN);
}
}
Expand Down
2 changes: 1 addition & 1 deletion Source/Core/Core/ConfigManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ struct SConfig
bool m_meleeUserIniBootstrapped = false;
bool m_blockingPipes = false;
bool m_coutEnabled = false;
int m_delayFrames = 2;
int m_delayFrames = 1;
std::string m_details_game_id = "";

// files
Expand Down
15 changes: 11 additions & 4 deletions Source/Core/Core/HW/EXI/EXIBrawlback.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#include "Core/HW/Memmap.h"
#include "VideoCommon/OnScreenDisplay.h"
#include <regex>
#include "Core/ConfigManager.h"

namespace fs = std::filesystem;
// --- Mutexes
Expand Down Expand Up @@ -289,6 +290,9 @@ void CEXIBrawlback::handleLocalPadData(u8* data)
PlayerFrameData playerFramedata;
std::memcpy(&playerFramedata, data, sizeof(PlayerFrameData));

const SConfig& settings = SConfig::GetInstance();
int frame_delay = settings.m_delayFrames;

// first 4 bytes are current game frame
SwapPlayerFrameDataEndianness(playerFramedata);
auto frame = playerFramedata.frame;
Expand All @@ -297,7 +301,7 @@ void CEXIBrawlback::handleLocalPadData(u8* data)
if (frame == GAME_START_FRAME && !this->hasGameStarted)
{
// push framedatas for first few delay frames
for (int i = GAME_START_FRAME; i < FRAME_DELAY; i++)
for (int i = GAME_START_FRAME; i < frame_delay; i++)
{
auto pfd = CreateBlankPlayerFrameData(i, playerIdx);
this->remotePlayerFrameData[playerIdx].push_back(std::make_unique<PlayerFrameData>(pfd));
Expand Down Expand Up @@ -558,23 +562,26 @@ void CEXIBrawlback::handleFrameAdvanceRequest(u8* data)

void CEXIBrawlback::storeLocalInputs(PlayerFrameData* localPlayerFramedata)
{
const SConfig& settings = SConfig::GetInstance();
int frame_delay = settings.m_delayFrames;

#ifdef RANDOM_INPUTS
if (this->localPlayerIdx == 0)
*localPlayerFramedata =
generateRandomInput(localPlayerFramedata->frame, localPlayerFramedata->playerIdx);
#endif
// local inputs offset by FRAME_DELAY to mask latency
// local inputs offset by frame_delay to mask latency
// Once we hit frame X, we send inputs for that frame, but pretend they're from frame X+2
// so those inputs now have an extra 2 frames to get to the opponent before the opponent's
// client hits frame X+2.
localPlayerFramedata->frame += FRAME_DELAY;
localPlayerFramedata->frame += frame_delay;

/*std::fstream synclogFile;
File::OpenFStream(synclogFile, File::GetExeDirectory() + "/local_inputs.txt", std::ios_base::out |
std::ios_base::app); synclogFile << Sync::stringifyFramedata(*localPlayerFramedata) << "\n";
synclogFile.close();*/

// pFD->frame += FRAME_DELAY;
// pFD->frame += frame_delay;
std::unique_ptr<PlayerFrameData> pFD = std::make_unique<PlayerFrameData>(*localPlayerFramedata);
// INFO_LOG_FMT(BRAWLBACK, "Frame %u PlayerIdx: %u numPlayers %u\n", localPlayerFramedata->frame,
// localPlayerFramedata->playerIdx, this->numPlayers);
Expand Down
Loading