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

fingolfin at users.sourceforge.net fingolfin at users.sourceforge.net
Mon Dec 28 22:03:15 CET 2009


Revision: 46687
          http://scummvm.svn.sourceforge.net/scummvm/?rev=46687&view=rev
Author:   fingolfin
Date:     2009-12-28 21:03:13 +0000 (Mon, 28 Dec 2009)

Log Message:
-----------
SCI: Start objectifying MusicEntry

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-28 21:00:59 UTC (rev 46686)
+++ scummvm/trunk/engines/sci/engine/savegame.cpp	2009-12-28 21:03:13 UTC (rev 46687)
@@ -102,53 +102,53 @@
 
 #define DEFROBNICATE_HANDLE(handle) (make_reg((handle >> 16) & 0xffff, handle & 0xffff))
 
-static void syncSong(Common::Serializer &s, MusicEntry *song) {
+void MusicEntry::saveLoadWithSerializer(Common::Serializer &s) {
 	if (s.getVersion() < 14) {
 		// Old sound system data. This data is only loaded, never saved (as we're never
 		// saving in the older version format)
 		uint32 handle = 0;
 		s.syncAsSint32LE(handle);
-		song->soundObj = DEFROBNICATE_HANDLE(handle);
-		s.syncAsSint32LE(song->resnum);
-		s.syncAsSint32LE(song->prio);
-		s.syncAsSint32LE(song->status);
+		soundObj = DEFROBNICATE_HANDLE(handle);
+		s.syncAsSint32LE(resnum);
+		s.syncAsSint32LE(prio);
+		s.syncAsSint32LE(status);
 		s.skip(4);	// restoreBehavior
 		uint32 restoreTime = 0;
 		s.syncAsSint32LE(restoreTime);
-		song->ticker = restoreTime * 60 / 1000;
-		s.syncAsSint32LE(song->loop);
+		ticker = restoreTime * 60 / 1000;
+		s.syncAsSint32LE(loop);
 		s.skip(4);	// hold
 		// volume and dataInc will be synced from the sound objects
 		// when the sound list is reconstructed in gamestate_restore()
-		song->volume = 100;
-		song->dataInc = 0;
+		volume = 100;
+		dataInc = 0;
 		// No fading info
-		song->fadeTo = 0;
-		song->fadeStep = 0;
-		song->fadeTicker = 0;
-		song->fadeTickerStep = 0;
+		fadeTo = 0;
+		fadeStep = 0;
+		fadeTicker = 0;
+		fadeTickerStep = 0;
 	} else {
 		// A bit more optimized saving
-		sync_reg_t(s, song->soundObj);
-		s.syncAsSint16LE(song->resnum);
-		s.syncAsSint16LE(song->dataInc);
-		s.syncAsSint16LE(song->ticker);
-		s.syncAsByte(song->prio);
-		s.syncAsByte(song->loop);
-		s.syncAsByte(song->volume);
-		s.syncAsByte(song->fadeTo);
-		s.syncAsSint16LE(song->fadeStep);
-		s.syncAsSint32LE(song->fadeTicker);
-		s.syncAsSint32LE(song->fadeTickerStep);
-		s.syncAsByte(song->status);
+		sync_reg_t(s, soundObj);
+		s.syncAsSint16LE(resnum);
+		s.syncAsSint16LE(dataInc);
+		s.syncAsSint16LE(ticker);
+		s.syncAsByte(prio);
+		s.syncAsByte(loop);
+		s.syncAsByte(volume);
+		s.syncAsByte(fadeTo);
+		s.syncAsSint16LE(fadeStep);
+		s.syncAsSint32LE(fadeTicker);
+		s.syncAsSint32LE(fadeTickerStep);
+		s.syncAsByte(status);
 	}
 
 	// pMidiParser and pStreamAud will be initialized when the
 	// sound list is reconstructed in gamestate_restore()
 	if (s.isLoading()) {
-		song->soundRes = 0;
-		song->pMidiParser = 0;
-		song->pStreamAud = 0;
+		soundRes = 0;
+		pMidiParser = 0;
+		pStreamAud = 0;
 	}
 }
 #endif
@@ -649,12 +649,12 @@
 
 		for (int i = 0; i < songcount; i++) {
 			MusicEntry *curSong = new MusicEntry();
-			syncSong(s, curSong);
+			curSong->saveLoadWithSerializer(s);
 			_playList.push_back(curSong);
 		}
 	} else {
 		for (int i = 0; i < songcount; i++) {
-			syncSong(s, _playList[i]);
+			_playList[i]->saveLoadWithSerializer(s);
 		}
 	}
 }

Modified: scummvm/trunk/engines/sci/sfx/music.cpp
===================================================================
--- scummvm/trunk/engines/sci/sfx/music.cpp	2009-12-28 21:00:59 UTC (rev 46686)
+++ scummvm/trunk/engines/sci/sfx/music.cpp	2009-12-28 21:03:13 UTC (rev 46687)
@@ -37,10 +37,6 @@
 
 namespace Sci {
 
-static int f_compare(const void *arg1, const void *arg2) {
-	return ((const MusicEntry *)arg2)->prio - ((const MusicEntry *)arg1)->prio;
-}
-
 SciMusic::SciMusic(SciVersion soundVersion)
 	: _soundVersion(soundVersion), _soundOn(true), _inCriticalSection(false) {
 
@@ -115,19 +111,20 @@
 void SciMusic::stopAll() {
 	SegManager *segMan = ((SciEngine *)g_engine)->getEngineState()->_segMan;	// HACK
 	
-	for (uint32 i = 0; i < _playList.size(); i++) {
+	const MusicList::iterator end = _playList.end();
+	for (MusicList::iterator i = _playList.begin(); i != end; ++i) {
 		if (_soundVersion <= SCI_VERSION_0_LATE)
-			PUT_SEL32V(segMan, _playList[i]->soundObj, state, kSoundStopped);
+			PUT_SEL32V(segMan, (*i)->soundObj, state, kSoundStopped);
 		else
-			PUT_SEL32V(segMan, _playList[i]->soundObj, signal, SIGNAL_OFFSET);
+			PUT_SEL32V(segMan, (*i)->soundObj, signal, SIGNAL_OFFSET);
 
-		_playList[i]->dataInc = 0;
-		soundStop(_playList[i]);
+		(*i)->dataInc = 0;
+		soundStop(*i);
 	}
 }
 
 void SciMusic::miditimerCallback(void *p) {
-	SciMusic* aud = (SciMusic *)p;
+	SciMusic *aud = (SciMusic *)p;
 	aud->onTimer();
 }
 
@@ -146,6 +143,10 @@
 	}
 }
 
+static int f_compare(const void *arg1, const void *arg2) {
+	return ((const MusicEntry *)arg2)->prio - ((const MusicEntry *)arg1)->prio;
+}
+
 void SciMusic::sortPlayList() {
 	MusicEntry ** pData = _playList.begin();
 	qsort(pData, _playList.size(), sizeof(MusicEntry *), &f_compare);
@@ -495,4 +496,28 @@
 	}
 }
 
+
+MusicEntry::MusicEntry() {
+	soundObj = NULL_REG;
+
+	soundRes = 0;
+	resnum = 0;
+
+	dataInc = 0;
+	ticker = 0;
+	prio = 0;
+	loop = 0;
+	volume = 0;
+
+	fadeTo = 0;
+	fadeStep = 0;
+	fadeTicker = 0;
+	fadeTickerStep = 0;
+
+	status = kSoundStopped;
+
+	pStreamAud = 0;
+	pMidiParser = 0;
+}
+
 } // End of namespace Sci

Modified: scummvm/trunk/engines/sci/sfx/music.h
===================================================================
--- scummvm/trunk/engines/sci/sfx/music.h	2009-12-28 21:00:59 UTC (rev 46686)
+++ scummvm/trunk/engines/sci/sfx/music.h	2009-12-28 21:03:13 UTC (rev 46687)
@@ -58,7 +58,12 @@
 
 class MidiParser_SCI;
 
-struct MusicEntry {
+class MusicEntry
+#ifndef USE_OLD_MUSIC_FUNCTIONS
+	: public Common::Serializable
+#endif
+{
+public:
 	reg_t soundObj;
 
 	SoundResource *soundRes;
@@ -75,10 +80,21 @@
 	uint32 fadeTicker;
 	uint32 fadeTickerStep;
 
+	SoundStatus status;
+
+#ifndef USE_OLD_MUSIC_FUNCTIONS
+//protected:
+#endif
 	MidiParser_SCI *pMidiParser;
 	Audio::AudioStream* pStreamAud;
 	Audio::SoundHandle hCurrentAud;
-	SoundStatus status;
+
+public:
+	MusicEntry();
+
+#ifndef USE_OLD_MUSIC_FUNCTIONS
+	virtual void saveLoadWithSerializer(Common::Serializer &ser);
+#endif
 };
 
 typedef Common::Array<MusicEntry *> MusicList;
@@ -120,9 +136,10 @@
 	uint32 soundGetTempo() const { return _dwTempo; }
 
 	MusicEntry *getSlot(reg_t obj) { 
-		for (uint32 i = 0; i < _playList.size(); i++) {
-			if (_playList[i]->soundObj == obj) {
-				return _playList[i];
+		const MusicList::iterator end = _playList.end();
+		for (MusicList::iterator i = _playList.begin(); i != end; ++i) {
+			if ((*i)->soundObj == obj) {
+				return *i;
 			}
 		}
 

Modified: scummvm/trunk/engines/sci/sfx/soundcmd.cpp
===================================================================
--- scummvm/trunk/engines/sci/sfx/soundcmd.cpp	2009-12-28 21:00:59 UTC (rev 46686)
+++ scummvm/trunk/engines/sci/sfx/soundcmd.cpp	2009-12-28 21:03:13 UTC (rev 46687)
@@ -283,7 +283,6 @@
 
 #ifndef USE_OLD_MUSIC_FUNCTIONS
 	MusicEntry *newSound = new MusicEntry();
-	newSound->soundRes = 0;
 	newSound->resnum = number;
 	if (number && _resMan->testResource(ResourceId(kResourceTypeSound, number)))
 		newSound->soundRes = new SoundResource(number, _resMan, _soundVersion);
@@ -291,15 +290,6 @@
 	newSound->loop = GET_SEL32V(_segMan, obj, loop) == 0xFFFF ? 1 : 0;
 	newSound->prio = GET_SEL32V(_segMan, obj, pri) & 0xFF;
 	newSound->volume = CLIP<int>(GET_SEL32V(_segMan, obj, vol), 0, Audio::Mixer::kMaxChannelVolume);
-	newSound->dataInc = 0;
-	newSound->pStreamAud = 0;
-	newSound->pMidiParser = 0;
-	newSound->ticker = 0;
-	newSound->fadeTo = 0;
-	newSound->fadeStep = 0;
-	newSound->fadeTicker = 0;
-	newSound->fadeTickerStep = 0;
-	newSound->status = kSoundStopped;
 
 	// Check if a track with the same sound object is already playing
 	MusicEntry *oldSound = _music->getSlot(obj);
@@ -317,7 +307,6 @@
 		// Found a relevant audio resource, play it
 		int sampleLen;
 		newSound->pStreamAud = _audio->getAudioStream(number, 65535, &sampleLen);
-		newSound->hCurrentAud = Audio::SoundHandle();
 	} else {
 		if (newSound->soundRes)
 			_music->soundInitSnd(newSound);


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