diff --git a/src/rendering/skybox.cpp b/src/rendering/skybox.cpp index 1e08ac4f..d8cfba06 100644 --- a/src/rendering/skybox.cpp +++ b/src/rendering/skybox.cpp @@ -202,10 +202,9 @@ void Skybox::update(float deltaTime) { } void Skybox::setTimeOfDay(float time) { - // Clamp to 0-24 range - while (time < 0.0f) time += 24.0f; - while (time >= 24.0f) time -= 24.0f; - + // Wrap to [0, 24) range using fmod instead of iterative subtraction + time = std::fmod(time, 24.0f); + if (time < 0.0f) time += 24.0f; timeOfDay = time; } diff --git a/src/rendering/starfield.cpp b/src/rendering/starfield.cpp index b51d419b..30847d0c 100644 --- a/src/rendering/starfield.cpp +++ b/src/rendering/starfield.cpp @@ -13,6 +13,14 @@ namespace wowee { namespace rendering { +// Day/night cycle thresholds (hours, 24h clock) for star visibility. +// Stars fade in over 2 hours at dusk, stay full during night, fade out at dawn. +static constexpr float kDuskStart = 18.0f; // stars begin fading in +static constexpr float kNightStart = 20.0f; // full star visibility +static constexpr float kDawnStart = 4.0f; // stars begin fading out +static constexpr float kDawnEnd = 6.0f; // stars fully gone +static constexpr float kFadeDuration = 2.0f; + StarField::StarField() = default; StarField::~StarField() { @@ -303,22 +311,20 @@ void StarField::destroyStarBuffers() { } float StarField::getStarIntensity(float timeOfDay) const { - // Full night: 20:00–4:00 - if (timeOfDay >= 20.0f || timeOfDay < 4.0f) { + // Full night + if (timeOfDay >= kNightStart || timeOfDay < kDawnStart) { return 1.0f; } - // Fade in at dusk: 18:00–20:00 - else if (timeOfDay >= 18.0f && timeOfDay < 20.0f) { - return (timeOfDay - 18.0f) / 2.0f; // 0 → 1 over 2 hours + // Fade in at dusk + if (timeOfDay >= kDuskStart) { + return (timeOfDay - kDuskStart) / kFadeDuration; } - // Fade out at dawn: 4:00–6:00 - else if (timeOfDay >= 4.0f && timeOfDay < 6.0f) { - return 1.0f - (timeOfDay - 4.0f) / 2.0f; // 1 → 0 over 2 hours + // Fade out at dawn + if (timeOfDay < kDawnEnd) { + return 1.0f - (timeOfDay - kDawnStart) / kFadeDuration; } // Daytime: no stars - else { - return 0.0f; - } + return 0.0f; } } // namespace rendering diff --git a/src/rendering/weather.cpp b/src/rendering/weather.cpp index 0492432b..dcc673d6 100644 --- a/src/rendering/weather.cpp +++ b/src/rendering/weather.cpp @@ -353,12 +353,11 @@ void Weather::resetParticles(const Camera& camera) { } glm::vec3 Weather::getRandomPosition(const glm::vec3& center) const { - static std::random_device rd; - static std::mt19937 gen(rd()); + // Reuse the shared weather RNG to avoid duplicate generator state static std::uniform_real_distribution dist(-1.0f, 1.0f); - float x = center.x + dist(gen) * SPAWN_VOLUME_SIZE; - float z = center.z + dist(gen) * SPAWN_VOLUME_SIZE; + float x = center.x + dist(weatherRng()) * SPAWN_VOLUME_SIZE; + float z = center.z + dist(weatherRng()) * SPAWN_VOLUME_SIZE; float y = center.y; return glm::vec3(x, y, z); @@ -440,7 +439,6 @@ void Weather::initializeZoneWeatherDefaults() { setZoneWeather(148, Type::RAIN, 0.1f, 0.4f, 0.15f); // Darkshore setZoneWeather(331, Type::RAIN, 0.1f, 0.3f, 0.1f); // Ashenvale setZoneWeather(405, Type::RAIN, 0.1f, 0.3f, 0.1f); // Desolace - setZoneWeather(15, Type::RAIN, 0.2f, 0.5f, 0.2f); // Dustwallow Marsh setZoneWeather(490, Type::RAIN, 0.1f, 0.4f, 0.15f); // Un'Goro Crater setZoneWeather(493, Type::RAIN, 0.1f, 0.3f, 0.1f); // Moonglade