This commit is contained in:
ALIENJACK\alien 2025-01-26 09:40:20 +08:00
commit 5ae970673a
7 changed files with 44 additions and 20 deletions

View File

@ -1,4 +1,5 @@
using System.Collections.Generic;
using UnityEngine;
namespace AxiReplay
{
@ -23,7 +24,7 @@ namespace AxiReplay
/// <summary>
/// 网络数据队列
/// </summary>
Queue<ReplayStep> mNetReplayQueue = new Queue<ReplayStep>();
public Queue<ReplayStep> mNetReplayQueue { get; private set; } = new Queue<ReplayStep>();
/// <summary>
/// 当前数据
/// </summary>
@ -45,9 +46,11 @@ namespace AxiReplay
mCurrReplay.FrameStartID = int.MinValue;
bNetInit = false;
}
public void InData(ReplayStep inputData, int ServerFrameIdx)
public void InData(ReplayStep inputData, int ServerFrameIdx, uint ServerForwardCount)
{
mRemoteForwardCount = (int)ServerForwardCount;
mNetReplayQueue.Enqueue(inputData);
Debug.Log($"InData=>{inputData.FrameStartID} QCount = >{mNetReplayQueue.Count}");
mRemoteFrameIdx = inputData.FrameStartID;
if (!bNetInit)
{
@ -89,8 +92,9 @@ namespace AxiReplay
bool TakeFrameToTargetFrame(int targetFrame, out ReplayStep data, out int bFrameDiff, out bool inputDiff)
{
bool result;
inputDiff = false;
if (targetFrame == mNextReplay.FrameStartID && targetFrame <= mRemoteFrameIdx && mNetReplayQueue.Count > 0)
inputDiff = false;
//if (targetFrame == mNextReplay.FrameStartID && targetFrame <= mRemoteFrameIdx && mNetReplayQueue.Count > 0)
if (targetFrame == mNextReplay.FrameStartID && targetFrame <= mRemoteFrameIdx && mNetReplayQueue.Count >= mRemoteForwardCount)
{
//当前帧追加
mCurrClientFrameIdx = targetFrame;
@ -112,7 +116,7 @@ namespace AxiReplay
public int GetSkipFrameCount()
{
if(!bNetInit)
if (!bNetInit)
return 0;
//本地队列差异高于服务器提前量的值
int moreNum = mDiffFrameCount - mRemoteForwardCount;
@ -125,13 +129,23 @@ namespace AxiReplay
int skip = 0;
if (mDiffFrameCount > short.MaxValue) skip = 0;
else if (moreNum <= 1) skip = 0;
else if (moreNum <= 3) skip = 2;
else if (moreNum <= 6) skip = 2;
else if (moreNum <= 20) skip = moreNum / 2; //20帧以内平滑跳帧数
else if (moreNum <= mRemoteForwardCount) skip = 0;
else if (moreNum <= mRemoteForwardCount + 2) skip = 0;
else if (moreNum <= mRemoteForwardCount + 5) skip = 1;
else if (moreNum <= mRemoteForwardCount + 6) skip = 2;
else if (moreNum <= mRemoteForwardCount + 20) skip = moreNum / 2; //20帧以内平滑跳帧数
else skip = moreNum;//完全追上
return skip;
//int skip = 0;
//if (mDiffFrameCount > short.MaxValue) skip = 0;
//else if (moreNum <= 1) skip = 0;
//else if (moreNum <= 3) skip = 2;
//else if (moreNum <= 6) skip = 2;
//else if (moreNum <= 20) skip = moreNum / 2; //20帧以内平滑跳帧数
//else skip = moreNum;//完全追上
//return skip;
//var frameGap = mDiffFrameCount;
//if (frameGap > 10000) return 0;
//if (frameGap <= 2) skip = 0;

View File

@ -46,6 +46,7 @@ namespace MAME.Core
Thread.Sleep(20);
State.loadstate_callback.Invoke(sr);
Mame.postload();
mameMainMotion.ResetFreameIndex();
Thread.Sleep(20);
Mame.paused = false;
}

View File

@ -289,6 +289,15 @@ namespace MAME.Core
}
}
public void ResetFreameIndex()
{
Mame.paused = true;
Thread.Sleep(20);
Video.screenstate.frame_number = 0;
Thread.Sleep(20);
Mame.paused = false;
}
private void itemSelect()
{
switch (Machine.sBoard)

View File

@ -262,9 +262,9 @@ RectTransform:
m_Father: {fileID: 3471319444171359701}
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_AnchorMin: {x: 0, y: 1}
m_AnchorMax: {x: 0, y: 1}
m_AnchoredPosition: {x: 454.963, y: -46.19702}
m_SizeDelta: {x: 871.1646, y: 70.007}
m_AnchorMax: {x: 1, y: 1}
m_AnchoredPosition: {x: 2.8257446, y: -46.19702}
m_SizeDelta: {x: -33.109863, y: 70.007}
m_Pivot: {x: 0.5, y: 0.5}
--- !u!222 &3471319444327146580
CanvasRenderer:
@ -296,10 +296,10 @@ MonoBehaviour:
m_Calls: []
m_FontData:
m_Font: {fileID: 10102, guid: 0000000000000000e000000000000000, type: 0}
m_FontSize: 41
m_FontSize: 18
m_FontStyle: 0
m_BestFit: 0
m_MinSize: 10
m_MinSize: 1
m_MaxSize: 107
m_Alignment: 0
m_AlignByGeometry: 0

View File

@ -163,8 +163,6 @@ public class UMAME : MonoBehaviour, IEmuCore
}
void Update()
{
mFPS.text = ($"fpsv {mUniVideoPlayer.videoFPS.ToString("F2")} fpsa {mUniSoundPlayer.audioFPS.ToString("F2")}");
if (!bInGame)
return;
@ -176,13 +174,15 @@ public class UMAME : MonoBehaviour, IEmuCore
}
mUniVideoPlayer.ApplyFilterEffect();
mUniVideoPlayer.ApplyScreenScaler();
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}");
}
//是否跳帧,单机无效
void FixEmulatorFrame()
{
var skipFrameCount = App.roomMgr.netReplay.GetSkipFrameCount();
if (skipFrameCount > 0) App.log.Debug($"SKIP FRAME : {skipFrameCount}");
if (skipFrameCount > 0) App.log.Debug($"SKIP FRAME : {skipFrameCount} ,CF:{App.roomMgr.netReplay.mCurrClientFrameIdx},RFIdx:{App.roomMgr.netReplay.mRemoteFrameIdx},RForward:{App.roomMgr.netReplay.mRemoteForwardCount} ,queue:{App.roomMgr.netReplay.mNetReplayQueue.Count}");
for (var i = 0; i < skipFrameCount; i++)
if (!PushEmulatorFrame())
break;

View File

@ -327,7 +327,7 @@ namespace AxibugEmuOnline.Client.Manager
{
UserDataBase newplayer = App.user.GetUserByUid(newJoin);
string newplayerName = newplayer != null ? newplayer.NickName : "Player";
OverlayManager.PopTip($"[{newplayer}]进入房间");
OverlayManager.PopTip($"[{newplayer.NickName}]进入房间");
Eventer.Instance.PostEvent(EEvent.OnOtherPlayerJoinRoom, newJoin);
}
@ -527,7 +527,7 @@ namespace AxibugEmuOnline.Client.Manager
TestAllData = msg.InputData;
App.log.Debug($"ServerFrameID->{msg.ServerFrameID} FrameID->{msg.FrameID} ClientFrame->{netReplay.mCurrClientFrameIdx} InputData->{msg.InputData}");
}
netReplay.InData(new ReplayStep() { FrameStartID = (int)msg.FrameID, InPut = msg.InputData }, (int)msg.ServerFrameID);
netReplay.InData(new ReplayStep() { FrameStartID = (int)msg.FrameID, InPut = msg.InputData }, (int)msg.ServerFrameID, msg.ServerForwardCount);
}
public void SendScreen(byte[] RenderBuffer)

View File

@ -83,7 +83,7 @@ namespace AxibugEmuOnline.Client.Network
{
//抛出网络数据
//网络线程直接抛
if (CMDID == (int)CommandID.CmdPing || CMDID == (int)CommandID.CmdPong)
if (CMDID <= (int)CommandID.CmdPong)
NetMsg.Instance.PostNetMsgEvent(CMDID, ERRCODE, data);
else//加入队列,主线程来取
NetMsg.Instance.EnqueueNesMsg(CMDID, ERRCODE, data);