diff --git a/AxibugEmuOnline.Client/Assets/Script/AppMain/Emulator/EssgeeEmulator/UEssgee.cs b/AxibugEmuOnline.Client/Assets/Script/AppMain/Emulator/EssgeeEmulator/UEssgee.cs index 17ed2dca..69ef9530 100644 --- a/AxibugEmuOnline.Client/Assets/Script/AppMain/Emulator/EssgeeEmulator/UEssgee.cs +++ b/AxibugEmuOnline.Client/Assets/Script/AppMain/Emulator/EssgeeEmulator/UEssgee.cs @@ -1,6 +1,7 @@ using AxibugEmuOnline.Client; using AxibugEmuOnline.Client.ClientCore; using AxibugProtobuf; +using AxiReplay; using Essgee; using Essgee.Emulation; using Essgee.Emulation.Configuration; @@ -11,13 +12,12 @@ using Essgee.Metadata; using Essgee.Utilities; using System; using System.Collections.Generic; -using System.Drawing; using System.Linq; using System.Text; using UnityEngine; using UnityEngine.UI; -public class UEssgee : IEmuCore +public class UEssgee : EmuCore { public static UEssgee instance; public static System.Diagnostics.Stopwatch sw = System.Diagnostics.Stopwatch.StartNew(); @@ -125,7 +125,7 @@ public class UEssgee : IEmuCore public override void Dispose() { if (!emulatorHandler.IsRunning) - { + { emulatorHandler.SaveCartridge(); } ShutdownEmulation(); @@ -141,21 +141,32 @@ public class UEssgee : IEmuCore { return mUniKeyboard.ControllerMapper; } - - public override bool PushEmulatorFrame() - { + protected override bool OnPushEmulatorFrame(ulong InputData) + { if (!emulatorHandler.IsRunning) return false; - if (!bLogicUpdatePause) return false; - - //采集本帧Input - bool bhadNext = mUniKeyboard.SampleInput(); - //如果未收到Input数据,核心帧不推进 - if (!bhadNext) return false; - - emulatorHandler.Update_Frame(); - return true; + if (!bLogicUpdatePause) return false; + + mUniKeyboard.SetCurrKeyArr(InputData); + emulatorHandler.Update_Frame(); + + return true; } + protected override ulong ConvertInputDataFromNet(ReplayStep step) + { + return step.InPut; + } + + protected override ulong InputDataToNet(ulong inputData) + { + return inputData; + } + + protected override ulong GetLocalInput() + { + return mUniKeyboard.DoLocalPressedKeys(); + } + public override void AfterPushFrame() { } diff --git a/AxibugEmuOnline.Client/Assets/Script/AppMain/Emulator/EssgeeEmulator/UEssgeeInterface/UEGKeyboard.cs b/AxibugEmuOnline.Client/Assets/Script/AppMain/Emulator/EssgeeEmulator/UEssgeeInterface/UEGKeyboard.cs index 5b730853..409fee6e 100644 --- a/AxibugEmuOnline.Client/Assets/Script/AppMain/Emulator/EssgeeEmulator/UEssgeeInterface/UEGKeyboard.cs +++ b/AxibugEmuOnline.Client/Assets/Script/AppMain/Emulator/EssgeeEmulator/UEssgeeInterface/UEGKeyboard.cs @@ -315,45 +315,7 @@ public class UEGKeyboard : MonoBehaviour //mUniKeyboard.btnABC.Key = new long[] { (long)MotionKey.P1_BTN_1, (long)MotionKey.P1_BTN_2, (long)MotionKey.P1_BTN_3 }; } - public bool SampleInput() - { - //Net模式 - if (InGameUI.Instance.IsNetPlay) - { - bool bHadNetData = false; - int targetFrame; ReplayStep replayData; int frameDiff; bool inputDiff; - if (App.roomMgr.netReplay.TryGetNextFrame((int)UEssgee.instance.Frame, out replayData, out frameDiff, out inputDiff)) - { - if (inputDiff) - { - App.log.Debug($"{DateTime.Now.ToString("hh:mm:ss.fff")} TryGetNextFrame remoteFrame->{App.roomMgr.netReplay.mRemoteFrameIdx} diff->{frameDiff} " + - $"frame=>{replayData.FrameStartID} InPut=>{replayData.InPut}"); - } - CurrRemoteInpuAllData = replayData.InPut; - SetCurrKeyArr(CurrRemoteInpuAllData); - bHadNetData = true; - } - else//无输入 - { - CurrRemoteInpuAllData = 0; - } - - //发送本地操作 - App.roomMgr.SendRoomSingelPlayerInput(UEssgee.instance.Frame, - DoLocalPressedKeys()); - - return bHadNetData; - } - //单机模式 - else - { - ulong inputData = DoLocalPressedKeys(); - SetCurrKeyArr(inputData); - return true; - } - } - - void SetCurrKeyArr(ulong inputData) + public void SetCurrKeyArr(ulong inputData) { temp.Clear(); for (int i = 0; i < CheckList.Length; i++) @@ -368,7 +330,7 @@ public class UEGKeyboard : MonoBehaviour mCurrKey = temp.ToArray(); } - ulong DoLocalPressedKeys() + public ulong DoLocalPressedKeys() { //tempInputAllData = 0; //for (int i = 0; i < CheckList.Length; i++) diff --git a/AxibugEmuOnline.Client/Assets/Script/AppMain/Emulator/MameEmulator/UMAME.cs b/AxibugEmuOnline.Client/Assets/Script/AppMain/Emulator/MameEmulator/UMAME.cs index 764a1a18..253836be 100644 --- a/AxibugEmuOnline.Client/Assets/Script/AppMain/Emulator/MameEmulator/UMAME.cs +++ b/AxibugEmuOnline.Client/Assets/Script/AppMain/Emulator/MameEmulator/UMAME.cs @@ -9,7 +9,7 @@ using System.Text; using UnityEngine; using UnityEngine.UI; -public class UMAME : IEmuCore +public class UMAME : EmuCore { public static UMAME instance { get; private set; } public MAMEEmu emu { get; private set; } @@ -95,7 +95,7 @@ public class UMAME : IEmuCore { mPlatform = romFile.Platform; mTimeSpan.InitStandTime(); - if (LoadGame(romFile.FileName, false)) + if (LoadGame(romFile.FileName)) return true; else return "Rom加载失败"; @@ -107,7 +107,7 @@ public class UMAME : IEmuCore public override void DoReset() { StopGame(); - LoadGame(mChangeRomName, false); + LoadGame(mChangeRomName); } public override IControllerSetuper GetControllerSetuper() { @@ -121,7 +121,7 @@ public class UMAME : IEmuCore } #endregion - bool LoadGame(string loadRom, bool bReplay = false) + bool LoadGame(string loadRom) { emu.ResetRomRoot(RomPath); //Application.targetFrameRate = 60; @@ -133,12 +133,6 @@ public class UMAME : IEmuCore //读取成功 if (emu.bRom) { - if (bReplay) - { - string Path = SavePath + Machine.sName + ".rp"; - mReplayReader = new ReplayReader(Path); - mUniKeyboard.SetRePlay(true); - } //读取ROM之后获得宽高初始化画面 int _width; int _height; IntPtr _framePtr; @@ -159,22 +153,32 @@ public class UMAME : IEmuCore return false; } } - - public override bool PushEmulatorFrame() + protected override bool OnPushEmulatorFrame(ulong InputData) { if (!bInGame) return false; if (!bLogicUpdatePause) return false; - //采集本帧Input - bool bhadNext = mUniKeyboard.SampleInput(); - //如果未收到Input数据,核心帧不推进 - if (!bhadNext) return false; - //放行下一帧 - //emu.UnlockNextFreme(); - //推帧 - emu.UpdateFrame(); - return true; + mUniKeyboard.SyncInput(InputData); + emu.UpdateFrame(); + + return true; } + + protected override ulong ConvertInputDataFromNet(ReplayStep step) + { + return step.InPut; + } + + protected override ulong InputDataToNet(ulong inputData) + { + return inputData; + } + + protected override ulong GetLocalInput() + { + return mUniKeyboard.DoLocalPressedKeys(); + } + public override void AfterPushFrame() { mFPS.text = ($"fpsv {mUniVideoPlayer.videoFPS.ToString("F2")} fpsa {mUniSoundPlayer.audioFPS.ToString("F2")} ,Idx:{App.roomMgr.netReplay?.mCurrClientFrameIdx},RIdx:{App.roomMgr.netReplay?.mRemoteFrameIdx},RForward:{App.roomMgr.netReplay?.mRemoteForwardCount} ,RD:{App.roomMgr.netReplay?.mRemoteForwardCount} ,D:{App.roomMgr.netReplay?.mDiffFrameCount} ,Q:{App.roomMgr.netReplay?.mNetReplayQueue.Count}"); diff --git a/AxibugEmuOnline.Client/Assets/Script/AppMain/Emulator/MameEmulator/UniInterface/UniKeyboard.cs b/AxibugEmuOnline.Client/Assets/Script/AppMain/Emulator/MameEmulator/UniInterface/UniKeyboard.cs index 20521e68..92b63622 100644 --- a/AxibugEmuOnline.Client/Assets/Script/AppMain/Emulator/MameEmulator/UniInterface/UniKeyboard.cs +++ b/AxibugEmuOnline.Client/Assets/Script/AppMain/Emulator/MameEmulator/UniInterface/UniKeyboard.cs @@ -12,43 +12,34 @@ using UnityEngine; public class UniKeyboard : MonoBehaviour, IKeyboard { public MameControllerMapper ControllerMapper { get; private set; } - bool bReplayMode; PlayMode mPlayMode; - ReplayMode mReplayMode; void Awake() { ControllerMapper = new MameControllerMapper(); - Init(false); + Init(); } public ulong GetPressedKeys() { - ulong InputData; - if (!bReplayMode)//游玩模式(单机或联机) - return mPlayMode.GetPressedKeys(); - else//Replay模式 - return mReplayMode.GetPressedKeys(); + return mPlayMode.GetPressedKeys(); + } + public void SyncInput(ulong inputData) + { + mPlayMode.CurrLocalInpuAllData = inputData; } - public bool SampleInput() - { - if (bReplayMode) return true; - return mPlayMode.SampleInput(); + public ulong DoLocalPressedKeys() + { + return mPlayMode.DoLocalPressedKeys(); } #region - public void SetRePlay(bool IsReplay) - { - bReplayMode = IsReplay; - } - public void Init(bool IsReplay) + public void Init() { - bReplayMode = IsReplay; mPlayMode = new PlayMode(this); - mReplayMode = new ReplayMode(); } public static IEnumerable GetInputpDataToMotionKey(ulong inputdata) @@ -80,41 +71,7 @@ public class UniKeyboard : MonoBehaviour, IKeyboard return CurrLocalInpuAllData; } - public bool SampleInput() - { - //Net模式 - if (InGameUI.Instance.IsNetPlay) - { - bool bHadNetData = false; - int targetFrame; ReplayStep replayData; int frameDiff; bool inputDiff; - if (App.roomMgr.netReplay.TryGetNextFrame((int)UMAME.instance.Frame, out replayData, out frameDiff, out inputDiff)) - { - if (inputDiff) - { - App.log.Debug($"{DateTime.Now.ToString("hh:mm:ss.fff")} TryGetNextFrame remoteFrame->{App.roomMgr.netReplay.mRemoteFrameIdx} diff->{frameDiff} " + - $"frame=>{replayData.FrameStartID} InPut=>{replayData.InPut}"); - } - CurrRemoteInpuAllData = replayData.InPut; - - bHadNetData = true; - } - else//无输入 - { - CurrRemoteInpuAllData = 0; - } - //发送本地操作 - App.roomMgr.SendRoomSingelPlayerInput(UMAME.instance.Frame, DoLocalPressedKeys()); - return bHadNetData; - } - //单人模式 - else - { - DoLocalPressedKeys(); - return true; - } - } - - ulong DoLocalPressedKeys() + public ulong DoLocalPressedKeys() { ulong tempLocalInputAllData = 0; tempLocalInputAllData |= mUniKeyboard.ControllerMapper.Controller0.GetSingleAllInput(); diff --git a/AxibugEmuOnline.Client/Assets/Script/AppMain/Emulator/StoicGooseEmulator/UStoicGoose.cs b/AxibugEmuOnline.Client/Assets/Script/AppMain/Emulator/StoicGooseEmulator/UStoicGoose.cs index 469b7ed0..7ec435cb 100644 --- a/AxibugEmuOnline.Client/Assets/Script/AppMain/Emulator/StoicGooseEmulator/UStoicGoose.cs +++ b/AxibugEmuOnline.Client/Assets/Script/AppMain/Emulator/StoicGooseEmulator/UStoicGoose.cs @@ -1,6 +1,7 @@ using AxibugEmuOnline.Client; using AxibugEmuOnline.Client.ClientCore; using AxibugProtobuf; +using AxiReplay; using StoicGoose.Common.Utilities; using StoicGoose.Core.Machines; using System; @@ -11,7 +12,7 @@ using UnityEngine; using UnityEngine.UI; using CartridgeMetadata = StoicGoose.Core.Cartridges.Metadata; -public class UStoicGoose : IEmuCore +public class UStoicGoose : EmuCore { public static UStoicGoose instance; public static System.Diagnostics.Stopwatch sw = System.Diagnostics.Stopwatch.StartNew(); @@ -124,11 +125,25 @@ public class UStoicGoose : IEmuCore { throw new NotImplementedException(); } - - public override bool PushEmulatorFrame() - { - throw new NotImplementedException(); - } + protected override bool OnPushEmulatorFrame(ulong InputData) + { + throw new NotImplementedException(); + } + + protected override ulong ConvertInputDataFromNet(ReplayStep step) + { + return step.InPut; + } + + protected override ulong InputDataToNet(ulong inputData) + { + return inputData; + } + + protected override ulong GetLocalInput() + { + throw new NotImplementedException(); + } public override void AfterPushFrame() {