Исходник Fatality Playermove Ported to Supremacy

Начинающий
Статус
Оффлайн
Регистрация
22 Сен 2018
Сообщения
25
Реакции[?]
5
Поинты[?]
3K
Purpose for this: After reviewing the leaked fatality source, it seems how the calculations are being done to predict player movement are a lot more consistent. It was fairly straightforward moving this to default supremacy, no additional things should be needed.

Edit - Add Dot to vector3.h in sdk.

LagComp - PlayerMove:
void LagCompensation::PlayerMove(LagRecord* record)
{
    ConVar* sv_gravity = g_csgo.m_cvar->FindVar( HASH( "sv_gravity" ) );
    ConVar* sv_jump_impulse = g_csgo.m_cvar->FindVar( HASH( "sv_jump_impulse" ) );

    if ( ~( record->m_pred_flags & FL_ONGROUND ) )
    {
        record->m_pred_velocity.z -= g_csgo.m_globals->m_interval * sv_gravity->GetFloat( );
        record->m_pred_velocity.z += g_csgo.m_globals->m_interval * record->m_velocity.z;
    }

    const vec3_t min = record->m_mins;
    const vec3_t maxs = record->m_maxs;

    const vec3_t start = record->m_pred_origin;

    vec3_t end = start + ( record->m_pred_velocity * g_csgo.m_globals->m_interval );

    CGameTrace trace;
    CTraceFilterWorldOnly filter;

    // trace.
    g_csgo.m_engine_trace->TraceRay(Ray(start, end, min, maxs), MASK_PLAYERSOLID, &filter, &trace);

    if (trace.m_fraction != 1.f)
    {
        for (int i = 0; i < 2; ++i)
        {
            const float dot = record->m_pred_velocity.Dot( trace.m_plane.m_normal );

            if (dot < 0.f)
            {
                record->m_pred_velocity.x -= dot * trace.m_plane.m_normal.x;
                record->m_pred_velocity.y -= dot * trace.m_plane.m_normal.y;
                record->m_pred_velocity.z -= dot * trace.m_plane.m_normal.z;
            }

            end = trace.m_endpos + ( record->m_pred_velocity * ( g_csgo.m_globals->m_interval * ( 1.f - trace.m_fraction ) ) );

            g_csgo.m_engine_trace->TraceRay(Ray(start, end, min, maxs), MASK_PLAYERSOLID, &filter, &trace);

            if (trace.m_fraction == 1.f)
                break;
        }
    }

    // set new final origin.
    start == trace.m_endpos;
    end = trace.m_endpos;

    // move endpos 2 units down.
    // this way we can check if we are in/on the ground.
    end.z -= 2.f;

    // trace.
    g_csgo.m_engine_trace->TraceRay(Ray(start, end, min, maxs), MASK_PLAYERSOLID, &filter, &trace);

    // strip onground flag.
    record->m_pred_flags &= ~FL_ONGROUND;

    // add back onground flag if we are onground.
    if (trace.m_fraction != 1.f && trace.m_plane.m_normal.z > 0.7f)
        record->m_pred_flags |= FL_ONGROUND;
}
vector3.h:
 __forceinline float Dot(const vec3_t& vOther) const
    {
        const vec3_t& a = *this;

        return(ax * vOther.x + ay * vOther.y + az * vOther.z);
    }
 
Начинающий
Статус
Оффлайн
Регистрация
5 Авг 2023
Сообщения
65
Реакции[?]
20
Поинты[?]
20K
Purpose for this: After reviewing the leaked fatality source, it seems how the calculations are being done to predict player movement are a lot more consistent. It was fairly straightforward moving this to default supremacy, no additional things should be needed.

Edit - Add Dot to vector3.h in sdk.

LagComp - PlayerMove:
void LagCompensation::PlayerMove(LagRecord* record)
{
    ConVar* sv_gravity = g_csgo.m_cvar->FindVar( HASH( "sv_gravity" ) );
    ConVar* sv_jump_impulse = g_csgo.m_cvar->FindVar( HASH( "sv_jump_impulse" ) );

    if ( ~( record->m_pred_flags & FL_ONGROUND ) )
    {
        record->m_pred_velocity.z -= g_csgo.m_globals->m_interval * sv_gravity->GetFloat( );
        record->m_pred_velocity.z += g_csgo.m_globals->m_interval * record->m_velocity.z;
    }

    const vec3_t min = record->m_mins;
    const vec3_t maxs = record->m_maxs;

    const vec3_t start = record->m_pred_origin;

    vec3_t end = start + ( record->m_pred_velocity * g_csgo.m_globals->m_interval );

    CGameTrace trace;
    CTraceFilterWorldOnly filter;

    // trace.
    g_csgo.m_engine_trace->TraceRay(Ray(start, end, min, maxs), MASK_PLAYERSOLID, &filter, &trace);

    if (trace.m_fraction != 1.f)
    {
        for (int i = 0; i < 2; ++i)
        {
            const float dot = record->m_pred_velocity.Dot( trace.m_plane.m_normal );

            if (dot < 0.f)
            {
                record->m_pred_velocity.x -= dot * trace.m_plane.m_normal.x;
                record->m_pred_velocity.y -= dot * trace.m_plane.m_normal.y;
                record->m_pred_velocity.z -= dot * trace.m_plane.m_normal.z;
            }

            end = trace.m_endpos + ( record->m_pred_velocity * ( g_csgo.m_globals->m_interval * ( 1.f - trace.m_fraction ) ) );

            g_csgo.m_engine_trace->TraceRay(Ray(start, end, min, maxs), MASK_PLAYERSOLID, &filter, &trace);

            if (trace.m_fraction == 1.f)
                break;
        }
    }

    // set new final origin.
    start == trace.m_endpos;
    end = trace.m_endpos;

    // move endpos 2 units down.
    // this way we can check if we are in/on the ground.
    end.z -= 2.f;

    // trace.
    g_csgo.m_engine_trace->TraceRay(Ray(start, end, min, maxs), MASK_PLAYERSOLID, &filter, &trace);

    // strip onground flag.
    record->m_pred_flags &= ~FL_ONGROUND;

    // add back onground flag if we are onground.
    if (trace.m_fraction != 1.f && trace.m_plane.m_normal.z > 0.7f)
        record->m_pred_flags |= FL_ONGROUND;
}
vector3.h:
 __forceinline float Dot(const vec3_t& vOther) const
    {
        const vec3_t& a = *this;

        return(ax * vOther.x + ay * vOther.y + az * vOther.z);
    }
1) this is missing the whole AirMove/AirAccel func so this will be useless
2) supremacy already has .dot lol
 
Начинающий
Статус
Оффлайн
Регистрация
22 Сен 2018
Сообщения
25
Реакции[?]
5
Поинты[?]
3K
1) this is missing the whole AirMove/AirAccel func so this will be useless
2) supremacy already has .dot lol
the one included in supremacy i thought wasnt going to perform the same so figured to bring it over incase.

Here is my port of airmove/airaccel from what is used in fatality, just wasn't wanting to share it.

Fatality AirMove & AirAccel (combined into one for sup):
void LagCompensation::AirAccelerate(LagRecord* record, ang_t angle, float fmove, float smove)
{
    vec3_t forward, right;

    // determine movement angles.
    math::AngleVectors(angle, &forward, &right);

    forward.z = 0.f;
    right.z = 0.f;
    forward.normalize( );
    right.normalize( );

    vec3_t wishvel(forward.x * fmove + right.x * smove, forward.y * fmove + right.y * smove, 0.f);

    vec3_t wishdir = wishvel;
    float wishspeed = wishdir.normalize();

    if ( wishspeed != 0 && ( wishspeed >= record->m_player->m_flMaxspeed( ) ) )
    {
        wishvel = wishvel * ( record->m_player->m_flMaxspeed( ) / wishspeed );
        wishspeed = record->m_player->m_flMaxspeed( );
    }

    float wishspd = wishspeed;

    math::clamp(wishspd, 1.f, 30.f);

    // determine veer amount.
    float currentspeed = record->m_pred_velocity.dot(wishdir);

    // see how much to add.
    const float addspeed = wishspd - currentspeed;

    // if not adding any, done.
    if (addspeed <= 0.f)
        return;

    // define our acceleration.
    float accelspeed = g_csgo.sv_airaccelerate->GetFloat() * wishspeed * g_csgo.m_globals->m_interval * record->m_player->m_surfaceFriction();

    // cap it.
    if (accelspeed > addspeed)
        accelspeed = addspeed;

    // add accel.
    record->m_pred_velocity += (wishdir * accelspeed);
}
 
Последнее редактирование:
Сверху Снизу