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