修复bug

This commit is contained in:
ALIENJACK\alien 2024-11-11 20:09:54 +08:00
parent 5e94eb4d16
commit 9324e185ef
2 changed files with 39 additions and 8 deletions

View File

@ -13,6 +13,10 @@ namespace AxiReplay
/// </summary> /// </summary>
public int mRemoteFrameIdx { get; private set; } = int.MinValue; public int mRemoteFrameIdx { get; private set; } = int.MinValue;
/// <summary> /// <summary>
/// Remote 2 Client Frame Gap
/// </summary>
public int mDiffFrameCount => mRemoteFrameIdx - mCurrClientFrameIdx;
/// <summary>
/// 网络数据队列 /// 网络数据队列
/// </summary> /// </summary>
Queue<ReplayStep> mNetReplayQueue = new Queue<ReplayStep>(); Queue<ReplayStep> mNetReplayQueue = new Queue<ReplayStep>();

View File

@ -56,14 +56,9 @@ namespace AxibugEmuOnline.Client
if (NesCore != null) if (NesCore != null)
{ {
Supporter.SampleInput(); PushEmulatorFrame();
var controlState = Supporter.GetControllerState(); if (InGameUI.Instance.IsNetPlay)
FixEmulatorFrame();
//如果未收到Input数据,核心帧不推进
if (!controlState.valid) return;
NesCore.pad.Sync(controlState);
NesCore.EmulateFrame(true);
var screenBuffer = NesCore.ppu.GetScreenPtr(); var screenBuffer = NesCore.ppu.GetScreenPtr();
var lineColorMode = NesCore.ppu.GetLineColorMode(); var lineColorMode = NesCore.ppu.GetLineColorMode();
@ -71,6 +66,38 @@ namespace AxibugEmuOnline.Client
} }
} }
private void FixEmulatorFrame()
{
int skipFrameCount = 0;
var frameGap = App.roomMgr.netReplay.mDiffFrameCount;
if (frameGap > 10000) return;
if (frameGap > 3 && frameGap < 6) skipFrameCount = 1;
else if (frameGap > 7 && frameGap < 12) skipFrameCount = 2;
else if (frameGap > 13 && frameGap < 20) skipFrameCount = 3;
else skipFrameCount = frameGap - 3;
if (skipFrameCount > 0) App.log.Debug($"SKIP FRAME : {skipFrameCount}");
for (int i = 0; i < skipFrameCount; i++)
{
if (!PushEmulatorFrame()) break;
}
}
private bool PushEmulatorFrame()
{
Supporter.SampleInput();
var controlState = Supporter.GetControllerState();
//如果未收到Input数据,核心帧不推进
if (!controlState.valid) return false;
NesCore.pad.Sync(controlState);
NesCore.EmulateFrame(true);
return true;
}
public void Pause() public void Pause()
{ {
m_bPause = true; m_bPause = true;