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.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<ulong>
{
public static UEssgee instance;
public static System.Diagnostics.Stopwatch sw = System.Diagnostics.Stopwatch.StartNew();
@ -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;
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()
{
}

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 };
}
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++)

View File

@ -9,7 +9,7 @@ using System.Text;
using UnityEngine;
using UnityEngine.UI;
public class UMAME : IEmuCore
public class UMAME : EmuCore<ulong>
{
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();
//推帧
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}");

View File

@ -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();
}
public void SyncInput(ulong inputData)
{
mPlayMode.CurrLocalInpuAllData = inputData;
}
public bool SampleInput()
public ulong DoLocalPressedKeys()
{
if (bReplayMode) return true;
return mPlayMode.SampleInput();
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<string> 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();

View File

@ -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<ulong>
{
public static UStoicGoose instance;
public static System.Diagnostics.Stopwatch sw = System.Diagnostics.Stopwatch.StartNew();
@ -124,8 +125,22 @@ public class UStoicGoose : IEmuCore
{
throw new NotImplementedException();
}
protected override bool OnPushEmulatorFrame(ulong InputData)
{
throw new NotImplementedException();
}
public override bool PushEmulatorFrame()
protected override ulong ConvertInputDataFromNet(ReplayStep step)
{
return step.InPut;
}
protected override ulong InputDataToNet(ulong inputData)
{
return inputData;
}
protected override ulong GetLocalInput()
{
throw new NotImplementedException();
}