时间计数

This commit is contained in:
sin365 2025-01-16 11:14:23 +08:00
parent fb463f9bc2
commit aa984889d9
6 changed files with 103 additions and 17 deletions

View File

@ -5,6 +5,7 @@ using System.Collections.Generic;
using System.IO; using System.IO;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
using System.Threading;
using UnityEngine; using UnityEngine;
using UnityEngine.UI; using UnityEngine.UI;
@ -30,10 +31,12 @@ public class UMAME : MonoBehaviour
public Dictionary<string, RomInfo> ALLGame; public Dictionary<string, RomInfo> ALLGame;
public List<RomInfo> HadGameList = new List<RomInfo>(); public List<RomInfo> HadGameList = new List<RomInfo>();
string mChangeRomName = string.Empty; string mChangeRomName = string.Empty;
public UniTimeSpan mTimeSpan;
public bool bQuickTestRom = false; public bool bQuickTestRom = false;
public string mQuickTestRom = string.Empty; public string mQuickTestRom = string.Empty;
public ReplayWriter mReplayWriter; public ReplayWriter mReplayWriter;
public ReplayReader mReplayReader; public ReplayReader mReplayReader;
public long currEmuFrame => emu.currEmuFrame;
Dropdown optionDropdown; Dropdown optionDropdown;
@ -70,8 +73,9 @@ public class UMAME : MonoBehaviour
mUniKeyboard = this.gameObject.AddComponent<UniKeyboard>(); mUniKeyboard = this.gameObject.AddComponent<UniKeyboard>();
mUniResources = new UniResources(); mUniResources = new UniResources();
mChangeRomName = UniMAMESetting.instance.LastGameRom; mChangeRomName = UniMAMESetting.instance.LastGameRom;
mTimeSpan = new UniTimeSpan();
emu.Init(RomPath, mUniLog, mUniResources, mUniVideoPlayer, mUniSoundPlayer, mUniKeyboard.mKeyCodeCore, mUniMouse); emu.Init(RomPath, mUniLog, mUniResources, mUniVideoPlayer, mUniSoundPlayer, mUniKeyboard.mKeyCodeCore, mUniMouse, mTimeSpan);
ALLGame = emu.GetGameList(); ALLGame = emu.GetGameList();
Debug.Log($"ALLGame:{ALLGame.Count}"); Debug.Log($"ALLGame:{ALLGame.Count}");
@ -106,6 +110,8 @@ public class UMAME : MonoBehaviour
void LoadGame(bool bReplay = false) void LoadGame(bool bReplay = false)
{ {
Application.targetFrameRate = 60;
mReplayWriter = new ReplayWriter(mChangeRomName, "fuck", ReplayData.ReplayFormat.FM32IP64, Encoding.UTF8); mReplayWriter = new ReplayWriter(mChangeRomName, "fuck", ReplayData.ReplayFormat.FM32IP64, Encoding.UTF8);
mChangeRomName = HadGameList[optionDropdown.value].Name; mChangeRomName = HadGameList[optionDropdown.value].Name;
UniMAMESetting.instance.LastGameRom = mChangeRomName; UniMAMESetting.instance.LastGameRom = mChangeRomName;
@ -137,10 +143,19 @@ public class UMAME : MonoBehaviour
Debug.Log($"ROM¼ÓÔØʧ°Ü"); Debug.Log($"ROM¼ÓÔØʧ°Ü");
} }
} }
private void Update()
void Update()
{ {
mFPS.text = ($"fpsv {mUniVideoPlayer.videoFPS.ToString("F2")} fpsa {mUniSoundPlayer.audioFPS.ToString("F2")}"); mFPS.text = ($"fpsv {mUniVideoPlayer.videoFPS.ToString("F2")} fpsa {mUniSoundPlayer.audioFPS.ToString("F2")}");
if (!bInGame)
return;
//采集本帧Input
mUniKeyboard.UpdateInputKey();
//放行下一帧
emu.UnlockNextFreme();
if (Input.GetKeyDown(KeyCode.F1)) if (Input.GetKeyDown(KeyCode.F1))
{ {
SaveReplay(); SaveReplay();

View File

@ -16,12 +16,30 @@ public class KeyCodeCore : IKeyboard
bool bReplayMode; bool bReplayMode;
List<MotionKey> ReplayCheckKey = new List<MotionKey>(); List<MotionKey> ReplayCheckKey = new List<MotionKey>();
ulong last_CurryInpuAllData_test = 0;
public MotionKey[] GetPressedKeys() public MotionKey[] GetPressedKeys()
{ {
if (!bReplayMode) if (!bReplayMode)
{ {
//UMAME.instance.mReplayWriter.NextFrame(CurryInpuAllData); //UMAME.instance.mReplayWriter.NextFramebyFrameIdx((int)UMAME.instance.mUniVideoPlayer.mFrame, CurryInpuAllData);
UMAME.instance.mReplayWriter.NextFramebyFrameIdx((int)UMAME.instance.mUniVideoPlayer.mFrame, CurryInpuAllData); UMAME.instance.mReplayWriter.NextFramebyFrameIdx((int)UMAME.instance.mUniVideoPlayer.mFrame, CurryInpuAllData);
#if UNITY_EDITOR
if (last_CurryInpuAllData_test != CurryInpuAllData)
{
last_CurryInpuAllData_test = CurryInpuAllData;
string TempStr = "";
foreach (var item in mCurrKey)
{
TempStr += $"{item.ToString()}|";
}
if (!string.IsNullOrEmpty(TempStr))
Debug.Log($"{UMAME.instance.mUniVideoPlayer.mFrame} | Input-> {TempStr}");
else
Debug.Log($"{UMAME.instance.mUniVideoPlayer.mFrame} | Input-> 0");
}
#endif
return mCurrKey; return mCurrKey;
} }
else else
@ -39,7 +57,7 @@ public class KeyCodeCore : IKeyboard
temp.Add(ReplayCheckKey[i]); temp.Add(ReplayCheckKey[i]);
} }
mCurrKey = temp.ToArray(); mCurrKey = temp.ToArray();
}
#if UNITY_EDITOR #if UNITY_EDITOR
string TempStr = ""; string TempStr = "";
@ -48,8 +66,12 @@ public class KeyCodeCore : IKeyboard
TempStr += $"{item.ToString()}|"; TempStr += $"{item.ToString()}|";
} }
if (!string.IsNullOrEmpty(TempStr)) if (!string.IsNullOrEmpty(TempStr))
Debug.Log($"Input-》{CurryInpuAllData} => {TempStr}"); Debug.Log($"{UMAME.instance.mUniVideoPlayer.mFrame} | Input-> {TempStr}");
else
Debug.Log($"{UMAME.instance.mUniVideoPlayer.mFrame} | Input-> 0");
#endif #endif
}
return mCurrKey; return mCurrKey;
} }
} }
@ -66,9 +88,8 @@ public class KeyCodeCore : IKeyboard
{ {
ReplayCheckKey.Add(mkey); ReplayCheckKey.Add(mkey);
} }
dictKeyCfgs.Clear(); dictKeyCfgs.Clear();
dictKeyCfgs.Add(KeyCode.P, MotionKey.EMU_PAUSED); //dictKeyCfgs.Add(KeyCode.P, MotionKey.EMU_PAUSED);
dictKeyCfgs.Add(KeyCode.Alpha1, MotionKey.P1_GAMESTART); dictKeyCfgs.Add(KeyCode.Alpha1, MotionKey.P1_GAMESTART);
dictKeyCfgs.Add(KeyCode.Alpha5, MotionKey.P1_INSERT_COIN); dictKeyCfgs.Add(KeyCode.Alpha5, MotionKey.P1_INSERT_COIN);
dictKeyCfgs.Add(KeyCode.W, MotionKey.P1_UP); dictKeyCfgs.Add(KeyCode.W, MotionKey.P1_UP);

View File

@ -66,11 +66,8 @@ public class UniKeyboard : MonoBehaviour
mKeyCodeCore.Init(this,false); mKeyCodeCore.Init(this,false);
} }
void OnEnable()
{
}
void Update() public void UpdateInputKey()
{ {
mKeyCodeCore.UpdateLogic(); mKeyCodeCore.UpdateLogic();
} }

View File

@ -0,0 +1,41 @@
using MAME.Core;
public class UniTimeSpan : ITimeSpan
{
public ulong tick;
double tickDetailus = 16666.666667;
object tickLock = new object();
public void SetTick(ulong nexttick)
{
//lock (tickLock)
{
tick = nexttick;
}
}
//Õâ¸öº¯ÊýÎÞÒâÒå
public uint GetTickCount()
{
//lock (tickLock)
{
//return (uint)(tick * tickDetail);
return 0;
}
}
public bool QueryPerformanceCounter(ref long lpPerformanceCount)
{
lock (tickLock)
{
lpPerformanceCount = (long)tick;
return true;
}
}
public bool QueryPerformanceFrequency(ref long PerformanceFrequency)
{
PerformanceFrequency = (long)(1000000 / tickDetailus);
return true;
}
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: a35bf49414a7b194eb8d359004336a8c
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -72,6 +72,7 @@ public class UniVideoPlayer : MonoBehaviour, IVideoPlayer
public void SubmitVideo(int[] data, long frame_number) public void SubmitVideo(int[] data, long frame_number)
{ {
mFrame = (ulong)frame_number; mFrame = (ulong)frame_number;
UMAME.instance.mTimeSpan.SetTick(mFrame);
var current = UMAME.sw.Elapsed; var current = UMAME.sw.Elapsed;
var delta = current - lastElapsed; var delta = current - lastElapsed;
lastElapsed = current; lastElapsed = current;