[Scummvm-cvs-logs] CVS: scummvm/saga music.cpp,1.54,1.55 music.h,1.22,1.23 saga.cpp,1.115,1.116 script.h,1.88,1.89 sfuncs.cpp,1.127,1.128

Eugene Sandulenko sev at users.sourceforge.net
Sun Jun 19 14:18:44 CEST 2005


Update of /cvsroot/scummvm/scummvm/saga
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv6575

Modified Files:
	music.cpp music.h saga.cpp script.h sfuncs.cpp 
Log Message:
Implement sfPlayLoopedSound, sfFadeMusic and sfPlayVoice.
sfPlayVoice is untested. Please, inform me where you encounter it.


Index: music.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/saga/music.cpp,v
retrieving revision 1.54
retrieving revision 1.55
diff -u -d -r1.54 -r1.55
--- music.cpp	5 Jun 2005 09:28:40 -0000	1.54
+++ music.cpp	19 Jun 2005 21:18:00 -0000	1.55
@@ -282,7 +282,7 @@
 Music::Music(Audio::Mixer *mixer, MidiDriver *driver, int enabled) : _mixer(mixer), _enabled(enabled), _adlib(false) {
 	_player = new MusicPlayer(driver);
 	_musicInitialized = 1;
-	_mixer->setVolumeForSoundType(Audio::Mixer::kMusicSoundType, ConfMan.getInt("music_volume"));
+	_currentVolume = 0;
 
 	if (_vm->getGameType() == GType_ITE) {
 		Common::File file;
@@ -336,6 +336,50 @@
 	delete _player;
 }
 
+void Music::musicVolumeGaugeCallback(void *refCon) {
+	((Music *)refCon)->musicVolumeGauge();
+}                                                                               
+
+void Music::musicVolumeGauge() {
+	int volume;
+
+	_currentVolumePercent += 10;
+
+	if (_currentVolume - _targetVolume > 0) { // Volume decrease
+		volume = _targetVolume + (_currentVolume - _targetVolume) * (100 - _currentVolumePercent) / 100;
+	} else {
+		volume = _currentVolume + (_targetVolume - _currentVolume) * _currentVolumePercent / 100;
+	}
+
+	if (volume < 0)
+		volume = 1;
+
+	_vm->_mixer->setVolumeForSoundType(Audio::Mixer::kMusicSoundType, volume);
+	_player->setVolume(volume);
+
+	if (_currentVolumePercent == 100) {
+		Common::g_timer->removeTimerProc(&musicVolumeGaugeCallback);
+		_currentVolume = _targetVolume;
+	}
+}
+
+void Music::setVolume(int volume, int time) {
+	_targetVolume = volume * 2; // ScummVM has different volume scale
+	_currentVolumePercent = 0;
+
+	if (volume == -1) // Set Full volume
+		volume = ConfMan.getInt("music_volume");
+
+	if (time == 1) {
+		_vm->_mixer->setVolumeForSoundType(Audio::Mixer::kMusicSoundType, volume);
+		Common::g_timer->removeTimerProc(&musicVolumeGaugeCallback);
+		_currentVolume = volume;
+		return;
+	}
+
+	Common::g_timer->installTimerProc(&musicVolumeGaugeCallback, time * 100L, this);
+}
+
 bool Music::isPlaying() {
 	return _mixer->isSoundHandleActive(_musicHandle) || _player->isPlaying();
 }

Index: music.h
===================================================================
RCS file: /cvsroot/scummvm/scummvm/saga/music.h,v
retrieving revision 1.22
retrieving revision 1.23
diff -u -d -r1.22 -r1.23
--- music.h	11 May 2005 00:01:25 -0000	1.22
+++ music.h	19 Jun 2005 21:18:00 -0000	1.23
@@ -120,6 +120,8 @@
 	int resume(void);
 	int stop(void);
 
+	void setVolume(int volume, int time);
+
 private:
 
 	Audio::Mixer *_mixer;
@@ -136,8 +138,15 @@
 	bool _hasDigiMusic;
 	bool _adlib;
 
+	int _targetVolume;
+	int _currentVolume;
+	int _currentVolumePercent;
+
 	RSCFILE_CONTEXT *_musicContext;
 	const char *_musicFname;
+
+	static void musicVolumeGaugeCallback(void *refCon);
+	void musicVolumeGauge(void);
 };
 
 } // End of namespace Saga

Index: saga.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/saga/saga.cpp,v
retrieving revision 1.115
retrieving revision 1.116
diff -u -d -r1.115 -r1.116
--- saga.cpp	2 Jun 2005 22:14:57 -0000	1.115
+++ saga.cpp	19 Jun 2005 21:18:00 -0000	1.116
@@ -164,7 +164,6 @@
 	}
 
 	_mixer->setVolumeForSoundType(Audio::Mixer::kSFXSoundType, ConfMan.getInt("sfx_volume"));
-	_mixer->setVolumeForSoundType(Audio::Mixer::kMusicSoundType, ConfMan.getInt("music_volume"));
 
 	_vm = this;
 }
@@ -293,6 +292,8 @@
 	_interface->converseInit();
 	_script->setVerb(kVerbWalkTo);
 
+	_music->setVolume(-1, 1);
+
 	return SUCCESS;
 }
 

Index: script.h
===================================================================
RCS file: /cvsroot/scummvm/scummvm/saga/script.h,v
retrieving revision 1.88
retrieving revision 1.89
diff -u -d -r1.88 -r1.89
--- script.h	19 Jun 2005 14:06:20 -0000	1.88
+++ script.h	19 Jun 2005 21:18:00 -0000	1.89
@@ -534,13 +534,13 @@
 	void sfPuzzleWon(SCRIPTFUNC_PARAMS);
 	void sfEnableEscape(SCRIPTFUNC_PARAMS);
 	void sfPlaySound(SCRIPTFUNC_PARAMS);
-	void SF_playLoopedSound(SCRIPTFUNC_PARAMS);
+	void sfPlayLoopedSound(SCRIPTFUNC_PARAMS);
 	void sfGetDeltaFrame(SCRIPTFUNC_PARAMS);
 	void sfShowProtect(SCRIPTFUNC_PARAMS);
 	void sfProtectResult(SCRIPTFUNC_PARAMS);
 	void sfRand(SCRIPTFUNC_PARAMS);
-	void SF_fadeMusic(SCRIPTFUNC_PARAMS);
-	void SF_playVoice(SCRIPTFUNC_PARAMS);
+	void sfFadeMusic(SCRIPTFUNC_PARAMS);
+	void sfPlayVoice(SCRIPTFUNC_PARAMS);
 	void SF_stub(SCRIPTFUNC_PARAMS);
 };
 

Index: sfuncs.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/saga/sfuncs.cpp,v
retrieving revision 1.127
retrieving revision 1.128
diff -u -d -r1.127 -r1.128
--- sfuncs.cpp	19 Jun 2005 14:06:20 -0000	1.127
+++ sfuncs.cpp	19 Jun 2005 21:18:00 -0000	1.128
@@ -45,6 +45,8 @@
 #include "saga/scene.h"
 #include "saga/isomap.h"
 
+#include "common/config-manager.h"
+
 namespace Saga {
 
 #define OPCODE(x) {&Script::x, #x}
@@ -122,13 +124,13 @@
 		OPCODE(sfPuzzleWon),
 		OPCODE(sfEnableEscape),
 		OPCODE(sfPlaySound),
-		OPCODE(SF_playLoopedSound),
+		OPCODE(sfPlayLoopedSound),
 		OPCODE(sfGetDeltaFrame),
 		OPCODE(sfShowProtect),
 		OPCODE(sfProtectResult),
 		OPCODE(sfRand),
-		OPCODE(SF_fadeMusic),
-		OPCODE(SF_playVoice),
+		OPCODE(sfFadeMusic),
+		OPCODE(sfPlayVoice),
 		OPCODE(SF_stub),
 		OPCODE(SF_stub),
 		OPCODE(SF_stub),
@@ -634,7 +636,7 @@
 	for (int i = 0; i < nArgs; i++)
 		thread->pop();
 
-	debug(0, "STUB: SF_cycleColors(), %d args", nArgs);
+	error("STUB: SF_cycleColors(), %d args", nArgs);
 }
 
 // Script function #25 (0x19)
@@ -1573,10 +1575,12 @@
 	if (_vm->getGameType() == GType_ITE) {
 		int16 param = thread->pop() + 9;
 
-		if (param >= 9 && param <= 34)
+		if (param >= 9 && param <= 34) {
+			_vm->_music->setVolume(-1, 1);
 			_vm->_music->play(param);
-		else
+		} else {
 			_vm->_music->stop();
+		}
 	} else {
 		int16 param1 = thread->pop();
 		int16 param2 = thread->pop();
@@ -1591,7 +1595,7 @@
 	for (int i = 0; i < nArgs; i++)
 		thread->pop();
 
-	debug(0, "STUB: SF_pickClimbOutPos(), %d args", nArgs);
+	error("STUB: SF_pickClimbOutPos(), %d args", nArgs);
 }
 
 // Script function #65 (0x41)
@@ -1599,7 +1603,7 @@
 	for (int i = 0; i < nArgs; i++)
 		thread->pop();
 
-	debug(0, "STUB: SF_tossRif(), %d args", nArgs);
+	error("STUB: SF_tossRif(), %d args", nArgs);
 }
 
 // Script function #66 (0x42)
@@ -1607,7 +1611,7 @@
 	for (int i = 0; i < nArgs; i++)
 		thread->pop();
 
-	debug(0, "STUB: SF_showControls(), %d args", nArgs);
+	error("STUB: SF_showControls(), %d args", nArgs);
 }
 
 // Script function #67 (0x43)
@@ -1718,15 +1722,22 @@
 	} else {
 		_vm->_sound->stopSound();
 	}
-
 }
 
 // Script function #71 (0x47)
-void Script::SF_playLoopedSound(SCRIPTFUNC_PARAMS) {
-	for (int i = 0; i < nArgs; i++)
-		thread->pop();
+void Script::sfPlayLoopedSound(SCRIPTFUNC_PARAMS) {
+	int16 param = thread->pop();
+	int res;
 
-	debug(0, "STUB: SF_playLoopedSound(), %d args", nArgs);
+	if (param < ARRAYSIZE(sfxTable)) {
+		res = sfxTable[param].res;
+		if (_vm->getFeatures() & GF_CD_FX)
+			res -= 14;
+
+		_vm->_sndRes->playSound(res, sfxTable[param].vol, true);
+	} else {
+		_vm->_sound->stopSound();
+	}
 }
 
 // Script function #72 (0x48)
@@ -1775,16 +1786,20 @@
 }
 
 // Script function #76 (0x4c)
-void Script::SF_fadeMusic(SCRIPTFUNC_PARAMS) {
-	debug(0, "STUB: SF_fadeMusic()");
+void Script::sfFadeMusic(SCRIPTFUNC_PARAMS) {
+	_vm->_music->setVolume(0, 1000);
 }
 
 // Script function #77 (0x4d)
-void Script::SF_playVoice(SCRIPTFUNC_PARAMS) {
-	for (int i = 0; i < nArgs; i++)
-		thread->pop();
+void Script::sfPlayVoice(SCRIPTFUNC_PARAMS) {
+	int16 param = thread->pop();
 
-	debug(0, "STUB: SF_playVoice(), %d args", nArgs);
+	warning("sfPlayVoice(%d)", param);
+	if (param > 0) {
+		_vm->_sndRes->playVoice(param + 3712);
+	} else {
+		_vm->_sound->stopSound();
+	}
 }
 
 void Script::finishDialog(int replyID, int flags, int bitOffset) {





More information about the Scummvm-git-logs mailing list