16
0
mirror of https://github.com/MaSzyna-EU07/maszyna.git synced 2026-07-18 00:49:19 +02:00

Replace interpolate with std::lerp and glm::mix

This commit is contained in:
docentYT
2026-05-02 01:31:38 +02:00
parent 362338ee5e
commit 3628eb0fc3
21 changed files with 108 additions and 116 deletions

View File

@@ -935,7 +935,7 @@ TCommandType TController::TableUpdate(double &fVelDes, double &fDist, double &fN
if( brakingdistance > 0.0 ) {
// maintain desired acc while we have enough room to brake safely, when close enough start paying attention
// try to make a smooth transition instead of sharp change
a = interpolate( a, AccPreferred, std::clamp( ( d - brakingdistance ) / brakingdistance, 0.0, 1.0 ) );
a = std::lerp( a, AccPreferred, std::clamp( ( d - brakingdistance ) / brakingdistance, 0.0, 1.0 ) );
}
}
if( ( d < fMinProximityDist )
@@ -1740,7 +1740,7 @@ TController::braking_distance_multiplier( float const Targetvelocity ) const {
&& ( Targetvelocity == 0.f ) ) {
auto const multiplier { std::clamp( 1.f + iVehicles * 0.5f, 2.f, 4.f ) };
return (
interpolate(
std::lerp(
multiplier, 1.f,
static_cast<float>( mvOccupied->Vel / 40.0 ) )
* frictionmultiplier );
@@ -1750,7 +1750,7 @@ TController::braking_distance_multiplier( float const Targetvelocity ) const {
&& ( ( true == IsCargoTrain )
|| ( fAccGravity > 0.025 ) ) ) {
return (
interpolate(
std::lerp(
1.f, 2.f,
std::clamp(
( fBrake_a0[ 1 ] - 0.2 ) / 0.2,
@@ -1762,7 +1762,7 @@ TController::braking_distance_multiplier( float const Targetvelocity ) const {
}
// stretch the braking distance up to 3 times; the lower the speed, the greater the stretch
return (
interpolate(
std::lerp(
3.f, 1.f,
( Targetvelocity - 5.f ) / 60.f )
* frictionmultiplier );
@@ -3180,7 +3180,7 @@ bool TController::IncBrake()
auto const initialbrakeposition { mvOccupied->fBrakeCtrlPos };
auto const AccMax { std::min( fBrake_a0[ 0 ] + 12 * fBrake_a1[ 0 ], mvOccupied->MED_amax ) };
mvOccupied->BrakeLevelSet(
interpolate(
std::lerp(
mvOccupied->Handle->GetPos( bh_EPR ),
mvOccupied->Handle->GetPos( bh_EPB ),
std::clamp( -AccDesired / AccMax * mvOccupied->AIHintLocalBrakeAccFactor, 0.0, 1.0 ) ) );
@@ -3312,7 +3312,7 @@ bool TController::DecBrake() {
auto const initialbrakeposition { mvOccupied->fBrakeCtrlPos };
auto const AccMax { std::min( fBrake_a0[ 0 ] + 12 * fBrake_a1[ 0 ], mvOccupied->MED_amax ) };
mvOccupied->BrakeLevelSet(
interpolate(
std::lerp(
mvOccupied->Handle->GetPos( bh_EPR ),
mvOccupied->Handle->GetPos( bh_EPB ),
std::clamp( -AccDesired / AccMax * mvOccupied->AIHintLocalBrakeAccFactor, 0.0, 1.0 ) ) );
@@ -3454,7 +3454,7 @@ bool TController::IncSpeed()
auto const minvoltage { ( mvPantographUnit->EnginePowerSource.SourceType == TPowerSource::CurrentCollector ? mvPantographUnit->EnginePowerSource.CollectorParameters.MinV : 0.0 ) };
auto const maxvoltage { ( mvPantographUnit->EnginePowerSource.SourceType == TPowerSource::CurrentCollector ? mvPantographUnit->EnginePowerSource.CollectorParameters.MaxV : 0.0 ) };
auto const seriesmodevoltage {
interpolate(
std::lerp(
minvoltage,
maxvoltage,
( IsHeavyCargoTrain ? 0.35 : 0.40 ) ) };
@@ -6447,7 +6447,7 @@ TController::control_handles() {
}
// if the power station is heavily burdened drop down to series mode to reduce the load
auto const useseriesmodevoltage {
interpolate(
std::lerp(
mvControlling->EnginePowerSource.CollectorParameters.MinV,
mvControlling->EnginePowerSource.CollectorParameters.MaxV,
( IsHeavyCargoTrain ? 0.35 : 0.40 ) ) };
@@ -7768,7 +7768,7 @@ TController::adjust_desired_speed_for_current_speed() {
// stop accelerating when close enough to target speed
AccDesired = std::min(
AccDesired, // but don't override decceleration for VelNext
interpolate( // ease off as you close to the target velocity
std::lerp( // ease off as you close to the target velocity
EU07_AI_NOACCELERATION, AccPreferred,
std::clamp( VelDesired - speedestimate, 0.0, fVelMinus ) / fVelMinus ) );
}

View File

@@ -724,7 +724,7 @@ void TDynamicObject::UpdatePlatformTranslate( TAnim *pAnim ) {
pAnim->smAnimated->SetTranslate(
glm::vec3{
interpolate( 0.f, MoverParameters->Doors.step_range, door.step_position ),
std::lerp( 0.f, MoverParameters->Doors.step_range, door.step_position ),
0.0,
0.0 } );
}
@@ -741,7 +741,7 @@ void TDynamicObject::UpdatePlatformRotate( TAnim *pAnim ) {
pAnim->smAnimated->SetRotate(
float3( 0, 1, 0 ),
interpolate( 0.f, MoverParameters->Doors.step_range, door.step_position ) );
std::lerp( 0.f, MoverParameters->Doors.step_range, door.step_position ) );
}
// mirror animation, rotate
@@ -758,11 +758,11 @@ void TDynamicObject::UpdateMirror( TAnim *pAnim ) {
if( pAnim->iNumber & 1 )
pAnim->smAnimated->SetRotate(
float3( 0, 1, 0 ),
interpolate( 0.0, MoverParameters->MirrorMaxShift, dMirrorMoveR * isactive ) );
std::lerp( 0.0, MoverParameters->MirrorMaxShift, dMirrorMoveR * isactive ) );
else
pAnim->smAnimated->SetRotate(
float3( 0, 1, 0 ),
interpolate( 0.0, MoverParameters->MirrorMaxShift, dMirrorMoveL * isactive ) );
std::lerp( 0.0, MoverParameters->MirrorMaxShift, dMirrorMoveL * isactive ) );
}
// wipers
@@ -2753,7 +2753,7 @@ void TDynamicObject::Move(double fDistance)
case e_tunnel: { shadefrom = 0.2f; break; }
default: {break; }
}
fShade = interpolate( shadefrom, shadeto, static_cast<float>( d ) );
fShade = std::lerp( shadefrom, shadeto, static_cast<float>( d ) );
/*
switch (t0->eEnvironment)
{ // typ zmiany oświetlenia - zakładam, że
@@ -3076,7 +3076,7 @@ TDynamicObject::update_load_offset() {
0.0 :
100.0 * MoverParameters->LoadAmount / MoverParameters->MaxLoad ) };
LoadOffset = interpolate( MoverParameters->LoadType.offset_min, 0.f, std::clamp( 0.0, 1.0, loadpercentage * 0.01 ) );
LoadOffset = std::lerp( MoverParameters->LoadType.offset_min, 0.f, std::clamp( 0.0, 1.0, loadpercentage * 0.01 ) );
}
void
@@ -3683,7 +3683,7 @@ bool TDynamicObject::Update(double dt, double dt1)
if( MoverParameters->Vel > 0 ) {
// TODO: track quality and/or environment factors as separate subroutine
auto volume =
interpolate(
std::lerp(
0.8, 1.2,
std::clamp(
MyTrack->iQualityFlag / 10.0,
@@ -4634,7 +4634,7 @@ void TDynamicObject::RenderSounds() {
m_emergencybrakeflow = (
m_emergencybrakeflow == 0.0 ?
MoverParameters->EmergencyValveFlow :
interpolate( m_emergencybrakeflow, MoverParameters->EmergencyValveFlow, 0.1 ) );
std::lerp( m_emergencybrakeflow, MoverParameters->EmergencyValveFlow, 0.1 ) );
// scale volume based on the flow rate and on the pressure in the main pipe
auto const flowpressure { std::clamp( m_emergencybrakeflow, 0.0, 1.0 ) + std::clamp( 0.1 * MoverParameters->PipePress, 0.0, 0.5 ) };
m_emergencybrake
@@ -4651,7 +4651,7 @@ void TDynamicObject::RenderSounds() {
if( m_lastbrakepressure != -1.f ) {
// calculate rate of pressure drop in brake cylinder, once it's been initialized
auto const brakepressuredifference{ m_lastbrakepressure - MoverParameters->BrakePress };
m_brakepressurechange = interpolate<float>( m_brakepressurechange, brakepressuredifference / dt, 0.05f );
m_brakepressurechange = std::lerp( m_brakepressurechange, brakepressuredifference / dt, 0.05f );
}
m_lastbrakepressure = MoverParameters->BrakePress;
// ensure some basic level of volume and scale it up depending on pressure in the cylinder; scale this by the air release rate
@@ -4719,7 +4719,7 @@ void TDynamicObject::RenderSounds() {
0.0, 1.0 );
rsBrake
.pitch( rsBrake.m_frequencyoffset + MoverParameters->Vel * rsBrake.m_frequencyfactor )
.gain( rsBrake.m_amplitudeoffset + std::sqrt( brakeforceratio * interpolate( 0.4, 1.0, ( MoverParameters->Vel / ( 1 + MoverParameters->Vmax ) ) ) ) * rsBrake.m_amplitudefactor )
.gain( rsBrake.m_amplitudeoffset + std::sqrt( brakeforceratio * std::lerp( 0.4, 1.0, ( MoverParameters->Vel / ( 1 + MoverParameters->Vmax ) ) ) ) * rsBrake.m_amplitudefactor )
.play( sound_flags::exclusive | sound_flags::looping );
}
else {
@@ -4736,7 +4736,7 @@ void TDynamicObject::RenderSounds() {
// McZapkie-280302 - pisk mocno zacisnietych hamulcow
if( MoverParameters->Vel > 2.5 ) {
volume = rsPisk.m_amplitudeoffset + interpolate( -1.0, 1.0, brakeforceratio ) * rsPisk.m_amplitudefactor;
volume = rsPisk.m_amplitudeoffset + std::lerp( -1.0, 1.0, brakeforceratio ) * rsPisk.m_amplitudefactor;
if( volume > 0.075 ) {
rsPisk
.pitch(
@@ -4964,7 +4964,7 @@ void TDynamicObject::RenderSounds() {
// scale volume by track quality
// TODO: track quality and/or environment factors as separate subroutine
volume *=
interpolate(
std::lerp(
0.8, 1.2,
std::clamp(
MyTrack->iQualityFlag / 20.0,
@@ -4972,7 +4972,7 @@ void TDynamicObject::RenderSounds() {
// for single sample sounds muffle the playback at low speeds
if( false == bogiesound.is_combined() ) {
volume *=
interpolate(
std::lerp(
0.0, 1.0,
std::clamp(
MoverParameters->Vel / 40.0,
@@ -5051,7 +5051,7 @@ void TDynamicObject::RenderSounds() {
// scale volume with curve radius and vehicle speed
volume =
std::abs( MoverParameters->AccN ) // * MoverParameters->AccN
* interpolate(
* std::lerp(
0.5, 1.0,
std::clamp(
MoverParameters->Vel / 40.0,
@@ -8090,7 +8090,7 @@ TDynamicObject::update_shake( double const Timedelta ) {
( MoverParameters->enrot - EngineShake.fadein_offset ) * EngineShake.fadein_factor,
0.0, 1.0 )
// fade out with rpm above threshold
* interpolate(
* std::lerp(
1.0, 0.0,
std::clamp(
( MoverParameters->enrot - EngineShake.fadeout_offset ) * EngineShake.fadeout_factor,
@@ -8103,7 +8103,7 @@ TDynamicObject::update_shake( double const Timedelta ) {
// hunting oscillation
HuntingAngle = clamp_circular( HuntingAngle + 4.0 * HuntingShake.frequency * Timedelta * MoverParameters->Vel, 360.0 );
auto const huntingamount =
interpolate(
std::lerp(
0.0, 1.0,
std::clamp(
( MoverParameters->Vel - HuntingShake.fadein_begin ) / ( HuntingShake.fadein_end - HuntingShake.fadein_begin ),
@@ -8376,7 +8376,7 @@ TDynamicObject::powertrain_sounds::render( TMoverParameters const &Vehicle, doub
fake_engine.stop();
}
engine_volume = interpolate( engine_volume, volume, 0.25 );
engine_volume = std::lerp( engine_volume, volume, 0.25 );
if( engine_volume < 0.05 ) {
engine.stop();
}
@@ -8519,7 +8519,7 @@ TDynamicObject::powertrain_sounds::render( TMoverParameters const &Vehicle, doub
+ std::abs( Vehicle.Mm ) / 60.0 * Deltatime,
0.0, 1.25 );
volume *= std::max( 0.25f, motor_momentum );
motor_volume = interpolate( motor_volume, volume, 0.25 );
motor_volume = std::lerp( motor_volume, volume, 0.25 );
if( motor_volume >= 0.05 ) {
// apply calculated parameters to all motor instances
for( auto &motor : motors ) {

View File

@@ -457,7 +457,7 @@ float TGauge::GetScaledValue() const {
( false == m_interpolatescale ) ?
m_value * m_scale + m_offset :
m_value
* interpolate(
* std::lerp(
m_scale, m_endscale,
std::clamp(
m_value / m_endvalue,

View File

@@ -1713,7 +1713,7 @@ void TTrain::OnCommand_trainbrakeset( TTrain *Train, command_data const &Command
if( Command.action != GLFW_RELEASE ) {
// press or hold
Train->mvOccupied->BrakeLevelSet(
interpolate(
std::lerp(
Train->mvOccupied->Handle->GetPos( bh_MIN ),
Train->mvOccupied->Handle->GetPos( bh_MAX ),
std::clamp(
@@ -8552,7 +8552,7 @@ TTrain::update_sounds( double const Deltatime ) {
if( m_lastlocalbrakepressure != -1.f ) {
// calculate rate of pressure drop in local brake cylinder, once it's been initialized
auto const brakepressuredifference { mvOccupied->LocBrakePress - m_lastlocalbrakepressure };
m_localbrakepressurechange = interpolate<float>( m_localbrakepressurechange, 10 * ( brakepressuredifference / Deltatime ), 0.1f );
m_localbrakepressurechange = std::lerp( m_localbrakepressurechange, 10 * ( brakepressuredifference / Deltatime ), 0.1f );
}
m_lastlocalbrakepressure = mvOccupied->LocBrakePress;
// local brake, release
@@ -8593,7 +8593,7 @@ TTrain::update_sounds( double const Deltatime ) {
|| ( mvOccupied->BrakeHandle == TBrakeHandle::FVel6 ) ) {
// upuszczanie z PG
if( rsHiss ) {
fPPress = interpolate( fPPress, static_cast<float>( mvOccupied->Handle->GetSound( s_fv4a_b ) ), 0.05f );
fPPress = std::lerp( fPPress, static_cast<float>( mvOccupied->Handle->GetSound( s_fv4a_b ) ), 0.05f );
volume = (
fPPress > 0 ?
rsHiss->m_amplitudefactor * fPPress * 0.25 + rsHiss->m_amplitudeoffset :
@@ -8608,7 +8608,7 @@ TTrain::update_sounds( double const Deltatime ) {
}
// napelnianie PG
if( rsHissU ) {
fNPress = interpolate( fNPress, static_cast<float>( mvOccupied->Handle->GetSound( s_fv4a_u ) ), 0.25f );
fNPress = std::lerp( fNPress, static_cast<float>( mvOccupied->Handle->GetSound( s_fv4a_u ) ), 0.25f );
volume = (
fNPress > 0 ?
rsHissU->m_amplitudefactor * fNPress + rsHissU->m_amplitudeoffset :
@@ -8703,7 +8703,7 @@ TTrain::update_sounds( double const Deltatime ) {
FreeFlyModeFlag ?
0.0 :
rsBrake->m_amplitudeoffset
+ std::sqrt( brakeforceratio * interpolate( 0.4, 1.0, ( mvOccupied->Vel / ( 1 + mvOccupied->Vmax ) ) ) ) * rsBrake->m_amplitudefactor );
+ std::sqrt( brakeforceratio * std::lerp( 0.4, 1.0, ( mvOccupied->Vel / ( 1 + mvOccupied->Vmax ) ) ) ) * rsBrake->m_amplitudefactor );
rsBrake->pitch( rsBrake->m_frequencyoffset + mvOccupied->Vel * rsBrake->m_frequencyfactor );
rsBrake->gain( volume );
rsBrake->play( sound_flags::exclusive | sound_flags::looping );
@@ -8776,7 +8776,7 @@ TTrain::update_sounds( double const Deltatime ) {
update_sounds_runningnoise( *rsHuntingNoise );
// modify calculated sound volume by hunting amount
auto const huntingamount =
interpolate(
std::lerp(
0.0, 1.0,
std::clamp(
( mvOccupied->Vel - DynamicObject->HuntingShake.fadein_begin ) / ( DynamicObject->HuntingShake.fadein_end - DynamicObject->HuntingShake.fadein_begin ),
@@ -8905,7 +8905,7 @@ void TTrain::update_sounds_resonancenoise(sound_source &Sound)
auto const frequency{Sound.m_frequencyoffset + Sound.m_frequencyfactor * mvOccupied->Vel * normalizer};
// volume calculation
auto volume = Sound.m_amplitudeoffset + Sound.m_amplitudefactor * interpolate(mvOccupied->Vel / (1 + mvOccupied->Vmax), 1.0, 0.5); // scale base volume between 0.5-1.0
auto volume = Sound.m_amplitudeoffset + Sound.m_amplitudefactor * std::lerp(mvOccupied->Vel / (1 + mvOccupied->Vmax), 1.0, 0.5); // scale base volume between 0.5-1.0
if (volume > 0.05)
{
@@ -8930,7 +8930,7 @@ void TTrain::update_sounds_runningnoise( sound_source &Sound ) {
// volume calculation
auto volume =
Sound.m_amplitudeoffset
+ Sound.m_amplitudefactor * interpolate(
+ Sound.m_amplitudefactor * std::lerp(
mvOccupied->Vel / ( 1 + mvOccupied->Vmax ), 1.0,
0.5 ); // scale base volume between 0.5-1.0
if( std::abs( mvOccupied->nrot ) > 0.01 ) {
@@ -8945,7 +8945,7 @@ void TTrain::update_sounds_runningnoise( sound_source &Sound ) {
// scale volume by track quality
// TODO: track quality and/or environment factors as separate subroutine
volume *=
interpolate(
std::lerp(
0.8, 1.2,
std::clamp(
DynamicObject->MyTrack->iQualityFlag / 20.0,
@@ -8953,7 +8953,7 @@ void TTrain::update_sounds_runningnoise( sound_source &Sound ) {
// for single sample sounds muffle the playback at low speeds
if( false == Sound.is_combined() ) {
volume *=
interpolate(
std::lerp(
0.0, 1.0,
std::clamp(
mvOccupied->Vel / 25.0,
@@ -9542,7 +9542,7 @@ glm::dvec3 TTrain::MirrorPosition(bool lewe)
glm::dvec4(
mvOccupied->Dim.W * ( 0.5 * shiftdirection ) + ( 0.2 * shiftdirection ),
1.5 + Cabine[iCabn].CabPos1.y,
interpolate( Cabine[ iCabn ].CabPos1.z , Cabine[ iCabn ].CabPos2.z, 0.5 ), 1.0);
std::lerp( Cabine[ iCabn ].CabPos1.z , Cabine[ iCabn ].CabPos2.z, 0.5 ), 1.0);
};
void TTrain::DynamicSet(TDynamicObject *d)