float frac = 0.0f;
if (previous &&
(record->m_sim_time < flTargetTime) &&
(record->m_sim_time < previous->m_sim_time)) {
// we didn't find the exact time but have a valid previous record
// so interpolate between these two records;
// calc fraction between both records
frac = (flTargetTime - record->m_sim_time) /
(previous->m_sim_time - record->m_sim_time);
Assert(frac > 0 && frac < 1); // should never extrapolate
ang = math::Lerp(frac, record->m_abs_ang, previous->m_abs_ang);
org = math::Lerp(frac, record->m_origin, previous->m_origin);
mins = math::Lerp(frac, record->m_mins, previous->m_mins);
maxs = math::Lerp(frac, record->m_maxs, previous->m_maxs);
}
else {
// we found the exact record or no other record to interpolate with
// just copy these values since they are the best we have
ang = record->m_abs_ang;
org = record->m_origin;
mins = record->m_mins;
maxs = record->m_maxs;
}
int flags = 0;
ang_t angdiff = record->m_abs_ang - ang;
vec3_t orgdiff = record->m_origin - org;
#define LAG_COMPENSATION_EPS_SQR ( 0.1f * 0.1f )
// Allow 4 units of error ( about 1 / 8 bbox width )
#define LAG_COMPENSATION_ERROR_EPS_SQR ( 4.0f * 4.0f )
#define LC_NONE 0
#define LC_ALIVE (1<<0)
#define LC_ORIGIN_CHANGED (1<<8)
#define LC_ANGLES_CHANGED (1<<9)
#define LC_SIZE_CHANGED (1<<10)
#define LC_ANIMATION_CHANGED (1<<11)
if (angdiff.length_sqr() > LAG_COMPENSATION_EPS_SQR)
{
flags |= LC_ANGLES_CHANGED;
record->m_player->SetAbsAngles(ang);
}
// Use absolute equality here
if ((mins != record->m_mins/*record->m_player->WorldAlignMins()*/) ||
(maxs != record->m_maxs/*record->m_player->WorldAlignMaxs()*/))
{
flags |= LC_SIZE_CHANGED;
//entity->SetSize(mins, maxs);
record->m_player->SetMins(mins);
record->m_player->SetMaxs(maxs);
}
// Note, do origin at end since it causes a relink into the k/d tree
if (orgdiff.length_sqr() > LAG_COMPENSATION_EPS_SQR)
{
flags |= LC_ORIGIN_CHANGED;
record->m_player->SetAbsOrigin(org);
}
}