aboutsummaryrefslogtreecommitdiff
path: root/sword2
diff options
context:
space:
mode:
authorTorbjörn Andersson2003-10-29 07:53:05 +0000
committerTorbjörn Andersson2003-10-29 07:53:05 +0000
commitd7bd7d44b83fb3dce91567fd0d241758ea706b78 (patch)
tree52294c5c40f09427fa6730c68f201d8b3b8fade7 /sword2
parent494d5269a2a0274a58e6bb30f211383cdaf5465f (diff)
downloadscummvm-rg350-d7bd7d44b83fb3dce91567fd0d241758ea706b78.tar.gz
scummvm-rg350-d7bd7d44b83fb3dce91567fd0d241758ea706b78.tar.bz2
scummvm-rg350-d7bd7d44b83fb3dce91567fd0d241758ea706b78.zip
Use the ScummVM config manager instead of a separate BS2-specific config
file, plus some other cleanup. I don't know how the config manager decides if/when to save the settings to file, but we can worry about that later. svn-id: r11001
Diffstat (limited to 'sword2')
-rw-r--r--sword2/anims.cpp4
-rw-r--r--sword2/controls.cpp159
-rw-r--r--sword2/controls.h17
-rw-r--r--sword2/driver/d_sound.cpp79
-rw-r--r--sword2/driver/d_sound.h27
-rw-r--r--sword2/function.cpp8
-rw-r--r--sword2/speech.cpp2
7 files changed, 151 insertions, 145 deletions
diff --git a/sword2/anims.cpp b/sword2/anims.cpp
index a29cc75e48..138e6e15ad 100644
--- a/sword2/anims.cpp
+++ b/sword2/anims.cpp
@@ -29,7 +29,7 @@
#include "sword2/driver/d_draw.h"
#include "sword2/anims.h"
#include "sword2/console.h"
-#include "sword2/controls.h" // for 'speechSelected' & 'subtitles'
+#include "sword2/controls.h" // for 'subtitles'
#include "sword2/defs.h"
#include "sword2/header.h"
#include "sword2/interpreter.h"
@@ -540,7 +540,7 @@ void CreateSequenceSpeech(_movieTextObject *sequenceText[]) {
sequence_text_list[line].speech_mem = NULL;
sequenceText[line]->speech = NULL;
- if (gui._speechSelected) {
+ if (!g_sound->isSpeechMute()) {
// speech is selected, so try that first
// set up path to speech cluster
diff --git a/sword2/controls.cpp b/sword2/controls.cpp
index 7ca0844509..a7d46380d3 100644
--- a/sword2/controls.cpp
+++ b/sword2/controls.cpp
@@ -18,6 +18,7 @@
*/
#include "stdafx.h"
+#include "common/config-manager.h"
#include "sword2/driver/driver96.h"
#include "sword2/build_display.h"
#include "sword2/console.h"
@@ -717,8 +718,6 @@ private:
Button *_okButton;
Button *_cancelButton;
- void writeOptionSettings(void);
-
public:
OptionsDialog() {
_fr = new FontRendererGui(g_sword2->_controlsFontId);
@@ -781,9 +780,9 @@ public:
_objectLabelsSwitch->setValue(gui._pointerTextSelected != 0);
_subtitlesSwitch->setValue(gui._subtitles != 0);
_reverseStereoSwitch->setValue(gui._stereoReversed != 0);
- _musicSwitch->setValue(g_sound->isMusicMute() == 0);
- _speechSwitch->setValue(g_sound->isSpeechMute() == 0);
- _fxSwitch->setValue(g_sound->isFxMute() == 0);
+ _musicSwitch->setValue(!g_sound->isMusicMute());
+ _speechSwitch->setValue(!g_sound->isSpeechMute());
+ _fxSwitch->setValue(!g_sound->isFxMute());
_musicSlider->setValue(g_sound->getMusicVolume());
_speechSlider->setValue(g_sound->getSpeechVolume());
_fxSlider->setValue(g_sound->getFxVolume());
@@ -862,9 +861,9 @@ public:
gui.updateGraphicsLevel(result);
} else if (widget == _okButton) {
// Apply the changes
- g_sound->muteMusic(_musicSwitch->getValue() == 0);
- g_sound->muteSpeech(_speechSwitch->getValue() == 0);
- g_sound->muteFx(_fxSwitch->getValue() == 0);
+ g_sound->muteMusic(!_musicSwitch->getValue());
+ g_sound->muteSpeech(!_speechSwitch->getValue());
+ g_sound->muteFx(!_fxSwitch->getValue());
g_sound->setMusicVolume(_musicSlider->getValue());
g_sound->setSpeechVolume(_speechSlider->getValue());
g_sound->setFxVolume(_fxSlider->getValue());
@@ -873,10 +872,9 @@ public:
gui._subtitles = _subtitlesSwitch->getValue();
gui._pointerTextSelected = _objectLabelsSwitch->getValue();
- gui._speechSelected = _speechSwitch->getValue();
gui._stereoReversed = _reverseStereoSwitch->getValue();
- writeOptionSettings();
+ gui.writeOptionSettings();
setResult(1);
} else if (widget == _cancelButton) {
// Revert the changes
@@ -886,34 +884,6 @@ public:
}
};
-void OptionsDialog::writeOptionSettings(void) {
- uint8 buff[10];
- char filename[256];
- SaveFile *fp;
- SaveFileManager *mgr = g_system->get_savefile_manager();
-
- sprintf(filename, "%s-settings.dat", g_sword2->_targetName);
-
- buff[0] = g_sound->getMusicVolume();
- buff[1] = g_sound->getSpeechVolume();
- buff[2] = g_sound->getFxVolume();
- buff[3] = g_sound->isMusicMute();
- buff[4] = g_sound->isSpeechMute();
- buff[5] = g_sound->isFxMute();
- buff[6] = g_display->getRenderLevel();
- buff[7] = gui._subtitles;
- buff[8] = gui._pointerTextSelected;
- buff[9] = gui._stereoReversed;
-
- fp = mgr->open_savefile(filename, g_sword2->getSavePath(), true);
-
- if (fp)
- fp->write(buff, 10);
-
- delete fp;
- delete mgr;
-}
-
enum {
kSaveDialog,
kLoadDialog
@@ -1367,6 +1337,66 @@ void SaveLoadDialog::saveLoadError(char* text) {
RemoveMsg();
}
+Gui::Gui() : _baseSlot(0) {
+ int i;
+
+ for (i = 0; i < ARRAYSIZE(_musicVolume); i++) {
+ _musicVolume[i] = (i * 255) / (ARRAYSIZE(_musicVolume) - 1);
+ if ((i * 255) % (ARRAYSIZE(_musicVolume) - 1))
+ _musicVolume[i]++;
+ }
+
+ for (i = 0; i < ARRAYSIZE(_soundVolume); i++) {
+ _soundVolume[i] = (i * 255) / (ARRAYSIZE(_soundVolume) - 1);
+ if ((i * 255) % (ARRAYSIZE(_soundVolume) - 1))
+ _soundVolume[i]++;
+ }
+
+ ConfMan.registerDefault("music_volume", _musicVolume[12]);
+ ConfMan.registerDefault("speech_volume", _soundVolume[10]);
+ ConfMan.registerDefault("sfx_volume", _soundVolume[10]);
+ ConfMan.registerDefault("music_mute", false);
+ ConfMan.registerDefault("speech_mute", false);
+ ConfMan.registerDefault("sfx_mute", false);
+ ConfMan.registerDefault("gfx_details", 2);
+ ConfMan.registerDefault("nosubtitles", false);
+ ConfMan.registerDefault("object_labels", true);
+ ConfMan.registerDefault("reverse_stereo", false);
+}
+
+void Gui::readOptionSettings(void) {
+ bool newStereoReversed;
+
+ g_sound->setMusicVolume((16 * ConfMan.getInt("music_volume")) / 255);
+ g_sound->setSpeechVolume((14 * ConfMan.getInt("speech_volume")) / 255);
+ g_sound->setFxVolume((14 * ConfMan.getInt("sfx_volume")) / 255);
+ g_sound->muteMusic(ConfMan.getBool("music_mute"));
+ g_sound->muteSpeech(ConfMan.getBool("speech_mute"));
+ g_sound->muteFx(ConfMan.getBool("sfx_mute"));
+ updateGraphicsLevel((uint8) ConfMan.getInt("gfx_details"));
+ _subtitles = !ConfMan.getBool("nosubtitles");
+ _pointerTextSelected = ConfMan.getBool("object_labels");
+ newStereoReversed = ConfMan.getBool("reverse_stereo");
+
+ if (_stereoReversed != newStereoReversed)
+ g_sound->reverseStereo();
+
+ _stereoReversed = newStereoReversed;
+}
+
+void Gui::writeOptionSettings(void) {
+ ConfMan.set("music_volume", _musicVolume[g_sound->getMusicVolume()]);
+ ConfMan.set("speech_volume", _soundVolume[g_sound->getSpeechVolume()]);
+ ConfMan.set("sfx_volume", _soundVolume[g_sound->getFxVolume()]);
+ ConfMan.set("music_mute", g_sound->isMusicMute());
+ ConfMan.set("speech_mute", g_sound->isSpeechMute());
+ ConfMan.set("sfx_mute", g_sound->isFxMute());
+ ConfMan.set("gfx_details", g_display->getRenderLevel());
+ ConfMan.set("nosubtitles", !gui._subtitles);
+ ConfMan.set("object_labels", gui._pointerTextSelected);
+ ConfMan.set("reverse_stereo", gui._stereoReversed);
+}
+
uint32 Gui::restoreControl(void) {
// returns 0 for no restore
// 1 for restored ok
@@ -1459,52 +1489,6 @@ void Gui::restartControl(void) {
this_screen.new_palette = 99;
}
-void Gui::readOptionSettings(void) {
- // settings file is 9 bytes long:
- // 1 music volume
- // 2 speech volume
- // 3 fx volume
- // 4 music mute
- // 5 speech mute
- // 6 fx mute
- // 7 graphics level
- // 8 subtitles
- // 9 object labels
-
- uint8 buff[10];
- uint8 default_settings[10] = { 14, 12, 12, 0, 0, 0, 2, 1, 1 };
- char filename[256];
- SaveFile *fp;
- SaveFileManager *mgr = g_system->get_savefile_manager();
-
- sprintf(filename, "%s-settings.dat", g_sword2->_targetName);
-
- fp = mgr->open_savefile(filename, g_sword2->getSavePath(), false);
- if (!fp || fp->read(buff, 10) != 10)
- memcpy(buff, default_settings, sizeof(buff));
-
- delete fp;
- delete mgr;
-
- g_sound->setMusicVolume(buff[0]);
- g_sound->setSpeechVolume(buff[1]);
- g_sound->setFxVolume(buff[2]);
- g_sound->muteMusic(buff[3]);
- g_sound->muteSpeech(buff[4]);
- g_sound->muteFx(buff[5]);
-
- updateGraphicsLevel(buff[6]);
-
- _speechSelected = !buff[4];
- _subtitles = buff[7];
- _pointerTextSelected = buff[8];
-
- if (buff[9] != _stereoReversed)
- g_sound->reverseStereo();
-
- gui._stereoReversed = buff[9];
-}
-
void Gui::optionControl(void) {
OptionsDialog optionsDialog;
@@ -1512,7 +1496,12 @@ void Gui::optionControl(void) {
return;
}
-void Gui::updateGraphicsLevel(uint8 newLevel) {
+void Gui::updateGraphicsLevel(int newLevel) {
+ if (newLevel < 0)
+ newLevel = 0;
+ else if (newLevel > 3)
+ newLevel = 3;
+
g_display->setRenderLevel(newLevel);
// update our global variable - which needs to be checked when dimming
diff --git a/sword2/controls.h b/sword2/controls.h
index ea5ff2fd8e..2e11459877 100644
--- a/sword2/controls.h
+++ b/sword2/controls.h
@@ -23,17 +23,19 @@
namespace Sword2 {
class Gui {
+private:
+ int _musicVolume[17];
+ int _soundVolume[15];
+
public:
int _baseSlot;
uint8 _currentGraphicsLevel;
- uint8 _subtitles;
- uint8 _speechSelected;
- uint8 _stereoReversed;
- uint8 _pointerTextSelected;
+ bool _subtitles;
+ bool _stereoReversed;
+ bool _pointerTextSelected;
- Gui() : _baseSlot(0), _stereoReversed(0),
- _pointerTextSelected(0) {}
+ Gui();
uint32 restoreControl(void);
void saveControl(void);
@@ -41,7 +43,8 @@ public:
void restartControl(void);
void optionControl(void);
void readOptionSettings(void);
- void updateGraphicsLevel(uint8 newLevel);
+ void writeOptionSettings(void);
+ void updateGraphicsLevel(int newLevel);
};
extern Gui gui;
diff --git a/sword2/driver/d_sound.cpp b/sword2/driver/d_sound.cpp
index cc8df01562..ca776e1118 100644
--- a/sword2/driver/d_sound.cpp
+++ b/sword2/driver/d_sound.cpp
@@ -36,9 +36,9 @@
#include "sound/audiostream.h"
#include "sound/mixer.h"
#include "sound/rate.h"
+#include "sword2/sword2.h"
#include "sword2/driver/driver96.h"
#include "sword2/driver/d_sound.h"
-#include "sword2/sword2.h"
namespace Sword2 {
@@ -130,10 +130,10 @@ static void premix_proc(void *param, int16 *data, uint len) {
Sound::Sound(SoundMixer *mixer) {
_mutex = g_system->create_mutex();
- _soundOn = 0;
- _speechStatus = 0;
- _fxPaused = 0;
- _speechPaused = 0;
+ _soundOn = false;
+ _speechStatus = false;
+ _fxPaused = false;
+ _speechPaused = false;
_speechVol = 14;
_fxVol = 14;
_speechMuted = 0;
@@ -146,7 +146,7 @@ Sound::Sound(SoundMixer *mixer) {
memset(_fx, 0, sizeof(_fx));
_soundHandleSpeech = 0;
- _soundOn = 1;
+ _soundOn = true;
_converter = makeRateConverter(_music[0].getRate(), _mixer->getOutputRate(), _music[0].isStereo(), false);
@@ -411,13 +411,13 @@ int32 Sound::playCompSpeech(const char *filename, uint32 speechid, uint8 vol, in
// Start the speech playing
- _speechPaused = 1;
+ _speechPaused = true;
uint32 flags = SoundMixer::FLAG_16BITS | SoundMixer::FLAG_AUTOFREE;
_mixer->playRaw(&_soundHandleSpeech, data16, bufferSize, 22050, flags, -1, volume, p);
- _speechStatus = 1;
+ _speechStatus = true;
}
// DipMusic();
@@ -435,7 +435,7 @@ int32 Sound::stopSpeech(void) {
if (_speechStatus) {
g_engine->_mixer->stopHandle(_soundHandleSpeech);
- _speechStatus = 0;
+ _speechStatus = false;
return RD_OK;
}
return RDERR_SPEECHNOTPLAYING;
@@ -453,7 +453,7 @@ int32 Sound::getSpeechStatus(void) {
return RDSE_SAMPLEPLAYING;
if (!_soundHandleSpeech) {
- _speechStatus = 0;
+ _speechStatus = false;
return RDSE_SAMPLEFINISHED;
}
return RDSE_SAMPLEPLAYING;
@@ -465,7 +465,11 @@ int32 Sound::getSpeechStatus(void) {
*/
void Sound::setSpeechVolume(uint8 volume) {
+ if (volume > 14)
+ volume = 14;
+
_speechVol = volume;
+
if (_soundHandleSpeech != 0 && !_speechMuted && getSpeechStatus() == RDSE_SAMPLEPLAYING) {
g_engine->_mixer->setChannelVolume(_soundHandleSpeech, 16 * _speechVol);
}
@@ -481,11 +485,11 @@ uint8 Sound::getSpeechVolume() {
/**
* Mutes/Unmutes the speech.
- * @param mute If mute is 0, restore the volume to the last set master level.
- * Otherwise the speech is muted (volume 0).
+ * @param mute If mute is false, restore the volume to the last set master
+ * level. Otherwise the speech is muted (volume 0).
*/
-void Sound::muteSpeech(uint8 mute) {
+void Sound::muteSpeech(bool mute) {
_speechMuted = mute;
if (getSpeechStatus() == RDSE_SAMPLEPLAYING) {
@@ -496,10 +500,10 @@ void Sound::muteSpeech(uint8 mute) {
}
/**
- * @return the speech's mute state, 1 if mute, 0 if not mute
+ * @return the speech's mute state, true if mute, false if not mute
*/
-uint8 Sound::isSpeechMute(void) {
+bool Sound::isSpeechMute(void) {
return _speechMuted;
}
@@ -509,7 +513,7 @@ uint8 Sound::isSpeechMute(void) {
void Sound::pauseSpeech(void) {
if (getSpeechStatus() == RDSE_SAMPLEPLAYING) {
- _speechPaused = 1;
+ _speechPaused = true;
g_engine->_mixer->pauseHandle(_soundHandleSpeech, true);
}
}
@@ -520,7 +524,7 @@ void Sound::pauseSpeech(void) {
void Sound::unpauseSpeech(void) {
if (_speechPaused) {
- _speechPaused = 0;
+ _speechPaused = false;
g_engine->_mixer->pauseHandle(_soundHandleSpeech, false);
}
}
@@ -649,7 +653,7 @@ int32 Sound::playFx(int32 id, uint8 *data, uint8 vol, int8 pan, uint8 type) {
_fx[i]._flags |= SoundMixer::FLAG_LOOP;
else
_fx[i]._flags &= ~SoundMixer::FLAG_LOOP;
-
+
_fx[i]._volume = vol;
// Start the sound effect playing
@@ -722,11 +726,16 @@ int32 Sound::setFxIdVolumePan(int32 id, uint8 vol, int8 pan) {
if (i == MAXFX)
return RDERR_FXNOTOPEN;
+ if (vol > 14)
+ vol = 14;
+
_fx[i]._volume = vol;
+
if (!_fxMuted) {
- g_engine->_mixer->setChannelVolume(_fx[i]._handle, vol * _fxVol);
+ g_engine->_mixer->setChannelVolume(_fx[i]._handle, _fx[i]._volume * _fxVol);
g_engine->_mixer->setChannelPan(_fx[i]._handle, panTable[pan + 16]);
}
+
return RD_OK;
}
@@ -807,7 +816,7 @@ void Sound::pauseFx(void) {
} else
_fx[i]._paused = false;
}
- _fxPaused = 1;
+ _fxPaused = true;
}
}
@@ -821,7 +830,7 @@ void Sound::pauseFxForSequence(void) {
_fx[i]._paused = false;
}
}
- _fxPaused = 1;
+ _fxPaused = true;
}
}
@@ -832,7 +841,7 @@ void Sound::unpauseFx(void) {
g_engine->_mixer->pauseHandle(_fx[i]._handle, false);
}
}
- _fxPaused = 0;
+ _fxPaused = false;
}
}
@@ -851,6 +860,9 @@ uint8 Sound::getFxVolume() {
*/
void Sound::setFxVolume(uint8 volume) {
+ if (volume > 14)
+ volume = 14;
+
_fxVol = volume;
// Now update the volume of any fxs playing
@@ -862,11 +874,11 @@ void Sound::setFxVolume(uint8 volume) {
/**
* Mutes/Unmutes the sound effects.
- * @param mute If mute is 0, restore the volume to the last set master level.
- * Otherwise the sound effects are muted (volume 0).
+ * @param mute If mute is false, restore the volume to the last set master
+ * level. Otherwise the sound effects are muted (volume 0).
*/
-void Sound::muteFx(uint8 mute) {
+void Sound::muteFx(bool mute) {
_fxMuted = mute;
// Now update the volume of any fxs playing
@@ -880,10 +892,10 @@ void Sound::muteFx(uint8 mute) {
}
/**
- * @return the sound effects's mute state, 1 if mute, 0 if not mute
+ * @return the sound effects's mute state, true if mute, false if not mute
*/
-uint8 Sound::isFxMute(void) {
+bool Sound::isFxMute(void) {
return _fxMuted;
}
@@ -1117,6 +1129,9 @@ void Sound::unpauseMusic(void) {
*/
void Sound::setMusicVolume(uint8 volume) {
+ if (volume > 16)
+ volume = 16;
+
_musicVol = volume;
}
@@ -1130,19 +1145,19 @@ uint8 Sound::getMusicVolume() {
/**
* Mutes/Unmutes the music.
- * @param mute If mute is 0, restore the volume to the last set master level.
- * Otherwise the music is muted (volume 0).
+ * @param mute If mute is false, restore the volume to the last set master
+ * level. Otherwise the music is muted (volume 0).
*/
-void Sound::muteMusic(uint8 mute) {
+void Sound::muteMusic(bool mute) {
_musicMuted = mute;
}
/**
- * @return the music's mute state, 1 if mute, 0 if not mute
+ * @return the music's mute state, true if mute, false if not mute
*/
-uint8 Sound::isMusicMute(void) {
+bool Sound::isMusicMute(void) {
return _musicMuted;
}
diff --git a/sword2/driver/d_sound.h b/sword2/driver/d_sound.h
index 9c5b045821..3b30b80ebd 100644
--- a/sword2/driver/d_sound.h
+++ b/sword2/driver/d_sound.h
@@ -79,19 +79,18 @@ private:
FxHandle _fx[MAXFX];
MusicHandle _music[MAXMUS + 1];
+ bool _soundOn;
+ bool _speechStatus;
+ bool _speechPaused;
+ bool _fxPaused;
+ bool _musicMuted;
+ bool _speechMuted;
+ bool _fxMuted;
uint8 _musicVol;
-
- uint8 _soundOn;
- uint8 _speechStatus;
- uint8 _fxPaused;
- uint8 _speechPaused;
uint8 _speechVol;
uint8 _fxVol;
- uint8 _speechMuted;
- uint8 _fxMuted;
PlayingSoundHandle _soundHandleSpeech;
- uint8 _musicMuted;
int32 getFxIndex(int32 id);
int32 dipMusic();
@@ -127,16 +126,16 @@ public:
uint8 getFxVolume(void);
uint8 getSpeechVolume(void);
uint8 getMusicVolume(void);
- uint8 isMusicMute(void);
- uint8 isFxMute(void);
- uint8 isSpeechMute(void);
+ bool isMusicMute(void);
+ bool isFxMute(void);
+ bool isSpeechMute(void);
void stopMusic(void);
void setFxVolume(uint8 vol);
void setSpeechVolume(uint8 vol);
void setMusicVolume(uint8 vol);
- void muteMusic(uint8 mute);
- void muteFx(uint8 mute);
- void muteSpeech(uint8 mute);
+ void muteMusic(bool mute);
+ void muteFx(bool mute);
+ void muteSpeech(bool mute);
int32 isFxOpen(int32 id);
int32 setFxIdVolumePan(int32 id, uint8 vol, int8 pan);
int32 setFxIdVolume(int32 id, uint8 vol);
diff --git a/sword2/function.cpp b/sword2/function.cpp
index 05958e9ba0..7c9dea03fd 100644
--- a/sword2/function.cpp
+++ b/sword2/function.cpp
@@ -392,8 +392,8 @@ int32 Logic::fnPlayCredits(int32 *params) {
g_sound->saveMusicState();
- g_sound->muteFx(1);
- g_sound->muteSpeech(1);
+ g_sound->muteFx(true);
+ g_sound->muteSpeech(true);
g_sound->stopMusic();
memcpy(oldPal, g_display->_palCopy, 1024);
@@ -448,8 +448,8 @@ int32 Logic::fnPlayCredits(int32 *params) {
Build_display();
g_display->waitForFade();
- g_sound->muteFx(0);
- g_sound->muteSpeech(0);
+ g_sound->muteFx(false);
+ g_sound->muteSpeech(false);
}
// FIXME: This probably isn't the correct way of shutting down ScummVM
diff --git a/sword2/speech.cpp b/sword2/speech.cpp
index 73bf3f917c..da073c73c8 100644
--- a/sword2/speech.cpp
+++ b/sword2/speech.cpp
@@ -1122,7 +1122,7 @@ int32 Logic::fnISpeak(int32 *params) {
// if speech is selected, and this line is allowed speech
// (not if it's an fx subtitle!)
- if (gui._speechSelected && WantSpeechForLine(officialTextNumber)) {
+ if (!g_sound->isSpeechMute() && WantSpeechForLine(officialTextNumber)) {
// if the wavId paramter is zero because not yet
// compiled into speech command, we can still get it
// from the 1st 2 chars of the text line