diff options
author | Kae <80987908+Novaenia@users.noreply.github.com> | 2023-06-26 19:25:37 +1000 |
---|---|---|
committer | Kae <80987908+Novaenia@users.noreply.github.com> | 2023-06-26 19:25:37 +1000 |
commit | 68d20787cf8540ebc22a45e6e82afbf8ad4dea15 (patch) | |
tree | dd9e900c85120fb76749e02085686c836f082ae9 /source/frontend/StarMainMixer.cpp | |
parent | 4b9b02783f1bbfc1049e11b606883c5cfa0b215e (diff) |
The camera is now also an audio listener
Diffstat (limited to 'source/frontend/StarMainMixer.cpp')
-rw-r--r-- | source/frontend/StarMainMixer.cpp | 26 |
1 files changed, 23 insertions, 3 deletions
diff --git a/source/frontend/StarMainMixer.cpp b/source/frontend/StarMainMixer.cpp index 46c26cd..c49a0fc 100644 --- a/source/frontend/StarMainMixer.cpp +++ b/source/frontend/StarMainMixer.cpp @@ -6,6 +6,7 @@ #include "StarPlayer.hpp" #include "StarAssets.hpp" #include "StarWorldClient.hpp" +#include "StarWorldPainter.hpp" namespace Star { @@ -17,6 +18,10 @@ void MainMixer::setUniverseClient(UniverseClientPtr universeClient) { m_universeClient = move(universeClient); } +void MainMixer::setWorldPainter(WorldPainterPtr worldPainter) { + m_worldPainter = move(worldPainter); +} + void MainMixer::update(bool muteSfx, bool muteMusic) { auto assets = Root::singleton().assets(); @@ -30,7 +35,7 @@ void MainMixer::update(bool muteSfx, bool muteMusic) { m_mixer->setGroupVolume(group, m_groupVolumes[group], 1.0f); } } else if (!m_mutedGroups.contains(group)) { - float volumeSetting = Root::singleton().configuration()->get(settingName).toFloat() / 100; + float volumeSetting = Root::singleton().configuration()->get(settingName).toFloat() / 100.0f; if (!m_groupVolumes.contains(group) || volumeSetting != m_groupVolumes[group]) { m_mixer->setGroupVolume(group, volumeSetting); m_groupVolumes[group] = volumeSetting; @@ -72,11 +77,26 @@ void MainMixer::update(bool muteSfx, bool muteMusic) { Vec2F stereoAdjustmentRange = jsonToVec2F(assets->json("/sfx.config:stereoAdjustmentRange")); float attenuationGamma = assets->json("/sfx.config:attenuationGamma").toFloat(); auto playerPos = m_universeClient->mainPlayer()->position(); + auto cameraPos = m_worldPainter->camera().centerWorldPosition(); auto worldGeometry = currentWorld->geometry(); m_mixer->update([&](unsigned channel, Vec2F pos, float rangeMultiplier) { - Vec2F diff = worldGeometry.diff(pos, playerPos); - float diffMagnitude = diff.magnitude(); + Vec2F playerDiff = worldGeometry.diff(pos, playerPos); + Vec2F cameraDiff = worldGeometry.diff(pos, cameraPos); + float playerMagSq = playerDiff.magnitudeSquared(); + float cameraMagSq = cameraDiff.magnitudeSquared(); + + Vec2F diff; + float diffMagnitude; + if (playerMagSq < cameraMagSq) { + diff = playerDiff; + diffMagnitude = sqrt(playerMagSq); + } + else { + diff = cameraDiff; + diffMagnitude = sqrt(cameraMagSq); + } + if (diffMagnitude == 0.0f) return 0.0f; |