mirror of
https://github.com/Kelsidavis/WoWee.git
synced 2026-04-13 16:13:51 +00:00
fix: remove duplicate zone weather, consolidate RNG, name star constants
- weather: remove duplicate setZoneWeather(15) for Dustwallow Marsh — second call silently overwrote the first with different parameters - weather: replace duplicate static RNG in getRandomPosition() with shared weatherRng() to avoid redundant generator state - starfield: extract day/night cycle thresholds into named constants (kDuskStart/kNightStart/kDawnStart/kDawnEnd/kFadeDuration) - skybox: replace while-loop time wrapping with std::fmod — avoids O(n) iterations on large time jumps
This commit is contained in:
parent
086f32174f
commit
74f0ba010a
3 changed files with 23 additions and 20 deletions
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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<float> 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
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue