MCPcopy Create free account
hub / github.com/OpenStarbound/OpenStarbound / update

Method update

source/game/StarWeather.cpp:63–106  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

61}
62
63void 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
108float ServerWeather::wind() const {
109 return m_currentWind * m_currentWeatherIntensity;

Callers

nothing calls this directly

Calls 14

singletonClass · 0.85
randdFunction · 0.85
randbFunction · 0.85
clampFunction · 0.85
assetsMethod · 0.80
toDoubleMethod · 0.80
jsonMethod · 0.80
selectIndexMethod · 0.80
weatherTypeMethod · 0.80
biomeDatabaseMethod · 0.80
yMaxMethod · 0.80
timeMethod · 0.45

Tested by

no test coverage detected