QDENGINE: Use ConfMan for sound settings

Signed-off-by: kunxl-gg <tiwari.25@iitj.ac.in>
This commit is contained in:
kunxl-gg 2024-08-25 23:23:46 +05:30 committed by Eugene Sandulenko
parent 747555bca1
commit 927dedc1d3
8 changed files with 55 additions and 18 deletions

View File

@ -206,8 +206,7 @@ int QDEngineEngine::engineMain() {
sndDispatcher *sndD = new sndDispatcher;
qdGameConfig::get_config().update_sound_settings();
qdGameConfig::get_config().update_music_settings();
g_engine->syncSoundSettings();
winVideo::init();

View File

@ -19,6 +19,7 @@
*
*/
#include "common/config-manager.h"
#include "common/debug.h"
#include "common/savefile.h"
@ -642,13 +643,13 @@ bool qdInterfaceDispatcher::handle_event(int event_code, const char *event_data,
int qdInterfaceDispatcher::option_value(int option_id, const char *option_data) {
switch (option_id) {
case qdInterfaceElement::OPTION_SOUND:
return (int)qdGameConfig::get_config().is_sound_enabled();
return ConfMan.getBool("enable_sound");
case qdInterfaceElement::OPTION_SOUND_VOLUME:
return qdGameConfig::get_config().sound_volume();
return ConfMan.getInt("sound_volume");
case qdInterfaceElement::OPTION_MUSIC:
return (int)qdGameConfig::get_config().is_music_enabled();
return ConfMan.getBool("enable_music");
case qdInterfaceElement::OPTION_MUSIC_VOLUME:
return qdGameConfig::get_config().music_volume();
return ConfMan.getInt("music_volume");
case qdInterfaceElement::OPTION_ACTIVE_PERSONAGE:
if (option_data) {
if (qdGameObjectMoving * p = qdGameDispatcher::get_dispatcher()->get_active_personage()) {
@ -663,24 +664,20 @@ int qdInterfaceDispatcher::option_value(int option_id, const char *option_data)
bool qdInterfaceDispatcher::set_option_value(int option_id, int value, const char *option_data) {
switch (option_id) {
case qdInterfaceElement::OPTION_SOUND:
qdGameConfig::get_config().toggle_sound(value > 0);
qdGameConfig::get_config().update_sound_settings();
qdGameConfig::get_config().save();
ConfMan.setBool("enable_sound", value > 0);
g_engine->syncSoundSettings();
return true;
case qdInterfaceElement::OPTION_SOUND_VOLUME:
qdGameConfig::get_config().set_sound_volume(value);
qdGameConfig::get_config().update_sound_settings();
qdGameConfig::get_config().save();
ConfMan.setInt("sound_volume", value);
g_engine->syncSoundSettings();
return true;
case qdInterfaceElement::OPTION_MUSIC:
qdGameConfig::get_config().toggle_music(value > 0);
qdGameConfig::get_config().update_music_settings();
qdGameConfig::get_config().save();
ConfMan.setBool("enable_music", value > 0);
g_engine->syncSoundSettings();
return true;
case qdInterfaceElement::OPTION_MUSIC_VOLUME:
qdGameConfig::get_config().set_music_volume(value);
qdGameConfig::get_config().update_music_settings();
qdGameConfig::get_config().save();
ConfMan.setInt("music_volume", value);
g_engine->syncSoundSettings();
return true;
case qdInterfaceElement::OPTION_ACTIVE_PERSONAGE:
if (option_data) {
@ -747,4 +744,5 @@ const char *qdInterfaceDispatcher::get_save_title() const {
return nullptr;
}
} // namespace QDEngine

View File

@ -19,6 +19,7 @@
*
*/
#include "common/config-manager.h"
#include "common/debug.h"
#include "common/stream.h"
@ -157,4 +158,13 @@ mpegPlayer &mpegPlayer::instance() {
return player;
}
void mpegPlayer::syncMusicSettings() {
set_volume(ConfMan.getInt("music_volume"));
if (ConfMan.getBool("enable_music"))
enable();
else
disable();
}
} // namespace QDEngine

View File

@ -73,6 +73,8 @@ public:
}
void set_volume(uint32 vol);
void syncMusicSettings();
static bool init_library(void *dsound_device);
static void deinit_library();

View File

@ -34,6 +34,8 @@
#include "qdengine/console.h"
#include "qdengine/parser/qdscr_parser.h"
#include "qdengine/qdcore/qd_game_dispatcher.h"
#include "qdengine/qdcore/util/plaympp_api.h"
#include "qdengine/system/sound/snd_dispatcher.h"
namespace QDEngine {
@ -48,9 +50,13 @@ QDEngineEngine::QDEngineEngine(OSystem *syst, const ADGameDescription *gameDesc)
_screenH = 480;
ConfMan.registerDefault("game_speed", 1);
ConfMan.registerDefault("enable_sound", true);
ConfMan.registerDefault("enable_music", true);
ConfMan.registerDefault("logic_period", 25);
ConfMan.registerDefault("logic_synchro_by_clock", true);
ConfMan.registerDefault("music_volume", 255);
ConfMan.registerDefault("show_fps", false);
ConfMan.registerDefault("sound_volume", 255);
ConfMan.registerDefault("splash_enabled", true);
ConfMan.registerDefault("splash_time", 3000);
@ -134,6 +140,13 @@ Common::Error QDEngineEngine::loadGameStream(Common::SeekableReadStream *stream)
return Common::kReadingFailed;
}
void QDEngineEngine::syncSoundSettings() {
Engine::syncSoundSettings();
sndDispatcher::get_dispatcher()->syncSoundSettings();
mpegPlayer::instance().syncMusicSettings();
}
} // namespace QDEngine
// Translates cp-1251..utf-8

View File

@ -113,6 +113,8 @@ public:
Common::Error saveGameStream(Common::WriteStream *stream, bool isAutosave = false) override;
Common::Error loadGameStream(Common::SeekableReadStream *stream) override;
void syncSoundSettings() override;
int engineMain();
int _thumbSizeX = 0, _thumbSizeY = 0;

View File

@ -19,6 +19,7 @@
*
*/
#include "common/config-manager.h"
#include "qdengine/qd_fwd.h"
#include "qdengine/xmath.h"
#include "qdengine/system/graphics/gr_dispatcher.h"
@ -199,4 +200,14 @@ void sndDispatcher::resume_sounds() {
it->resume();
}
}
void sndDispatcher::syncSoundSettings() {
set_volume(ConfMan.getInt("sound_volume"));
if (ConfMan.getBool("enable_sound"))
enable();
else
disable();
}
} // namespace QDEngine

View File

@ -106,6 +106,8 @@ public:
stop_sounds();
}
void syncSoundSettings();
//! Возвращает указатель на текущий диспетчер.
static inline sndDispatcher *get_dispatcher() {
return _dispatcher_ptr;