[Scummvm-cvs-logs] scummvm master -> 5ea896b069df70e7c1fa8467b89457b200e33dc0

bluegr bluegr at gmail.com
Mon Sep 10 23:35:26 CEST 2012


This automated email contains information about 6 new commits which have been
pushed to the 'scummvm' repo located at https://github.com/scummvm/scummvm .

Summary:
72cdd019fc TOLTECS: Implement volume handling and toggling of speech/text
a9a579891e TOLTECS: Open the save menu with F5 and the load menu with F9
c0a1d78e0e TOLTECS: Store channel volume/panning information in saved games
455ad8a5bc TOLTECS: Read the sound rate for each video file
de75d25725 TOLTECS: Remove a superfluous seek
5ea896b069 TOLTECS: Stop reallocating the chunk buffer on each movie frame


Commit: 72cdd019fc5797f1250e346828a8fcef11fb28a4
    https://github.com/scummvm/scummvm/commit/72cdd019fc5797f1250e346828a8fcef11fb28a4
Author: Filippos Karapetis (md5 at scummvm.org)
Date: 2012-09-10T14:34:23-07:00

Commit Message:
TOLTECS: Implement volume handling and toggling of speech/text

Changed paths:
    engines/toltecs/menu.cpp
    engines/toltecs/menu.h
    engines/toltecs/music.cpp
    engines/toltecs/music.h
    engines/toltecs/screen.cpp
    engines/toltecs/sound.cpp
    engines/toltecs/sound.h
    engines/toltecs/toltecs.cpp
    engines/toltecs/toltecs.h



diff --git a/engines/toltecs/menu.cpp b/engines/toltecs/menu.cpp
index 415f19c..d983652 100644
--- a/engines/toltecs/menu.cpp
+++ b/engines/toltecs/menu.cpp
@@ -21,8 +21,11 @@
  *
  */
 
+#include "audio/mixer.h"
 #include "common/savefile.h"
 
+#include "common/config-manager.h"
+
 #include "toltecs/toltecs.h"
 #include "toltecs/menu.h"
 #include "toltecs/palette.h"
@@ -53,14 +56,8 @@ int MenuSystem::run() {
 	_newMenuID = kMenuIdMain;
 	_currItemID = kItemIdNone;
 	_editingDescription = false;
-	_cfgText = true;
-	_cfgVoices = true;
-	_cfgMasterVolume = 10;
-	_cfgVoicesVolume = 10;
-	_cfgMusicVolume = 10;
-	_cfgSoundFXVolume = 10;
-	_cfgBackgroundVolume = 10;
-	_running = true;    	
+
+	_running = true;
 	_top = 30 - _vm->_guiHeight / 2;
 	_needRedraw = false;
 
@@ -241,8 +238,8 @@ void MenuSystem::initMenu(MenuID menuID) {
 		drawString(0, 74, 320, 1, 229, _vm->getSysString(kStrWhatCanIDoForYou));
 		addClickTextItem(kItemIdLoad, 0, 115, 320, 0, _vm->getSysString(kStrLoad), 229, 255);
 		addClickTextItem(kItemIdSave, 0, 135, 320, 0, _vm->getSysString(kStrSave), 229, 255);
-		addClickTextItem(kItemIdToggleText, 0, 165, 320, 0, _vm->getSysString(kStrTextOn), 229, 255);
-		addClickTextItem(kItemIdToggleVoices, 0, 185, 320, 0, _vm->getSysString(kStrVoicesOn), 229, 255);
+		addClickTextItem(kItemIdToggleText, 0, 165, 320, 0, _vm->getSysString(_vm->_cfgText ? kStrTextOn : kStrTextOff), 229, 255);
+		addClickTextItem(kItemIdToggleVoices, 0, 185, 320, 0, _vm->getSysString(_vm->_cfgVoices ? kStrVoicesOn : kStrVoicesOff), 229, 255);
 		addClickTextItem(kItemIdVolumesMenu, 0, 215, 320, 0, _vm->getSysString(kStrVolume), 229, 255);
 		addClickTextItem(kItemIdPlay, 0, 245, 320, 0, _vm->getSysString(kStrPlay), 229, 255);
 		addClickTextItem(kItemIdQuit, 0, 275, 320, 0, _vm->getSysString(kStrQuit), 229, 255);
@@ -326,13 +323,13 @@ void MenuSystem::clickItem(ItemID id) {
 		_newMenuID = kMenuIdLoad;
 		break;
 	case kItemIdToggleText:
-		setCfgText(!_cfgText, true);
-		if (!_cfgVoices && !_cfgText)
+		setCfgText(!_vm->_cfgText, true);
+		if (!_vm->_cfgVoices && !_vm->_cfgText)
 			setCfgVoices(true, false);
 		break;
 	case kItemIdToggleVoices:
-		setCfgVoices(!_cfgVoices, true);
-		if (!_cfgVoices && !_cfgText)
+		setCfgVoices(!_vm->_cfgVoices, true);
+		if (!_vm->_cfgVoices && !_vm->_cfgText)
 			setCfgText(true, false);
 		break;
 	case kItemIdVolumesMenu:
@@ -518,22 +515,24 @@ void MenuSystem::clickSavegameItem(ItemID id) {
 }
 
 void MenuSystem::setCfgText(bool value, bool active) {
-	if (_cfgText != value) {
+	if (_vm->_cfgText != value) {
 		Item *item = getItem(kItemIdToggleText);
-		_cfgText = value;
+		_vm->_cfgText = value;
 		restoreRect(item->rect.left, item->rect.top, item->rect.width() + 1, item->rect.height() - 2);
-		setItemCaption(item, _vm->getSysString(_cfgText ? kStrTextOn : kStrTextOff));
+		setItemCaption(item, _vm->getSysString(_vm->_cfgText ? kStrTextOn : kStrTextOff));
 		drawItem(kItemIdToggleText, true);
+		ConfMan.setBool("subtitles", value);
 	}
 }
 
 void MenuSystem::setCfgVoices(bool value, bool active) {
-	if (_cfgVoices != value) {
+	if (_vm->_cfgVoices != value) {
 		Item *item = getItem(kItemIdToggleVoices);
-		_cfgVoices = value;
+		_vm->_cfgVoices = value;
 		restoreRect(item->rect.left, item->rect.top, item->rect.width() + 1, item->rect.height() - 2);
-		setItemCaption(item, _vm->getSysString(_cfgVoices ? kStrVoicesOn : kStrVoicesOff));
+		setItemCaption(item, _vm->getSysString(_vm->_cfgVoices ? kStrVoicesOn : kStrVoicesOff));
 		drawItem(kItemIdToggleVoices, true);
+		ConfMan.setBool("speech_mute", !value);
 	}
 }
 
@@ -542,25 +541,25 @@ void MenuSystem::drawVolumeBar(ItemID itemID) {
 	char text[21];
 	
 	switch (itemID) {
-	case kItemIdMaster:
+	case kItemIdMaster:	// unused in ScummVM, always 20
 		y = 130 + 25 * 0;
-		volume = _cfgMasterVolume;
+		volume = 20;
 		break;
 	case kItemIdVoices:
 		y = 130 + 25 * 1;
-		volume = _cfgVoicesVolume;
+		volume = _vm->_cfgVoicesVolume;
 		break;
 	case kItemIdMusic:
 		y = 130 + 25 * 2;
-		volume = _cfgMusicVolume;
+		volume = _vm->_cfgMusicVolume;
 		break;
 	case kItemIdSoundFX:
 		y = 130 + 25 * 3;
-		volume = _cfgSoundFXVolume;
+		volume = _vm->_cfgSoundFXVolume;
 		break;
-	case kItemIdBackground:
+	case kItemIdBackground:	// unused in ScummVM, always 20
 		y = 130 + 25 * 4;
-		volume = _cfgBackgroundVolume;
+		volume = 20;
 		break;
 	default:
 		return;
@@ -578,36 +577,37 @@ void MenuSystem::drawVolumeBar(ItemID itemID) {
 }
 
 void MenuSystem::changeVolumeBar(ItemID itemID, int delta) {
-
-	int *volume, newVolume;
+	byte newVolume;
 
 	switch (itemID) {
-	case kItemIdMaster:
-		volume = &_cfgMasterVolume;
-		break;
 	case kItemIdVoices:
-		volume = &_cfgVoicesVolume;
+		_vm->_cfgVoicesVolume = CLIP(_vm->_cfgVoicesVolume + delta, 0, 20);
+		newVolume = ceil((double)_vm->_cfgVoicesVolume * Audio::Mixer::kMaxChannelVolume / 20);
+		_vm->_mixer->setVolumeForSoundType(Audio::Mixer::kSpeechSoundType, newVolume);
+		ConfMan.setInt("speech_volume", newVolume);
 		break;
 	case kItemIdMusic:
-		volume = &_cfgMusicVolume;
+		_vm->_cfgMusicVolume = CLIP(_vm->_cfgMusicVolume + delta, 0, 20);
+		newVolume = ceil((double)_vm->_cfgMusicVolume * Audio::Mixer::kMaxChannelVolume / 20);
+		_vm->_mixer->setVolumeForSoundType(Audio::Mixer::kMusicSoundType, newVolume);
+		ConfMan.setInt("music_volume", newVolume);
 		break;
 	case kItemIdSoundFX:
-		volume = &_cfgSoundFXVolume;
+		_vm->_cfgSoundFXVolume = CLIP(_vm->_cfgSoundFXVolume + delta, 0, 20);
+		newVolume = ceil((double)_vm->_cfgSoundFXVolume * Audio::Mixer::kMaxChannelVolume / 20);
+		_vm->_mixer->setVolumeForSoundType(Audio::Mixer::kSFXSoundType, newVolume);
+		ConfMan.setInt("sfx_volume", newVolume);
 		break;
+	case kItemIdMaster:
 	case kItemIdBackground:
-		volume = &_cfgBackgroundVolume;
+		// unused in ScummVM
 		break;
 	default:
 		return;
 	}
 
-	newVolume = CLIP(*volume + delta, 0, 20);
-
-	if (newVolume != *volume) {
-		*volume = newVolume;
-		drawVolumeBar(itemID);
-	}
-
+	_vm->syncSoundSettings();
+	drawVolumeBar(itemID);
 }
 
 } // End of namespace Toltecs
diff --git a/engines/toltecs/menu.h b/engines/toltecs/menu.h
index 3e2c2da..999744e 100644
--- a/engines/toltecs/menu.h
+++ b/engines/toltecs/menu.h
@@ -125,9 +125,6 @@ protected:
 	Common::Array<Item> _items;
 	Common::Array<SavegameItem> _savegames;
 	
-	bool _cfgText, _cfgVoices;
-	int _cfgMasterVolume, _cfgVoicesVolume, _cfgMusicVolume, _cfgSoundFXVolume,	_cfgBackgroundVolume;
-
 	void addClickTextItem(ItemID id, int x, int y, int w, uint fontNum, const char *caption, byte defaultColor, byte activeColor);
 
 	void drawItem(ItemID itemID, bool active);
diff --git a/engines/toltecs/music.cpp b/engines/toltecs/music.cpp
index c322961..2cd36ca 100644
--- a/engines/toltecs/music.cpp
+++ b/engines/toltecs/music.cpp
@@ -20,15 +20,13 @@
  *
  */
 
-// FIXME: This code is taken from SAGA and needs more work (e.g. setVolume).
+#include "audio/midiparser.h"
+#include "common/textconsole.h"
 
 #include "toltecs/toltecs.h"
 #include "toltecs/music.h"
 #include "toltecs/resource.h"
 
-#include "audio/midiparser.h"
-#include "common/textconsole.h"
-
 namespace Toltecs {
 
 MusicPlayer::MusicPlayer(bool isGM) : _isGM(isGM), _buffer(NULL) {
@@ -77,7 +75,7 @@ void MusicPlayer::playMIDI(const byte *data, uint32 size, bool loop) {
 
 		_parser = parser;
 
-		setVolume(127);
+		syncVolume();
 
 		_isLooping = loop;
 		_isPlaying = true;
@@ -86,16 +84,6 @@ void MusicPlayer::playMIDI(const byte *data, uint32 size, bool loop) {
 	}
 }
 
-void MusicPlayer::pause() {
-	setVolume(-1);
-	_isPlaying = false;
-}
-
-void MusicPlayer::resume() {
-	setVolume(127);
-	_isPlaying = true;
-}
-
 void MusicPlayer::stopAndClear() {
 	Common::StackLock lock(_mutex);
 	stop();
diff --git a/engines/toltecs/music.h b/engines/toltecs/music.h
index 79df1ea..8d364db 100644
--- a/engines/toltecs/music.h
+++ b/engines/toltecs/music.h
@@ -37,8 +37,6 @@ public:
 	MusicPlayer(bool isGM = true);
 
 	void playMIDI(const byte *data, uint32 size, bool loop = false);
-	void pause();
-	void resume();
 	void stopAndClear();
 
 	// MidiDriver_BASE interface implementation
diff --git a/engines/toltecs/screen.cpp b/engines/toltecs/screen.cpp
index 634917a..7ec6e94 100644
--- a/engines/toltecs/screen.cpp
+++ b/engines/toltecs/screen.cpp
@@ -469,7 +469,6 @@ void Screen::addTalkTextRect(Font &font, int16 x, int16 &y, int16 length, int16
 }
 
 void Screen::addTalkTextItemsToRenderQueue() {
-
 	for (int16 i = 0; i <= _talkTextItemNum; i++) {
 		TalkTextItem *item = &_talkTextItems[i];
 		byte *text = _vm->_script->getSlotData(item->slotIndex) + item->slotOffset;
@@ -482,14 +481,15 @@ void Screen::addTalkTextItemsToRenderQueue() {
 		if (item->duration < 0)
 			item->duration = 0;
 
+		if (!_vm->_cfgText)
+			return;
+
 		for (byte j = 0; j < item->lineCount; j++) {
-			_renderQueue->addText(item->lines[j].x, item->lines[j].y, item->color, _fontResIndexArray[item->fontNum],
-				text, item->lines[j].length);
+			_renderQueue->addText(item->lines[j].x, item->lines[j].y, item->color,
+					_fontResIndexArray[item->fontNum], text, item->lines[j].length);
 			text += item->lines[j].length;
 		}
-		
 	}
-
 }
 
 int16 Screen::getTalkTextDuration() {
diff --git a/engines/toltecs/sound.cpp b/engines/toltecs/sound.cpp
index c9ef00e..7cb96ca 100644
--- a/engines/toltecs/sound.cpp
+++ b/engines/toltecs/sound.cpp
@@ -44,39 +44,23 @@ Sound::~Sound() {
 
 void Sound::playSpeech(int16 resIndex) {
 	debug(0, "playSpeech(%d)", resIndex);
-	internalPlaySound(resIndex, kChannelTypeSpeech, 50 /*TODO*/, 0);
+
+	if (_vm->_cfgVoices)
+		internalPlaySound(resIndex, kChannelTypeSpeech, 50 /*TODO*/, 0);
 }
 
 void Sound::playSound(int16 resIndex, int16 type, int16 volume) {
-
-	// TODO: Use the right volumes
-
 	debug(0, "playSound(%d, %d, %d)", resIndex, type, volume);
 	
-	if (volume == -1 || type == -2) {
-		if (type == kChannelTypeBackground) {
-			internalPlaySound(resIndex, type, 50 /*TODO*/, 0);
-		} else {
-			internalPlaySound(resIndex, type, 100 /*TODO*/, 0);
-		}
-	} else {
-		internalPlaySound(resIndex, type, 100 /*TODO*/, 0);
-	}
-
+	internalPlaySound(resIndex, type, volume, 0);
 }
 
 void Sound::playSoundAtPos(int16 resIndex, int16 x, int16 y) {
-
 	debug(0, "playSoundAtPos(%d, %d, %d)", resIndex, x, y);
 
-	int16 volume, panning = 0, deltaX = 0;
-	int8 scaling = _vm->_segmap->getScalingAtPoint(x, y);
-
-	if (scaling >= 0)
-		volume = 50 + ABS(scaling) / 2;
-	else
-		volume = 50 - ABS(scaling) / 2;
-
+	int16 volume = 50 + ABS(_vm->_segmap->getScalingAtPoint(x, y)) / 2;
+	int16 panning = 0, deltaX = 0;
+	
 	if (_vm->_cameraX > x)
 		deltaX = _vm->_cameraX - x;
 	else if (_vm->_cameraX + 640 < x)
@@ -91,11 +75,12 @@ void Sound::playSoundAtPos(int16 resIndex, int16 x, int16 y) {
 	}
 
 	internalPlaySound(resIndex, 1, volume, panning);
-
 }
 
 void Sound::internalPlaySound(int16 resIndex, int16 type, int16 volume, int16 panning) {
-
+	// Change the game's sound volume (0 - 100) to Scummvm's scale (0 - 255)
+	volume = (volume == -1) ? 255 : volume * 255 / 100;
+	
 	if (resIndex == -1) {
 		// Stop all sounds
 		_vm->_mixer->stopAll();
@@ -142,14 +127,10 @@ void Sound::internalPlaySound(int16 resIndex, int16 type, int16 volume, int16 pa
 			channels[freeChannel].type = type;
 			channels[freeChannel].resIndex = resIndex;
 
-			Audio::Mixer::SoundType soundType = Audio::Mixer::kPlainSoundType;
-			/*
-			switch (type) {
-			}
-			*/
+			Audio::Mixer::SoundType soundType = getScummVMSoundType((SoundChannelType)type);
 
 			_vm->_mixer->playStream(soundType, &channels[freeChannel].handle,
-				stream, -1, volume, panning);
+			                        stream, -1, volume, panning);
 		}
 
 	}
@@ -206,11 +187,7 @@ void Sound::loadState(Common::ReadStream *in) {
 								DisposeAfterUse::NO),
 								channels[i].type == kChannelTypeBackground ? 0 : 1);
 
-			Audio::Mixer::SoundType soundType = Audio::Mixer::kPlainSoundType;
-			/*
-			switch (type) {
-			}
-			*/
+			Audio::Mixer::SoundType soundType = getScummVMSoundType((SoundChannelType)channels[i].type);
 
 			// TODO: Volume and panning
 			int16 volume = (channels[i].type == kChannelTypeBackground) ? 50 : 100;
@@ -221,4 +198,18 @@ void Sound::loadState(Common::ReadStream *in) {
 	}
 }
 
+Audio::Mixer::SoundType Sound::getScummVMSoundType(SoundChannelType type) const {
+	switch (type) {
+	case kChannelTypeBackground:
+	case kChannelTypeSfx:
+		return Audio::Mixer::kSFXSoundType;
+	case kChannelTypeSpeech:
+		return Audio::Mixer::kSpeechSoundType;
+		break;
+	default:
+		return Audio::Mixer::kSFXSoundType;
+		break;
+	}
+}
+
 } // End of namespace Toltecs
diff --git a/engines/toltecs/sound.h b/engines/toltecs/sound.h
index e292d22..4e8db6d 100644
--- a/engines/toltecs/sound.h
+++ b/engines/toltecs/sound.h
@@ -68,7 +68,7 @@ protected:
 	SoundChannel channels[kMaxChannels];
 
 	void internalPlaySound(int16 resIndex, int16 type, int16 volume, int16 panning);
-
+	Audio::Mixer::SoundType getScummVMSoundType(SoundChannelType type) const;
 };
 
 
diff --git a/engines/toltecs/toltecs.cpp b/engines/toltecs/toltecs.cpp
index 6d6c37d..9871942 100644
--- a/engines/toltecs/toltecs.cpp
+++ b/engines/toltecs/toltecs.cpp
@@ -62,11 +62,6 @@ struct GameSettings {
 };
 
 ToltecsEngine::ToltecsEngine(OSystem *syst, const ToltecsGameDescription *gameDesc) : Engine(syst), _gameDescription(gameDesc) {
-
-	// Setup mixer
-	_mixer->setVolumeForSoundType(Audio::Mixer::kSFXSoundType, ConfMan.getInt("sfx_volume"));
-	_mixer->setVolumeForSoundType(Audio::Mixer::kMusicSoundType, ConfMan.getInt("music_volume"));
-
 	_rnd = new Common::RandomSource("toltecs");
 }
 
@@ -129,14 +124,24 @@ Common::Error ToltecsEngine::run() {
 	
 	_sound = new Sound(this);
 
+	_cfgText = ConfMan.getBool("subtitles");
+	_cfgVoices = !ConfMan.getBool("speech_mute");
+
+	bool mute = false;
+	if (ConfMan.hasKey("mute"))
+		mute = ConfMan.getBool("mute");
+
+	_mixer->setVolumeForSoundType(Audio::Mixer::kSpeechSoundType, mute ? 0 : ConfMan.getInt("speech_volume"));
+	_mixer->setVolumeForSoundType(Audio::Mixer::kMusicSoundType,  mute ? 0 : ConfMan.getInt("music_volume"));
+	_mixer->setVolumeForSoundType(Audio::Mixer::kSFXSoundType,    mute ? 0 : ConfMan.getInt("sfx_volume"));
 	syncSoundSettings();
 
 	CursorMan.showMouse(true);
 
 	setupSysStrings();
 
-//#define TEST_MENU
-#ifdef TEST_MENU
+#if 0
+	// Menu test
 	_screen->registerFont(0, 0x0D);
 	_screen->registerFont(1, 0x0E);
 	_screen->loadMouseCursor(12);
@@ -321,7 +326,6 @@ void ToltecsEngine::updateInput() {
 
 			//debug("key: flags = %02X; keycode = %d", _keyState.flags, _keyState.keycode);
 
-			// FIXME: This is just for debugging
 			switch (event.kbd.keycode) {
 			case Common::KEYCODE_F7:
 				savegame("toltecs.001", "Quicksave");
@@ -638,4 +642,16 @@ int16 ToltecsEngine::findRectAtPoint(byte *rectData, int16 x, int16 y, int16 ind
 
 }
 
+void ToltecsEngine::syncSoundSettings() {
+	Engine::syncSoundSettings();
+
+	bool mute = false;
+	if (ConfMan.hasKey("mute"))
+		mute = ConfMan.getBool("mute");
+
+	_cfgVoicesVolume  = (mute ? 0 : ConfMan.getInt("speech_volume")) * 20 / Audio::Mixer::kMaxChannelVolume;
+	_cfgMusicVolume   = (mute ? 0 : ConfMan.getInt("music_volume"))  * 20 / Audio::Mixer::kMaxChannelVolume;
+	_cfgSoundFXVolume = (mute ? 0 : ConfMan.getInt("sfx_volume"))    * 20 / Audio::Mixer::kMaxChannelVolume;
+}
+
 } // End of namespace Toltecs
diff --git a/engines/toltecs/toltecs.h b/engines/toltecs/toltecs.h
index efa1f9d..58678f2 100644
--- a/engines/toltecs/toltecs.h
+++ b/engines/toltecs/toltecs.h
@@ -99,6 +99,7 @@ public:
 	uint32 getFeatures() const;
 	Common::Language getLanguage() const;
 	const Common::String& getTargetName() const { return _targetName; }
+	void syncSoundSettings();
 
 	void setupSysStrings();
 	void requestSavegame(int slotNum, Common::String &description);
@@ -127,6 +128,8 @@ public:
 	int16 findRectAtPoint(byte *rectData, int16 x, int16 y, int16 index, int16 itemSize, 
 		byte *rectDataEnd);
 
+	int _cfgVoicesVolume, _cfgMusicVolume, _cfgSoundFXVolume;
+	bool _cfgText, _cfgVoices;
 public:
 
 	AnimationPlayer *_anim;


Commit: a9a579891e2e267cf665f68ed1c9f4a2314d502e
    https://github.com/scummvm/scummvm/commit/a9a579891e2e267cf665f68ed1c9f4a2314d502e
Author: Filippos Karapetis (md5 at scummvm.org)
Date: 2012-09-10T14:34:27-07:00

Commit Message:
TOLTECS: Open the save menu with F5 and the load menu with F9

Also, this changes the dialog skip key to space instead of escape

Changed paths:
    engines/toltecs/menu.cpp
    engines/toltecs/menu.h
    engines/toltecs/script.cpp
    engines/toltecs/script.h
    engines/toltecs/toltecs.cpp
    engines/toltecs/toltecs.h



diff --git a/engines/toltecs/menu.cpp b/engines/toltecs/menu.cpp
index d983652..d7ba254 100644
--- a/engines/toltecs/menu.cpp
+++ b/engines/toltecs/menu.cpp
@@ -40,7 +40,7 @@ MenuSystem::MenuSystem(ToltecsEngine *vm) : _vm(vm) {
 MenuSystem::~MenuSystem() {
 }
 
-int MenuSystem::run() {
+int MenuSystem::run(MenuID menuId) {
 
 	//debug("MenuSystem::run()");
 
@@ -53,7 +53,7 @@ int MenuSystem::run() {
 	memcpy(backgroundOrig.getBasePtr(0,0), _vm->_screen->_frontScreen, 640 * 400);
 
 	_currMenuID = kMenuIdNone;
-	_newMenuID = kMenuIdMain;
+	_newMenuID = menuId;
 	_currItemID = kItemIdNone;
 	_editingDescription = false;
 
diff --git a/engines/toltecs/menu.h b/engines/toltecs/menu.h
index 999744e..9234a56 100644
--- a/engines/toltecs/menu.h
+++ b/engines/toltecs/menu.h
@@ -29,14 +29,6 @@
 
 namespace Toltecs {
 
-enum MenuID {
-	kMenuIdNone,
-	kMenuIdMain,
-	kMenuIdSave,
-	kMenuIdLoad,
-	kMenuIdVolumes
-};
-
 enum ItemID {
 	kItemIdNone,
 	// Main menu
@@ -85,7 +77,7 @@ public:
 	MenuSystem(ToltecsEngine *vm);
 	~MenuSystem();
 
-	int run();
+	int run(MenuID menuId);
 	void update();
 	void handleEvents();
 	
diff --git a/engines/toltecs/script.cpp b/engines/toltecs/script.cpp
index 9683831..40b1352 100644
--- a/engines/toltecs/script.cpp
+++ b/engines/toltecs/script.cpp
@@ -1060,15 +1060,7 @@ void ScriptInterpreter::sfHandleInput() {
 }
 
 void ScriptInterpreter::sfRunOptionsScreen() {
-	_vm->_screen->loadMouseCursor(12);
-	_vm->_palette->loadAddPalette(9, 224);
-	_vm->_palette->setDeltaPalette(_vm->_palette->getMainPalette(), 7, 0, 31, 224);
-	_vm->_screen->finishTalkTextItems();
-	_vm->_screen->clearSprites();
-	CursorMan.showMouse(true);
-	_vm->_menuSystem->run();
-	_vm->_keyState.reset();
-	_switchLocalDataNear = true;
+	_vm->showMenu(kMenuIdMain);
 }
 
 /* NOTE: The opcodes sfPrecacheSprites, sfPrecacheSounds1, sfPrecacheSounds2 and
diff --git a/engines/toltecs/script.h b/engines/toltecs/script.h
index 0c1898c..7a50d22 100644
--- a/engines/toltecs/script.h
+++ b/engines/toltecs/script.h
@@ -56,6 +56,8 @@ public:
 	void saveState(Common::WriteStream *out);
 	void loadState(Common::ReadStream *in);
 
+	void setSwitchLocalDataNear(bool newValue) { _switchLocalDataNear = newValue; }
+
 protected:
 
 	struct ScriptRegs {
diff --git a/engines/toltecs/toltecs.cpp b/engines/toltecs/toltecs.cpp
index 9871942..b1f60c5 100644
--- a/engines/toltecs/toltecs.cpp
+++ b/engines/toltecs/toltecs.cpp
@@ -327,13 +327,13 @@ void ToltecsEngine::updateInput() {
 			//debug("key: flags = %02X; keycode = %d", _keyState.flags, _keyState.keycode);
 
 			switch (event.kbd.keycode) {
-			case Common::KEYCODE_F7:
-				savegame("toltecs.001", "Quicksave");
+			case Common::KEYCODE_F5:
+				showMenu(kMenuIdSave);
 				break;
-			case Common::KEYCODE_F9:
-				loadgame("toltecs.001");
+			case Common::KEYCODE_F7:
+				showMenu(kMenuIdLoad);
 				break;
-			case Common::KEYCODE_ESCAPE:
+			case Common::KEYCODE_SPACE:
 				// Skip current dialog line, if a dialog is active
 				if (_screen->getTalkTextDuration() > 0) {
 					_sound->stopSpeech();
@@ -639,7 +639,18 @@ int16 ToltecsEngine::findRectAtPoint(byte *rectData, int16 x, int16 y, int16 ind
 	}
 	
 	return -1;
+}
 
+void ToltecsEngine::showMenu(MenuID menuId) {
+	_screen->loadMouseCursor(12);
+	_palette->loadAddPalette(9, 224);
+	_palette->setDeltaPalette(_palette->getMainPalette(), 7, 0, 31, 224);
+	_screen->finishTalkTextItems();
+	_screen->clearSprites();
+	CursorMan.showMouse(true);
+	_menuSystem->run(menuId);
+	_keyState.reset();
+	_script->setSwitchLocalDataNear(true);
 }
 
 void ToltecsEngine::syncSoundSettings() {
diff --git a/engines/toltecs/toltecs.h b/engines/toltecs/toltecs.h
index 58678f2..e82a88b 100644
--- a/engines/toltecs/toltecs.h
+++ b/engines/toltecs/toltecs.h
@@ -81,6 +81,14 @@ enum SysString {
 	kSysStrCount
 };
 
+enum MenuID {
+	kMenuIdNone,
+	kMenuIdMain,
+	kMenuIdSave,
+	kMenuIdLoad,
+	kMenuIdVolumes
+};
+
 class ToltecsEngine : public ::Engine {
 	Common::KeyState _keyPressed;
 
@@ -120,7 +128,9 @@ public:
 	void scrollCameraLeft(int16 delta);
 	void scrollCameraRight(int16 delta);
 	void updateCamera();
-	
+
+	void showMenu(MenuID menuId);
+
 	void talk(int16 slotIndex, int16 slotOffset);
 
 	void walk(byte *walkData);


Commit: c0a1d78e0e07ff308edee823e47c869efc2c64ca
    https://github.com/scummvm/scummvm/commit/c0a1d78e0e07ff308edee823e47c869efc2c64ca
Author: Filippos Karapetis (md5 at scummvm.org)
Date: 2012-09-10T14:34:28-07:00

Commit Message:
TOLTECS: Store channel volume/panning information in saved games

Changed paths:
    engines/toltecs/saveload.cpp
    engines/toltecs/sound.cpp
    engines/toltecs/sound.h



diff --git a/engines/toltecs/saveload.cpp b/engines/toltecs/saveload.cpp
index c24d214..4de2510 100644
--- a/engines/toltecs/saveload.cpp
+++ b/engines/toltecs/saveload.cpp
@@ -36,12 +36,11 @@
 namespace Toltecs {
 
 /* TODO:
-	- Save with F7; Load with F9
 	- Saving during an animation (AnimationPlayer) is not working correctly yet
 	- Maybe switch to SCUMM/Tinsel serialization approach?
 */
 
-#define TOLTECS_SAVEGAME_VERSION 3
+#define TOLTECS_SAVEGAME_VERSION 4
 
 ToltecsEngine::kReadSaveHeaderError ToltecsEngine::readSaveHeader(Common::SeekableReadStream *in, bool loadThumbnail, SaveHeader &header) {
 
@@ -141,8 +140,8 @@ void ToltecsEngine::savegame(const char *filename, const char *description) {
 }
 
 void ToltecsEngine::loadgame(const char *filename) {
-	Common::InSaveFile *in;
-	if (!(in = g_system->getSavefileManager()->openForLoading(filename))) {
+	Common::InSaveFile *in = g_system->getSavefileManager()->openForLoading(filename);
+	if (!in) {
 		warning("Can't open file '%s', game not loaded", filename);
 		return;
 	}
@@ -191,7 +190,7 @@ void ToltecsEngine::loadgame(const char *filename) {
 	_anim->loadState(in);
 	_screen->loadState(in);
 	if (header.version >= 2)
-		_sound->loadState(in);
+		_sound->loadState(in, header.version);
 	if (header.version >= 3)
 		_music->loadState(in);
 
diff --git a/engines/toltecs/sound.cpp b/engines/toltecs/sound.cpp
index 7cb96ca..2705efe 100644
--- a/engines/toltecs/sound.cpp
+++ b/engines/toltecs/sound.cpp
@@ -34,14 +34,20 @@ namespace Toltecs {
 
 Sound::Sound(ToltecsEngine *vm) : _vm(vm) {
 	for (int i = 0; i < kMaxChannels; i++) {
-		channels[i].type = kChannelTypeEmpty;
-		channels[i].resIndex = -1;
+		clearChannel(i);
 	}
 }
 
 Sound::~Sound() {
 }
 
+void Sound::clearChannel(int channel) {
+	channels[channel].type = kChannelTypeEmpty;
+	channels[channel].resIndex = -1;
+	channels[channel].volume = 0;
+	channels[channel].panning = 0;
+}
+
 void Sound::playSpeech(int16 resIndex) {
 	debug(0, "playSpeech(%d)", resIndex);
 
@@ -86,16 +92,14 @@ void Sound::internalPlaySound(int16 resIndex, int16 type, int16 volume, int16 pa
 		_vm->_mixer->stopAll();
 		_vm->_screen->keepTalkTextItemsAlive();
 		for (int i = 0; i < kMaxChannels; i++) {
-			channels[i].type = kChannelTypeEmpty;
-			channels[i].resIndex = -1;
+			clearChannel(i);
 		}
 	} else if (type == -2) {
 		// Stop sounds with specified resIndex
 		for (int i = 0; i < kMaxChannels; i++) {
 			if (channels[i].resIndex == resIndex) {
 				_vm->_mixer->stopHandle(channels[i].handle);
-				channels[i].type = kChannelTypeEmpty;
-				channels[i].resIndex = -1;
+				clearChannel(i);
 			}
 		}
 	} else {
@@ -126,6 +130,8 @@ void Sound::internalPlaySound(int16 resIndex, int16 type, int16 volume, int16 pa
 
 			channels[freeChannel].type = type;
 			channels[freeChannel].resIndex = resIndex;
+			channels[freeChannel].volume = volume;
+			channels[freeChannel].panning = panning;
 
 			Audio::Mixer::SoundType soundType = getScummVMSoundType((SoundChannelType)type);
 
@@ -151,8 +157,7 @@ void Sound::stopSpeech() {
 		if (channels[i].type == kChannelTypeSpeech) {
 			_vm->_mixer->stopHandle(channels[i].handle);
 			_vm->_screen->keepTalkTextItemsAlive();
-			channels[i].type = kChannelTypeEmpty;
-			channels[i].resIndex = -1;
+			clearChannel(i);
 		}
 	}
 }
@@ -161,8 +166,7 @@ void Sound::stopAll() {
 	for (int i = 0; i < kMaxChannels; i++) {
 		_vm->_mixer->stopHandle(channels[i].handle);
 		_vm->_screen->keepTalkTextItemsAlive();
-		channels[i].type = kChannelTypeEmpty;
-		channels[i].resIndex = -1;
+		clearChannel(i);
 	}
 }
 
@@ -170,13 +174,22 @@ void Sound::saveState(Common::WriteStream *out) {
 	for (int i = 0; i < kMaxChannels; i++) {
 		out->writeSint16LE(channels[i].type);
 		out->writeSint16LE(channels[i].resIndex);
+		out->writeSint16LE(channels[i].volume);
+		out->writeSint16LE(channels[i].panning);
 	}
 }
 
-void Sound::loadState(Common::ReadStream *in) {
+void Sound::loadState(Common::ReadStream *in, int version) {
 	for (int i = 0; i < kMaxChannels; i++) {
 		channels[i].type = in->readSint16LE();
 		channels[i].resIndex = in->readSint16LE();
+		if (version < 4) {
+			channels[i].volume = (channels[i].type == kChannelTypeBackground) ? 50 : 100;
+			channels[i].panning = 0;
+		} else {
+			channels[i].volume = in->readSint16LE();
+			channels[i].panning = in->readSint16LE();
+		}
 
 		if (channels[i].type != kChannelTypeEmpty) {
 			Resource *soundResource = _vm->_res->load(channels[i].resIndex);
@@ -189,11 +202,8 @@ void Sound::loadState(Common::ReadStream *in) {
 
 			Audio::Mixer::SoundType soundType = getScummVMSoundType((SoundChannelType)channels[i].type);
 
-			// TODO: Volume and panning
-			int16 volume = (channels[i].type == kChannelTypeBackground) ? 50 : 100;
-
 			_vm->_mixer->playStream(soundType, &channels[i].handle,
-				stream, -1, volume, /*panning*/0);
+				stream, -1, channels[i].volume, channels[i].panning);
 		}
 	}
 }
diff --git a/engines/toltecs/sound.h b/engines/toltecs/sound.h
index 4e8db6d..48a6cd1 100644
--- a/engines/toltecs/sound.h
+++ b/engines/toltecs/sound.h
@@ -42,6 +42,8 @@ enum SoundChannelType {
 struct SoundChannel {
 	int16 resIndex;
 	int16 type;
+	int16 volume;
+	int16 panning;
 	Audio::SoundHandle handle;
 };
 
@@ -60,13 +62,14 @@ public:
 	void stopAll();
 
 	void saveState(Common::WriteStream *out);
-	void loadState(Common::ReadStream *in);
+	void loadState(Common::ReadStream *in, int version);
 
 protected:
 	ToltecsEngine *_vm;
 
 	SoundChannel channels[kMaxChannels];
 
+	void clearChannel(int channel);
 	void internalPlaySound(int16 resIndex, int16 type, int16 volume, int16 panning);
 	Audio::Mixer::SoundType getScummVMSoundType(SoundChannelType type) const;
 };


Commit: 455ad8a5bc4a443850847f960f8eeda262aee0bb
    https://github.com/scummvm/scummvm/commit/455ad8a5bc4a443850847f960f8eeda262aee0bb
Author: Filippos Karapetis (md5 at scummvm.org)
Date: 2012-09-10T14:34:29-07:00

Commit Message:
TOLTECS: Read the sound rate for each video file

Changed paths:
    engines/toltecs/movie.cpp



diff --git a/engines/toltecs/movie.cpp b/engines/toltecs/movie.cpp
index 76d42eb..d4e260d 100644
--- a/engines/toltecs/movie.cpp
+++ b/engines/toltecs/movie.cpp
@@ -78,7 +78,7 @@ void MoviePlayer::playMovie(uint resIndex) {
 	_vm->_arc->readUint32LE();
 	_vm->_arc->readUint32LE();
 	_framesPerSoundChunk = _vm->_arc->readUint32LE();
-	_vm->_arc->readUint32LE();
+	int rate = _vm->_arc->readUint32LE();
 
 	_vm->_sceneWidth = 640;
 	_vm->_sceneHeight = 400;
@@ -87,7 +87,7 @@ void MoviePlayer::playMovie(uint resIndex) {
 	_vm->_cameraY = 0;
 	_vm->_guiHeight = 0;
 
-	_audioStream = Audio::makeQueuingAudioStream(22050, false);
+	_audioStream = Audio::makeQueuingAudioStream(rate, false);
 
 	_vm->_mixer->playStream(Audio::Mixer::kPlainSoundType, &_audioStreamHandle, _audioStream);
 


Commit: de75d25725bb58870b74f780d4941eb7f66639b0
    https://github.com/scummvm/scummvm/commit/de75d25725bb58870b74f780d4941eb7f66639b0
Author: Filippos Karapetis (md5 at scummvm.org)
Date: 2012-09-10T14:34:30-07:00

Commit Message:
TOLTECS: Remove a superfluous seek

Changed paths:
    engines/toltecs/movie.cpp



diff --git a/engines/toltecs/movie.cpp b/engines/toltecs/movie.cpp
index d4e260d..5f6fe2c 100644
--- a/engines/toltecs/movie.cpp
+++ b/engines/toltecs/movie.cpp
@@ -103,7 +103,6 @@ void MoviePlayer::playMovie(uint resIndex) {
 		byte chunkType = _vm->_arc->readByte();
 		uint32 chunkSize = _vm->_arc->readUint32LE();
 		byte *chunkBuffer = NULL;
-		uint32 movieOffset;
 
 		debug(0, "chunkType = %d; chunkSize = %d", chunkType, chunkSize);
 		
@@ -116,8 +115,6 @@ void MoviePlayer::playMovie(uint resIndex) {
 			_vm->_arc->read(chunkBuffer, chunkSize);
 		}
 
-		movieOffset = _vm->_arc->pos();
-
 		switch (chunkType) {
 		case kChunkFirstImage:
 		case kChunkSubsequentImages:
@@ -177,9 +174,7 @@ void MoviePlayer::playMovie(uint resIndex) {
 		}
 
 		delete[] chunkBuffer;
-
-		_vm->_arc->seek(movieOffset, SEEK_SET);
-		
+	
 		if (!handleInput())
 			break;
 


Commit: 5ea896b069df70e7c1fa8467b89457b200e33dc0
    https://github.com/scummvm/scummvm/commit/5ea896b069df70e7c1fa8467b89457b200e33dc0
Author: Filippos Karapetis (md5 at scummvm.org)
Date: 2012-09-10T14:34:31-07:00

Commit Message:
TOLTECS: Stop reallocating the chunk buffer on each movie frame

This somewhat reduces the stuttering in the intro movie (but it's still there)

Changed paths:
    engines/toltecs/movie.cpp



diff --git a/engines/toltecs/movie.cpp b/engines/toltecs/movie.cpp
index 5f6fe2c..79cdd08 100644
--- a/engines/toltecs/movie.cpp
+++ b/engines/toltecs/movie.cpp
@@ -97,12 +97,12 @@ void MoviePlayer::playMovie(uint resIndex) {
 	fetchAudioChunks();
 
 	uint32 lastTime = _vm->_mixer->getSoundElapsedTime(_audioStreamHandle);
+	byte *chunkBuffer = NULL;
+	uint32 prevChunkSize = 0;
 
 	while (_chunkCount--) {
-
 		byte chunkType = _vm->_arc->readByte();
 		uint32 chunkSize = _vm->_arc->readUint32LE();
-		byte *chunkBuffer = NULL;
 
 		debug(0, "chunkType = %d; chunkSize = %d", chunkType, chunkSize);
 		
@@ -111,7 +111,13 @@ void MoviePlayer::playMovie(uint resIndex) {
 		if (chunkType == kChunkAudio) {
 			_vm->_arc->skip(chunkSize);
 		} else {
-			chunkBuffer = new byte[chunkSize];
+			// Only reallocate the chunk buffer if it's smaller than the previous frame
+			if (chunkSize > prevChunkSize) {
+				delete[] chunkBuffer;
+				chunkBuffer = new byte[chunkSize];
+			}
+
+			prevChunkSize = chunkSize;
 			_vm->_arc->read(chunkBuffer, chunkSize);
 		}
 
@@ -172,14 +178,13 @@ void MoviePlayer::playMovie(uint resIndex) {
 		default:
 			error("MoviePlayer::playMovie(%04X) Unknown chunk type %d at %08X", resIndex, chunkType, _vm->_arc->pos() - 5 - chunkSize);
 		}
-
-		delete[] chunkBuffer;
-	
+		
 		if (!handleInput())
 			break;
-
 	}
 
+	delete[] chunkBuffer;
+
 	_audioStream->finish();
 	_vm->_mixer->stopHandle(_audioStreamHandle);
 






More information about the Scummvm-git-logs mailing list