Example #1
0
void Player_Mac::saveLoadWithSerializer(Serializer *ser) {
	Common::StackLock lock(_mutex);
	if (ser->getVersion() < VER(94)) {
		if (_vm->_game.id == GID_MONKEY && ser->isLoading()) {
			IMuse *dummyImuse = IMuse::create(_vm->_system, NULL, NULL);
			dummyImuse->save_or_load(ser, _vm, false);
			delete dummyImuse;
		}
	} else {
		static const SaveLoadEntry musicEntries[] = {
			MKLINE(Player_Mac, _sampleRate, sleUint32, VER(94)),
			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()
		};

		uint32 mixerSampleRate = _sampleRate;
		int i;

		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 (i = 0; i < _numberOfChannels; i++) {
			ser->saveLoadEntries(&_channel[i], instrumentEntries);
		}

		if (ser->isLoading()) {
			// If necessary, adjust the channel data to fit the
			// current sample rate.
			if (_soundPlaying != -1 && _sampleRate != mixerSampleRate) {
				double mult = (double)_sampleRate / (double)mixerSampleRate;
				for (i = 0; i < _numberOfChannels; i++) {
					_channel[i]._pitchModifier = (int)((double)_channel[i]._pitchModifier * mult);
					_channel[i]._remaining = (int)((double)_channel[i]._remaining / mult);
				}
			}
			_sampleRate = mixerSampleRate;
		}
	}
}
Example #2
0
void Player_AD::saveLoadWithSerializer(Serializer *ser) {
	Common::StackLock lock(_mutex);

	if (ser->getVersion() < VER(95)) {
		IMuse *dummyImuse = IMuse::create(_vm->_system, NULL, NULL);
		dummyImuse->save_or_load(ser, _vm, false);
		delete dummyImuse;
		return;
	}

	if (ser->getVersion() >= VER(96)) {
		int32 res[4] = {
			_soundPlaying, _sfx[0].resource, _sfx[1].resource, _sfx[2].resource
		};

		// The first thing we save is a list of sound resources being played
		// at the moment.
		ser->saveLoadArrayOf(res, 4, sizeof(res[0]), sleInt32);

		// If we are loading start the music again at this point.
		if (ser->isLoading()) {
			if (res[0] != -1) {
				startSound(res[0]);
			}
		}

		uint32 musicOffset = _curOffset;

		static const SaveLoadEntry musicData[] = {
			MKLINE(Player_AD, _engineMusicTimer, sleInt32, VER(96)),
			MKLINE(Player_AD, _musicTimer, sleUint32, VER(96)),
			MKLINE(Player_AD, _internalMusicTimer, sleUint32, VER(96)),
			MKLINE(Player_AD, _curOffset, sleUint32, VER(96)),
			MKLINE(Player_AD, _nextEventTimer, sleUint32, VER(96)),
			MKEND()
		};

		ser->saveLoadEntries(this, musicData);

		// We seek back to the old music position.
		if (ser->isLoading()) {
			SWAP(musicOffset, _curOffset);
			musicSeekTo(musicOffset);
		}

		// Finally start up the SFX. This makes sure that they are not
		// accidently stopped while seeking to the old music position.
		if (ser->isLoading()) {
			for (int i = 1; i < ARRAYSIZE(res); ++i) {
				if (res[i] != -1) {
					startSound(res[i]);
				}
			}
		}
	}
}
Example #3
0
void Player_AD::saveLoadWithSerializer(Common::Serializer &s) {
	Common::StackLock lock(_mutex);

	if (s.getVersion() < VER(95)) {
		IMuse *dummyImuse = IMuse::create(_vm->_system, NULL, NULL);
		dummyImuse->saveLoadIMuse(s, _vm, false);
		delete dummyImuse;
		return;
	}

	if (s.getVersion() >= VER(96)) {
		int32 res[4] = {
			_musicResource, _sfx[0].resource, _sfx[1].resource, _sfx[2].resource
		};

		// The first thing we save is a list of sound resources being played
		// at the moment.
		s.syncArray(res, 4, Common::Serializer::Sint32LE);

		// If we are loading start the music again at this point.
		if (s.isLoading()) {
			if (res[0] != -1) {
				startSound(res[0]);
			}
		}

		uint32 musicOffset = _curOffset;

		s.syncAsSint32LE(_engineMusicTimer, VER(96));
		s.syncAsUint32LE(_musicTimer, VER(96));
		s.syncAsUint32LE(_internalMusicTimer, VER(96));
		s.syncAsUint32LE(_curOffset, VER(96));
		s.syncAsUint32LE(_nextEventTimer, VER(96));

		// We seek back to the old music position.
		if (s.isLoading()) {
			SWAP(musicOffset, _curOffset);
			musicSeekTo(musicOffset);
		}

		// Finally start up the SFX. This makes sure that they are not
		// accidently stopped while seeking to the old music position.
		if (s.isLoading()) {
			for (int i = 1; i < ARRAYSIZE(res); ++i) {
				if (res[i] != -1) {
					startSound(res[i]);
				}
			}
		}
	}
}