| 117 | } |
| 118 | |
| 119 | AudioInstancePtr AmbientManager::updateWeather(WeatherNoisesDescriptionPtr current) { |
| 120 | auto assets = Root::singleton().assets(); |
| 121 | |
| 122 | if (m_weatherTrack) { |
| 123 | if (m_weatherTrack->finished()) |
| 124 | m_weatherTrack = {}; |
| 125 | } |
| 126 | |
| 127 | StringList tracks; |
| 128 | if (current) |
| 129 | tracks = current->tracks; |
| 130 | |
| 131 | if (m_weatherTrack) { |
| 132 | if (!tracks.contains(m_weatherTrackName)) { |
| 133 | m_weatherTrack->stop(10.0f); |
| 134 | m_weatherTrack = {}; |
| 135 | } |
| 136 | } |
| 137 | |
| 138 | if (!m_weatherTrack) { |
| 139 | m_weatherTrackName = Random::randValueFrom(tracks); |
| 140 | if (!m_weatherTrackName.empty()) { |
| 141 | if (auto audio = assets->tryAudio(m_weatherTrackName)) { |
| 142 | m_weatherTrack = make_shared<AudioInstance>(*audio); |
| 143 | m_weatherTrack->setLoops(-1); |
| 144 | m_weatherTrack->setVolume(0.0f); |
| 145 | m_weatherTrack->setVolume(1, m_trackFadeInTime); |
| 146 | return m_weatherTrack; |
| 147 | } |
| 148 | } |
| 149 | } |
| 150 | |
| 151 | return {}; |
| 152 | } |
| 153 | |
| 154 | void AmbientManager::cancelAll() { |
| 155 | if (m_weatherTrack) { |