1
0
mirror of https://github.com/rwengine/openrw.git synced 2024-07-08 13:54:52 +02:00

Use enum class to describe actual state

This commit is contained in:
Filip Gawin 2019-05-18 23:07:38 +02:00
parent 03c155d2ba
commit 4e068591bd
3 changed files with 15 additions and 10 deletions

View File

@ -51,16 +51,16 @@ bool SoundBuffer::isStopped() const {
}
void SoundBuffer::play() {
running = true;
state = State::Playing;
alCheck(alSourcePlay(source));
}
void SoundBuffer::pause() {
running = false;
state = State::Stopped;
alCheck(alSourcePause(source));
}
void SoundBuffer::stop() {
running = false;
state = State::Stopped;
alCheck(alSourceStop(source));
}

View File

@ -27,8 +27,13 @@ struct SoundBuffer {
void setGain(float gain);
void setMaxDistance(float maxDist);
enum class State {
Stopped,
Playing
};
ALuint source;
bool running = false;
State state = State::Stopped;
private:
ALuint buffer;
};

View File

@ -59,8 +59,8 @@ void SoundBufferStreamed::play() {
alSourcePlay(source);
// Maybe another thread is running, we should tell him to stop
if (running) {
running = false;
if (state == State::Playing) {
state = State::Stopped;
}
}
// Use preloaded data (and give another thread time to stop)
@ -72,11 +72,11 @@ void SoundBufferStreamed::play() {
}
void SoundBufferStreamed::updateBuffers() {
running = true;
state = State::Playing;
while (true) {
{
std::lock_guard<std::mutex> lock(soundSource->mutex);
if (!running) {
if (state == State::Stopped) {
return;
}
@ -131,11 +131,11 @@ void SoundBufferStreamed::updateBuffers() {
void SoundBufferStreamed::pause() {
std::lock_guard<std::mutex> lock(soundSource->mutex);
running = false;
state = State::Stopped;
alCheck(alSourcePause(source));
}
void SoundBufferStreamed::stop() {
std::lock_guard<std::mutex> lock(soundSource->mutex);
running = false;
state = State::Stopped;
alCheck(alSourceStop(source));
}