Fixed lag compensation with low fps
This commit is contained in:
parent
2e5867b300
commit
cd6ecdc726
4 changed files with 20 additions and 60 deletions
|
@ -1328,7 +1328,7 @@ void CInput::CreateMove ( int sequence_number, float input_sample_frametime, boo
|
|||
}
|
||||
|
||||
cmd->has_animation[pBasePlayer->index] = true;
|
||||
cmd->animationdata[pBasePlayer->index].m_flAnimTime = pBasePlayer->m_flAnimTime;
|
||||
cmd->animationdata[pBasePlayer->index].m_flUninterpolatedSimulationTime = pBasePlayer->m_flSimulationTime;
|
||||
}
|
||||
|
||||
pVerified->m_cmd = *cmd;
|
||||
|
|
|
@ -388,33 +388,6 @@ void CLagCompensationManager::StartLagCompensation( CBasePlayer *player, CUserCm
|
|||
}
|
||||
}
|
||||
|
||||
template <class T>
|
||||
inline T LoopingLerp( float flPercent, T flFrom, T flTo )
|
||||
{
|
||||
T s = flTo * flPercent + flFrom * (1.0f - flPercent);
|
||||
return s;
|
||||
}
|
||||
|
||||
template <>
|
||||
inline float LoopingLerp( float flPercent, float flFrom, float flTo )
|
||||
{
|
||||
if ( fabs( flTo - flFrom ) >= 0.5f )
|
||||
{
|
||||
if (flFrom < flTo)
|
||||
flFrom += 1.0f;
|
||||
else
|
||||
flTo += 1.0f;
|
||||
}
|
||||
|
||||
float s = flTo * flPercent + flFrom * (1.0f - flPercent);
|
||||
|
||||
s = s - (int)(s);
|
||||
if (s < 0.0f)
|
||||
s = s + 1.0f;
|
||||
|
||||
return s;
|
||||
}
|
||||
|
||||
void CLagCompensationManager::BacktrackPlayer( CBasePlayer *pPlayer, CUserCmd *cmd )
|
||||
{
|
||||
Vector org;
|
||||
|
@ -440,8 +413,10 @@ void CLagCompensationManager::BacktrackPlayer( CBasePlayer *pPlayer, CUserCmd *c
|
|||
|
||||
LagRecord *prevRecordSim = NULL;
|
||||
LagRecord *recordSim = NULL;
|
||||
LagRecord *recordAnim = NULL;
|
||||
|
||||
Vector prevOrg = pPlayer->GetLocalOrigin();
|
||||
bool foundAnimationData = false;
|
||||
|
||||
// Walk context looking for any invalidating event
|
||||
while( trackSim->IsValidIndex(currSim) )
|
||||
|
@ -452,6 +427,13 @@ void CLagCompensationManager::BacktrackPlayer( CBasePlayer *pPlayer, CUserCmd *c
|
|||
// get next record
|
||||
recordSim = &trackSim->Element(currSim);
|
||||
|
||||
if (recordSim->m_flSimulationTime
|
||||
<= animationData->m_flUninterpolatedSimulationTime and !foundAnimationData)
|
||||
{
|
||||
recordAnim = recordSim;
|
||||
foundAnimationData = true;
|
||||
}
|
||||
|
||||
if ( !(recordSim->m_fFlags & LC_ALIVE) )
|
||||
{
|
||||
// player most be alive, lost track
|
||||
|
@ -470,31 +452,6 @@ void CLagCompensationManager::BacktrackPlayer( CBasePlayer *pPlayer, CUserCmd *c
|
|||
currSim = trackSim->Next( currSim );
|
||||
}
|
||||
|
||||
intp currAnim = trackAnim->Head();
|
||||
LagRecord *recordAnim = NULL;
|
||||
|
||||
// Walk context looking for any invalidating event
|
||||
while( trackAnim->IsValidIndex(currAnim) )
|
||||
{
|
||||
// get next record
|
||||
recordAnim = &trackAnim->Element( currAnim );
|
||||
|
||||
if ( !(recordAnim->m_fFlags & LC_ALIVE) )
|
||||
{
|
||||
// player most be alive, lost track
|
||||
return;
|
||||
}
|
||||
|
||||
// TODO: do proper teleportation checks.
|
||||
|
||||
// did we find a context smaller than target time ?
|
||||
if ( recordAnim->m_flAnimTime <= animationData->m_flAnimTime )
|
||||
break; // hurra, stop
|
||||
|
||||
// go one step back
|
||||
currAnim = trackAnim->Next( currAnim );
|
||||
}
|
||||
|
||||
Assert( recordAnim );
|
||||
Assert( recordSim );
|
||||
|
||||
|
@ -706,7 +663,7 @@ void CLagCompensationManager::BacktrackPlayer( CBasePlayer *pPlayer, CUserCmd *c
|
|||
|
||||
// Set lag compensated player's times
|
||||
pPlayer->SetSimulationTime(flTargetSimulationTime);
|
||||
pPlayer->SetAnimTime(animationData->m_flAnimTime);
|
||||
// pPlayer->SetAnimTime(animationData->m_flAnimTime);
|
||||
|
||||
if ( sv_lagflushbonecache.GetBool() )
|
||||
pPlayer->InvalidateBoneCache();
|
||||
|
|
|
@ -204,10 +204,10 @@ void WriteUsercmd( bf_write *buf, const CUserCmd *to, const CUserCmd *from )
|
|||
continue;
|
||||
}
|
||||
|
||||
if (to->animationdata[i].m_flAnimTime != from->animationdata[i].m_flAnimTime)
|
||||
if (to->animationdata[i].m_flUninterpolatedSimulationTime != from->animationdata[i].m_flUninterpolatedSimulationTime)
|
||||
{
|
||||
buf->WriteOneBit( 1 );
|
||||
buf->WriteFloat( to->animationdata[i].m_flAnimTime );
|
||||
buf->WriteFloat( to->animationdata[i].m_flUninterpolatedSimulationTime );
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -360,7 +360,7 @@ void ReadUsercmd( bf_read *buf, CUserCmd *move, CUserCmd *from )
|
|||
|
||||
if (buf->ReadOneBit())
|
||||
{
|
||||
move->animationdata[i].m_flAnimTime = buf->ReadFloat();
|
||||
move->animationdata[i].m_flUninterpolatedSimulationTime = buf->ReadFloat();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -53,7 +53,10 @@ struct LayerRecord
|
|||
|
||||
struct ClientSideAnimationData
|
||||
{
|
||||
float m_flAnimTime;
|
||||
// TODO_ENHANCED:
|
||||
// For now we send the last received update for animations.
|
||||
// anim time is unreliable on low fps.
|
||||
float m_flUninterpolatedSimulationTime;
|
||||
};
|
||||
|
||||
class CEntityGroundContact
|
||||
|
|
Loading…
Reference in a new issue