mirror of
https://github.com/rwengine/openrw.git
synced 2025-04-28 12:58:05 +03:00
Use enum class to describe actual state
This commit is contained in:
parent
03c155d2ba
commit
4e068591bd
3 changed files with 15 additions and 10 deletions
|
@ -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));
|
||||
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
};
|
||||
|
|
|
@ -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));
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue