using System.Collections.Generic;
namespace AxiReplay
{
public class NetReplay
{
///
/// 客户端当前帧
///
public int mCurrClientFrameIdx => mCurrReplay.FrameStartID;
//public int mCurrClientFrameIdx
///
/// 服务器远端当前帧
///
public int mRemoteFrameIdx { get; private set; } = -1;
///
/// 网络数据队列
///
Queue mNetReplayQueue = new Queue();
///
/// 当前数据
///
ReplayStep mCurrReplay;
///
/// 下一个数据数据
///
ReplayStep mNextReplay;
public NetReplay()
{
ResetData();
}
public void ResetData()
{
mNetReplayQueue.Clear();
mRemoteFrameIdx = 0;
mCurrReplay = default(ReplayStep);
mCurrReplay.FrameStartID = 0;
mNextReplay = default(ReplayStep);
mNextReplay.FrameStartID = -1;
}
public void InData(ReplayStep inputData, int ServerFrameIdx)
{
mNetReplayQueue.Enqueue(inputData);
mRemoteFrameIdx = inputData.FrameStartID;
}
public bool TryGetNextFrame(out ReplayStep data, out int frameDiff, out bool inputDiff)
{
TakeFrame(1, out data, out frameDiff, out inputDiff);
return frameDiff > 0;
}
void TakeFrame(int addFrame, out ReplayStep data, out int bFrameDiff, out bool inputDiff)
{
inputDiff = false;
int targetFrame = mCurrClientFrameIdx + addFrame;
if (targetFrame >= mNextReplay.FrameStartID && targetFrame <= mRemoteFrameIdx && mNetReplayQueue.Count > 0)
{
//当前帧追加
//mCurrClientFrameIdx = targetFrame;
ulong oldInput = mCurrReplay.InPut;
mCurrReplay = mNextReplay;
if (oldInput != mCurrReplay.InPut)
inputDiff = true;
mNextReplay = mNetReplayQueue.Dequeue();
}
bFrameDiff = mRemoteFrameIdx - mCurrClientFrameIdx;
data = mCurrReplay;
}
}
}