diff --git a/Source/Core/Core/Core.cpp b/Source/Core/Core/Core.cpp index e08c3f58d2..604de6f170 100644 --- a/Source/Core/Core/Core.cpp +++ b/Source/Core/Core/Core.cpp @@ -29,6 +29,7 @@ #include "Core/Host.h" #include "Core/MemTools.h" #include "Core/Movie.h" +#include "Core/NetPlayClient.h" #include "Core/NetPlayProto.h" #include "Core/PatchEngine.h" #include "Core/State.h" @@ -129,6 +130,12 @@ void SetIsFramelimiterTempDisabled(bool disable) std::string GetStateFileName() { return s_state_filename; } void SetStateFileName(const std::string& val) { s_state_filename = val; } +void FrameUpdateOnCPUThread() +{ + if (NetPlay::IsNetPlayRunning()) + NetPlayClient::SendTimeBase(); +} + // Display messages and return values // Formatted stop message diff --git a/Source/Core/Core/Core.h b/Source/Core/Core/Core.h index b86168f3f6..1eea2be226 100644 --- a/Source/Core/Core/Core.h +++ b/Source/Core/Core/Core.h @@ -63,6 +63,8 @@ void SetStateFileName(const std::string& val); void SetBlockStart(u32 addr); +void FrameUpdateOnCPUThread(); + bool ShouldSkipFrame(int skipped); void VideoThrottle(); void RequestRefreshInfo(); diff --git a/Source/Core/Core/Movie.cpp b/Source/Core/Core/Movie.cpp index facef9ce6a..de457e7b16 100644 --- a/Source/Core/Core/Movie.cpp +++ b/Source/Core/Core/Movie.cpp @@ -140,6 +140,8 @@ std::string GetInputDisplay() void FrameUpdate() { + // TODO[comex]: This runs on the GPU thread, yet it messes with the CPU + // state directly. That's super sketchy. g_currentFrame++; if (!s_bPolled) g_currentLagCount++; @@ -164,9 +166,6 @@ void FrameUpdate() FrameSkipping(); s_bPolled = false; - - if (NetPlay::IsNetPlayRunning()) - NetPlayClient::SendTimeBase(); } // called when game is booting up, even if no movie is active, diff --git a/Source/Core/Core/NetPlayClient.cpp b/Source/Core/Core/NetPlayClient.cpp index d456ae0da2..eeae193110 100644 --- a/Source/Core/Core/NetPlayClient.cpp +++ b/Source/Core/Core/NetPlayClient.cpp @@ -663,6 +663,8 @@ bool NetPlayClient::StartGame(const std::string &path) m_dialog->AppendChat(" -- STARTING GAME -- "); + m_timebase_frame = 0; + m_is_running.store(true); NetPlay_Enable(this); @@ -1074,7 +1076,7 @@ void NetPlayClient::SendTimeBase() *spac << (MessageId)NP_MSG_TIMEBASE; *spac << (u32)timebase; *spac << (u32)(timebase << 32); - *spac << (u32)Movie::g_currentFrame; + *spac << netplay_client->m_timebase_frame++; netplay_client->SendAsync(spac); } diff --git a/Source/Core/Core/NetPlayClient.h b/Source/Core/Core/NetPlayClient.h index f12b489b7d..c80afda9f7 100644 --- a/Source/Core/Core/NetPlayClient.h +++ b/Source/Core/Core/NetPlayClient.h @@ -143,6 +143,8 @@ private: std::string m_player_name; bool m_connecting; TraversalClient* m_traversal_client; + + u32 m_timebase_frame; }; void NetPlay_Enable(NetPlayClient* const np); diff --git a/Source/Core/VideoCommon/PixelEngine.cpp b/Source/Core/VideoCommon/PixelEngine.cpp index 45db963d23..91662e9931 100644 --- a/Source/Core/VideoCommon/PixelEngine.cpp +++ b/Source/Core/VideoCommon/PixelEngine.cpp @@ -11,6 +11,7 @@ #include "Common/ChunkFile.h" #include "Common/CommonTypes.h" #include "Core/ConfigManager.h" +#include "Core/Core.h" #include "Core/CoreTiming.h" #include "Core/State.h" #include "Core/HW/MMIO.h" @@ -282,6 +283,8 @@ void SetFinish_OnMainThread(u64 userdata, int cyclesLate) s_signal_finish_interrupt.store(1); UpdateInterrupts(); CommandProcessor::SetInterruptFinishWaiting(false); + + Core::FrameUpdateOnCPUThread(); } // SetToken