MCPcopy Create free account
hub / github.com/OpenLoco/OpenLoco / updateSingleVehicleSound

Function updateSingleVehicleSound

src/OpenLoco/src/Audio/VehicleAudio.cpp:163–211  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

161 }
162
163 static void updateSingleVehicleSound(Vehicles::VehicleBase& base, Vehicles::VehicleSound& sound, EntityId headId)
164 {
165 if (sound.drivingSoundId == SoundObjectId::null)
166 {
167 if (sound.audioHandle != AudioHandle::null)
168 {
169 stopVehicleSound(sound);
170 }
171 return;
172 }
173
174 auto* viewport = findBestViewportForEntity(base.position, headId);
175 if (viewport == nullptr)
176 {
177 if (sound.audioHandle != AudioHandle::null)
178 {
179 stopVehicleSound(sound);
180 }
181 return;
182 }
183
184 auto sid = makeObjectSoundId(sound.drivingSoundId);
185 auto attribs = getVehicleAudioAttributes(base, sound, *viewport);
186
187 if (sound.audioHandle == AudioHandle::null)
188 {
189 attribs.loop = shouldSoundLoop(sid);
190 auto buffer = getSoundBuffer(sid);
191 if (buffer)
192 {
193 sound.activeSoundId = sound.drivingSoundId;
194 sound.audioHandle = create(*buffer, ChannelId::vehicles, attribs);
195 setReverb(sound.audioHandle, isUnderground(base.position) ? kTunnelReverb : kNoReverb);
196 Audio::play(sound.audioHandle);
197 }
198 return;
199 }
200
201 if (sound.drivingSoundId != sound.activeSoundId)
202 {
203 stopVehicleSound(sound);
204 return;
205 }
206
207 setVolume(sound.audioHandle, attribs.volume);
208 setPan(sound.audioHandle, attribs.pan);
209 setPitch(sound.audioHandle, attribs.frequency);
210 setReverb(sound.audioHandle, isUnderground(base.position) ? kTunnelReverb : kNoReverb);
211 }
212
213 void updateVehicleNoise()
214 {

Callers 1

updateVehicleNoiseFunction · 0.85

Calls 13

stopVehicleSoundFunction · 0.85
makeObjectSoundIdFunction · 0.85
shouldSoundLoopFunction · 0.85
getSoundBufferFunction · 0.85
setReverbFunction · 0.85
isUndergroundFunction · 0.85
setVolumeFunction · 0.85
setPanFunction · 0.85
setPitchFunction · 0.85
playFunction · 0.70

Tested by

no test coverage detected