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->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;
|
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 )
|
void CLagCompensationManager::BacktrackPlayer( CBasePlayer *pPlayer, CUserCmd *cmd )
|
||||||
{
|
{
|
||||||
Vector org;
|
Vector org;
|
||||||
|
@ -440,8 +413,10 @@ void CLagCompensationManager::BacktrackPlayer( CBasePlayer *pPlayer, CUserCmd *c
|
||||||
|
|
||||||
LagRecord *prevRecordSim = NULL;
|
LagRecord *prevRecordSim = NULL;
|
||||||
LagRecord *recordSim = NULL;
|
LagRecord *recordSim = NULL;
|
||||||
|
LagRecord *recordAnim = NULL;
|
||||||
|
|
||||||
Vector prevOrg = pPlayer->GetLocalOrigin();
|
Vector prevOrg = pPlayer->GetLocalOrigin();
|
||||||
|
bool foundAnimationData = false;
|
||||||
|
|
||||||
// Walk context looking for any invalidating event
|
// Walk context looking for any invalidating event
|
||||||
while( trackSim->IsValidIndex(currSim) )
|
while( trackSim->IsValidIndex(currSim) )
|
||||||
|
@ -450,7 +425,14 @@ void CLagCompensationManager::BacktrackPlayer( CBasePlayer *pPlayer, CUserCmd *c
|
||||||
prevRecordSim = recordSim;
|
prevRecordSim = recordSim;
|
||||||
|
|
||||||
// get next record
|
// get next record
|
||||||
recordSim = &trackSim->Element( currSim );
|
recordSim = &trackSim->Element(currSim);
|
||||||
|
|
||||||
|
if (recordSim->m_flSimulationTime
|
||||||
|
<= animationData->m_flUninterpolatedSimulationTime and !foundAnimationData)
|
||||||
|
{
|
||||||
|
recordAnim = recordSim;
|
||||||
|
foundAnimationData = true;
|
||||||
|
}
|
||||||
|
|
||||||
if ( !(recordSim->m_fFlags & LC_ALIVE) )
|
if ( !(recordSim->m_fFlags & LC_ALIVE) )
|
||||||
{
|
{
|
||||||
|
@ -470,31 +452,6 @@ void CLagCompensationManager::BacktrackPlayer( CBasePlayer *pPlayer, CUserCmd *c
|
||||||
currSim = trackSim->Next( currSim );
|
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( recordAnim );
|
||||||
Assert( recordSim );
|
Assert( recordSim );
|
||||||
|
|
||||||
|
@ -706,7 +663,7 @@ void CLagCompensationManager::BacktrackPlayer( CBasePlayer *pPlayer, CUserCmd *c
|
||||||
|
|
||||||
// Set lag compensated player's times
|
// Set lag compensated player's times
|
||||||
pPlayer->SetSimulationTime(flTargetSimulationTime);
|
pPlayer->SetSimulationTime(flTargetSimulationTime);
|
||||||
pPlayer->SetAnimTime(animationData->m_flAnimTime);
|
// pPlayer->SetAnimTime(animationData->m_flAnimTime);
|
||||||
|
|
||||||
if ( sv_lagflushbonecache.GetBool() )
|
if ( sv_lagflushbonecache.GetBool() )
|
||||||
pPlayer->InvalidateBoneCache();
|
pPlayer->InvalidateBoneCache();
|
||||||
|
|
|
@ -204,10 +204,10 @@ void WriteUsercmd( bf_write *buf, const CUserCmd *to, const CUserCmd *from )
|
||||||
continue;
|
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->WriteOneBit( 1 );
|
||||||
buf->WriteFloat( to->animationdata[i].m_flAnimTime );
|
buf->WriteFloat( to->animationdata[i].m_flUninterpolatedSimulationTime );
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -360,7 +360,7 @@ void ReadUsercmd( bf_read *buf, CUserCmd *move, CUserCmd *from )
|
||||||
|
|
||||||
if (buf->ReadOneBit())
|
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
|
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
|
class CEntityGroundContact
|
||||||
|
|
Loading…
Reference in a new issue