[Scummvm-cvs-logs] SF.net SVN: scummvm:[46623] scummvm/trunk/engines/sci

thebluegr at users.sourceforge.net thebluegr at users.sourceforge.net
Sun Dec 27 12:43:34 CET 2009


Revision: 46623
          http://scummvm.svn.sourceforge.net/scummvm/?rev=46623&view=rev
Author:   thebluegr
Date:     2009-12-27 11:43:34 +0000 (Sun, 27 Dec 2009)

Log Message:
-----------
SCI/new music code: 
- Removed a lot of accessors to the music list, and protected the 2 which are used now with mutexes
- Rewrote the music list save/load code to be methods of the SciMusic class

Modified Paths:
--------------
    scummvm/trunk/engines/sci/engine/savegame.cpp
    scummvm/trunk/engines/sci/sfx/music.cpp
    scummvm/trunk/engines/sci/sfx/music.h
    scummvm/trunk/engines/sci/sfx/soundcmd.cpp

Modified: scummvm/trunk/engines/sci/engine/savegame.cpp
===================================================================
--- scummvm/trunk/engines/sci/engine/savegame.cpp	2009-12-27 11:12:26 UTC (rev 46622)
+++ scummvm/trunk/engines/sci/engine/savegame.cpp	2009-12-27 11:43:34 UTC (rev 46623)
@@ -72,8 +72,6 @@
 
 #ifdef USE_OLD_MUSIC_FUNCTIONS
 static void sync_songlib(Common::Serializer &s, SongLibrary &obj);
-#else
-static void sync_songlib(Common::Serializer &s, SciMusic *music);
 #endif
 
 static void sync_reg_t(Common::Serializer &s, reg_t &obj) {
@@ -430,7 +428,7 @@
 #ifdef USE_OLD_MUSIC_FUNCTIONS
 	sync_songlib(s, _sound._songlib);
 #else
-	sync_songlib(s, _soundCmd->_music);
+	_soundCmd->_music->saveLoadWithSerializer(s);
 #endif
 }
 
@@ -618,27 +616,31 @@
 	}
 }
 #else
-static void sync_songlib(Common::Serializer &s, SciMusic *music) {
+void SciMusic::saveLoadWithSerializer(Common::Serializer &s) {
 	// Sync song lib data. When loading, the actual song lib will be initialized
 	// afterwards in gamestate_restore()
+	_mutex.lock();
+
 	int songcount = 0;
 	if (s.isSaving())
-		songcount = music->listSize();
+		songcount = _playList.size();
 	s.syncAsUint32LE(songcount);
 
 	if (s.isLoading()) {
-		music->stopAll();
+		stopAll();
 
 		for (int i = 0; i < songcount; i++) {
 			MusicEntry *curSong = new MusicEntry();
 			syncSong(s, curSong);
-			music->pushBackSlot(curSong);
+			_playList.push_back(curSong);
 		}
 	} else {
 		for (int i = 0; i < songcount; i++) {
-			syncSong(s, music->getSlot(i));
+			syncSong(s, _playList[i]);
 		}
 	}
+
+	_mutex.unlock();
 }
 #endif
 
@@ -951,21 +953,7 @@
 	retval->_sound._suspended = s->_sound._suspended;
 	reconstruct_sounds(retval);
 #else
-	// Reconstruct sounds
-	SciMusic *music = retval->_soundCmd->_music;
-	for (uint32 i = 0; i < music->listSize(); i++) {
-		if (meta.savegame_version < 14) {
-			if (retval->detectDoSoundType() >= SCI_VERSION_1_EARLY) {
-				music->getSlot(i)->dataInc = GET_SEL32V(retval->_segMan, music->getSlot(i)->soundObj, dataInc);
-				music->getSlot(i)->volume = GET_SEL32V(retval->_segMan, music->getSlot(i)->soundObj, vol);
-			} else {
-				music->getSlot(i)->volume = 100;
-			}
-		}
-
-		music->getSlot(i)->soundRes = new SoundResource(music->getSlot(i)->resnum, retval->resMan, retval->detectDoSoundType());
-		music->soundInitSnd(music->getSlot(i));
-	}
+	retval->_soundCmd->_music->reconstructSounds(meta.savegame_version);
 #endif
 
 	// Message state:

Modified: scummvm/trunk/engines/sci/sfx/music.cpp
===================================================================
--- scummvm/trunk/engines/sci/sfx/music.cpp	2009-12-27 11:12:26 UTC (rev 46622)
+++ scummvm/trunk/engines/sci/sfx/music.cpp	2009-12-27 11:43:34 UTC (rev 46623)
@@ -123,13 +123,6 @@
 }
 
 //----------------------------------------
-bool SciMusic::restoreState(Common::InSaveFile *pFile){
-	if (pFile->readLine() != "AUDIO")
-		return false;
-
-	return true;
-}
-//----------------------------------------
 void SciMusic::stopAll() {
 	_pMixer->stopAll();
 
@@ -360,7 +353,7 @@
 
 				// Signal the engine scripts that the sound is done playing
 				// FIXME: is there any other place this can be triggered properly?
-				SegManager *segMan = ((SciEngine *)g_engine)->getEngineState()->_segMan;
+				SegManager *segMan = ((SciEngine *)g_engine)->getEngineState()->_segMan;	// HACK
 				PUT_SEL32V(segMan, _playList[i]->soundObj, signal, SIGNAL_OFFSET);
 				if (_soundVersion <= SCI_VERSION_0_LATE)
 					PUT_SEL32V(segMan, _playList[i]->soundObj, state, kSndStatusStopped);
@@ -495,4 +488,27 @@
 	_pMixer->setVolumeForSoundType(Audio::Mixer::kPlainSoundType, vol);
 }
 
+void SciMusic::reconstructSounds(int savegame_version) {
+	_mutex.lock();
+
+	SegManager *segMan = ((SciEngine *)g_engine)->getEngineState()->_segMan;	// HACK
+	ResourceManager *resMan = ((SciEngine *)g_engine)->getEngineState()->resMan;	// HACK
+
+	for (uint32 i = 0; i < _playList.size(); i++) {
+		if (savegame_version < 14) {
+			if (_soundVersion >= SCI_VERSION_1_EARLY) {
+				_playList[i]->dataInc = GET_SEL32V(segMan, _playList[i]->soundObj, dataInc);
+				_playList[i]->volume = GET_SEL32V(segMan, _playList[i]->soundObj, vol);
+			} else {
+				_playList[i]->volume = 100;
+			}
+		}
+
+		_playList[i]->soundRes = new SoundResource(_playList[i]->resnum, resMan, _soundVersion);
+		soundInitSnd(_playList[i]);
+	}
+
+	_mutex.unlock();
+}
+
 } // end of namespace SCI

Modified: scummvm/trunk/engines/sci/sfx/music.h
===================================================================
--- scummvm/trunk/engines/sci/sfx/music.h	2009-12-27 11:12:26 UTC (rev 46622)
+++ scummvm/trunk/engines/sci/sfx/music.h	2009-12-27 11:43:34 UTC (rev 46623)
@@ -26,12 +26,14 @@
 #ifndef SCI_MUSIC_H
 #define SCI_MUSIC_H
 
+#include "common/savefile.h"
+#include "common/serializer.h"
+#include "common/mutex.h"
+
 #include "sound/mixer.h"
 #include "sound/audiostream.h"
 #include "sound/mididrv.h"
 #include "sound/midiparser.h"
-#include "common/mutex.h"
-#include "common/savefile.h"
 
 #include "sci/sci.h"
 #include "sci/resource.h"
@@ -84,7 +86,7 @@
 
 typedef Common::Array<MusicEntry *> MusicList;
 
-class SciMusic {
+class SciMusic : public Common::Serializable {
 public:
 	SciMusic(SciVersion soundVersion);
 	~SciMusic();
@@ -95,7 +97,6 @@
 #endif
 	void onTimer();
 	bool saveState(Common::OutSaveFile *pFile);
-	bool restoreState(Common::InSaveFile *pFile);
 	void stopAll();
 
 	// sound and midi functions
@@ -113,25 +114,29 @@
 		return _dwTempo;
 	}
 
-	int findListSlot(reg_t obj) {
+	MusicEntry *getSlot(reg_t obj) { 
+		_mutex.lock();
+
 		for (uint32 i = 0; i < _playList.size(); i++) {
-			if (_playList[i]->soundObj == obj)
-				return i;
+			if (_playList[i]->soundObj == obj) {
+				_mutex.unlock();
+				return _playList[i];
+			}
 		}
-		return -1;
+
+		_mutex.unlock();
+		return NULL;
 	}
 
-	MusicEntry *getSlot(int slot) { return _playList[slot]; }
-
 	void pushBackSlot(MusicEntry *slotEntry) {
 		_mutex.lock();
 		_playList.push_back(slotEntry);
 		_mutex.unlock();
 	}
 
-	uint32 listSize() { return _playList.size(); }
+	void reconstructSounds(int savegame_version);
 
-	uint16 _savelen;
+	virtual void saveLoadWithSerializer(Common::Serializer &ser);
 
 protected:
 	byte findAudEntry(uint16 nAud, byte&oVolume, uint32& oOffset, uint32&oSize);

Modified: scummvm/trunk/engines/sci/sfx/soundcmd.cpp
===================================================================
--- scummvm/trunk/engines/sci/sfx/soundcmd.cpp	2009-12-27 11:12:26 UTC (rev 46622)
+++ scummvm/trunk/engines/sci/sfx/soundcmd.cpp	2009-12-27 11:43:34 UTC (rev 46623)
@@ -273,9 +273,9 @@
 
 #ifndef USE_OLD_MUSIC_FUNCTIONS
 	// Check if a track with the same sound object is already playing
-	int prevTrack = _music->findListSlot(obj);
-	if (prevTrack > -1)
-		_music->soundKill(_music->getSlot(prevTrack));
+	MusicEntry *oldSound = _music->getSlot(obj);
+	if (oldSound)
+		_music->soundKill(oldSound);
 
 	MusicEntry *newSound = new MusicEntry();
 	newSound->soundRes = 0;
@@ -386,19 +386,19 @@
 
 #else
 
-	int slot = _music->findListSlot(obj);
-	if (slot < 0) {
+	MusicEntry *musicSlot = _music->getSlot(obj);
+	if (!musicSlot) {
 		warning("cmdPlayHandle: Slot not found");
 		return;
 	}
 
 	int number = obj.segment ? GET_SEL32V(_segMan, obj, number) : -1;
 
-	if (_music->getSlot(slot)->resnum != number) { // another sound loaded into struct
+	if (musicSlot->resnum != number) { // another sound loaded into struct
 		cmdDisposeHandle(obj, value);
 		cmdInitHandle(obj, value);
 		// Find slot again :)
-		slot = _music->findListSlot(obj);
+		musicSlot = _music->getSlot(obj);
 	}
 
 	if (_hasNodePtr) {
@@ -410,7 +410,6 @@
 		PUT_SEL32V(_segMan, obj, state, kSndStatusPlaying);
 	}
 
-	MusicEntry *musicSlot = _music->getSlot(slot);
 	musicSlot->loop = GET_SEL32V(_segMan, obj, loop) == 0xFFFF ? 1 : 0;
 	musicSlot->prio = GET_SEL32V(_segMan, obj, priority);
 	// vol selector doesnt get used before sci1late
@@ -456,15 +455,15 @@
 
 #else
 
-	int slot = _music->findListSlot(obj);
-	if (slot < 0) {
+	MusicEntry *musicSlot = _music->getSlot(obj);
+	if (!musicSlot) {
 		warning("cmdDisposeHandle: Slot not found");
 		return;
 	}
 
 	cmdStopHandle(obj, value);
 
-	_music->soundKill(_music->getSlot(slot));
+	_music->soundKill(musicSlot);
 	if (_hasNodePtr)
 		PUT_SEL32(_segMan, obj, nodePtr, NULL_REG);
 	else
@@ -482,8 +481,8 @@
 	if (_hasNodePtr)
 		PUT_SEL32V(_segMan, obj, signal, SIGNAL_OFFSET);
 #else
-	int slot = _music->findListSlot(obj);
-	if (slot < 0) {
+	MusicEntry *musicSlot = _music->getSlot(obj);
+	if (!musicSlot) {
 		warning("cmdStopHandle: Slot not found");
 		return;
 	}
@@ -494,8 +493,8 @@
 	else
 		PUT_SEL32V(_segMan, obj, signal, SIGNAL_OFFSET);
 
-	_music->getSlot(slot)->dataInc = 0;
-	_music->soundStop(_music->getSlot(slot));
+	musicSlot->dataInc = 0;
+	_music->soundStop(musicSlot);
 #endif
 }
 
@@ -509,20 +508,20 @@
 	else
 		changeHandleStatus(obj, value ? SOUND_STATUS_SUSPENDED : SOUND_STATUS_PLAYING);
 #else
-	int slot = _music->findListSlot(obj);
-	if (slot < 0) {
+	MusicEntry *musicSlot = _music->getSlot(obj);
+	if (!musicSlot) {
 		warning("cmdPauseHandle: Slot not found");
 		return;
 	}
 
 	if (!_hasNodePtr) {
 		PUT_SEL32V(_segMan, obj, state, kSndStatusPaused);
-		_music->soundPause(_music->getSlot(slot));
+		_music->soundPause(musicSlot);
 	} else {
 		if (value)
-			_music->soundPause(_music->getSlot(slot));
+			_music->soundPause(musicSlot);
 		else
-			_music->soundPlay(_music->getSlot(slot));
+			_music->soundPlay(musicSlot);
 	}
 #endif
 }
@@ -536,14 +535,14 @@
 #ifdef USE_OLD_MUSIC_FUNCTIONS
 	changeHandleStatus(obj, SOUND_STATUS_PLAYING);
 #else
-	int slot = _music->findListSlot(obj);
-	if (slot < 0) {
+	MusicEntry *musicSlot = _music->getSlot(obj);
+	if (!musicSlot) {
 		warning("cmdResumeHandle: Slot not found");
 		return;
 	}
 
 	PUT_SEL32V(_segMan, obj, state, kSndStatusPlaying);
-	_music->soundPlay(_music->getSlot(slot));
+	_music->soundPlay(musicSlot);
 #endif
 }
 
@@ -613,14 +612,13 @@
 		}
 	}
 #else
-	int slot = _music->findListSlot(obj);
-	if (slot < 0) {
+	MusicEntry *musicSlot = _music->getSlot(obj);
+	if (!musicSlot) {
 		warning("cmdFadeHandle: Slot not found");
 		return;
 	}
 
 	int volume = GET_SEL32V(_segMan, obj, vol);
-	MusicEntry *musicSlot = _music->getSlot(slot);
 	musicSlot->fadeTo = _argv[2].toUint16();
 	musicSlot->fadeStep = volume > _argv[2].toUint16() ? -_argv[4].toUint16() : _argv[4].toUint16();
 	musicSlot->fadeTickerStep = _argv[3].toUint16() * 16667 / _music->soundGetTempo();
@@ -647,13 +645,12 @@
  		script_set_priority(_resMan, _segMan, _state, obj, GET_SEL32V(_segMan, obj, pri));
  	}
 #else
-	int slot = _music->findListSlot(obj);
-	if (slot < 0) {
+	MusicEntry *musicSlot = _music->getSlot(obj);
+	if (!musicSlot) {
 		warning("cmdUpdateHandle: Slot not found");
 		return;
 	}
 
-	MusicEntry *musicSlot = _music->getSlot(slot);
 	musicSlot->loop = (GET_SEL32V(_segMan, obj, loop) == 0xFFFF ? 1 : 0);
 	uint32 objVol = CLIP<int>(GET_SEL32V(_segMan, obj, vol), 0, 255);
 	if (objVol != musicSlot->volume)
@@ -741,14 +738,14 @@
 	}
 #else
 
-	int slot = _music->findListSlot(obj);
-	if (slot < 0) {
+	MusicEntry *musicSlot = _music->getSlot(obj);
+	if (!musicSlot) {
 		warning("cmdUpdateCues: Slot not found");
 		return;
 	}
 
 	uint16 signal = GET_SEL32V(_segMan, obj, signal);
-	uint16 dataInc = _music->getSlot(slot)->dataInc;
+	uint16 dataInc = musicSlot->dataInc;
 
 	switch (signal) {
 		case 0:
@@ -764,7 +761,7 @@
 			break;
 	}
 
-	uint16 ticker = _music->getSlot(slot)->ticker;
+	uint16 ticker = musicSlot->ticker;
 	PUT_SEL32V(_segMan, obj, min, ticker / 3600);
 	PUT_SEL32V(_segMan, obj, sec, ticker % 3600 / 60);
 	PUT_SEL32V(_segMan, obj, frame, ticker);
@@ -811,17 +808,17 @@
 		return;
 
 #ifndef USE_OLD_MUSIC_FUNCTIONS
-	int slot = _music->findListSlot(obj);
-	if (slot < 0) {
+	MusicEntry *musicSlot = _music->getSlot(obj);
+	if (!musicSlot) {
 		warning("cmdSetHandleVolume: Slot not found");
 		return;
 	}
 
 	value = CLIP<int>(value, 0, Audio::Mixer::kMaxChannelVolume);
 
-	if (_music->getSlot(slot)->volume != value) {
-		_music->getSlot(slot)->volume = value;
-		_music->soundSetVolume(_music->getSlot(slot), value);
+	if (musicSlot->volume != value) {
+		musicSlot->volume = value;
+		_music->soundSetVolume(musicSlot, value);
 		PUT_SEL32V(_segMan, obj, vol, value);
 	}
 #endif
@@ -834,12 +831,6 @@
 #ifdef USE_OLD_MUSIC_FUNCTIONS
 	script_set_priority(_resMan, _segMan, _state, obj, value);
 #else
-	int slot = _music->findListSlot(obj);
-	if (slot < 0) {
-		warning("cmdSetHandlePriority: Slot not found");
-		return;
-	}
-
 	if (value == -1) {
 		//pSnd->prio=0;field_15B=0
 		PUT_SEL32V(_segMan, obj, flags, GET_SEL32V(_segMan, obj, flags) & 0xFD);
@@ -861,16 +852,16 @@
 		_state->sfx_song_set_loops(handle, value);
 	}
 #else
-	int slot = _music->findListSlot(obj);
-	if (slot < 0) {
+	MusicEntry *musicSlot = _music->getSlot(obj);
+	if (!musicSlot) {
 		warning("cmdSetHandleLoop: Slot not found");
 		return;
 	}
 	if (value == -1) {
-		_music->getSlot(slot)->loop = 1;
+		musicSlot->loop = 1;
 		PUT_SEL32V(_segMan, obj, loop, 0xFFFF);
 	} else {
-		_music->getSlot(slot)->loop = 0;
+		musicSlot->loop = 0;
 		PUT_SEL32V(_segMan, obj, loop, 1);
 	}
 #endif


This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.




More information about the Scummvm-git-logs mailing list