From edc84fc3cfab90bb7edb62a7f4057723baaa3dcc Mon Sep 17 00:00:00 2001 From: "ALIENJACK\\alien" Date: Tue, 12 Nov 2024 09:58:30 +0800 Subject: [PATCH] =?UTF-8?q?=E5=BC=80=E6=94=BE=E6=A8=A1=E6=8B=9F=E5=99=A8?= =?UTF-8?q?=E6=A0=B8=E5=BF=83=E5=B8=A7=E5=BA=8F=E5=8F=B7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Script/NesEmulator/CoreSupporter.cs | 2 +- .../Assets/Script/NesEmulator/NesEmulator.cs | 10 +++++++++- .../Assets/VirtualNes.Core/NES.cs | 7 ++++--- .../Supporter/ControllerState.cs | 19 +++++++++++++++++++ .../VirtualNes.Core/Supporter/Supporter.cs | 6 +++--- 5 files changed, 36 insertions(+), 8 deletions(-) diff --git a/AxibugEmuOnline.Client/Assets/Script/NesEmulator/CoreSupporter.cs b/AxibugEmuOnline.Client/Assets/Script/NesEmulator/CoreSupporter.cs index 089fd19..dfb882b 100644 --- a/AxibugEmuOnline.Client/Assets/Script/NesEmulator/CoreSupporter.cs +++ b/AxibugEmuOnline.Client/Assets/Script/NesEmulator/CoreSupporter.cs @@ -99,7 +99,7 @@ namespace AxibugEmuOnline.Client } uint LastTestInput = 0; - public void SampleInput() + public void SampleInput(uint frameIndex) { if (InGameUI.Instance.IsNetPlay) { diff --git a/AxibugEmuOnline.Client/Assets/Script/NesEmulator/NesEmulator.cs b/AxibugEmuOnline.Client/Assets/Script/NesEmulator/NesEmulator.cs index 156d771..fd937a9 100644 --- a/AxibugEmuOnline.Client/Assets/Script/NesEmulator/NesEmulator.cs +++ b/AxibugEmuOnline.Client/Assets/Script/NesEmulator/NesEmulator.cs @@ -84,17 +84,25 @@ namespace AxibugEmuOnline.Client } } + ControllerState lastState; private bool PushEmulatorFrame() { - Supporter.SampleInput(); + Supporter.SampleInput(NesCore.FrameCount); var controlState = Supporter.GetControllerState(); //如果未收到Input数据,核心帧不推进 if (!controlState.valid) return false; + if (controlState != lastState) + { + App.log.Info($"[LOCALDEBUG]{NesCore.FrameCount}-->{controlState}"); + } + NesCore.pad.Sync(controlState); NesCore.EmulateFrame(true); + lastState = controlState; + return true; } diff --git a/AxibugEmuOnline.Client/Assets/VirtualNes.Core/NES.cs b/AxibugEmuOnline.Client/Assets/VirtualNes.Core/NES.cs index 8c22e83..b3fa228 100644 --- a/AxibugEmuOnline.Client/Assets/VirtualNes.Core/NES.cs +++ b/AxibugEmuOnline.Client/Assets/VirtualNes.Core/NES.cs @@ -459,11 +459,9 @@ namespace VirtualNes.Core m_CheatCode.Clear(); } - private int FrameCount = 0; + public uint FrameCount { get; private set; } public void EmulateFrame(bool bDraw) { - FrameCount++; - int scanline = 0; if (rom.IsNSF()) { @@ -772,6 +770,8 @@ namespace VirtualNes.Core { DrawPad(); } + + FrameCount++; } private void DrawPad() @@ -1901,6 +1901,7 @@ namespace VirtualNes.Core public void LoadState(State state) { + FrameCount = 0; //HEADER { state.HEADER.ID = "VirtuaNES ST"; diff --git a/AxibugEmuOnline.Client/Assets/VirtualNes.Core/Supporter/ControllerState.cs b/AxibugEmuOnline.Client/Assets/VirtualNes.Core/Supporter/ControllerState.cs index 642b198..352e192 100644 --- a/AxibugEmuOnline.Client/Assets/VirtualNes.Core/Supporter/ControllerState.cs +++ b/AxibugEmuOnline.Client/Assets/VirtualNes.Core/Supporter/ControllerState.cs @@ -24,6 +24,25 @@ namespace VirtualNes.Core valid = true; } + public static bool operator ==(ControllerState left, ControllerState right) + { + return + left.raw0 == right.raw0 && + left.raw1 == right.raw1 && + left.raw2 == right.raw2 && + left.raw3 == right.raw3; + } + + public static bool operator !=(ControllerState left, ControllerState right) + { + return !(left == right); + } + + public override string ToString() + { + return $"{raw0}|{raw1}|{raw2}|{raw3}"; + } + public bool HasButton(int player, EnumButtonType button) { uint raw = 0; diff --git a/AxibugEmuOnline.Client/Assets/VirtualNes.Core/Supporter/Supporter.cs b/AxibugEmuOnline.Client/Assets/VirtualNes.Core/Supporter/Supporter.cs index 3ecd65c..393210d 100644 --- a/AxibugEmuOnline.Client/Assets/VirtualNes.Core/Supporter/Supporter.cs +++ b/AxibugEmuOnline.Client/Assets/VirtualNes.Core/Supporter/Supporter.cs @@ -59,9 +59,9 @@ namespace VirtualNes.Core return s_support.GetControllerState(); } - public static void SampleInput() + public static void SampleInput(uint frameCount) { - s_support.SampleInput(); + s_support.SampleInput(frameCount); } public static EmulatorConfig Config => s_support.Config; @@ -81,6 +81,6 @@ namespace VirtualNes.Core Stream OpenFile(string directPath, string fileName); bool TryGetMapperNo(ROM rom, out int mapperNo); ControllerState GetControllerState(); - void SampleInput(); + void SampleInput(uint frameCount); } }