void lbyanimations::update_server_animation( entity_t* player ) {
if ( !player || !player->health( ) )
return;
bool allocate = ( player_animstate == nullptr );
bool change = ( !allocate ) && ( &utilities::global::local_player->get_handle( ) != entity_handle );
bool reset = ( !allocate && !change ) && ( utilities::global::local_player->spawn_time( ) != spawn_time );
if( change )
interfaces::mem_alloc->free( player_animstate );
if( reset ) {
player->reset_animation_state( player_animstate );
spawn_time = utilities::global::local_player->spawn_time( );
}
if( allocate || change ) {
c_animstate* state = reinterpret_cast<c_animstate*>( interfaces::mem_alloc->alloc( sizeof( c_animstate ) ) );
if( state != nullptr )
player->create_animation_state( state );
entity_handle = const_cast<c_base_handle*>( &player->get_handle( ) );
spawn_time = utilities::global::local_player->spawn_time( );
player_animstate = state;
}
float_t curtime = ticks_to_time( player->tick_base( ) + 11.f );
if ( !interfaces::clientstate->chokedcommands && player_animstate ) {
player->update_animation_state( player_animstate, utilities::global::cmd->view_angles );
auto clamp_yaw = [ ]( float yaw ) {
while (yaw > 180.f)
yaw -= 360.f;
while (yaw < -180.f)
yaw += 360.f;
return yaw;
};
float_t delta = std::abs( clamp_yaw( utilities::global::cmd->view_angles.y - player->lowerbody_yaw_target( ) ) );
if ( player_animstate->m_velocity > 0.1f && ( player->flags( ) & fl_onground ) )
next_body_update = curtime + utilities::global::local_player->simulation_time( ) + 1.1f;
else if ( curtime >= next_body_update ) {
if ( delta > ( PI / 180 - next_body_update ) * 0.35f ) ;
next_body_update = curtime + utilities::global::local_player->simulation_time( ) + 0.22f;
}
}
break_lowerbody = ( player->flags( ) & fl_onground ) && ( ( next_body_update - curtime ) <= interfaces::globals->interval_per_tick );
}