refactor(core/audio): helper effectiveVolume compartit (DUP-02)
setSoundVolume i setMusicVolume repetien la mateixa lògica de clamp + gate (enabled_ && channel_enabled_) + multiplicació pel master config_.volume. S'extreu effectiveVolume(volume, channel_enabled) privat i els dos setters es limiten a la crida Ja::*. Any canvi futur a la política (p.ex. una corba logarítmica) queda en un sol lloc. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
1 parent
256a232a95
commit
893e5b27e4
3 files changed
+15
-12
No files matched your search
@@ -172,20 +172,22 @@ auto Audio::getRealMusicState() -> MusicState {
|
||||
}
|
||||
}
|
||||
|
||||
// Aplica el gate master (enabled_) + el gate del canal (sound/music_enabled_)
|
||||
// i retorna el volum escalat pel master config_.volume. 0 si algun gate està
|
||||
// tancat. Així els dos setters comparteixen la mateixa política.
|
||||
auto Audio::effectiveVolume(float volume, bool channel_enabled) const -> float {
|
||||
volume = std::clamp(volume, MIN_VOLUME, MAX_VOLUME);
|
||||
return (enabled_ && channel_enabled) ? volume * config_.volume : 0.0F;
|
||||
}
|
||||
|
||||
// Estableix el volum dels sons (float 0.0..1.0)
|
||||
void Audio::setSoundVolume(float sound_volume, Group group) const {
|
||||
sound_volume = std::clamp(sound_volume, MIN_VOLUME, MAX_VOLUME);
|
||||
const bool ACTIVE = enabled_ && sound_enabled_;
|
||||
const float CONVERTED_VOLUME = ACTIVE ? sound_volume * config_.volume : 0.0F;
|
||||
Ja::setSoundVolume(CONVERTED_VOLUME, static_cast<int>(group));
|
||||
Ja::setSoundVolume(effectiveVolume(sound_volume, sound_enabled_), static_cast<int>(group));
|
||||
}
|
||||
|
||||
// Estableix el volum de la música (float 0.0..1.0)
|
||||
void Audio::setMusicVolume(float music_volume) const {
|
||||
music_volume = std::clamp(music_volume, MIN_VOLUME, MAX_VOLUME);
|
||||
const bool ACTIVE = enabled_ && music_enabled_;
|
||||
const float CONVERTED_VOLUME = ACTIVE ? music_volume * config_.volume : 0.0F;
|
||||
Ja::setMusicVolume(CONVERTED_VOLUME);
|
||||
Ja::setMusicVolume(effectiveVolume(music_volume, music_enabled_));
|
||||
}
|
||||
|
||||
// Aplica una nova configuració (substitueix la cache i reaplica enables/volums)
|
||||
|
||||
Reference in new issue
Block a user