refactor(core/audio): remove engine enable flags (INCONS-05)
Ja::Engine tenia music_enabled_ i sound_enabled_ com a membres amb el
seu propi enableMusic/enableSound setter, i disseminava checks
`if (!music_enabled_)` / `if (!sound_enabled_)` per gairebé totes les
operacions. Després del commit 3, ningú crida aquests setters: Audio
gestiona el gating per gain (effectiveVolume retorna 0 quan
music_enabled_/sound_enabled_ d'Audio són false). L'usuari ha confirmat
que vol mantenir aquesta semàntica (silenciar per gain, no parar).
Es retira tot el camí mort:
- Membres music_enabled_ / sound_enabled_ eliminats.
- Mètodes Engine::enableMusic(bool) / Engine::enableSound(bool)
eliminats.
- Checks `if (!music_enabled_)` / `if (!sound_enabled_)` eliminats de
playMusic, pauseMusic, resumeMusic, fadeOutMusic, crossfadeMusic,
updateCurrentMusic, playSound, playSoundOnChannel, pauseChannel,
resumeChannel, updateSoundChannels.
- Enum MusicState::DISABLED eliminat (inabastable sense el flag).
- Enum ChannelState::INVALID i SOUND_DISABLED eliminats (no usats
després de DEAD-04).
- Audio::getMusicState treu el case DISABLED del switch.
Audio::enableMusic/enableSound i els seus flags music_enabled_/
sound_enabled_ d'Audio romanen — són ells els qui porten la decisió al
motor via setXxxVolume(config_.X_volume) → effectiveVolume → gain.
Tanca la meitat restant d'INCONS-05.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
1 parent
961a59c460
commit
4e0dcfe739
3 files changed
+6
-34
No files matched your search
@@ -145,7 +145,7 @@ namespace Ja {
|
||||
}
|
||||
|
||||
void Engine::updateCurrentMusic() {
|
||||
if (!music_enabled_ || current_music_ == nullptr || current_music_->state != MusicState::PLAYING) { return; }
|
||||
if (current_music_ == nullptr || current_music_->state != MusicState::PLAYING) { return; }
|
||||
|
||||
updateIncomingFade();
|
||||
|
||||
@@ -156,8 +156,6 @@ namespace Ja {
|
||||
}
|
||||
|
||||
void Engine::updateSoundChannels() {
|
||||
if (!sound_enabled_) { return; }
|
||||
|
||||
for (int i = 0; i < MAX_SIMULTANEOUS_CHANNELS; ++i) {
|
||||
if (channels_[i].state != ChannelState::PLAYING) { continue; }
|
||||
|
||||
@@ -214,7 +212,7 @@ namespace Ja {
|
||||
}
|
||||
|
||||
void Engine::playMusic(Music* music, const int loop) {
|
||||
if (!music_enabled_ || music == nullptr || music->vorbis == nullptr) { return; }
|
||||
if (music == nullptr || music->vorbis == nullptr) { return; }
|
||||
|
||||
stopMusic();
|
||||
|
||||
@@ -240,7 +238,6 @@ namespace Ja {
|
||||
}
|
||||
|
||||
void Engine::pauseMusic() {
|
||||
if (!music_enabled_) { return; }
|
||||
if (current_music_ == nullptr || current_music_->state != MusicState::PLAYING) { return; }
|
||||
|
||||
current_music_->state = MusicState::PAUSED;
|
||||
@@ -248,7 +245,6 @@ namespace Ja {
|
||||
}
|
||||
|
||||
void Engine::resumeMusic() {
|
||||
if (!music_enabled_) { return; }
|
||||
if (current_music_ == nullptr || current_music_->state != MusicState::PAUSED) { return; }
|
||||
|
||||
current_music_->state = MusicState::PLAYING;
|
||||
@@ -276,7 +272,6 @@ namespace Ja {
|
||||
}
|
||||
|
||||
void Engine::fadeOutMusic(const int milliseconds) {
|
||||
if (!music_enabled_) { return; }
|
||||
if (current_music_ == nullptr || current_music_->state != MusicState::PLAYING) { return; }
|
||||
|
||||
stealCurrentIntoOutgoing(milliseconds);
|
||||
@@ -284,7 +279,7 @@ namespace Ja {
|
||||
}
|
||||
|
||||
void Engine::crossfadeMusic(Music* music, const int crossfade_ms, const int loop) {
|
||||
if (!music_enabled_ || music == nullptr || music->vorbis == nullptr) { return; }
|
||||
if (music == nullptr || music->vorbis == nullptr) { return; }
|
||||
|
||||
stealCurrentIntoOutgoing(crossfade_ms);
|
||||
|
||||
@@ -312,7 +307,6 @@ namespace Ja {
|
||||
}
|
||||
|
||||
auto Engine::getMusicState() const -> MusicState {
|
||||
if (!music_enabled_) { return MusicState::DISABLED; }
|
||||
if (current_music_ == nullptr) { return MusicState::INVALID; }
|
||||
return current_music_->state;
|
||||
}
|
||||
@@ -325,11 +319,6 @@ namespace Ja {
|
||||
return music_volume_;
|
||||
}
|
||||
|
||||
void Engine::enableMusic(const bool value) {
|
||||
if (!value && current_music_ != nullptr && (current_music_->state == MusicState::PLAYING)) { stopMusic(); }
|
||||
music_enabled_ = value;
|
||||
}
|
||||
|
||||
void Engine::onMusicDeleted(const Music* music) {
|
||||
if (music == nullptr) { return; }
|
||||
if (current_music_ == music) {
|
||||
@@ -341,7 +330,7 @@ namespace Ja {
|
||||
// --- Sound ---
|
||||
|
||||
auto Engine::playSound(Sound* sound, const int loop, const int group) -> int {
|
||||
if (!sound_enabled_ || sound == nullptr) { return -1; }
|
||||
if (sound == nullptr) { return -1; }
|
||||
|
||||
int channel = 0;
|
||||
while (channel < MAX_SIMULTANEOUS_CHANNELS && channels_[channel].state != ChannelState::FREE) { channel++; }
|
||||
@@ -354,7 +343,7 @@ namespace Ja {
|
||||
}
|
||||
|
||||
auto Engine::playSoundOnChannel(Sound* sound, const int channel, const int loop, const int group) -> int {
|
||||
if (!sound_enabled_ || sound == nullptr) { return -1; }
|
||||
if (sound == nullptr) { return -1; }
|
||||
if (channel < 0 || channel >= MAX_SIMULTANEOUS_CHANNELS) { return -1; }
|
||||
|
||||
stopChannel(channel);
|
||||
@@ -380,7 +369,6 @@ namespace Ja {
|
||||
}
|
||||
|
||||
void Engine::pauseChannel(const int channel) {
|
||||
if (!sound_enabled_) { return; }
|
||||
forEachTargetChannel(channel, [](Channel& ch) {
|
||||
if (ch.state == ChannelState::PLAYING) {
|
||||
ch.state = ChannelState::PAUSED;
|
||||
@@ -390,7 +378,6 @@ namespace Ja {
|
||||
}
|
||||
|
||||
void Engine::resumeChannel(const int channel) {
|
||||
if (!sound_enabled_) { return; }
|
||||
const SDL_AudioDeviceID DEVICE = sdl_audio_device_;
|
||||
forEachTargetChannel(channel, [DEVICE](Channel& ch) {
|
||||
if (ch.state == ChannelState::PAUSED) {
|
||||
@@ -435,13 +422,6 @@ namespace Ja {
|
||||
return V;
|
||||
}
|
||||
|
||||
void Engine::enableSound(const bool value) {
|
||||
if (!value) {
|
||||
stopChannel(-1);
|
||||
}
|
||||
sound_enabled_ = value;
|
||||
}
|
||||
|
||||
void Engine::onSoundDeleted(const Sound* sound) {
|
||||
if (sound == nullptr) { return; }
|
||||
for (int i = 0; i < MAX_SIMULTANEOUS_CHANNELS; ++i) {
|
||||
|
||||
Reference in new issue
Block a user