mirror of
https://github.com/rwengine/openrw.git
synced 2024-10-06 09:07:19 +02:00
Use enum class to describe actual state
This commit is contained in:
parent
03c155d2ba
commit
4e068591bd
@ -51,16 +51,16 @@ bool SoundBuffer::isStopped() const {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void SoundBuffer::play() {
|
void SoundBuffer::play() {
|
||||||
running = true;
|
state = State::Playing;
|
||||||
alCheck(alSourcePlay(source));
|
alCheck(alSourcePlay(source));
|
||||||
|
|
||||||
}
|
}
|
||||||
void SoundBuffer::pause() {
|
void SoundBuffer::pause() {
|
||||||
running = false;
|
state = State::Stopped;
|
||||||
alCheck(alSourcePause(source));
|
alCheck(alSourcePause(source));
|
||||||
}
|
}
|
||||||
void SoundBuffer::stop() {
|
void SoundBuffer::stop() {
|
||||||
running = false;
|
state = State::Stopped;
|
||||||
alCheck(alSourceStop(source));
|
alCheck(alSourceStop(source));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -27,8 +27,13 @@ struct SoundBuffer {
|
|||||||
void setGain(float gain);
|
void setGain(float gain);
|
||||||
void setMaxDistance(float maxDist);
|
void setMaxDistance(float maxDist);
|
||||||
|
|
||||||
|
enum class State {
|
||||||
|
Stopped,
|
||||||
|
Playing
|
||||||
|
};
|
||||||
|
|
||||||
ALuint source;
|
ALuint source;
|
||||||
bool running = false;
|
State state = State::Stopped;
|
||||||
private:
|
private:
|
||||||
ALuint buffer;
|
ALuint buffer;
|
||||||
};
|
};
|
||||||
|
@ -59,8 +59,8 @@ void SoundBufferStreamed::play() {
|
|||||||
alSourcePlay(source);
|
alSourcePlay(source);
|
||||||
|
|
||||||
// Maybe another thread is running, we should tell him to stop
|
// Maybe another thread is running, we should tell him to stop
|
||||||
if (running) {
|
if (state == State::Playing) {
|
||||||
running = false;
|
state = State::Stopped;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Use preloaded data (and give another thread time to stop)
|
// Use preloaded data (and give another thread time to stop)
|
||||||
@ -72,11 +72,11 @@ void SoundBufferStreamed::play() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void SoundBufferStreamed::updateBuffers() {
|
void SoundBufferStreamed::updateBuffers() {
|
||||||
running = true;
|
state = State::Playing;
|
||||||
while (true) {
|
while (true) {
|
||||||
{
|
{
|
||||||
std::lock_guard<std::mutex> lock(soundSource->mutex);
|
std::lock_guard<std::mutex> lock(soundSource->mutex);
|
||||||
if (!running) {
|
if (state == State::Stopped) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -131,11 +131,11 @@ void SoundBufferStreamed::updateBuffers() {
|
|||||||
|
|
||||||
void SoundBufferStreamed::pause() {
|
void SoundBufferStreamed::pause() {
|
||||||
std::lock_guard<std::mutex> lock(soundSource->mutex);
|
std::lock_guard<std::mutex> lock(soundSource->mutex);
|
||||||
running = false;
|
state = State::Stopped;
|
||||||
alCheck(alSourcePause(source));
|
alCheck(alSourcePause(source));
|
||||||
}
|
}
|
||||||
void SoundBufferStreamed::stop() {
|
void SoundBufferStreamed::stop() {
|
||||||
std::lock_guard<std::mutex> lock(soundSource->mutex);
|
std::lock_guard<std::mutex> lock(soundSource->mutex);
|
||||||
running = false;
|
state = State::Stopped;
|
||||||
alCheck(alSourceStop(source));
|
alCheck(alSourceStop(source));
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user