mirror of
https://github.com/MaSzyna-EU07/maszyna.git
synced 2026-07-20 05:39:18 +02:00
Replace clamp with std::clamp
This commit is contained in:
@@ -140,11 +140,11 @@ state_manager::update_scripting_interface() {
|
||||
if( simulation::is_ready ) {
|
||||
// potentially adjust weather
|
||||
if( weather->Value1() != m_scriptinginterface.weather->Value1() ) {
|
||||
Global.Overcast = clamp<float>( weather->Value1(), 0, 2 );
|
||||
Global.Overcast = std::clamp( (float)weather->Value1(), 0.f, 2.f );
|
||||
simulation::Environment.compute_weather();
|
||||
}
|
||||
if( weather->Value2() != m_scriptinginterface.weather->Value2() ) {
|
||||
Global.fFogEnd = clamp<float>( weather->Value2(), 10, 25000 );
|
||||
Global.fFogEnd = std::clamp( (float)weather->Value2(), 10.f, 25000.f );
|
||||
}
|
||||
}
|
||||
else {
|
||||
@@ -324,7 +324,7 @@ void state_manager::process_commands() {
|
||||
simulation::Environment.compute_season(yearday);
|
||||
if( weather != Global.Weather ) {
|
||||
// HACK: force re-calculation of precipitation
|
||||
Global.Overcast = clamp( Global.Overcast - 0.0001f, 0.0f, 2.0f );
|
||||
Global.Overcast = std::clamp( Global.Overcast - 0.0001f, 0.0f, 2.0f );
|
||||
}
|
||||
|
||||
simulation::Environment.update_moon();
|
||||
|
||||
@@ -48,7 +48,7 @@ world_environment::compute_season( int const Yearday ) {
|
||||
auto const lookup =
|
||||
std::lower_bound(
|
||||
std::begin( seasonsequence ), std::end( seasonsequence ),
|
||||
clamp( Yearday, 1, seasonsequence.back().first ),
|
||||
std::clamp( Yearday, 1, seasonsequence.back().first ),
|
||||
[]( dayseasonpair const &Left, const int Right ) {
|
||||
return Left.first < Right; } );
|
||||
|
||||
@@ -117,7 +117,7 @@ world_environment::update() {
|
||||
m_moon.update();
|
||||
// ...determine source of key light and adjust global state accordingly...
|
||||
// diffuse (sun) intensity goes down after twilight, and reaches minimum 18 degrees below horizon
|
||||
float twilightfactor = clamp( -m_sun.getAngle(), 0.0f, 18.0f ) / 18.0f;
|
||||
float twilightfactor = std::clamp( -m_sun.getAngle(), 0.0f, 18.0f ) / 18.0f;
|
||||
// NOTE: sun light receives extra padding to prevent moon from kicking in too soon
|
||||
auto const sunlightlevel = m_sun.getIntensity() + 0.05f * ( 1.f - twilightfactor );
|
||||
auto const moonlightlevel = m_moon.getIntensity() * 0.65f; // scaled down by arbitrary factor, it's pretty bright otherwise
|
||||
@@ -127,8 +127,8 @@ world_environment::update() {
|
||||
// turbidity varies from 2-3 during the day based on overcast, 3-4 after sunset to deal with sunlight bleeding too much into the sky from below horizon
|
||||
m_skydome.SetTurbidity(
|
||||
2.25f
|
||||
+ clamp( Global.Overcast, 0.f, 1.f )
|
||||
+ interpolate( 0.f, 1.f, clamp( twilightfactor * 1.5f, 0.f, 1.f ) ) );
|
||||
+ std::clamp( Global.Overcast, 0.f, 1.f )
|
||||
+ interpolate( 0.f, 1.f, std::clamp( twilightfactor * 1.5f, 0.f, 1.f ) ) );
|
||||
m_skydome.SetOvercastFactor( Global.Overcast );
|
||||
m_skydome.Update( m_sun.getDirection() );
|
||||
|
||||
@@ -155,7 +155,7 @@ world_environment::update() {
|
||||
keylightintensity = sunlightlevel;
|
||||
m_lightintensity = 1.0f;
|
||||
// include 'golden hour' effect in twilight lighting
|
||||
float const duskfactor = 1.25f - clamp( Global.SunAngle, 0.0f, 18.0f ) / 18.0f;
|
||||
float const duskfactor = 1.25f - std::clamp( Global.SunAngle, 0.0f, 18.0f ) / 18.0f;
|
||||
keylightcolor = interpolate(
|
||||
glm::vec3( 255.0f / 255.0f, 242.0f / 255.0f, 231.0f / 255.0f ),
|
||||
glm::vec3( 235.0f / 255.0f, 120.0f / 255.0f, 36.0f / 255.0f ),
|
||||
@@ -180,8 +180,8 @@ world_environment::update() {
|
||||
|
||||
// tonal impact of skydome color is inversely proportional to how high the sun is above the horizon
|
||||
// (this is pure conjecture, aimed more to 'look right' than be accurate)
|
||||
float const ambienttone = clamp( 1.0f - ( Global.SunAngle / 90.0f ), 0.0f, 1.0f );
|
||||
float const ambientintensitynightfactor = 1.f - 0.75f * clamp( -m_sun.getAngle(), 0.0f, 18.0f ) / 18.0f;
|
||||
float const ambienttone = std::clamp( 1.0f - ( Global.SunAngle / 90.0f ), 0.0f, 1.0f );
|
||||
float const ambientintensitynightfactor = 1.f - 0.75f * std::clamp( -m_sun.getAngle(), 0.0f, 18.0f ) / 18.0f;
|
||||
Global.DayLight.ambient[ 0 ] = interpolate( skydomehsv.z, skydomecolour.r, ambienttone ) * ambientintensitynightfactor;
|
||||
Global.DayLight.ambient[ 1 ] = interpolate( skydomehsv.z, skydomecolour.g, ambienttone ) * ambientintensitynightfactor;
|
||||
Global.DayLight.ambient[ 2 ] = interpolate( skydomehsv.z, skydomecolour.b, ambienttone ) * ambientintensitynightfactor;
|
||||
@@ -191,7 +191,7 @@ world_environment::update() {
|
||||
// update the fog. setting it to match the average colour of the sky dome is cheap
|
||||
// but quite effective way to make the distant items blend with background better
|
||||
Global.FogColor = ((m_skydome.GetAverageHorizonColor()) * keylightcolor) *
|
||||
clamp<float>(Global.fLuminance, 0.0f, 1.f);
|
||||
std::clamp((float)Global.fLuminance, 0.f, 1.f);
|
||||
|
||||
|
||||
// weather-related simulation factors
|
||||
@@ -255,7 +255,7 @@ world_environment::update_wind() {
|
||||
// TBD, TODO: wind configuration
|
||||
m_wind.azimuth = clamp_circular( m_wind.azimuth + m_wind.azimuth_change * timedelta );
|
||||
// HACK: negative part of range allows for some quiet periods, without active wind
|
||||
m_wind.velocity = clamp<float>( m_wind.velocity + m_wind.velocity_change * timedelta, -2, 4 );
|
||||
m_wind.velocity = std::clamp( m_wind.velocity + m_wind.velocity_change * timedelta, -2.f, 4.f );
|
||||
// convert to force vector
|
||||
auto const polarangle { glm::radians( 90.f ) }; // theta
|
||||
auto const azimuthalangle{ glm::radians( m_wind.azimuth ) }; // phi
|
||||
|
||||
@@ -225,7 +225,7 @@ state_serializer::deserialize_atmo( cParser &Input, scene::scratch_data &Scratch
|
||||
}
|
||||
|
||||
Global.fFogEnd =
|
||||
clamp(
|
||||
std::clamp(
|
||||
Random( std::min( fograngestart, fograngeend ), std::max( fograngestart, fograngeend ) ),
|
||||
10.0, 25000.0 );
|
||||
}
|
||||
@@ -238,7 +238,7 @@ state_serializer::deserialize_atmo( cParser &Input, scene::scratch_data &Scratch
|
||||
// negative overcast means random value in range 0-abs(specified range)
|
||||
Global.Overcast =
|
||||
Random(
|
||||
clamp(
|
||||
std::clamp(
|
||||
std::abs( Global.Overcast ),
|
||||
0.f, 2.f ) );
|
||||
}
|
||||
|
||||
@@ -47,8 +47,8 @@ scenario_time::init(std::time_t timestamp) {
|
||||
daymonth( m_time.wDay, m_time.wMonth, m_time.wYear, static_cast<WORD>( Global.fMoveLight ) );
|
||||
}
|
||||
|
||||
if( requestedhour != -1 ) { m_time.wHour = static_cast<WORD>( clamp( requestedhour, 0, 23 ) ); }
|
||||
if( requestedminute != -1 ) { m_time.wMinute = static_cast<WORD>( clamp( requestedminute, 0, 59 ) ); }
|
||||
if( requestedhour != -1 ) { m_time.wHour = static_cast<WORD>( std::clamp( requestedhour, 0, 23 ) ); }
|
||||
if( requestedminute != -1 ) { m_time.wMinute = static_cast<WORD>( std::clamp( requestedminute, 0, 59 ) ); }
|
||||
// if the time is taken from the local clock leave the seconds intact, otherwise set them to zero
|
||||
if( ( requestedhour != -1 )
|
||||
|| ( requestedminute != 1 ) ) {
|
||||
|
||||
Reference in New Issue
Block a user