Compare commits

..

No commits in common. "62c6854172bbd642fa5f1b1ef12b248e656df3d1" and "0813e4af5d15c7014f19c6df9b4a3fcf82a18cfa" have entirely different histories.

7 changed files with 61 additions and 203 deletions

View File

@ -1,55 +0,0 @@
using System;
using System.Diagnostics;
namespace AxiReplay
{
public partial class FrameProfiler
{
private int m_headFrame;
private int m_cacheCount;
private int m_targetFrameRate;
private RingBuffer<double> m_timePoints;
private double m_lastTime;
private Stopwatch sw;
public void InputHead(int headFrame)
{
m_headFrame = headFrame;
var currentTimeMs = GetCurrTime();
if (m_timePoints.Available() == 60)
CalcCacheCount();
m_timePoints.Write(currentTimeMs - m_lastTime);
m_lastTime = currentTimeMs;
}
public void Reset(int targetFrameRate = 60)
{
if (sw != null) sw.Stop();
sw = Stopwatch.StartNew();
m_timePoints = new RingBuffer<double>(targetFrameRate);
m_lastTime = 0;
m_targetFrameRate = targetFrameRate;
}
void CalcCacheCount()
{
double deltaMax = 0;
while (m_timePoints.TryRead(out double delta))
{
deltaMax = Math.Max(deltaMax, delta);
}
int minCacheCount = (int)Math.Ceiling(deltaMax * m_targetFrameRate);
m_cacheCount = minCacheCount;
}
double GetCurrTime()
{
if (sw == null) return 0;
return sw.Elapsed.TotalMilliseconds;
}
}
}

View File

@ -1,2 +0,0 @@
fileFormatVersion: 2
guid: cfd4511a83ff0bf4ea7615b87e7d09aa

View File

@ -1,78 +0,0 @@
using System.Threading;
namespace AxiReplay
{
public partial class FrameProfiler
{
internal class RingBuffer<T>
{
private readonly T[] buffer;
private readonly int capacity;
private int writePos;
private int readPos;
private int count;
public RingBuffer(int capacity)
{
this.capacity = capacity;
this.buffer = new T[capacity];
this.writePos = 0;
this.readPos = 0;
this.count = 0;
}
public void Write(T item)
{
int localWritePos;
int localReadPos;
do
{
localWritePos = Volatile.Read(ref writePos);
localReadPos = Volatile.Read(ref readPos);
int nextWritePos = (localWritePos + 1) % capacity;
if (nextWritePos == localReadPos)
{
// 缓冲区已满,覆盖最旧的未读数据
Interlocked.CompareExchange(ref readPos, (localReadPos + 1) % capacity, localReadPos);
}
}
while (Interlocked.CompareExchange(ref writePos, (localWritePos + 1) % capacity, localWritePos) != localWritePos);
buffer[localWritePos] = item;
Interlocked.Increment(ref count);
}
public bool TryRead(out T item)
{
item = default(T);
int localReadPos;
int localWritePos;
do
{
localReadPos = Volatile.Read(ref readPos);
localWritePos = Volatile.Read(ref writePos);
if (localReadPos == localWritePos)
{
return false; // 缓冲区为空
}
}
while (Interlocked.CompareExchange(ref readPos, (localReadPos + 1) % capacity, localReadPos) != localReadPos);
item = buffer[localReadPos];
Interlocked.Decrement(ref count);
return true;
}
public int Available()
{
return Volatile.Read(ref count);
}
}
}
}

View File

@ -1,2 +0,0 @@
fileFormatVersion: 2
guid: b17d83b69bd47094594c32fcff9715f4

View File

@ -34,8 +34,6 @@ namespace AxiReplay
/// </summary> /// </summary>
ReplayStep mNextReplay; ReplayStep mNextReplay;
FrameProfiler frameProfiler = new FrameProfiler();
bool bNetInit = false; bool bNetInit = false;
public NetReplay() public NetReplay()
{ {
@ -47,8 +45,6 @@ namespace AxiReplay
mCurrReplay = default(ReplayStep); mCurrReplay = default(ReplayStep);
mCurrReplay.FrameStartID = int.MinValue; mCurrReplay.FrameStartID = int.MinValue;
bNetInit = false; bNetInit = false;
frameProfiler.Reset();
} }
public void InData(ReplayStep inputData, int ServerFrameIdx, uint ServerForwardCount) public void InData(ReplayStep inputData, int ServerFrameIdx, uint ServerForwardCount)
{ {
@ -61,10 +57,7 @@ namespace AxiReplay
bNetInit = true; bNetInit = true;
mNextReplay = mNetReplayQueue.Dequeue(); mNextReplay = mNetReplayQueue.Dequeue();
} }
frameProfiler.InputHead(inputData.FrameStartID);
} }
public bool TryGetNextFrame(out ReplayStep data, out int frameDiff, out bool inputDiff) public bool TryGetNextFrame(out ReplayStep data, out int frameDiff, out bool inputDiff)
{ {
if (!bNetInit) if (!bNetInit)
@ -100,15 +93,13 @@ namespace AxiReplay
{ {
bool result; bool result;
inputDiff = false; inputDiff = false;
//if (targetFrame == mNextReplay.FrameStartID && targetFrame <= mRemoteFrameIdx && mNetReplayQueue.Count > 0) //if (targetFrame == mNextReplay.FrameStartID && targetFrame <= mRemoteFrameIdx && mNetReplayQueue.Count > 0)
if (targetFrame == mNextReplay.FrameStartID && targetFrame <= mRemoteFrameIdx && mNetReplayQueue.Count >= mRemoteForwardCount) if (targetFrame == mNextReplay.FrameStartID && targetFrame <= mRemoteFrameIdx && mNetReplayQueue.Count >= mRemoteForwardCount)
{ {
//当前帧追加 //当前帧追加
mCurrClientFrameIdx = targetFrame; mCurrClientFrameIdx = targetFrame;
ulong oldInput = mCurrReplay.InPut; ulong oldInput = mCurrReplay.InPut;
mCurrReplay = mNextReplay; mCurrReplay = mNextReplay;
if (oldInput != mCurrReplay.InPut) if (oldInput != mCurrReplay.InPut)
inputDiff = true; inputDiff = true;
mNextReplay = mNetReplayQueue.Dequeue(); mNextReplay = mNetReplayQueue.Dequeue();

View File

@ -47,7 +47,7 @@ public class UMAME : MonoBehaviour, IEmuCore
//设为60帧 //设为60帧
Application.targetFrameRate = 60; Application.targetFrameRate = 120;
// 强制横屏 // 强制横屏
Screen.orientation = ScreenOrientation.LandscapeLeft; Screen.orientation = ScreenOrientation.LandscapeLeft;
instance = this; instance = this;

View File

@ -331,6 +331,7 @@ namespace AxibugEmuOnline.Client.Manager
Eventer.Instance.PostEvent(EEvent.OnOtherPlayerJoinRoom, newJoin); Eventer.Instance.PostEvent(EEvent.OnOtherPlayerJoinRoom, newJoin);
} }
bool bChangeSlot = false;
for (int i = 0; i < 4; i++) for (int i = 0; i < 4; i++)
{ {
var oldSlot = oldslotArr[i]; var oldSlot = oldslotArr[i];
@ -343,65 +344,68 @@ namespace AxibugEmuOnline.Client.Manager
oldSlot.PlayerLocalJoyIdx != newSlot.PlayerLocalJoyIdx oldSlot.PlayerLocalJoyIdx != newSlot.PlayerLocalJoyIdx
) )
{ {
bChangeSlot = true;
if (newSlot.PlayerUID > 0) if (newSlot.PlayerUID > 0)
{ {
OverlayManager.PopTip($"[{newSlot.PlayerNickName}]使用:P{i}"); OverlayManager.PopTip($"[{newSlot.PlayerNickName}]使用:P{i}");
} }
} }
} }
Eventer.Instance.PostEvent(EEvent.OnRoomSlotDataChanged); if (bChangeSlot)
{
Eventer.Instance.PostEvent(EEvent.OnRoomSlotDataChanged);
//for (int i = 0; i < 4; i++) }
//{
// long OldPlayer = oldRoomPlayer[i]; //for (int i = 0; i < 4; i++)
// long NewPlayer = newRoomPlayer[i]; //{
// if (OldPlayer == NewPlayer) // long OldPlayer = oldRoomPlayer[i];
// continue; // long NewPlayer = newRoomPlayer[i];
// if (OldPlayer == NewPlayer)
// //位置之前有人,但是离开了 // continue;
// if (OldPlayer > 0)
// { // //位置之前有人,但是离开了
// Eventer.Instance.PostEvent(EEvent.OnOtherPlayerLeavnRoom, i, OldPlayer); // if (OldPlayer > 0)
// UserDataBase oldplayer = App.user.GetUserByUid(OldPlayer); // {
// string oldPlayName = oldplayer != null ? oldplayer.NickName : "Player"; // Eventer.Instance.PostEvent(EEvent.OnOtherPlayerLeavnRoom, i, OldPlayer);
// OverlayManager.PopTip($"[{oldPlayName}]离开房间,手柄位:P{i}"); // UserDataBase oldplayer = App.user.GetUserByUid(OldPlayer);
// if (NewPlayer > 0)//而且害换了一个玩家 // string oldPlayName = oldplayer != null ? oldplayer.NickName : "Player";
// { // OverlayManager.PopTip($"[{oldPlayName}]离开房间,手柄位:P{i}");
// Eventer.Instance.PostEvent(EEvent.OnOtherPlayerJoinRoom, i, NewPlayer); // if (NewPlayer > 0)//而且害换了一个玩家
// mineRoomMiniInfo.GetPlayerNameByPlayerIdx((uint)i, out string PlayerName); // {
// OverlayManager.PopTip($"[{PlayerName}]进入房间,手柄位:P{i}"); // Eventer.Instance.PostEvent(EEvent.OnOtherPlayerJoinRoom, i, NewPlayer);
// } // mineRoomMiniInfo.GetPlayerNameByPlayerIdx((uint)i, out string PlayerName);
// } // OverlayManager.PopTip($"[{PlayerName}]进入房间,手柄位:P{i}");
// else //之前没人 // }
// { // }
// Eventer.Instance.PostEvent(EEvent.OnOtherPlayerJoinRoom, i, NewPlayer); // else //之前没人
// mineRoomMiniInfo.GetPlayerNameByPlayerIdx((uint)i, out string PlayerName); // {
// OverlayManager.PopTip($"[{PlayerName}]进入房间,手柄位:P{i}"); // Eventer.Instance.PostEvent(EEvent.OnOtherPlayerJoinRoom, i, NewPlayer);
// } // mineRoomMiniInfo.GetPlayerNameByPlayerIdx((uint)i, out string PlayerName);
// OverlayManager.PopTip($"[{PlayerName}]进入房间,手柄位:P{i}");
// //位置之前有人,但是离开了 // }
// if (OldPlayer > 0)
// { // //位置之前有人,但是离开了
// Eventer.Instance.PostEvent(EEvent.OnOtherPlayerLeavnRoom, i, OldPlayer); // if (OldPlayer > 0)
// UserDataBase oldplayer = App.user.GetUserByUid(OldPlayer); // {
// string oldPlayName = oldplayer != null ? oldplayer.NickName : "Player"; // Eventer.Instance.PostEvent(EEvent.OnOtherPlayerLeavnRoom, i, OldPlayer);
// OverlayManager.PopTip($"[{oldPlayName}]离开房间,手柄位:P{i}"); // UserDataBase oldplayer = App.user.GetUserByUid(OldPlayer);
// if (NewPlayer > 0)//而且害换了一个玩家 // string oldPlayName = oldplayer != null ? oldplayer.NickName : "Player";
// { // OverlayManager.PopTip($"[{oldPlayName}]离开房间,手柄位:P{i}");
// Eventer.Instance.PostEvent(EEvent.OnOtherPlayerJoinRoom, i, NewPlayer); // if (NewPlayer > 0)//而且害换了一个玩家
// mineRoomMiniInfo.GetPlayerNameByPlayerIdx((uint)i, out string PlayerName); // {
// OverlayManager.PopTip($"[{PlayerName}]进入房间,手柄位:P{i}"); // Eventer.Instance.PostEvent(EEvent.OnOtherPlayerJoinRoom, i, NewPlayer);
// } // mineRoomMiniInfo.GetPlayerNameByPlayerIdx((uint)i, out string PlayerName);
// } // OverlayManager.PopTip($"[{PlayerName}]进入房间,手柄位:P{i}");
// else //之前没人 // }
// { // }
// Eventer.Instance.PostEvent(EEvent.OnOtherPlayerJoinRoom, i, NewPlayer); // else //之前没人
// mineRoomMiniInfo.GetPlayerNameByPlayerIdx((uint)i, out string PlayerName); // {
// OverlayManager.PopTip($"[{PlayerName}]进入房间,手柄位:P{i}"); // Eventer.Instance.PostEvent(EEvent.OnOtherPlayerJoinRoom, i, NewPlayer);
// } // mineRoomMiniInfo.GetPlayerNameByPlayerIdx((uint)i, out string PlayerName);
//} // OverlayManager.PopTip($"[{PlayerName}]进入房间,手柄位:P{i}");
// }
//}
} }
/// <summary> /// <summary>