emucore基类替换

This commit is contained in:
ALIENJACK\alien 2025-04-30 15:41:20 +08:00
parent ace77987e4
commit cc57a1e0df
5 changed files with 85 additions and 136 deletions

View File

@ -1,6 +1,7 @@
using AxibugEmuOnline.Client; using AxibugEmuOnline.Client;
using AxibugEmuOnline.Client.ClientCore; using AxibugEmuOnline.Client.ClientCore;
using AxibugProtobuf; using AxibugProtobuf;
using AxiReplay;
using Essgee; using Essgee;
using Essgee.Emulation; using Essgee.Emulation;
using Essgee.Emulation.Configuration; using Essgee.Emulation.Configuration;
@ -11,13 +12,12 @@ using Essgee.Metadata;
using Essgee.Utilities; using Essgee.Utilities;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Drawing;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
using UnityEngine; using UnityEngine;
using UnityEngine.UI; using UnityEngine.UI;
public class UEssgee : IEmuCore public class UEssgee : EmuCore<ulong>
{ {
public static UEssgee instance; public static UEssgee instance;
public static System.Diagnostics.Stopwatch sw = System.Diagnostics.Stopwatch.StartNew(); public static System.Diagnostics.Stopwatch sw = System.Diagnostics.Stopwatch.StartNew();
@ -125,7 +125,7 @@ public class UEssgee : IEmuCore
public override void Dispose() public override void Dispose()
{ {
if (!emulatorHandler.IsRunning) if (!emulatorHandler.IsRunning)
{ {
emulatorHandler.SaveCartridge(); emulatorHandler.SaveCartridge();
} }
ShutdownEmulation(); ShutdownEmulation();
@ -141,21 +141,32 @@ public class UEssgee : IEmuCore
{ {
return mUniKeyboard.ControllerMapper; return mUniKeyboard.ControllerMapper;
} }
protected override bool OnPushEmulatorFrame(ulong InputData)
public override bool PushEmulatorFrame() {
{
if (!emulatorHandler.IsRunning) return false; if (!emulatorHandler.IsRunning) return false;
if (!bLogicUpdatePause) return false; if (!bLogicUpdatePause) return false;
//采集本帧Input mUniKeyboard.SetCurrKeyArr(InputData);
bool bhadNext = mUniKeyboard.SampleInput(); emulatorHandler.Update_Frame();
//如果未收到Input数据,核心帧不推进
if (!bhadNext) return false; return true;
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() public override void AfterPushFrame()
{ {
} }

View File

@ -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 }; //mUniKeyboard.btnABC.Key = new long[] { (long)MotionKey.P1_BTN_1, (long)MotionKey.P1_BTN_2, (long)MotionKey.P1_BTN_3 };
} }
public bool SampleInput() public void SetCurrKeyArr(ulong inputData)
{
//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)
{ {
temp.Clear(); temp.Clear();
for (int i = 0; i < CheckList.Length; i++) for (int i = 0; i < CheckList.Length; i++)
@ -368,7 +330,7 @@ public class UEGKeyboard : MonoBehaviour
mCurrKey = temp.ToArray(); mCurrKey = temp.ToArray();
} }
ulong DoLocalPressedKeys() public ulong DoLocalPressedKeys()
{ {
//tempInputAllData = 0; //tempInputAllData = 0;
//for (int i = 0; i < CheckList.Length; i++) //for (int i = 0; i < CheckList.Length; i++)

View File

@ -9,7 +9,7 @@ using System.Text;
using UnityEngine; using UnityEngine;
using UnityEngine.UI; using UnityEngine.UI;
public class UMAME : IEmuCore public class UMAME : EmuCore<ulong>
{ {
public static UMAME instance { get; private set; } public static UMAME instance { get; private set; }
public MAMEEmu emu { get; private set; } public MAMEEmu emu { get; private set; }
@ -95,7 +95,7 @@ public class UMAME : IEmuCore
{ {
mPlatform = romFile.Platform; mPlatform = romFile.Platform;
mTimeSpan.InitStandTime(); mTimeSpan.InitStandTime();
if (LoadGame(romFile.FileName, false)) if (LoadGame(romFile.FileName))
return true; return true;
else else
return "Rom加载失败"; return "Rom加载失败";
@ -107,7 +107,7 @@ public class UMAME : IEmuCore
public override void DoReset() public override void DoReset()
{ {
StopGame(); StopGame();
LoadGame(mChangeRomName, false); LoadGame(mChangeRomName);
} }
public override IControllerSetuper GetControllerSetuper() public override IControllerSetuper GetControllerSetuper()
{ {
@ -121,7 +121,7 @@ public class UMAME : IEmuCore
} }
#endregion #endregion
bool LoadGame(string loadRom, bool bReplay = false) bool LoadGame(string loadRom)
{ {
emu.ResetRomRoot(RomPath); emu.ResetRomRoot(RomPath);
//Application.targetFrameRate = 60; //Application.targetFrameRate = 60;
@ -133,12 +133,6 @@ public class UMAME : IEmuCore
//读取成功 //读取成功
if (emu.bRom) if (emu.bRom)
{ {
if (bReplay)
{
string Path = SavePath + Machine.sName + ".rp";
mReplayReader = new ReplayReader(Path);
mUniKeyboard.SetRePlay(true);
}
//读取ROM之后获得宽高初始化画面 //读取ROM之后获得宽高初始化画面
int _width; int _height; IntPtr _framePtr; int _width; int _height; IntPtr _framePtr;
@ -159,22 +153,32 @@ public class UMAME : IEmuCore
return false; return false;
} }
} }
protected override bool OnPushEmulatorFrame(ulong InputData)
public override bool PushEmulatorFrame()
{ {
if (!bInGame) return false; if (!bInGame) return false;
if (!bLogicUpdatePause) return false; if (!bLogicUpdatePause) return false;
//采集本帧Input mUniKeyboard.SyncInput(InputData);
bool bhadNext = mUniKeyboard.SampleInput(); emu.UpdateFrame();
//如果未收到Input数据,核心帧不推进
if (!bhadNext) return false; return true;
//放行下一帧
//emu.UnlockNextFreme();
//推帧
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() 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}"); 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}");

View File

@ -12,43 +12,34 @@ using UnityEngine;
public class UniKeyboard : MonoBehaviour, IKeyboard public class UniKeyboard : MonoBehaviour, IKeyboard
{ {
public MameControllerMapper ControllerMapper { get; private set; } public MameControllerMapper ControllerMapper { get; private set; }
bool bReplayMode;
PlayMode mPlayMode; PlayMode mPlayMode;
ReplayMode mReplayMode;
void Awake() void Awake()
{ {
ControllerMapper = new MameControllerMapper(); ControllerMapper = new MameControllerMapper();
Init(false); Init();
} }
public ulong GetPressedKeys() public ulong GetPressedKeys()
{ {
ulong InputData; return mPlayMode.GetPressedKeys();
if (!bReplayMode)//游玩模式(单机或联机) }
return mPlayMode.GetPressedKeys(); public void SyncInput(ulong inputData)
else//Replay模式 {
return mReplayMode.GetPressedKeys(); mPlayMode.CurrLocalInpuAllData = inputData;
} }
public bool SampleInput() public ulong DoLocalPressedKeys()
{ {
if (bReplayMode) return true; return mPlayMode.DoLocalPressedKeys();
return mPlayMode.SampleInput();
} }
#region #region
public void SetRePlay(bool IsReplay)
{
bReplayMode = IsReplay;
}
public void Init(bool IsReplay) public void Init()
{ {
bReplayMode = IsReplay;
mPlayMode = new PlayMode(this); mPlayMode = new PlayMode(this);
mReplayMode = new ReplayMode();
} }
public static IEnumerable<string> GetInputpDataToMotionKey(ulong inputdata) public static IEnumerable<string> GetInputpDataToMotionKey(ulong inputdata)
@ -80,41 +71,7 @@ public class UniKeyboard : MonoBehaviour, IKeyboard
return CurrLocalInpuAllData; return CurrLocalInpuAllData;
} }
public bool SampleInput() public ulong DoLocalPressedKeys()
{
//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()
{ {
ulong tempLocalInputAllData = 0; ulong tempLocalInputAllData = 0;
tempLocalInputAllData |= mUniKeyboard.ControllerMapper.Controller0.GetSingleAllInput(); tempLocalInputAllData |= mUniKeyboard.ControllerMapper.Controller0.GetSingleAllInput();

View File

@ -1,6 +1,7 @@
using AxibugEmuOnline.Client; using AxibugEmuOnline.Client;
using AxibugEmuOnline.Client.ClientCore; using AxibugEmuOnline.Client.ClientCore;
using AxibugProtobuf; using AxibugProtobuf;
using AxiReplay;
using StoicGoose.Common.Utilities; using StoicGoose.Common.Utilities;
using StoicGoose.Core.Machines; using StoicGoose.Core.Machines;
using System; using System;
@ -11,7 +12,7 @@ using UnityEngine;
using UnityEngine.UI; using UnityEngine.UI;
using CartridgeMetadata = StoicGoose.Core.Cartridges.Metadata; using CartridgeMetadata = StoicGoose.Core.Cartridges.Metadata;
public class UStoicGoose : IEmuCore public class UStoicGoose : EmuCore<ulong>
{ {
public static UStoicGoose instance; public static UStoicGoose instance;
public static System.Diagnostics.Stopwatch sw = System.Diagnostics.Stopwatch.StartNew(); public static System.Diagnostics.Stopwatch sw = System.Diagnostics.Stopwatch.StartNew();
@ -124,11 +125,25 @@ public class UStoicGoose : IEmuCore
{ {
throw new NotImplementedException(); throw new NotImplementedException();
} }
protected override bool OnPushEmulatorFrame(ulong InputData)
public override bool PushEmulatorFrame() {
{ throw new NotImplementedException();
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() public override void AfterPushFrame()
{ {