调整EmuCore基类中获取输入数据和推送的逻辑
This commit is contained in:
parent
6c23bdc1c2
commit
ef419928ed
@ -65,7 +65,7 @@ namespace AxiReplay
|
||||
frameProfiler.InputHead(inputData.FrameStartID);
|
||||
}
|
||||
|
||||
public bool TryGetNextFrame(out ReplayStep data, out int frameDiff, out bool inputDiff)
|
||||
public bool TryGetNextFrame(int targetFrame, bool indirectGet, out ReplayStep data, out int frameDiff, out bool inputDiff)
|
||||
{
|
||||
if (!bNetInit)
|
||||
{
|
||||
@ -74,37 +74,27 @@ namespace AxiReplay
|
||||
inputDiff = false;
|
||||
return false;
|
||||
}
|
||||
TakeFrame(1, out data, out frameDiff, out inputDiff);
|
||||
return frameDiff > 0;
|
||||
return TakeFrameToTargetFrame(targetFrame, indirectGet, out data, out frameDiff, out inputDiff);
|
||||
}
|
||||
|
||||
public bool TryGetNextFrame(int targetFrame, out ReplayStep data, out int frameDiff, out bool inputDiff)
|
||||
bool checkCanGetFrame(int targetFrame, bool indirectGet)
|
||||
{
|
||||
if (!bNetInit)
|
||||
if (indirectGet)
|
||||
{
|
||||
data = default(ReplayStep);
|
||||
frameDiff = default(int);
|
||||
inputDiff = false;
|
||||
return false;
|
||||
return targetFrame == mNextReplay.FrameStartID && targetFrame <= mRemoteFrameIdx;
|
||||
}
|
||||
else
|
||||
{
|
||||
return targetFrame == mNextReplay.FrameStartID && targetFrame <= mRemoteFrameIdx && mNetReplayQueue.Count >= frameProfiler.TempFrameCount(mRemoteForwardCount);
|
||||
}
|
||||
return TakeFrameToTargetFrame(targetFrame, out data, out frameDiff, out inputDiff);
|
||||
}
|
||||
|
||||
void TakeFrame(int addFrame, out ReplayStep data, out int bFrameDiff, out bool inputDiff)
|
||||
{
|
||||
int targetFrame = mCurrClientFrameIdx + addFrame;
|
||||
TakeFrameToTargetFrame(targetFrame, out data, out bFrameDiff, out inputDiff);
|
||||
}
|
||||
|
||||
bool TakeFrameToTargetFrame(int targetFrame, out ReplayStep data, out int bFrameDiff, out bool inputDiff)
|
||||
bool TakeFrameToTargetFrame(int targetFrame, bool indirectGet, out ReplayStep data, out int bFrameDiff, out bool inputDiff)
|
||||
{
|
||||
bool result;
|
||||
inputDiff = false;
|
||||
|
||||
|
||||
//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 >= frameProfiler.TempFrameCount(mRemoteForwardCount))
|
||||
if (checkCanGetFrame(targetFrame, indirectGet))
|
||||
{
|
||||
//当前帧追加
|
||||
mCurrClientFrameIdx = targetFrame;
|
||||
|
||||
@ -60,8 +60,11 @@ namespace AxibugEmuOnline.Client
|
||||
}
|
||||
}
|
||||
|
||||
/// <typeparam name="INPUTDATA">输入数据类型</typeparam>
|
||||
public abstract class EmuCore<INPUTDATA> : EmuCore
|
||||
{
|
||||
protected virtual bool EnableRollbackNetCode => false;
|
||||
|
||||
public sealed override void PushEmulatorFrame()
|
||||
{
|
||||
if (!TryPushEmulatorFrame()) return;
|
||||
@ -83,13 +86,31 @@ namespace AxibugEmuOnline.Client
|
||||
{
|
||||
if (SampleInputData(out var inputData))
|
||||
{
|
||||
if (IsNetPlay) SendLocalInput();
|
||||
|
||||
return OnPushEmulatorFrame(inputData);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
private void SendLocalInput()
|
||||
{
|
||||
var localState = GetLocalInput();
|
||||
var rawData = InputDataToNet(localState);
|
||||
App.roomMgr.SendRoomSingelPlayerInput(Frame, rawData);
|
||||
|
||||
if (m_lastTestInput != rawData)
|
||||
{
|
||||
m_lastTestInput = rawData;
|
||||
App.log.Debug($"{DateTime.Now.ToString("hh:mm:ss.fff")} Input F:{App.roomMgr.netReplay.mCurrClientFrameIdx} | I:{rawData}");
|
||||
}
|
||||
}
|
||||
|
||||
ulong m_lastTestInput;
|
||||
ReplayStep m_replayData;
|
||||
int m_frameDiff;
|
||||
bool m_inputDiff;
|
||||
protected bool SampleInputData(out INPUTDATA inputData)
|
||||
{
|
||||
bool result = false;
|
||||
@ -97,34 +118,21 @@ namespace AxibugEmuOnline.Client
|
||||
|
||||
if (IsNetPlay)
|
||||
{
|
||||
ReplayStep replayData;
|
||||
int frameDiff;
|
||||
bool inputDiff;
|
||||
|
||||
if (App.roomMgr.netReplay.TryGetNextFrame((int)Frame, out replayData, out frameDiff, out inputDiff))
|
||||
if (App.roomMgr.netReplay.TryGetNextFrame((int)Frame, EnableRollbackNetCode ? true : false, out m_replayData, out m_frameDiff, out m_inputDiff))
|
||||
{
|
||||
if (inputDiff)
|
||||
if (m_inputDiff)
|
||||
{
|
||||
App.log.Debug($"{DateTime.Now.ToString("hh:mm:ss.fff")} TryGetNextFrame remoteFrame->{App.roomMgr.netReplay.mRemoteFrameIdx} diff->{frameDiff} " +
|
||||
$"frame=>{replayData.FrameStartID} InPut=>{replayData.InPut}");
|
||||
App.log.Debug($"{DateTime.Now.ToString("hh:mm:ss.fff")} TryGetNextFrame remoteFrame->{App.roomMgr.netReplay.mRemoteFrameIdx} diff->{m_frameDiff} " +
|
||||
$"frame=>{m_replayData.FrameStartID} InPut=>{m_replayData.InPut}");
|
||||
}
|
||||
|
||||
inputData = ConvertInputDataFromNet(replayData);
|
||||
inputData = ConvertInputDataFromNet(m_replayData);
|
||||
result = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
result = false;
|
||||
}
|
||||
|
||||
var localState = GetLocalInput();
|
||||
var rawData = InputDataToNet(localState);
|
||||
if (m_lastTestInput != rawData)
|
||||
{
|
||||
m_lastTestInput = rawData;
|
||||
App.log.Debug($"{DateTime.Now.ToString("hh:mm:ss.fff")} Input F:{App.roomMgr.netReplay.mCurrClientFrameIdx} | I:{rawData}");
|
||||
}
|
||||
App.roomMgr.SendRoomSingelPlayerInput(Frame, rawData);
|
||||
}
|
||||
else//单机模式
|
||||
{
|
||||
|
||||
Loading…
Reference in New Issue
Block a user