16
0
mirror of https://github.com/MaSzyna-EU07/maszyna.git synced 2026-07-18 01:59:19 +02:00

improve handling of sound shutting down caused by distance

This commit is contained in:
milek7
2017-08-25 20:39:57 +02:00
parent 59317743fa
commit 9d91b19841
2 changed files with 33 additions and 8 deletions

View File

@@ -295,9 +295,9 @@ sound& sound::position(Math3D::vector3 const &pos)
sound& sound::dist(float dist)
{
max_dist = dist;
alSourcef(id, AL_MAX_DISTANCE, dist);
alSourcef(id, AL_REFERENCE_DISTANCE, dist / 3.82f);
max_dist = dist * 1.5f;
return *this;
}
@@ -407,6 +407,7 @@ complex_sound::complex_sound(sound_buffer* pre, sound_buffer* main, sound_buffer
post->ref();
samplerate = buffer->get_samplerate();
shut_by_dist = false;
cs = state::post;
}
@@ -428,19 +429,38 @@ void complex_sound::play()
alSourceRewind(id);
alSourcei(id, AL_LOOPING, AL_FALSE);
alSourcei(id, AL_BUFFER, 0);
ALuint buffers[] = { pre->get_id(), buffer->get_id() };
alSourceQueueBuffers(id, 2, buffers);
if (shut_by_dist)
{
shut_by_dist = false;
alSourcePlay(id);
alSourcei(id, AL_LOOPING, AL_TRUE);
alSourcei(id, AL_BUFFER, 0);
alSourcei(id, AL_BUFFER, buffer->get_id());
alSourcePlay(id);
cs = state::premain;
cs = state::main;
}
else
{
alSourcei(id, AL_LOOPING, AL_FALSE);
alSourcei(id, AL_BUFFER, 0);
ALuint buffers[] = { pre->get_id(), buffer->get_id() };
alSourceQueueBuffers(id, 2, buffers);
alSourcePlay(id);
cs = state::premain;
}
}
void complex_sound::stop()
{
if (cs == state::main || (Global::soundstopmode == Global::playstop && cs == state::premain))
if (shut_by_dist)
{
alSourceRewind(id);
cs = state::post;
}
else if (cs == state::main || (Global::soundstopmode == Global::playstop && cs == state::premain))
{
alSourceRewind(id);
@@ -495,7 +515,10 @@ void complex_sound::update(float dt)
if (cs == state::main)
if (spatial && glm::distance(pos, sound_man->pos) > max_dist)
{
shut_by_dist = true;
stop();
}
}
sound& complex_sound::loop(bool loop)

View File

@@ -109,6 +109,8 @@ class complex_sound : public sound
post // playing post or idling
} cs;
bool shut_by_dist;
public:
complex_sound(sound_buffer* pre, sound_buffer* main, sound_buffer* post);
~complex_sound();