| 24 | } |
| 25 | |
| 26 | void MainMixer::update(float dt, bool muteSfx, bool muteMusic) { |
| 27 | auto assets = Root::singleton().assets(); |
| 28 | |
| 29 | auto updateGroupVolume = [&](MixerGroup group, bool muted, String const& settingName) { |
| 30 | if (m_mutedGroups.contains(group) != muted) { |
| 31 | if (muted) { |
| 32 | m_mutedGroups.add(group); |
| 33 | m_mixer->setGroupVolume(group, 0, 1.0f); |
| 34 | } else { |
| 35 | m_mutedGroups.remove(group); |
| 36 | m_mixer->setGroupVolume(group, m_groupVolumes[group], 1.0f); |
| 37 | } |
| 38 | } else if (!m_mutedGroups.contains(group)) { |
| 39 | float volumeSetting = Root::singleton().configuration()->get(settingName).toFloat() / 100.0f; |
| 40 | volumeSetting = perceptualToAmplitude(volumeSetting); |
| 41 | if (!m_groupVolumes.contains(group) || volumeSetting != m_groupVolumes[group]) { |
| 42 | m_mixer->setGroupVolume(group, volumeSetting); |
| 43 | m_groupVolumes[group] = volumeSetting; |
| 44 | } |
| 45 | } |
| 46 | }; |
| 47 | |
| 48 | updateGroupVolume(MixerGroup::Effects, muteSfx, "sfxVol"); |
| 49 | updateGroupVolume(MixerGroup::Music, muteMusic, "musicVol"); |
| 50 | updateGroupVolume(MixerGroup::Cinematic, false, "sfxVol"); |
| 51 | updateGroupVolume(MixerGroup::Instruments, muteSfx, "instrumentVol"); |
| 52 | |
| 53 | WorldClientPtr currentWorld; |
| 54 | if (m_universeClient) |
| 55 | currentWorld = m_universeClient->worldClient(); |
| 56 | |
| 57 | if (currentWorld) { |
| 58 | for (auto audioInstance : currentWorld->pullPendingAudio()) |
| 59 | m_mixer->play(audioInstance); |
| 60 | |
| 61 | for (auto audioInstance : currentWorld->pullPendingMusic()) { |
| 62 | audioInstance->setMixerGroup(MixerGroup::Music); |
| 63 | m_mixer->play(audioInstance); |
| 64 | } |
| 65 | |
| 66 | if (m_universeClient && m_universeClient->mainPlayer()->underwater()) { |
| 67 | if (!m_mixer->hasEffect("lowpass")) |
| 68 | m_mixer->addEffect("lowpass", m_mixer->lowpass(32), 0.50f); |
| 69 | if (!m_mixer->hasEffect("echo")) |
| 70 | m_mixer->addEffect("echo", m_mixer->echo(0.2f, 0.6f, 0.4f), 0.50f); |
| 71 | } else { |
| 72 | if (m_mixer->hasEffect("lowpass")) |
| 73 | m_mixer->removeEffect("lowpass", 0.5f); |
| 74 | if (m_mixer->hasEffect("echo")) |
| 75 | m_mixer->removeEffect("echo", 0.5f); |
| 76 | } |
| 77 | |
| 78 | float baseMaxDistance = assets->json("/sfx.config:baseMaxDistance").toFloat(); |
| 79 | Vec2F stereoAdjustmentRange = jsonToVec2F(assets->json("/sfx.config:stereoAdjustmentRange")); |
| 80 | float attenuationGamma = assets->json("/sfx.config:attenuationGamma").toFloat(); |
| 81 | auto playerPos = m_universeClient->mainPlayer()->position(); |
| 82 | auto cameraPos = m_worldPainter->camera().centerWorldPosition(); |
| 83 | auto worldGeometry = currentWorld->geometry(); |
nothing calls this directly
no test coverage detected