aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFilippos Karapetis2009-12-27 11:43:34 +0000
committerFilippos Karapetis2009-12-27 11:43:34 +0000
commit0a771e14c1ffac674ac597d8960f9d7435436748 (patch)
treedca3e703432767502d95b2ba36df01d772e672fa
parent3c99391b49d1b4ee40d2f74f94b290f9cdcefb49 (diff)
downloadscummvm-rg350-0a771e14c1ffac674ac597d8960f9d7435436748.tar.gz
scummvm-rg350-0a771e14c1ffac674ac597d8960f9d7435436748.tar.bz2
scummvm-rg350-0a771e14c1ffac674ac597d8960f9d7435436748.zip
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 svn-id: r46623
-rw-r--r--engines/sci/engine/savegame.cpp34
-rw-r--r--engines/sci/sfx/music.cpp32
-rw-r--r--engines/sci/sfx/music.h29
-rw-r--r--engines/sci/sfx/soundcmd.cpp87
4 files changed, 91 insertions, 91 deletions
diff --git a/engines/sci/engine/savegame.cpp b/engines/sci/engine/savegame.cpp
index 735ba21836..cee1825b0b 100644
--- a/engines/sci/engine/savegame.cpp
+++ b/engines/sci/engine/savegame.cpp
@@ -72,8 +72,6 @@ SongIterator *build_iterator(ResourceManager *resMan, int song_nr, SongIteratorT
#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 @@ void EngineState::saveLoadWithSerializer(Common::Serializer &s) {
#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 @@ static void sync_songlib(Common::Serializer &s, SongLibrary &obj) {
}
}
#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 @@ EngineState *gamestate_restore(EngineState *s, Common::SeekableReadStream *fh) {
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:
diff --git a/engines/sci/sfx/music.cpp b/engines/sci/sfx/music.cpp
index fbaf2fde19..d6f00478bc 100644
--- a/engines/sci/sfx/music.cpp
+++ b/engines/sci/sfx/music.cpp
@@ -123,13 +123,6 @@ bool SciMusic::saveState(Common::OutSaveFile *pFile) {
}
//----------------------------------------
-bool SciMusic::restoreState(Common::InSaveFile *pFile){
- if (pFile->readLine() != "AUDIO")
- return false;
-
- return true;
-}
-//----------------------------------------
void SciMusic::stopAll() {
_pMixer->stopAll();
@@ -360,7 +353,7 @@ void SciMusic::onTimer() {
// 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 @@ void SciMusic::soundSetMasterVolume(uint16 vol) {
_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
diff --git a/engines/sci/sfx/music.h b/engines/sci/sfx/music.h
index a6d3a3f375..574dc15e6f 100644
--- a/engines/sci/sfx/music.h
+++ b/engines/sci/sfx/music.h
@@ -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 @@ struct MusicEntry {
typedef Common::Array<MusicEntry *> MusicList;
-class SciMusic {
+class SciMusic : public Common::Serializable {
public:
SciMusic(SciVersion soundVersion);
~SciMusic();
@@ -95,7 +97,6 @@ public:
#endif
void onTimer();
bool saveState(Common::OutSaveFile *pFile);
- bool restoreState(Common::InSaveFile *pFile);
void stopAll();
// sound and midi functions
@@ -113,15 +114,19 @@ public:
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;
- }
- MusicEntry *getSlot(int slot) { return _playList[slot]; }
+ _mutex.unlock();
+ return NULL;
+ }
void pushBackSlot(MusicEntry *slotEntry) {
_mutex.lock();
@@ -129,9 +134,9 @@ public:
_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);
diff --git a/engines/sci/sfx/soundcmd.cpp b/engines/sci/sfx/soundcmd.cpp
index 5723ad632b..c39321ef34 100644
--- a/engines/sci/sfx/soundcmd.cpp
+++ b/engines/sci/sfx/soundcmd.cpp
@@ -273,9 +273,9 @@ void SoundCommandParser::cmdInitHandle(reg_t obj, int16 value) {
#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 @@ void SoundCommandParser::cmdPlayHandle(reg_t obj, int16 value) {
#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 @@ void SoundCommandParser::cmdPlayHandle(reg_t obj, int16 value) {
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 @@ void SoundCommandParser::cmdDisposeHandle(reg_t obj, int16 value) {
#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 @@ void SoundCommandParser::cmdStopHandle(reg_t obj, int16 value) {
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 @@ void SoundCommandParser::cmdStopHandle(reg_t obj, int16 value) {
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 @@ void SoundCommandParser::cmdPauseHandle(reg_t obj, int16 value) {
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 @@ void SoundCommandParser::cmdResumeHandle(reg_t obj, int16 value) {
#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 @@ void SoundCommandParser::cmdFadeHandle(reg_t obj, int16 value) {
}
}
#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 @@ void SoundCommandParser::cmdUpdateHandle(reg_t obj, int16 value) {
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 @@ void SoundCommandParser::cmdUpdateCues(reg_t obj, int16 value) {
}
#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 @@ void SoundCommandParser::cmdUpdateCues(reg_t obj, int16 value) {
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 @@ void SoundCommandParser::cmdSetHandleVolume(reg_t obj, int16 value) {
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 @@ void SoundCommandParser::cmdSetHandlePriority(reg_t obj, int16 value) {
#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 @@ void SoundCommandParser::cmdSetHandleLoop(reg_t obj, int16 value) {
_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