From 1a2c5c9c1a1913b49bbf177883743ddfb0fa19c5 Mon Sep 17 00:00:00 2001 From: XProger Date: Fri, 29 Sep 2017 03:21:00 +0300 Subject: [PATCH] #23 fix static sounds volime control & flipmaps --- src/camera.h | 1 + src/level.h | 4 ++-- src/sound.h | 10 +++++++++- 3 files changed, 12 insertions(+), 3 deletions(-) diff --git a/src/camera.h b/src/camera.h index 50e4511..00a6200 100644 --- a/src/camera.h +++ b/src/camera.h @@ -96,6 +96,7 @@ struct Camera : ICamera { } void updateListener() { + Sound::flipped = level->isFlipped; Sound::listener.matrix = mViewInv; TR::Room &r = level->rooms[getRoomIndex()]; int h = (r.info.yBottom - r.info.yTop) / 1024; diff --git a/src/level.h b/src/level.h index f243a4d..044c85f 100644 --- a/src/level.h +++ b/src/level.h @@ -290,7 +290,7 @@ struct Level : IGame { } } if (b.flags.gain) volume = max(0.0f, volume - randf() * 0.25f); - if (b.flags.camera) flags &= ~Sound::PAN; + //if (b.flags.camera) flags &= ~Sound::PAN; return Sound::play(level.getSampleStream(index), pos, volume, pitch, flags, group * 1000 + index); } return NULL; @@ -539,7 +539,7 @@ struct Level : IGame { for (int i = 0; i < level.soundSourcesCount; i++) { TR::SoundSource &src = level.soundSources[i]; - lara->playSound(src.id, vec3(float(src.x), float(src.y), float(src.z)), Sound::PAN); + lara->playSound(src.id, vec3(float(src.x), float(src.y), float(src.z)), Sound::PAN | src.flags); } lastTitle = false; diff --git a/src/sound.h b/src/sound.h index 85d845b..8cd38aa 100644 --- a/src/sound.h +++ b/src/sound.h @@ -414,8 +414,12 @@ namespace Sound { REPLAY = 8, STATIC = 16, MUSIC = 32, + FLIPPED = 64, + UNFLIPPED = 128, }; + bool flipped; + struct Sample { Decoder *decoder; vec3 pos; @@ -505,7 +509,7 @@ namespace Sound { mat4 m = Sound::listener.matrix; vec3 v = pos - m.offset.xyz; - float dist = max(0.0f, 1.0f - (v.length2() / (SND_FADEOFF_DIST * SND_FADEOFF_DIST))); + float dist = max(0.0f, 1.0f - (v.length() / SND_FADEOFF_DIST)); float pan = m.right.xyz.dot(v.normal()); float l = min(1.0f, 1.0f - pan); @@ -575,6 +579,7 @@ namespace Sound { Filter::Reverberation reverb; void init() { + flipped = false; channelsCount = 0; callback = NULL; buffer = NULL; @@ -603,6 +608,9 @@ namespace Sound { continue; if (channels[i]->flags & STATIC) { + if (!(channels[i]->flags & (flipped ? FLIPPED : UNFLIPPED))) + continue; + vec3 d = channels[i]->pos - listener.matrix.getPos(); if (fabsf(d.x) > SND_FADEOFF_DIST || fabsf(d.y) > SND_FADEOFF_DIST || fabsf(d.z) > SND_FADEOFF_DIST) continue;