8000 zdxsv GGPO: the rollback rig role (ZDXSV_RBK) in one struct by inada-s-ai[bot] · Pull Request #712 · inada-s/pcsx2 · GitHub
[go: up one dir, main page]

Skip to content
< 8000 div id="pull-state" class="js-socket-channel js-updatable-content" data-channel="eyJjIjoiaXNzdWU6NjQ5NzY3ODU3ODpzdGF0ZSIsInQiOjE3OTU0NzE2NTR9--a2e73be7fcd9daf5e58442a9fca5e1a0ca83151efc8e565b648a4d1b3ff9ba09" data-url="/inada-s/pcsx2/pull/712/partials/state" data-gid="PR_kwDODttsW88AAAABQfjImQ" > Merged
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
8000
18 changes: 8 additions & 10 deletions pcsx2/Zdxsv/Ggpo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -276,16 +276,14 @@ namespace Zdxsv
bool g_gs_rerun_frame = false;
bool s_net_env = false; // net=1 in s_options, or a replay plays (GgpoOnVmInitialize)
// ZDXSV_RBK=i/N: until GGPO arms, every lobby / battle connect RPC is answered here (RbkCall).
int s_rbk_me = -1, s_rbk_n = 0;
bool RbkFromEnv()
RbkRole RbkFromEnv()
{
s_rbk_me = -1;
s_rbk_n = 0;
RbkRole r;
const char* e = Zdxsv::TestEnv("ZDXSV_RBK");
return e && std::sscanf(e, "%d/%d", &s_rbk_me, &s_rbk_n) == 2 && s_rbk_me >= 0 && s_rbk_me < s_rbk_n && s_rbk_n <= 4;
r.on = e && std::sscanf(e, "%d/%d", &r.me, &r.n) == 2 && r.me >= 0 && r.me < r.n && r.n <= 4;
return r;
}
// Also set by a replay's common start (PlayLoad); back to ZDXSV_RBK at VM shutdown.
bool s_rbk = RbkFromEnv();
RbkRole s_rbk = RbkFromEnv();
const char* s_rand_env = Zdxsv::TestEnv("ZDXSV_RAND_INPUT");
// ZDXSV_K3_LAG: a msg sent at GGPO frame s goes into the local input of frame s + lag. With lag above
// GGPO's 6 prediction frames, frame s is final when s + lag is added, so a send first made in a rerun
Expand Down Expand Up @@ -365,15 +363,15 @@ namespace Zdxsv

void GgpoOnVsync()
{
if (s_rbk && s_net_env && !s_battle.armed)
if (s_rbk.on && s_net_env && !s_battle.armed)
VMManager::SetLimiterMode(LimiterModeType::Turbo);
// Once: the rbk knobs as received; tests/zdxsv/rbk.py compares this line to what it meant to pass
static bool rbk_env_logged = false;
if (s_rbk && !s_play_env && !rbk_env_logged)
if (s_rbk.on && !s_play_env && !rbk_env_logged)
{
rbk_env_logged = true;
const auto env = [](const char* k) { const char* v = TestEnv(k); return v && *v ? v : "-"; };
Console.WriteLn("ZdxsvGgpo: rbk env pos=%d/%d rand=%s turbo=%s clamp=%s ggpo=%s", s_rbk_me, s_rbk_n,
Console.WriteLn("ZdxsvGgpo: rbk env pos=%d/%d rand=%s turbo=%s clamp=%s ggpo=%s", s_rbk.me, s_rbk.n,
env("ZDXSV_RAND_INPUT"), env("ZDXSV_RBK_TURBO"), env("ZDXSV_EE_CLAMP"), env("ZDXSV_GGPO"));
}
// ZDXSV_VM_TEST=frame:shutdown|reset|mute|ui (tests of GgpoOnVmShutdown; mute: the GGPO network goes silent): once, when a session or replay reaches GGPO frame `frame`
Expand Down
28 changes: 14 additions & 14 deletions pcsx2/Zdxsv/GgpoBattle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ namespace Zdxsv
// p <= ceil(N/2) side 1 (recorded 1, 2), else side 2 (recorded 3, 4).
int RbkRecordedIndex(int p)
{
const int half = (s_rbk_n + 1) / 2;
const int half = (s_rbk.n + 1) / 2;
return p <= half ? p - 1 : 2 + p - 1 - half;
}

Expand All @@ -170,7 +170,7 @@ namespace Zdxsv
static constexpr const char* PILOT = "カミーユ・ビダン";
const LobbyPlayer recorded[4] = {{"J9SXNM", "あああ", PILOT}, {"UJB9AM", "いいい", PILOT}, {"8VQKPC", "ううう", PILOT}, {"Z57CN2", "えええ", PILOT}};
std::vector<LobbyPlayer> players;
for (int p = 1; p <= s_rbk_n; p++)
for (int p = 1; p <= s_rbk.n; p++)
players.push_back(recorded[RbkRecordedIndex(p)]);
return players;
}
Expand All @@ -190,12 +190,12 @@ namespace Zdxsv
}
switch (cmd)
{
case 0x6911: return {static_cast<u8>(s_rbk_n)};
case 0x6912: return {static_cast<u8>(s_rbk_me + 1)};
case 0x6911: return {static_cast<u8>(s_rbk.n)};
case 0x6912: return {static_cast<u8>(s_rbk.me + 1)};
case 0x6913:
case 0x6917:
{
if (p < 1 || p > s_rbk_n)
if (p < 1 || p > s_rbk.n)
break;
std::vector<u8> b = Unhex((cmd == 0x6913 ? RBK_USERS : RBK_6917)[RbkRecordedIndex(p)]);
b.front() = static_cast<u8>(p);
Expand Down Expand Up @@ -317,9 +317,9 @@ namespace Zdxsv
if (!std::exchange(s_rbk_started, true))
{
RbkQueue(0x10, 0x6910, 0x1000, {});
Console.WriteLn("ZdxsvGgpo: rbk position %d of %d, battle start at vsync %u", s_rbk_me + 1, s_rbk_n, g_FrameCount);
Console.WriteLn("ZdxsvGgpo: rbk position %d of %d, battle start at vsync %u", s_rbk.me + 1, s_rbk.n, g_FrameCount);
}
BattleServerCall(s_rbk_rx, s_rbk_me, s_rbk_n, fno, len, d, result);
BattleServerCall(s_rbk_rx, s_rbk.me, s_rbk.n, fno, len, d, result);
break;
case NET_FNO_SEND:
{
Expand All @@ -338,7 +338,7 @@ namespace Zdxsv
}
}
else
BattleServerCall(s_rbk_rx, s_rbk_me, s_rbk_n, fno, len, d, result);
BattleServerCall(s_rbk_rx, s_rbk.me, s_rbk.n, fno, len, d, result);
break;
}
case 0x38:
Expand All @@ -351,7 +351,7 @@ namespace Zdxsv
case 0x46: // link up: 1 makes the game close the lobby it resumed with
break;
default:
if (!BattleServerCall(s_rbk_rx, s_rbk_me, s_rbk_n, fno, len, d, result))
if (!BattleServerCall(s_rbk_rx, s_rbk.me, s_rbk.n, fno, len, d, result))
return false;
}
*reinterpret_cast<s32*>(ram + NET_RES_LEN) = result;
Expand Down Expand Up @@ -629,7 +629,7 @@ namespace Zdxsv
u8* d = ram + NET_REQ_DATA;
const bool key = fno == NET_FNO_SEND && sock == NET_BATTLE_SOCK && len > 0 && len <= 0x3ca && HasKeyMsg(d, len);
// lobby=1: the battle server is answered on the EE (BattleServerCall); the game never reaches it
if (s_opt.lobby && !s_play_env && !s_rbk && fno == NET_FNO_CONNECT && (!s_battle.armed || s_battle.over))
if (s_opt.lobby && !s_play_env && !s_rbk.on && fno == NET_FNO_CONNECT && (!s_battle.armed || s_battle.over))
{
u32 ip;
std::memcpy(&ip, ram + NET_REQ_SOCK, 4);
Expand Down Expand Up @@ -674,7 +674,7 @@ namespace Zdxsv
{
// lobby=1: the first key msg of a battle with a new battle info starts the next GGPO battle; the
// sends of the ended battle (same battle info) stay with the IOP
if (s_opt.lobby && !s_play_env && !s_rbk && key && LobbyNewBattle())
if (s_opt.lobby && !s_play_env && !s_rbk.on && key && LobbyNewBattle())
{
NetReset();
Console.WriteLn("ZdxsvGgpo: next lobby battle at vsync %u", g_FrameCount);
Expand Down Expand Up @@ -704,7 +704,7 @@ namespace Zdxsv
return true;
}
}
if (s_rbk && !s_battle.armed && !key) // connect (fno 7) has the address in the sock field
if (s_rbk.on && !s_battle.armed && !key) // connect (fno 7) has the address in the sock field
return RbkCall(fno, len, d);
if (s_battle.lobby_cut)
return LobbyCutCall(fno, sock, len);
Expand All @@ -722,7 +722,7 @@ namespace Zdxsv
if (s_opt.lobby && !LobbyArm(me))
return s_battle.lobby_cut && LobbyCutCall(fno, sock, len);
s_battle.armed = true;
if (s_rbk)
if (s_rbk.on)
{
s_rb.net_rx.insert(s_rb.net_rx.end(), s_rbk_rx.begin(), s_rbk_rx.end());
s_rbk_rx.clear();
Expand All @@ -737,7 +737,7 @@ namespace Zdxsv
s_battle.local_server = true;
}
// ZDXSV_RBK_TURBO=1: the battle runs turbo too (GGPO paces the peers by frame)
if (!s_rbk || !Zdxsv::TestEnv("ZDXSV_RBK_TURBO"))
if (!s_rbk.on || !Zdxsv::TestEnv("ZDXSV_RBK_TURBO"))
VMManager::SetLimiterMode(LimiterModeType::Nominal);
if (me >= 0)
s_battle.me = me;
Expand Down
2 changes: 1 addition & 1 deletion pcsx2/Zdxsv/GgpoSession.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,7 @@ namespace Zdxsv
ReplayWrite(what);
NetReport();
}
if (s_rbk && !s_play_env && !s_vm_closing)
if (s_rbk.on && !s_play_env &&a 10BC8 mp; !s_vm_closing)
{
Console.WriteLn("ZdxsvGgpo: rbk exit (%s) at vsync %u", what, g_FrameCount);
Host::RunOnCPUThread([] { Host::RequestVMShutdown(false, false, false); });
Expand Down
9 changes: 7 additions & 2 deletions pcsx2/Zdxsv/GgpoShared.h
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,13 @@ namespace Zdxsv
void DesyncReport();
std::string DesyncReportLines();
extern bool s_net_env; // net=1 in s_options, or a replay plays (GgpoOnVmInitialize)
extern int s_rbk_me, s_rbk_n;
extern bool s_rbk; // also set by a replay's common start (PlayLoad); back to ZDXSV_RBK at VM shutdown
// ZDXSV_RBK=i/N; also set by a replay's common start (PlayLoad); back to ZDXSV_RBK at VM shutdown
struct RbkRole
{
bool on = false;
int me = -1, n = 0;
};
extern RbkRole s_rbk;
extern const char* s_rand_env;
extern const bool s_pw_hash;
constexpr u32 PW_BASE = 0x8395d8, PW_SIZE = 0x2200;
Expand Down
8 changes: 4 additions & 4 deletions pcsx2/Zdxsv/ReplayLoad.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -848,9 +848,9 @@ namespace Zdxsv
k3.clear();
s_opt.net = true;
s_battle.me = pov;
s_rbk = true;
s_rbk_me = pov;
s_rbk_n = s_opt.players;
s_rbk.on = true;
s_rbk.me = pov;
s_rbk.n = s_opt.players;
RbkReset();
Console.WriteLn("ZdxsvGgpo: replay: common start as position %d of %d, %zu lobby answers%s", pov, s_opt.players,
s_play_answers.size(), seek >= 0 ? fmt::format(", then seek to {}", seek).c_str() : "");
Expand Down Expand Up @@ -878,7 +878,7 @@ namespace Zdxsv
k0.ok = true;
// the file's HLE state is its recorder's position's
Console.WriteLn("ZdxsvGgpo: replay: common start armed at vsync %u as position %d (asked %d), frame 0 HLE state %s",
g_FrameCount, me, s_rbk_me, me != s_play.rng_pos ? "not compared" : hle_same ? "equals the file's" : "differs from the file's");
g_FrameCount, me, s_rbk.me, me != s_play.rng_pos ? "not compared" : hle_same ? "equals the file's" : "differs from the file's");
// PlayBegin loads that state as PlayLoad does
s_battle.started = false;
g_ggpo_active = false;
Expand Down
Loading
0