Make prediction margin take effect immediately

This commit is contained in:
trml 2023-11-19 19:46:54 +01:00
parent 7b16460334
commit 717aad2677
3 changed files with 10 additions and 29 deletions

View file

@ -348,7 +348,7 @@ void CClient::SendInput()
m_aInputs[i][m_aCurrentInput[i]].m_Tick = m_aPredTick[g_Config.m_ClDummy];
m_aInputs[i][m_aCurrentInput[i]].m_PredictedTime = m_PredictedTime.Get(Now);
m_aInputs[i][m_aCurrentInput[i]].m_PredictionMargin = m_PredictedTime.GetMargin(Now);
m_aInputs[i][m_aCurrentInput[i]].m_PredictionMargin = PredictionMargin() * time_freq() / 1000;
m_aInputs[i][m_aCurrentInput[i]].m_Time = Now;
// pack it
@ -1710,7 +1710,7 @@ void CClient::ProcessServerPacket(CNetChunk *pPacket, int Conn, bool Dummy)
if(m_aInputs[Conn][k].m_Tick == InputPredTick)
{
Target = m_aInputs[Conn][k].m_PredictedTime + (Now - m_aInputs[Conn][k].m_Time);
Target = Target - (int64_t)((TimeLeft / 1000.0f) * time_freq()) + m_aInputs[Conn][k].m_PredictionMargin;
Target = Target - (int64_t)((TimeLeft / 1000.0f) * time_freq());
break;
}
}

View file

@ -12,9 +12,7 @@ void CSmoothTime::Init(int64_t Target)
m_Snap = time_get();
m_Current = Target;
m_Target = Target;
m_SnapMargin = m_Snap;
m_CurrentMargin = 0;
m_TargetMargin = 0;
m_Margin = 0;
m_aAdjustSpeed[ADJUSTDIRECTION_DOWN] = 0.3f;
m_aAdjustSpeed[ADJUSTDIRECTION_UP] = 0.3f;
}
@ -41,15 +39,15 @@ int64_t CSmoothTime::Get(int64_t Now) const
a = 1.0f;
int64_t r = c + (int64_t)((t - c) * a);
return r + GetMargin(Now);
return r + m_Margin;
}
void CSmoothTime::UpdateInt(int64_t Target)
{
int64_t Now = time_get();
m_Current = Get(Now) - GetMargin(Now);
m_Current = Get(Now) - m_Margin;
m_Snap = Now;
m_Target = Target - GetMargin(Now);
m_Target = Target;
}
void CSmoothTime::Update(CGraph *pGraph, int64_t Target, int TimeLeft, EAdjustDirection AdjustDirection)
@ -97,20 +95,7 @@ void CSmoothTime::Update(CGraph *pGraph, int64_t Target, int TimeLeft, EAdjustDi
UpdateInt(Target);
}
int64_t CSmoothTime::GetMargin(int64_t Now) const
void CSmoothTime::UpdateMargin(int64_t Margin)
{
int64_t TimePassed = Now - m_SnapMargin;
int64_t Diff = m_TargetMargin - m_CurrentMargin;
float a = clamp(TimePassed / (float)time_freq(), -1.f, 1.f);
int64_t Lim = maximum((int64_t)(a * absolute(Diff)), 1 + TimePassed / 100);
return m_CurrentMargin + (int64_t)clamp(Diff, -Lim, Lim);
}
void CSmoothTime::UpdateMargin(int64_t TargetMargin)
{
int64_t Now = time_get();
m_CurrentMargin = GetMargin(Now);
m_SnapMargin = Now;
m_TargetMargin = TargetMargin;
m_Margin = Margin;
}

View file

@ -22,10 +22,7 @@ private:
int64_t m_Snap;
int64_t m_Current;
int64_t m_Target;
int64_t m_SnapMargin;
int64_t m_CurrentMargin;
int64_t m_TargetMargin;
int64_t m_Margin;
int m_SpikeCounter;
float m_aAdjustSpeed[NUM_ADJUSTDIRECTIONS];
@ -39,8 +36,7 @@ public:
void UpdateInt(int64_t Target);
void Update(CGraph *pGraph, int64_t Target, int TimeLeft, EAdjustDirection AdjustDirection);
int64_t GetMargin(int64_t Now) const;
void UpdateMargin(int64_t TargetMargin);
void UpdateMargin(int64_t Margin);
};
#endif