Skip to content

Commit

Permalink
SCUMM: Save/load Mac music engine state for Loom and MI1
Browse files Browse the repository at this point in the history
Note that while this removes _townsPlayer->saveLoadWithSerializer(s)
it really shouldn't break anything because _musicEngine also points
to the FM Towns player. Famous last words...
  • Loading branch information
Torbjörn Andersson committed Nov 15, 2012
1 parent b753493 commit f784d68
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 4 deletions.
6 changes: 6 additions & 0 deletions engines/scumm/music.h
Expand Up @@ -24,6 +24,7 @@
#define SCUMM_MUSIC_H

#include "common/scummsys.h"
#include "engines/scumm/saveload.h"

namespace Scumm {

Expand Down Expand Up @@ -78,6 +79,11 @@ class MusicEngine {
* @return the music timer
*/
virtual int getMusicTimer() { return 0; }

/**
* Save or load the music state.
*/
virtual void saveLoadWithSerializer(Serializer *ser) {}
};

} // End of namespace Scumm
Expand Down
42 changes: 42 additions & 0 deletions engines/scumm/player_mac.cpp
Expand Up @@ -97,6 +97,48 @@ Player_Mac::~Player_Mac() {
delete[] _channel;
}

void Player_Mac::saveLoadWithSerializer(Serializer *ser) {
Common::StackLock lock(_mutex);
if (ser->getVersion() < VER(94)) {
if (_vm->_game.id == GID_MONKEY && ser->isLoading()) {
// TODO: Skip old iMUSE save/load information
}
} else {
static const SaveLoadEntry musicEntries[] = {
MKLINE(Player_Mac, _soundPlaying, sleInt16, VER(94)),
MKEND()
};

static const SaveLoadEntry channelEntries[] = {
MKLINE(Channel, _pos, sleUint16, VER(94)),
MKLINE(Channel, _pitchModifier, sleInt32, VER(94)),
MKLINE(Channel, _velocity, sleUint8, VER(94)),
MKLINE(Channel, _remaining, sleUint32, VER(94)),
MKLINE(Channel, _notesLeft, sleUint8, VER(94)),
MKEND()
};

static const SaveLoadEntry instrumentEntries[] = {
MKLINE(Instrument, _pos, sleUint32, VER(94)),
MKLINE(Instrument, _subPos, sleUint32, VER(94)),
MKEND()
};

ser->saveLoadEntries(this, musicEntries);

if (ser->isLoading() && _soundPlaying != -1) {
const byte *ptr = _vm->getResourceAddress(rtSound, _soundPlaying);
assert(ptr);
loadMusic(ptr);
}

ser->saveLoadArrayOf(_channel, _numberOfChannels, sizeof(Channel), channelEntries);
for (int i = 0; i < _numberOfChannels; i++) {
ser->saveLoadEntries(&_channel[i], instrumentEntries);
}
}
}

void Player_Mac::setMusicVolume(int vol) {
debug(5, "Player_Mac::setMusicVolume(%d)", vol);
}
Expand Down
3 changes: 3 additions & 0 deletions engines/scumm/player_mac.h
Expand Up @@ -27,6 +27,7 @@
#include "common/util.h"
#include "common/mutex.h"
#include "scumm/music.h"
#include "scumm/saveload.h"
#include "audio/audiostream.h"
#include "audio/mixer.h"

Expand Down Expand Up @@ -62,6 +63,8 @@ class Player_Mac : public Audio::AudioStream, public MusicEngine {
virtual bool endOfData() const { return false; }
virtual int getRate() const { return _sampleRate; }

virtual void saveLoadWithSerializer(Serializer *ser);

private:
Common::Mutex _mutex;
Audio::Mixer *const _mixer;
Expand Down
10 changes: 7 additions & 3 deletions engines/scumm/saveload.cpp
Expand Up @@ -1477,9 +1477,13 @@ void ScummEngine::saveOrLoad(Serializer *s) {
}


// Save/load FM-Towns audio status
if (_townsPlayer)
_townsPlayer->saveLoadWithSerializer(s);
//
// Save/load music engine status
//
if (_musicEngine) {
_musicEngine->saveLoadWithSerializer(s);
}


//
// Save/load the charset renderer state
Expand Down
2 changes: 1 addition & 1 deletion engines/scumm/saveload.h
Expand Up @@ -47,7 +47,7 @@ namespace Scumm {
* only saves/loads those which are valid for the version of the savegame
* which is being loaded/saved currently.
*/
#define CURRENT_VER 93
#define CURRENT_VER 94

/**
* An auxillary macro, used to specify savegame versions. We use this instead
Expand Down

0 comments on commit f784d68

Please sign in to comment.