diff options
| author | Max Horn | 2009-12-28 21:03:13 +0000 | 
|---|---|---|
| committer | Max Horn | 2009-12-28 21:03:13 +0000 | 
| commit | 81a1d45821932bf847ccf9b5a6e805d59ba0f27a (patch) | |
| tree | 2d6f16fb8dd87f77dd5ccf1f590fe9686fd95562 | |
| parent | 594e202683d79ad7b34c7fa99938bb668dc89bbe (diff) | |
| download | scummvm-rg350-81a1d45821932bf847ccf9b5a6e805d59ba0f27a.tar.gz scummvm-rg350-81a1d45821932bf847ccf9b5a6e805d59ba0f27a.tar.bz2 scummvm-rg350-81a1d45821932bf847ccf9b5a6e805d59ba0f27a.zip  | |
SCI: Start objectifying MusicEntry
svn-id: r46687
| -rw-r--r-- | engines/sci/engine/savegame.cpp | 60 | ||||
| -rw-r--r-- | engines/sci/sfx/music.cpp | 45 | ||||
| -rw-r--r-- | engines/sci/sfx/music.h | 27 | ||||
| -rw-r--r-- | engines/sci/sfx/soundcmd.cpp | 11 | 
4 files changed, 87 insertions, 56 deletions
diff --git a/engines/sci/engine/savegame.cpp b/engines/sci/engine/savegame.cpp index 56e81c6e4b..7169e363e1 100644 --- a/engines/sci/engine/savegame.cpp +++ b/engines/sci/engine/savegame.cpp @@ -102,53 +102,53 @@ static void syncSong(Common::Serializer &s, Song &obj) {  #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 @@ void SciMusic::saveLoadWithSerializer(Common::Serializer &s) {  		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);  		}  	}  } diff --git a/engines/sci/sfx/music.cpp b/engines/sci/sfx/music.cpp index 8d2beff59f..83dc0b26a9 100644 --- a/engines/sci/sfx/music.cpp +++ b/engines/sci/sfx/music.cpp @@ -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::clearPlayList() {  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 @@ uint16 SciMusic::soundGetVoices() {  	}  } +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 @@ void SciMusic::reconstructPlayList(int savegame_version) {  	}  } + +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 diff --git a/engines/sci/sfx/music.h b/engines/sci/sfx/music.h index cb220cc25a..e2d195c54f 100644 --- a/engines/sci/sfx/music.h +++ b/engines/sci/sfx/music.h @@ -58,7 +58,12 @@ enum SoundStatus {  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 @@ struct MusicEntry {  	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 @@ public:  	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;  			}  		} diff --git a/engines/sci/sfx/soundcmd.cpp b/engines/sci/sfx/soundcmd.cpp index f7ed18968b..b85067b17f 100644 --- a/engines/sci/sfx/soundcmd.cpp +++ b/engines/sci/sfx/soundcmd.cpp @@ -283,7 +283,6 @@ void SoundCommandParser::cmdInitHandle(reg_t obj, int16 value) {  #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 @@ void SoundCommandParser::cmdInitHandle(reg_t obj, int16 value) {  	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 @@ void SoundCommandParser::cmdInitHandle(reg_t obj, int16 value) {  		// 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);  | 
