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

Replace clamp with std::clamp

This commit is contained in:
docentYT
2026-05-01 22:14:29 +02:00
parent 1bdd000443
commit d1f16411a1
36 changed files with 271 additions and 287 deletions

View File

@@ -192,8 +192,7 @@ openal_source::sync_with( sound_properties const &State ) {
auto const fadedistance { sound_range * 0.75f };
auto const rangefactor {
interpolate(
1.f, 0.f,
clamp<float>(
1.f, 0.f, std::clamp(
( distancesquared - rangesquared ) / ( fadedistance * fadedistance ),
0.f, 1.f ) ) };
::alSourcef( id, AL_GAIN, gain * rangefactor );
@@ -203,7 +202,7 @@ openal_source::sync_with( sound_properties const &State ) {
// pitch
if( State.pitch != properties.pitch ) {
// pitch value has changed
::alSourcef( id, AL_PITCH, clamp( State.pitch * pitch_variation, 0.1f, 10.f ) );
::alSourcef( id, AL_PITCH, std::clamp( State.pitch * pitch_variation, 0.1f, 10.f ) );
}
// all synced up
properties = State;

View File

@@ -185,7 +185,7 @@ sound_source::deserialize_mapping( cParser &Input ) {
>> soundproofing[ 5 ];
for( auto & soundproofingelement : soundproofing ) {
if( soundproofingelement != -1.f ) {
soundproofingelement = std::sqrt( clamp( soundproofingelement, 0.f, 1.f ) );
soundproofingelement = std::sqrt( std::clamp( soundproofingelement, 0.f, 1.f ) );
}
}
m_soundproofing = soundproofing;
@@ -206,7 +206,7 @@ sound_source::deserialize_mapping( cParser &Input ) {
}
else if( key == "pitchvariation:" ) {
auto const variation {
clamp(
std::clamp(
Input.getToken<float>( false, "\n\r\t ,;" ),
0.0f, 1.0f )
* 100.0f / 2.0f };
@@ -217,7 +217,7 @@ sound_source::deserialize_mapping( cParser &Input ) {
}
else if( key == "startoffset:" ) {
m_startoffset =
clamp(
std::clamp(
Input.getToken<float>( false, "\n\r\t ,;" ),
0.0f, 1.0f );
}
@@ -240,7 +240,7 @@ sound_source::deserialize_mapping( cParser &Input ) {
// for combined sounds, percentage of assigned range allocated to crossfade sections
Input.getTokens( 1, "\n\r\t ,;" );
Input >> m_crossfaderange;
m_crossfaderange = clamp( m_crossfaderange, 0, 100 );
m_crossfaderange = std::clamp( m_crossfaderange, 0, 100 );
}
else if( key == "placement:" ) {
auto const value { Input.getToken<std::string>( true, "\n\r\t ,;" ) };
@@ -480,7 +480,7 @@ sound_source::compute_combined_point() const {
return (
m_properties.pitch <= 1.f ?
// most sounds use 0-1 value range, we clamp these to 0-99 to allow more intuitive sound definition in .mmd files
clamp( m_properties.pitch, 0.f, 0.99f ) :
std::clamp( m_properties.pitch, 0.f, 0.99f ) :
std::max( 0.f, m_properties.pitch )
) * 100.f;
}
@@ -784,7 +784,7 @@ sound_source::update_crossfade( sound_handle const Chunk ) {
interpolate(
previouschunkdata.pitch / chunkdata.pitch,
1.f,
clamp(
std::clamp(
( soundpoint - previouschunkdata.threshold ) / ( chunkdata.threshold - previouschunkdata.threshold ),
0.f, 1.f ) );
}
@@ -799,7 +799,7 @@ sound_source::update_crossfade( sound_handle const Chunk ) {
interpolate(
1.f,
nextchunkdata.pitch / chunkdata.pitch,
clamp(
std::clamp(
( soundpoint - chunkdata.threshold ) / ( nextchunkdata.threshold - chunkdata.threshold ),
0.f, 1.f ) );
}
@@ -818,7 +818,7 @@ sound_source::update_crossfade( sound_handle const Chunk ) {
float lineargain =
interpolate(
0.f, 1.f,
clamp(
std::clamp(
( soundpoint - chunkdata.fadein ) / fadeinwidth,
0.f, 1.f ) );
m_properties.gain *=
@@ -838,7 +838,7 @@ sound_source::update_crossfade( sound_handle const Chunk ) {
float lineargain =
interpolate(
0.f, 1.f,
clamp(
std::clamp(
( soundpoint - fadeoutstart ) / fadeoutwidth,
0.f, 1.f ) );
m_properties.gain *= (-lineargain + 1) /
@@ -852,7 +852,7 @@ sound_source::update_crossfade( sound_handle const Chunk ) {
sound_source &
sound_source::gain( float const Gain ) {
m_properties.gain = clamp( Gain, 0.f, 2.f );
m_properties.gain = std::clamp( Gain, 0.f, 2.f );
return *this;
}