From 9324e185ef279bc421ae4ed15dbc48c014e4ab6f Mon Sep 17 00:00:00 2001 From: "ALIENJACK\\alien" Date: Mon, 11 Nov 2024 20:09:54 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8Dbug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Assets/Plugins/AxiReplay/NetReplay.cs | 4 ++ .../Assets/Script/NesEmulator/NesEmulator.cs | 43 +++++++++++++++---- 2 files changed, 39 insertions(+), 8 deletions(-) diff --git a/AxibugEmuOnline.Client/Assets/Plugins/AxiReplay/NetReplay.cs b/AxibugEmuOnline.Client/Assets/Plugins/AxiReplay/NetReplay.cs index 8e87aa0..086e06a 100644 --- a/AxibugEmuOnline.Client/Assets/Plugins/AxiReplay/NetReplay.cs +++ b/AxibugEmuOnline.Client/Assets/Plugins/AxiReplay/NetReplay.cs @@ -12,6 +12,10 @@ namespace AxiReplay /// 服务器远端当前帧 /// public int mRemoteFrameIdx { get; private set; } = int.MinValue; + /// + /// Remote 2 Client Frame Gap + /// + public int mDiffFrameCount => mRemoteFrameIdx - mCurrClientFrameIdx; /// /// 网络数据队列 /// diff --git a/AxibugEmuOnline.Client/Assets/Script/NesEmulator/NesEmulator.cs b/AxibugEmuOnline.Client/Assets/Script/NesEmulator/NesEmulator.cs index 1dff67b..a703ad2 100644 --- a/AxibugEmuOnline.Client/Assets/Script/NesEmulator/NesEmulator.cs +++ b/AxibugEmuOnline.Client/Assets/Script/NesEmulator/NesEmulator.cs @@ -56,14 +56,9 @@ namespace AxibugEmuOnline.Client if (NesCore != null) { - Supporter.SampleInput(); - var controlState = Supporter.GetControllerState(); - - //δյInput,֡ƽ - if (!controlState.valid) return; - - NesCore.pad.Sync(controlState); - NesCore.EmulateFrame(true); + PushEmulatorFrame(); + if (InGameUI.Instance.IsNetPlay) + FixEmulatorFrame(); var screenBuffer = NesCore.ppu.GetScreenPtr(); 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() { m_bPause = true;