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:
JailDesignerandClaude Opus 4.7 committed 2026-04-20 13:29:00 +02:00
1 parent 961a59c460
commit 4e0dcfe739
3 files changed
+6 -34

No files matched your search

-1
View File
@@ -156,7 +156,6 @@ auto Audio::getMusicState() -> MusicState {
return MusicState::PAUSED;
case Ja::MusicState::STOPPED:
case Ja::MusicState::INVALID:
case Ja::MusicState::DISABLED:
default:
return MusicState::STOPPED;
}
+5 -25
View File
@@ -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) {
+1 -8
View File
@@ -32,19 +32,16 @@ namespace Ja {
// --- Public Enums ---
enum class ChannelState : std::uint8_t {
INVALID,
FREE,
PLAYING,
PAUSED,
SOUND_DISABLED,
};
enum class MusicState : std::uint8_t {
INVALID,
INVALID, // Music carregat però mai play-ejat
PLAYING,
PAUSED,
STOPPED,
DISABLED,
};
// --- Constants ---
@@ -136,7 +133,6 @@ namespace Ja {
void crossfadeMusic(Music* music, int crossfade_ms, int loop = -1);
[[nodiscard]] auto getMusicState() const -> MusicState;
auto setMusicVolume(float volume) -> float;
void enableMusic(bool value);
// Notifica al motor que un Music s'està destruint: si és el current_music
// s'atura abans que els seus recursos (stream/vorbis) deixin de ser vàlids.
void onMusicDeleted(const Music* music);
@@ -148,7 +144,6 @@ namespace Ja {
void resumeChannel(int channel);
void stopChannel(int channel);
auto setSoundVolume(float volume, int group = -1) -> float;
void enableSound(bool value);
// Notifica al motor que un Sound s'està destruint: els canals que el
// referenciïn es paren abans d'alliberar el buffer.
void onSoundDeleted(const Sound* sound);
@@ -168,8 +163,6 @@ namespace Ja {
SDL_AudioSpec audio_spec_{DEFAULT_SPEC};
float music_volume_{1.0F};
float sound_volume_[MAX_GROUPS]{};
bool music_enabled_{true};
bool sound_enabled_{true};
SDL_AudioDeviceID sdl_audio_device_{0};
OutgoingMusic outgoing_music_;
FadeState incoming_fade_;