[Scummvm-cvs-logs] SF.net SVN: scummvm:[34251] scummvm/trunk/engines/lure

fingolfin at users.sourceforge.net fingolfin at users.sourceforge.net
Mon Sep 1 22:18:18 CEST 2008


Revision: 34251
          http://scummvm.svn.sourceforge.net/scummvm/?rev=34251&view=rev
Author:   fingolfin
Date:     2008-09-01 20:18:17 +0000 (Mon, 01 Sep 2008)

Log Message:
-----------
Merging more of the GSoC 2008 RTL branch: LURE

Modified Paths:
--------------
    scummvm/trunk/engines/lure/animseq.cpp
    scummvm/trunk/engines/lure/detection.cpp
    scummvm/trunk/engines/lure/events.cpp
    scummvm/trunk/engines/lure/events.h
    scummvm/trunk/engines/lure/fights.cpp
    scummvm/trunk/engines/lure/game.cpp
    scummvm/trunk/engines/lure/game.h
    scummvm/trunk/engines/lure/intro.cpp
    scummvm/trunk/engines/lure/lure.cpp
    scummvm/trunk/engines/lure/lure.h
    scummvm/trunk/engines/lure/menu.cpp
    scummvm/trunk/engines/lure/scripts.cpp
    scummvm/trunk/engines/lure/sound.cpp
    scummvm/trunk/engines/lure/sound.h
    scummvm/trunk/engines/lure/surface.cpp

Modified: scummvm/trunk/engines/lure/animseq.cpp
===================================================================
--- scummvm/trunk/engines/lure/animseq.cpp	2008-09-01 19:32:17 UTC (rev 34250)
+++ scummvm/trunk/engines/lure/animseq.cpp	2008-09-01 20:18:17 UTC (rev 34251)
@@ -44,12 +44,18 @@
 	while (g_system->getMillis() < delayCtr) {
 		while (events.pollEvent()) {
 			if ((events.type() == Common::EVENT_KEYDOWN) && (events.event().kbd.ascii != 0)) {
-				if (events.event().kbd.keycode == Common::KEYCODE_ESCAPE) return ABORT_END_INTRO;
-				else return ABORT_NEXT_SCENE;
-			} else if (events.type() == Common::EVENT_LBUTTONDOWN)
+				if (events.event().kbd.keycode == Common::KEYCODE_ESCAPE)
+					return ABORT_END_INTRO;
+				else
+					return ABORT_NEXT_SCENE;
+			} else if (events.type() == Common::EVENT_LBUTTONDOWN) {
 				return ABORT_NEXT_SCENE;
-			else if (events.type() == Common::EVENT_QUIT)
+			} else if ((events.type() == Common::EVENT_QUIT) || (events.type() == Common::EVENT_RTL)) {
 				return ABORT_END_INTRO;
+			} else if (events.type() == Common::EVENT_MAINMENU) {
+				return ABORT_NONE;
+			}
+
 		}
 
 		uint32 delayAmount = delayCtr - g_system->getMillis();

Modified: scummvm/trunk/engines/lure/detection.cpp
===================================================================
--- scummvm/trunk/engines/lure/detection.cpp	2008-09-01 19:32:17 UTC (rev 34250)
+++ scummvm/trunk/engines/lure/detection.cpp	2008-09-01 20:18:17 UTC (rev 34251)
@@ -26,6 +26,7 @@
 #include "base/plugins.h"
 
 #include "common/advancedDetector.h"
+#include "common/savefile.h"
 
 #include "lure/lure.h"
 
@@ -184,9 +185,19 @@
 		return "Lure of the Temptress (C) Revolution";
 	}
 
+	virtual bool hasFeature(MetaEngineFeature f) const;
 	virtual bool createInstance(OSystem *syst, Engine **engine, const Common::ADGameDescription *desc) const;
+	virtual SaveStateList listSaves(const char *target) const;
 };
 
+bool LureMetaEngine::hasFeature(MetaEngineFeature f) const {
+	return
+		(f == kSupportsRTL) ||
+		(f == kSupportsListSaves) ||
+		(f == kSupportsDirectLoad) ||
+		(f == kSupportsDeleteSave);
+}
+
 bool LureMetaEngine::createInstance(OSystem *syst, Engine **engine, const Common::ADGameDescription *desc) const {
 	const Lure::LureGameDescription *gd = (const Lure::LureGameDescription *)desc;
 	if (gd) {
@@ -195,6 +206,34 @@
 	return gd != 0;
 }
 
+SaveStateList LureMetaEngine::listSaves(const char *target) const {
+	Common::SaveFileManager *saveFileMan = g_system->getSavefileManager();
+	Common::StringList filenames;
+	Common::String saveDesc;
+	Common::String pattern = target;
+	pattern += ".???";
+
+	filenames = saveFileMan->listSavefiles(pattern.c_str());
+	sort(filenames.begin(), filenames.end());	// Sort (hopefully ensuring we are sorted numerically..)
+
+	SaveStateList saveList;
+	for (Common::StringList::const_iterator file = filenames.begin(); file != filenames.end(); ++file) {
+		// Obtain the last 3 digits of the filename, since they correspond to the save slot
+		int slotNum = atoi(file->c_str() + file->size() - 3);
+		
+		if (slotNum >= 0 && slotNum <= 999) {
+			Common::InSaveFile *in = saveFileMan->openForLoading(file->c_str());
+			if (in) {
+				saveDesc = Lure::getSaveName(in);
+				saveList.push_back(SaveStateDescriptor(slotNum, saveDesc, *file));
+				delete in;
+			}
+		}
+	}
+
+	return saveList;
+}
+
 #if PLUGIN_ENABLED_DYNAMIC(LURE)
 	REGISTER_PLUGIN_DYNAMIC(LURE, PLUGIN_TYPE_ENGINE, LureMetaEngine);
 #else

Modified: scummvm/trunk/engines/lure/events.cpp
===================================================================
--- scummvm/trunk/engines/lure/events.cpp	2008-09-01 19:32:17 UTC (rev 34250)
+++ scummvm/trunk/engines/lure/events.cpp	2008-09-01 20:18:17 UTC (rev 34251)
@@ -29,6 +29,7 @@
 #include "graphics/cursorman.h"
 
 #include "lure/events.h"
+#include "lure/lure.h"
 #include "lure/res.h"
 
 namespace Lure {
@@ -137,11 +138,12 @@
 
 void Mouse::waitForRelease() {
 	Events &e = Events::getReference();
+	LureEngine &engine = LureEngine::getReference();
 
 	do {
-		while (e.pollEvent() && !e.quitFlag) ;
+		while (e.pollEvent() && !engine.quit()) ;
 		g_system->delayMillis(20);
-	} while (!e.quitFlag && (lButton() || rButton() || mButton()));
+	} while (!engine.quit() && (lButton() || rButton() || mButton()));
 }
 
 /*--------------------------------------------------------------------------*/
@@ -150,7 +152,6 @@
 
 Events::Events() {
 	int_events = this;
-	quitFlag = false;
 }
 
 Events &Events::getReference() {
@@ -163,10 +164,6 @@
 
 	// Handle keypress
 	switch (_event.type) {
-	case Common::EVENT_QUIT:
-		quitFlag = true;
-		break;
-
 	case Common::EVENT_LBUTTONDOWN:
 	case Common::EVENT_LBUTTONUP:
 	case Common::EVENT_RBUTTONDOWN:
@@ -190,7 +187,7 @@
 	bool keyButton = false;
 	while (!keyButton) {
 		while (pollEvent()) {
-			if (_event.type == Common::EVENT_QUIT) return;
+			if ((_event.type == Common::EVENT_QUIT) || (_event.type == Common::EVENT_RTL)) return;
 			else if ((_event.type == Common::EVENT_KEYDOWN) && (_event.kbd.ascii != 0))
 				keyButton = true;
 			else if ((_event.type == Common::EVENT_LBUTTONDOWN) ||
@@ -210,10 +207,11 @@
 
 bool Events::interruptableDelay(uint32 milliseconds) {
 	Events &events = Events::getReference();
+	LureEngine &engine = LureEngine::getReference();
 	uint32 delayCtr = g_system->getMillis() + milliseconds;
 
 	while (g_system->getMillis() < delayCtr) {
-		if (events.quitFlag) return true;
+		if (engine.quit()) return true;
 
 		if (events.pollEvent()) {
 			if (((events.type() == Common::EVENT_KEYDOWN) && (events.event().kbd.ascii != 0)) ||

Modified: scummvm/trunk/engines/lure/events.h
===================================================================
--- scummvm/trunk/engines/lure/events.h	2008-09-01 19:32:17 UTC (rev 34250)
+++ scummvm/trunk/engines/lure/events.h	2008-09-01 20:18:17 UTC (rev 34251)
@@ -66,8 +66,6 @@
 private:
 	Common::Event _event;
 public:
-	bool quitFlag;
-
 	Events();
 	static Events &getReference();
 

Modified: scummvm/trunk/engines/lure/fights.cpp
===================================================================
--- scummvm/trunk/engines/lure/fights.cpp	2008-09-01 19:32:17 UTC (rev 34250)
+++ scummvm/trunk/engines/lure/fights.cpp	2008-09-01 20:18:17 UTC (rev 34251)
@@ -22,6 +22,7 @@
 #include "lure/fights.h"
 #include "lure/luredefs.h"
 #include "lure/game.h"
+#include "lure/lure.h"
 #include "lure/res.h"
 #include "lure/room.h"
 #include "lure/sound.h"
@@ -108,15 +109,15 @@
 }
 
 void FightsManager::fightLoop() {
+	LureEngine &engine = LureEngine::getReference();
 	Resources &res = Resources::getReference();
 	Game &game = Game::getReference();
 	Room &room = Room::getReference();
-	Events &events = Events::getReference();
 	FighterRecord &playerFight = getDetails(PLAYER_ID);
 	uint32 timerVal = g_system->getMillis();
 
 	// Loop for the duration of the battle
-	while (!events.quitFlag && (playerFight.fwhits != GENERAL_MAGIC_ID)) {
+	while (!engine.quit() && (playerFight.fwhits != GENERAL_MAGIC_ID)) {
 		checkEvents();
 
 		if (g_system->getMillis() > timerVal + GAME_FRAME_DELAY) {
@@ -184,6 +185,7 @@
 	{Common::KEYCODE_INVALID, 0}};
 
 void FightsManager::checkEvents() {
+	LureEngine &engine = LureEngine::getReference();
 	Game &game = Game::getReference();
 	Events &events = Events::getReference();
 	Mouse &mouse = Mouse::getReference();
@@ -196,7 +198,7 @@
 		if (events.type() == Common::EVENT_KEYDOWN) {
 			switch (events.event().kbd.keycode) {
 			case Common::KEYCODE_ESCAPE:
-				events.quitFlag = true;
+				engine.quitGame();
 				return;
 
 			case Common::KEYCODE_d:

Modified: scummvm/trunk/engines/lure/game.cpp
===================================================================
--- scummvm/trunk/engines/lure/game.cpp	2008-09-01 19:32:17 UTC (rev 34250)
+++ scummvm/trunk/engines/lure/game.cpp	2008-09-01 20:18:17 UTC (rev 34251)
@@ -23,10 +23,10 @@
  *
  */
 
-#include "lure/lure.h"
 #include "lure/game.h"
 #include "lure/animseq.h"
 #include "lure/fights.h"
+#include "lure/lure.h"
 #include "lure/res_struct.h"
 #include "lure/room.h"
 #include "lure/scripts.h"
@@ -125,6 +125,7 @@
 
 void Game::execute() {
 	OSystem &system = *g_system;
+	LureEngine &engine = LureEngine::getReference();
 	Room &room = Room::getReference();
 	Resources &res = Resources::getReference();
 	Events &events = Events::getReference();
@@ -137,12 +138,20 @@
 
 	screen.empty();
 	screen.setPaletteEmpty();
+	
+	bool _loadSavegame = false;
+	
+	if (engine.gameToLoad() != -1)
+		_loadSavegame = engine.loadGame(engine.gameToLoad());
+	
+	if (!_loadSavegame) {
+		// Flag for starting game
+		setState(GS_RESTART);
+	}
 
-	// Flag for starting game
-	setState(GS_RESTART);
 	bool initialRestart = true;
 
-	while (!events.quitFlag) {
+	while (!engine.quit()) {
 
 		if ((_state & GS_RESTART) != 0) {
 			res.reset();
@@ -162,7 +171,7 @@
 		mouse.cursorOn();
 
 		// Main game loop
-		while (!events.quitFlag && ((_state & GS_RESTART) == 0)) {
+		while (!engine.quit() && ((_state & GS_RESTART) == 0)) {
 			// If time for next frame, allow everything to update
 			if (system.getMillis() > timerVal + GAME_FRAME_DELAY) {
 				timerVal = system.getMillis();
@@ -291,10 +300,7 @@
 
 			if (restartFlag)
 				setState(GS_RESTART);
-
-		} else if ((_state & GS_RESTART) == 0)
-			// Exiting game
-			events.quitFlag = true;
+		}
 	}
 }
 
@@ -892,7 +898,7 @@
 void Game::doQuit() {
 	Sound.pause();
 	if (getYN())
-		Events::getReference().quitFlag = true;
+		LureEngine::getReference().quitGame();
 	Sound.resume();
 }
 
@@ -977,6 +983,7 @@
 	Events &events = Events::getReference();
 	Screen &screen = Screen::getReference();
 	Resources &res = Resources::getReference();
+	LureEngine &engine = LureEngine::getReference();
 
 	Common::Language l = LureEngine::getReference().getLanguage();
 	Common::KeyCode y = Common::KEYCODE_y;
@@ -1018,7 +1025,7 @@
 		}
 
 		g_system->delayMillis(10);
-	} while (!events.quitFlag && !breakFlag);
+	} while (!engine.quit() && !breakFlag);
 
 	screen.update();
 	if (!vKbdFlag)

Modified: scummvm/trunk/engines/lure/game.h
===================================================================
--- scummvm/trunk/engines/lure/game.h	2008-09-01 19:32:17 UTC (rev 34250)
+++ scummvm/trunk/engines/lure/game.h	2008-09-01 20:18:17 UTC (rev 34251)
@@ -27,6 +27,7 @@
 #define LURE_GAME_H
 
 
+#include "common/config-manager.h"
 #include "engines/engine.h"
 #include "lure/luredefs.h"
 #include "lure/menu.h"
@@ -85,8 +86,8 @@
 	bool &debugFlag() { return _debugFlag; }
 	bool fastTextFlag() { return _fastTextFlag; }
 	bool soundFlag() { return _soundFlag; }
-	uint8 sfxVolume() { return _sfxVolume; }
-	uint8 musicVolume() { return _musicVolume; }
+	uint8 sfxVolume() { return ConfMan.getInt("sfx_volume"); }
+	uint8 musicVolume() { return ConfMan.getInt("music_volume"); }
 	Debugger &debugger() { return *_debugger; }
 
 	// Menu item support methods

Modified: scummvm/trunk/engines/lure/intro.cpp
===================================================================
--- scummvm/trunk/engines/lure/intro.cpp	2008-09-01 19:32:17 UTC (rev 34250)
+++ scummvm/trunk/engines/lure/intro.cpp	2008-09-01 20:18:17 UTC (rev 34251)
@@ -55,17 +55,18 @@
 
 bool Introduction::showScreen(uint16 screenId, uint16 paletteId, uint16 delaySize) {
 	Screen &screen = Screen::getReference();
-	Events &events = Events::getReference();
 	bool isEGA = LureEngine::getReference().isEGA();
 	screen.screen().loadScreen(screenId);
 	screen.update();
 	Palette p(paletteId);
 
+	if (LureEngine::getReference().quit()) return true;
+	
 	if (isEGA) screen.setPalette(&p);
 	else screen.paletteFadeIn(&p);
 
 	bool result = interruptableDelay(delaySize);
-	if (events.quitFlag) return true;
+	if (LureEngine::getReference().quit()) return true;
 
 	if (!isEGA)
 		screen.paletteFadeOut();
@@ -83,6 +84,8 @@
 	if (events.interruptableDelay(milliseconds)) {
 		if (events.type() == Common::EVENT_KEYDOWN)
 			return events.event().kbd.keycode == 27;
+		else if (LureEngine::getReference().quit())
+			return true;
 		else if (events.type() == Common::EVENT_LBUTTONDOWN)
 			return false;
 	}

Modified: scummvm/trunk/engines/lure/lure.cpp
===================================================================
--- scummvm/trunk/engines/lure/lure.cpp	2008-09-01 19:32:17 UTC (rev 34250)
+++ scummvm/trunk/engines/lure/lure.cpp	2008-09-01 20:18:17 UTC (rev 34251)
@@ -92,6 +92,7 @@
 	_room = new Room();
 	_fights = new FightsManager();
 
+	_gameToLoad = -1;
 	_initialised = true;
 	return 0;
 }
@@ -121,38 +122,45 @@
 }
 
 int LureEngine::go() {
-
-	if (ConfMan.getBool("copy_protection")) {
-		CopyProtectionDialog *dialog = new CopyProtectionDialog();
-		bool result = dialog->show();
-		delete dialog;
-		if (_events->quitFlag)
-			return 0;
-
-		if (!result)
-			error("Sorry - copy protection failed");
+	Game *gameInstance = new Game();
+	
+	// If requested, load a savegame instead of showing the intro
+	if (ConfMan.hasKey("save_slot")) {
+		_gameToLoad = ConfMan.getInt("save_slot");
+		if (_gameToLoad < 0 || _gameToLoad > 999)
+			_gameToLoad = -1;
 	}
+	
+	if (_gameToLoad == -1) {
+		if (ConfMan.getBool("copy_protection")) {
+			CopyProtectionDialog *dialog = new CopyProtectionDialog();
+			bool result = dialog->show();
+			delete dialog;
+			if (quit())
+				return _eventMan->shouldRTL();
 
-	Game *gameInstance = new Game();
+			if (!result)
+				error("Sorry - copy protection failed");
+		}
 
-	if (ConfMan.getInt("boot_param") == 0) {
-		// Show the introduction
-		Sound.loadSection(Sound.isRoland() ? ROLAND_INTRO_SOUND_RESOURCE_ID : ADLIB_INTRO_SOUND_RESOURCE_ID);
-
-		Introduction *intro = new Introduction();
-		intro->show();
-		delete intro;
+		if (ConfMan.getInt("boot_param") == 0) {
+			// Show the introduction
+			Sound.loadSection(Sound.isRoland() ? ROLAND_INTRO_SOUND_RESOURCE_ID : ADLIB_INTRO_SOUND_RESOURCE_ID);
+			Introduction *intro = new Introduction();
+			intro->show();
+			delete intro;
+		}
 	}
 
 	// Play the game
-	if (!_events->quitFlag) {
+	if (!quit()) {
 		// Play the game
 		Sound.loadSection(Sound.isRoland() ? ROLAND_MAIN_SOUND_RESOURCE_ID : ADLIB_MAIN_SOUND_RESOURCE_ID);
 		gameInstance->execute();
 	}
 
 	delete gameInstance;
-	return 0;
+	return _eventMan->shouldRTL();
 }
 
 void LureEngine::pauseEngineIntern(bool pause) {
@@ -246,6 +254,10 @@
 	Engine::GUIErrorMessage(buffer);
 }
 
+void LureEngine::syncSoundSettings() {	
+	Sound.syncSounds();
+}
+
 Common::String *LureEngine::detectSave(int slotNumber) {
 	Common::ReadStream *f = this->_saveFileMan->openForLoading(
 		generateSaveName(slotNumber));
@@ -274,4 +286,23 @@
 	return result;
 }
 
+Common::String getSaveName(Common::InSaveFile *in) {
+	// Check for header
+	char saveName[MAX_DESC_SIZE];
+	char buffer[5];
+	in->read(&buffer[0], 5);
+	if (memcmp(&buffer[0], "lure", 5) == 0) {
+		// Check language version
+		in->readByte();
+		in->readByte();
+		char *p = saveName;
+		int decCtr = MAX_DESC_SIZE - 1;
+		while ((decCtr > 0) && ((*p++ = in->readByte()) != 0)) --decCtr;
+		*p = '\0';
+
+	}
+
+	return Common::String(saveName);
+}
+
 } // End of namespace Lure

Modified: scummvm/trunk/engines/lure/lure.h
===================================================================
--- scummvm/trunk/engines/lure/lure.h	2008-09-01 19:32:17 UTC (rev 34250)
+++ scummvm/trunk/engines/lure/lure.h	2008-09-01 20:18:17 UTC (rev 34251)
@@ -30,6 +30,7 @@
 #include "common/rect.h"
 #include "sound/mixer.h"
 #include "common/file.h"
+#include "common/savefile.h"
 
 #include "lure/disk.h"
 #include "lure/res.h"
@@ -47,6 +48,7 @@
 class LureEngine : public Engine {
 private:
 	bool _initialised;
+	int _gameToLoad;
 	uint8 _saveVersion;
 	Disk *_disk;
 	Resources *_resources;
@@ -70,9 +72,11 @@
 	virtual int init();
 	virtual int go();
 	virtual void pauseEngineIntern(bool pause);
+	virtual void syncSoundSettings();
 
 	Disk &disk() { return *_disk; }
 
+	int gameToLoad() { return _gameToLoad; }
 	bool loadGame(uint8 slotNumber);
 	bool saveGame(uint8 slotNumber, Common::String &caption);
 	Common::String *detectSave(int slotNumber);
@@ -84,7 +88,7 @@
 	Common::Platform getPlatform() const;
 	bool isEGA() const { return (getFeatures() & GF_EGA) != 0; }
 };
-
+	Common::String getSaveName(Common::InSaveFile *in);
 } // End of namespace Lure
 
 #endif

Modified: scummvm/trunk/engines/lure/menu.cpp
===================================================================
--- scummvm/trunk/engines/lure/menu.cpp	2008-09-01 19:32:17 UTC (rev 34250)
+++ scummvm/trunk/engines/lure/menu.cpp	2008-09-01 20:18:17 UTC (rev 34251)
@@ -116,6 +116,7 @@
 
 uint8 Menu::execute() {
 	OSystem &system = *g_system;
+	LureEngine &engine = LureEngine::getReference();
 	Mouse &mouse = Mouse::getReference();
 	Events &events = Events::getReference();
 	Screen &screen = Screen::getReference();
@@ -130,7 +131,7 @@
 
 	while (mouse.lButton() || mouse.rButton()) {
 		while (events.pollEvent()) {
-			if (events.quitFlag) return MENUITEM_NONE;
+			if (engine.quit()) return MENUITEM_NONE;
 
 			if (mouse.y() < MENUBAR_Y_SIZE) {
 				MenuRecord *p = getMenuAt(mouse.x());
@@ -467,6 +468,7 @@
 
 uint16 PopupMenu::Show(int numEntries, const char *actions[]) {
 	if (numEntries == 0) return 0xffff;
+	LureEngine &engine = LureEngine::getReference();
 	Events &e = Events::getReference();
 	Mouse &mouse = Mouse::getReference();
 	OSystem &system = *g_system;
@@ -545,7 +547,7 @@
 		}
 
 		while (e.pollEvent()) {
-			if (e.quitFlag) {
+			if (engine.quit()) {
 				selectedIndex = 0xffff;
 				goto bail_out;
 

Modified: scummvm/trunk/engines/lure/scripts.cpp
===================================================================
--- scummvm/trunk/engines/lure/scripts.cpp	2008-09-01 19:32:17 UTC (rev 34250)
+++ scummvm/trunk/engines/lure/scripts.cpp	2008-09-01 20:18:17 UTC (rev 34251)
@@ -26,6 +26,7 @@
 #include "lure/animseq.h"
 #include "lure/fights.h"
 #include "lure/game.h"
+#include "lure/lure.h"
 #include "lure/res.h"
 #include "lure/room.h"
 #include "lure/screen.h"
@@ -190,6 +191,7 @@
 }
 
 void Script::endgameSequence(uint16 v1, uint16 v2, uint16 v3) {
+	LureEngine &engine = LureEngine::getReference();
 	Screen &screen = Screen::getReference();
 	Mouse &mouse = Mouse::getReference();
 	Events &events = Events::getReference();
@@ -219,7 +221,7 @@
 	anim->show();
 	if (!events.interruptableDelay(30000)) {
 		// No key yet pressed, so keep waiting
-		while (Sound.musicInterface_CheckPlaying(6) && !events.quitFlag) {
+		while (Sound.musicInterface_CheckPlaying(6) && !engine.quit()) {
 			if (events.interruptableDelay(20))
 				break;
 		}
@@ -227,7 +229,7 @@
 	delete anim;
 
 	screen.paletteFadeOut();
-	events.quitFlag = true;
+	engine.quitGame();
 }
 
 // Setup the pig fight in the cave

Modified: scummvm/trunk/engines/lure/sound.cpp
===================================================================
--- scummvm/trunk/engines/lure/sound.cpp	2008-09-01 19:32:17 UTC (rev 34250)
+++ scummvm/trunk/engines/lure/sound.cpp	2008-09-01 20:18:17 UTC (rev 34251)
@@ -220,10 +220,12 @@
 	newEntry->channel = channelCtr;
 	newEntry->numChannels = numChannels;
 	newEntry->flags = rec.flags;
+
 	if (_isRoland)
 		newEntry->volume = rec.volume;
 	else /* resource volumes do not seem to work well with our adlib emu */
 		newEntry->volume = 240; /* 255 causes clipping with adlib */
+
 	_activeSounds.push_back(SoundList::value_type(newEntry));
 
 	musicInterface_Play(rec.soundNumber, channelCtr, numChannels);
@@ -280,6 +282,23 @@
 	return 0xff;   // Couldn't find entry
 }
 
+// Used to sync the volume for all channels with the Config Manager
+//
+void SoundManager::syncSounds() {
+	Game &game = Game::getReference();
+	musicInterface_TidySounds();
+
+	g_system->lockMutex(_soundMutex);
+	MusicListIterator i;
+	for (i = _playingSounds.begin(); i != _playingSounds.end(); ++i) {
+		if ((*i)->isMusic())
+			(*i)->setVolume(game.musicVolume());
+		else
+			(*i)->setVolume(game.sfxVolume());
+	}
+	g_system->unlockMutex(_soundMutex);
+}
+
 SoundDescResource *SoundManager::findSound(uint8 soundNumber) {
 	debugC(ERROR_BASIC, kLureDebugSounds, "SoundManager::findSound soundNumber=%d", soundNumber);
 	SoundListIterator i;
@@ -402,9 +421,8 @@
 		return;
 
 	bool isMusic = (soundNumber & 0x80) != 0;
-	uint8 volume = isMusic ? game.musicVolume() : game.sfxVolume();
 
-	if (!game.soundFlag() || (volume == 0))
+	if (!game.soundFlag())
 		// Don't play sounds if sound is turned off
 		return;
 
@@ -563,12 +581,12 @@
 /*------------------------------------------------------------------------*/
 
 MidiMusic::MidiMusic(MidiDriver *driver, ChannelEntry channels[NUM_CHANNELS],
-					 uint8 channelNum, uint8 soundNum, bool isMusic, uint8 numChannels, void *soundData, uint32 size) {
+					 uint8 channelNum, uint8 soundNum, bool isMus, uint8 numChannels, void *soundData, uint32 size) {
 	_driver = driver;
 	_channels = channels;
 	_soundNumber = soundNum;
 	_channelNumber = channelNum;
-	_isMusic = isMusic;
+	_isMusic = isMus;
 
 	_numChannels = numChannels;
 	_volume = 0;
@@ -576,8 +594,12 @@
 		/* 90 is power on default for midi compliant devices */
 		_channels[_channelNumber + i].volume = 90;
 	}
-	setVolume(240); /* 255 causes clipping with mastervol 192 and adlib */
 
+	if (_isMusic)
+		setVolume(ConfMan.getInt("music_volume"));
+	else
+		setVolume(ConfMan.getInt("sfx_volume"));		
+
 	_passThrough = false;
 
 	_parser = MidiParser::createParser_SMF();

Modified: scummvm/trunk/engines/lure/sound.h
===================================================================
--- scummvm/trunk/engines/lure/sound.h	2008-09-01 19:32:17 UTC (rev 34250)
+++ scummvm/trunk/engines/lure/sound.h	2008-09-01 20:18:17 UTC (rev 34251)
@@ -66,7 +66,7 @@
 
 public:
 	MidiMusic(MidiDriver *driver, ChannelEntry channels[NUM_CHANNELS],
-		 uint8 channelNum, uint8 soundNum, bool isMusic, uint8 numChannels, void *soundData, uint32 size);
+		 uint8 channelNum, uint8 soundNum, bool isMus, uint8 numChannels, void *soundData, uint32 size);
 	~MidiMusic();
 	void setVolume(int volume);
 	int getVolume() { return _volume; }
@@ -98,6 +98,7 @@
 	uint8 channelNumber() { return _channelNumber; }
 	uint8 soundNumber() { return _soundNumber; }
 	bool isPlaying() { return _isPlaying; }
+	bool isMusic() {return _isMusic; }
 };
 
 class SoundManager: public Common::Singleton<SoundManager> {
@@ -142,6 +143,7 @@
 	void stopSound(uint8 soundIndex);
 	void killSound(uint8 soundNumber);
 	void setVolume(uint8 soundNumber, uint8 volume);
+	void syncSounds();
 	void tidySounds();
 	uint8 descIndexOf(uint8 soundNumber);
 	SoundDescResource *findSound(uint8 soundNumber);

Modified: scummvm/trunk/engines/lure/surface.cpp
===================================================================
--- scummvm/trunk/engines/lure/surface.cpp	2008-09-01 19:32:17 UTC (rev 34250)
+++ scummvm/trunk/engines/lure/surface.cpp	2008-09-01 20:18:17 UTC (rev 34251)
@@ -506,6 +506,7 @@
 
 bool Surface::getString(Common::String &line, int maxSize, bool isNumeric, bool varLength, int16 x, int16 y) {
 	OSystem &system = *g_system;
+	LureEngine &engine = LureEngine::getReference();
 	Mouse &mouse = Mouse::getReference();
 	Events &events = Events::getReference();
 	Screen &screen = Screen::getReference();
@@ -533,7 +534,7 @@
 		// Loop until the input string changes
 		refreshFlag = false;
 		while (!refreshFlag && !abortFlag) {
-			abortFlag = events.quitFlag;
+			abortFlag = engine.quit();
 			if (abortFlag) break;
 
 			while (events.pollEvent()) {
@@ -975,7 +976,7 @@
 		// Provide highlighting of lines to select a save slot
 		while (!abortFlag && !(mouse.lButton() && (selectedLine != -1))
 				&& !mouse.rButton() && !mouse.mButton()) {
-			abortFlag = events.quitFlag;
+			abortFlag = engine.quit();
 			if (abortFlag) break;
 
 			while (events.pollEvent()) {
@@ -1178,7 +1179,7 @@
 		// Event loop for making selection
 		bool buttonPressed = false;
 
-		while (!events.quitFlag) {
+		while (!engine.quit()) {
 			// Handle events
 			while (events.pollEvent()) {
 				if ((events.type() == Common::EVENT_LBUTTONDOWN) && (highlightedButton != -1)) {
@@ -1230,7 +1231,7 @@
 
 	Sound.killSounds();
 
-	if (!restartFlag && !events.quitFlag) {
+	if (!restartFlag && !engine.quit()) {
 		// Need to show Restore game dialog
 		if (!SaveRestoreDialog::show(false))
 			// User cancelled, so fall back on Restart
@@ -1299,6 +1300,7 @@
 	Screen &screen = Screen::getReference();
 	Events &events = Events::getReference();
 	Common::RandomSource rnd;
+	LureEngine &engine = LureEngine::getReference();
 
 	screen.setPaletteEmpty();
 	Palette p(COPY_PROTECTION_RESOURCE_ID - 1);
@@ -1349,7 +1351,7 @@
 		// Clear any prior try
 		_charIndex = 0;
 
-		while (!events.quitFlag) {
+		while (!engine.quit()) {
 			while (events.pollEvent() && (_charIndex < 4)) {
 				if (events.type() == Common::EVENT_KEYDOWN) {
 					if ((events.event().kbd.keycode == Common::KEYCODE_BACKSPACE) && (_charIndex > 0)) {
@@ -1383,7 +1385,7 @@
 				break;
 		}
 
-		if (events.quitFlag)
+		if (engine.quit())
 			return false;
 
 		// At this point, two page numbers have been entered - validate them


This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.




More information about the Scummvm-git-logs mailing list