mirror of
https://github.com/SFML/SFML.git
synced 2024-11-28 22:31:09 +08:00
Refactor ternary into early-returning conditionals
A complex ternary expression here doesn't buy us anything. This refactor more clearly expresses what is going on in this function.
This commit is contained in:
parent
30a986e632
commit
ef5ee38576
@ -413,21 +413,23 @@ sf::Color getSnowcapTerrainColor(float elevation, float moisture)
|
|||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
sf::Color getTerrainColor(float elevation, float moisture)
|
sf::Color getTerrainColor(float elevation, float moisture)
|
||||||
{
|
{
|
||||||
sf::Color color = elevation < 0.11f ? sf::Color(0, 0, static_cast<std::uint8_t>(elevation / 0.11f * 74.f + 181.0f))
|
if (elevation < 0.11f)
|
||||||
: elevation < 0.14f
|
return {0, 0, static_cast<std::uint8_t>(elevation / 0.11f * 74.f + 181.0f)};
|
||||||
? sf::Color(static_cast<std::uint8_t>(std::pow((elevation - 0.11f) / 0.03f, 0.3f) * 48.f),
|
if (elevation < 0.14f)
|
||||||
|
return {static_cast<std::uint8_t>(std::pow((elevation - 0.11f) / 0.03f, 0.3f) * 48.f),
|
||||||
static_cast<std::uint8_t>(std::pow((elevation - 0.11f) / 0.03f, 0.3f) * 48.f),
|
static_cast<std::uint8_t>(std::pow((elevation - 0.11f) / 0.03f, 0.3f) * 48.f),
|
||||||
255)
|
255};
|
||||||
: elevation < 0.16f
|
if (elevation < 0.16f)
|
||||||
? sf::Color(static_cast<std::uint8_t>((elevation - 0.14f) * 128.f / 0.02f + 48.f),
|
return {static_cast<std::uint8_t>((elevation - 0.14f) * 128.f / 0.02f + 48.f),
|
||||||
static_cast<std::uint8_t>((elevation - 0.14f) * 128.f / 0.02f + 48.f),
|
static_cast<std::uint8_t>((elevation - 0.14f) * 128.f / 0.02f + 48.f),
|
||||||
static_cast<std::uint8_t>(127.0f + (0.16f - elevation) * 128.f / 0.02f))
|
static_cast<std::uint8_t>(127.0f + (0.16f - elevation) * 128.f / 0.02f)};
|
||||||
: elevation < 0.17f ? sf::Color(240, 230, 140)
|
if (elevation < 0.17f)
|
||||||
: elevation < 0.4f ? getLowlandsTerrainColor(moisture)
|
return {240, 230, 140};
|
||||||
: elevation < snowcapHeight ? getHighlandsTerrainColor(elevation, moisture)
|
if (elevation < 0.4f)
|
||||||
: getSnowcapTerrainColor(elevation, moisture);
|
return getLowlandsTerrainColor(moisture);
|
||||||
|
if (elevation < snowcapHeight)
|
||||||
return color;
|
return getHighlandsTerrainColor(elevation, moisture);
|
||||||
|
return getSnowcapTerrainColor(elevation, moisture);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user