时间计数
This commit is contained in:
parent
fb463f9bc2
commit
aa984889d9
@ -5,6 +5,7 @@ using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
@ -30,10 +31,12 @@ public class UMAME : MonoBehaviour
|
||||
public Dictionary<string, RomInfo> ALLGame;
|
||||
public List<RomInfo> HadGameList = new List<RomInfo>();
|
||||
string mChangeRomName = string.Empty;
|
||||
public UniTimeSpan mTimeSpan;
|
||||
public bool bQuickTestRom = false;
|
||||
public string mQuickTestRom = string.Empty;
|
||||
public ReplayWriter mReplayWriter;
|
||||
public ReplayReader mReplayReader;
|
||||
public long currEmuFrame => emu.currEmuFrame;
|
||||
|
||||
Dropdown optionDropdown;
|
||||
|
||||
@ -70,8 +73,9 @@ public class UMAME : MonoBehaviour
|
||||
mUniKeyboard = this.gameObject.AddComponent<UniKeyboard>();
|
||||
mUniResources = new UniResources();
|
||||
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();
|
||||
|
||||
Debug.Log($"ALLGame:{ALLGame.Count}");
|
||||
@ -106,6 +110,8 @@ public class UMAME : MonoBehaviour
|
||||
|
||||
void LoadGame(bool bReplay = false)
|
||||
{
|
||||
Application.targetFrameRate = 60;
|
||||
|
||||
mReplayWriter = new ReplayWriter(mChangeRomName, "fuck", ReplayData.ReplayFormat.FM32IP64, Encoding.UTF8);
|
||||
mChangeRomName = HadGameList[optionDropdown.value].Name;
|
||||
UniMAMESetting.instance.LastGameRom = mChangeRomName;
|
||||
@ -137,10 +143,19 @@ public class UMAME : MonoBehaviour
|
||||
Debug.Log($"ROM¼ÓÔØʧ°Ü");
|
||||
}
|
||||
}
|
||||
private void Update()
|
||||
|
||||
void Update()
|
||||
{
|
||||
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))
|
||||
{
|
||||
SaveReplay();
|
||||
|
@ -16,12 +16,30 @@ public class KeyCodeCore : IKeyboard
|
||||
bool bReplayMode;
|
||||
List<MotionKey> ReplayCheckKey = new List<MotionKey>();
|
||||
|
||||
ulong last_CurryInpuAllData_test = 0;
|
||||
|
||||
public MotionKey[] GetPressedKeys()
|
||||
{
|
||||
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);
|
||||
|
||||
#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;
|
||||
}
|
||||
else
|
||||
@ -39,17 +57,21 @@ public class KeyCodeCore : IKeyboard
|
||||
temp.Add(ReplayCheckKey[i]);
|
||||
}
|
||||
mCurrKey = temp.ToArray();
|
||||
}
|
||||
|
||||
|
||||
#if UNITY_EDITOR
|
||||
string TempStr = "";
|
||||
foreach (var item in mCurrKey)
|
||||
{
|
||||
TempStr += $"{item.ToString()}|";
|
||||
}
|
||||
if (!string.IsNullOrEmpty(TempStr))
|
||||
Debug.Log($"Input-》{CurryInpuAllData} => {TempStr}");
|
||||
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;
|
||||
}
|
||||
}
|
||||
@ -66,9 +88,8 @@ public class KeyCodeCore : IKeyboard
|
||||
{
|
||||
ReplayCheckKey.Add(mkey);
|
||||
}
|
||||
|
||||
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.Alpha5, MotionKey.P1_INSERT_COIN);
|
||||
dictKeyCfgs.Add(KeyCode.W, MotionKey.P1_UP);
|
||||
|
@ -66,11 +66,8 @@ public class UniKeyboard : MonoBehaviour
|
||||
mKeyCodeCore.Init(this,false);
|
||||
}
|
||||
|
||||
void OnEnable()
|
||||
{
|
||||
}
|
||||
|
||||
void Update()
|
||||
public void UpdateInputKey()
|
||||
{
|
||||
mKeyCodeCore.UpdateLogic();
|
||||
}
|
||||
|
41
MAME.Unity/Assets/Script/UMAME/UniInterface/UniTimeSpan.cs
Normal file
41
MAME.Unity/Assets/Script/UMAME/UniInterface/UniTimeSpan.cs
Normal 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;
|
||||
}
|
||||
}
|
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: a35bf49414a7b194eb8d359004336a8c
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@ -72,6 +72,7 @@ public class UniVideoPlayer : MonoBehaviour, IVideoPlayer
|
||||
public void SubmitVideo(int[] data, long frame_number)
|
||||
{
|
||||
mFrame = (ulong)frame_number;
|
||||
UMAME.instance.mTimeSpan.SetTick(mFrame);
|
||||
var current = UMAME.sw.Elapsed;
|
||||
var delta = current - lastElapsed;
|
||||
lastElapsed = current;
|
||||
|
Loading…
Reference in New Issue
Block a user