mirror of
https://github.com/MaSzyna-EU07/maszyna.git
synced 2026-07-22 11:39:19 +02:00
improve handling of sound shutting down caused by distance
This commit is contained in:
39
sound.cpp
39
sound.cpp
@@ -295,9 +295,9 @@ sound& sound::position(Math3D::vector3 const &pos)
|
|||||||
|
|
||||||
sound& sound::dist(float dist)
|
sound& sound::dist(float dist)
|
||||||
{
|
{
|
||||||
max_dist = dist;
|
|
||||||
alSourcef(id, AL_MAX_DISTANCE, dist);
|
alSourcef(id, AL_MAX_DISTANCE, dist);
|
||||||
alSourcef(id, AL_REFERENCE_DISTANCE, dist / 3.82f);
|
alSourcef(id, AL_REFERENCE_DISTANCE, dist / 3.82f);
|
||||||
|
max_dist = dist * 1.5f;
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -407,6 +407,7 @@ complex_sound::complex_sound(sound_buffer* pre, sound_buffer* main, sound_buffer
|
|||||||
post->ref();
|
post->ref();
|
||||||
|
|
||||||
samplerate = buffer->get_samplerate();
|
samplerate = buffer->get_samplerate();
|
||||||
|
shut_by_dist = false;
|
||||||
|
|
||||||
cs = state::post;
|
cs = state::post;
|
||||||
}
|
}
|
||||||
@@ -428,19 +429,38 @@ void complex_sound::play()
|
|||||||
|
|
||||||
alSourceRewind(id);
|
alSourceRewind(id);
|
||||||
|
|
||||||
alSourcei(id, AL_LOOPING, AL_FALSE);
|
if (shut_by_dist)
|
||||||
alSourcei(id, AL_BUFFER, 0);
|
{
|
||||||
ALuint buffers[] = { pre->get_id(), buffer->get_id() };
|
shut_by_dist = false;
|
||||||
alSourceQueueBuffers(id, 2, buffers);
|
|
||||||
|
|
||||||
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()
|
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);
|
alSourceRewind(id);
|
||||||
|
|
||||||
@@ -495,7 +515,10 @@ void complex_sound::update(float dt)
|
|||||||
|
|
||||||
if (cs == state::main)
|
if (cs == state::main)
|
||||||
if (spatial && glm::distance(pos, sound_man->pos) > max_dist)
|
if (spatial && glm::distance(pos, sound_man->pos) > max_dist)
|
||||||
|
{
|
||||||
|
shut_by_dist = true;
|
||||||
stop();
|
stop();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
sound& complex_sound::loop(bool loop)
|
sound& complex_sound::loop(bool loop)
|
||||||
|
|||||||
2
sound.h
2
sound.h
@@ -109,6 +109,8 @@ class complex_sound : public sound
|
|||||||
post // playing post or idling
|
post // playing post or idling
|
||||||
} cs;
|
} cs;
|
||||||
|
|
||||||
|
bool shut_by_dist;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
complex_sound(sound_buffer* pre, sound_buffer* main, sound_buffer* post);
|
complex_sound(sound_buffer* pre, sound_buffer* main, sound_buffer* post);
|
||||||
~complex_sound();
|
~complex_sound();
|
||||||
|
|||||||
Reference in New Issue
Block a user