| 61 | } |
| 62 | |
| 63 | void ServerWeather::update(double dt) { |
| 64 | spawnWeatherProjectiles(dt); |
| 65 | |
| 66 | if (m_referenceClock) { |
| 67 | double clockTime = m_referenceClock->time(); |
| 68 | if (!m_clockTrackingTime) { |
| 69 | m_clockTrackingTime = clockTime; |
| 70 | } else { |
| 71 | // If our reference clock is set, and we have a valid tracking time, then |
| 72 | // the dt should be driven by the reference clock. |
| 73 | dt = clockTime - *m_clockTrackingTime; |
| 74 | m_clockTrackingTime = clockTime; |
| 75 | } |
| 76 | } |
| 77 | |
| 78 | m_currentTime += dt; |
| 79 | |
| 80 | if (!m_weatherPool.empty()) { |
| 81 | auto assets = Root::singleton().assets(); |
| 82 | double weatherCooldownTime = assets->json("/weather.config:weatherCooldownTime").toDouble(); |
| 83 | double weatherWarmupTime = assets->json("/weather.config:weatherWarmupTime").toDouble(); |
| 84 | |
| 85 | if (m_currentTime >= m_nextWeatherChangeTime) { |
| 86 | m_currentWeatherIndex = m_weatherPool.selectIndex(); |
| 87 | if (m_currentWeatherIndex == NPos) |
| 88 | m_currentWeatherType = {}; |
| 89 | else |
| 90 | m_currentWeatherType = Root::singleton().biomeDatabase()->weatherType(m_weatherPool.item(m_currentWeatherIndex)); |
| 91 | |
| 92 | m_lastWeatherChangeTime = m_nextWeatherChangeTime; |
| 93 | m_nextWeatherChangeTime = m_currentTime + Random::randd(m_currentWeatherType->duration[0], m_currentWeatherType->duration[1]); |
| 94 | |
| 95 | // TODO: For now just set the wind at maximum either left or right, nothing exciting. |
| 96 | m_currentWind = m_currentWeatherType->maximumWind * (Random::randb() ? 1 : -1); |
| 97 | } |
| 98 | |
| 99 | m_currentWeatherIntensity = min(clamp((m_currentTime - m_lastWeatherChangeTime) / weatherWarmupTime, 0.0, 1.0), |
| 100 | clamp((m_nextWeatherChangeTime - m_currentTime) / weatherCooldownTime, 0.0, 1.0)); |
| 101 | |
| 102 | } else { |
| 103 | m_currentWeatherIndex = NPos; |
| 104 | m_currentWeatherType = {}; |
| 105 | } |
| 106 | } |
| 107 | |
| 108 | float ServerWeather::wind() const { |
| 109 | return m_currentWind * m_currentWeatherIntensity; |
nothing calls this directly
no test coverage detected