[Scummvm-cvs-logs] SF.net SVN: scummvm:[34255] scummvm/trunk/engines/sword1

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


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

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

Modified Paths:
--------------
    scummvm/trunk/engines/sword1/animation.cpp
    scummvm/trunk/engines/sword1/control.cpp
    scummvm/trunk/engines/sword1/control.h
    scummvm/trunk/engines/sword1/credits.cpp
    scummvm/trunk/engines/sword1/logic.cpp
    scummvm/trunk/engines/sword1/sword1.cpp
    scummvm/trunk/engines/sword1/sword1.h

Modified: scummvm/trunk/engines/sword1/animation.cpp
===================================================================
--- scummvm/trunk/engines/sword1/animation.cpp	2008-09-01 20:20:57 UTC (rev 34254)
+++ scummvm/trunk/engines/sword1/animation.cpp	2008-09-01 20:21:30 UTC (rev 34255)
@@ -300,9 +300,6 @@
 					terminated = true;
 				}
 				break;
-			case Common::EVENT_QUIT:
-				_system->quit();
-				break;
 			default:
 				break;
 			}

Modified: scummvm/trunk/engines/sword1/control.cpp
===================================================================
--- scummvm/trunk/engines/sword1/control.cpp	2008-09-01 20:20:57 UTC (rev 34254)
+++ scummvm/trunk/engines/sword1/control.cpp	2008-09-01 20:21:30 UTC (rev 34255)
@@ -215,7 +215,7 @@
 				notAccepted = false;
 			}
 		}
-	} while (notAccepted && (!SwordEngine::_systemVars.engineQuit));
+	} while (notAccepted && (!g_engine->quit()));
 
 	_resMan->resClose(fontId);
 	free(_screenBuf);
@@ -317,7 +317,7 @@
 		}
 		delay(1000 / 12);
 		newMode = getClicks(mode, &retVal);
-	} while ((newMode != BUTTON_DONE) && (retVal == 0) && (!SwordEngine::_systemVars.engineQuit));
+	} while ((newMode != BUTTON_DONE) && (retVal == 0) && (!g_engine->quit()));
 
 	if (SwordEngine::_systemVars.controlPanelMode == CP_NORMAL) {
 		uint8 volL, volR;
@@ -425,7 +425,7 @@
 			_buttons[5]->setSelected(SwordEngine::_systemVars.showText);
 		} else if (id == BUTTON_QUIT) {
 			if (getConfirm(_lStrings[STR_QUIT]))
-				SwordEngine::_systemVars.engineQuit = true;
+				g_engine->quitGame();
 			return mode;
 		}
 		break;
@@ -703,7 +703,7 @@
 bool Control::saveToFile(void) {
 	if ((_selectedSavegame == 255) || !strlen((char*)_saveNames[_selectedSavegame]))
 		return false; // no saveslot selected or no name entered
-	saveGameToFile(_selectedSavegame);
+	saveGameToFile(_numSaves);
 	writeSavegameDescriptions();
 	return true;
 }
@@ -741,6 +741,7 @@
 				curFileNum++;
 		} while ((ch != 255) && (!inf->eos()));
 		_saveFiles = curFileNum;
+		_numSaves = _saveFiles;
 	}
 	delete inf;
 }
@@ -1091,9 +1092,6 @@
 				_mouseDown = false;
 				_mouseState |= BS1_WHEEL_DOWN;
 				break;
-			case Common::EVENT_QUIT:
-				SwordEngine::_systemVars.engineQuit = true;
-				break;
 			default:
 				break;
 			}

Modified: scummvm/trunk/engines/sword1/control.h
===================================================================
--- scummvm/trunk/engines/sword1/control.h	2008-09-01 20:20:57 UTC (rev 34254)
+++ scummvm/trunk/engines/sword1/control.h	2008-09-01 20:21:30 UTC (rev 34255)
@@ -98,6 +98,7 @@
 	void deselectSaveslots(void);
 	uint8 *_restoreBuf;
 	uint8 _saveFiles;
+	uint8 _numSaves;
 	uint8 _saveScrollPos;
 	uint8 _selectedSavegame;
 	uint8 _saveNames[64][32];

Modified: scummvm/trunk/engines/sword1/credits.cpp
===================================================================
--- scummvm/trunk/engines/sword1/credits.cpp	2008-09-01 20:20:57 UTC (rev 34254)
+++ scummvm/trunk/engines/sword1/credits.cpp	2008-09-01 20:21:30 UTC (rev 34255)
@@ -125,7 +125,7 @@
 	uint16 renderY = BUFSIZE_Y / 2;
 	uint16 clearY = 0xFFFF;
 	bool clearLine = false;
-	while (((*textData != FNT_EOB) || (scrollY != renderY)) && !SwordEngine::_systemVars.engineQuit) {
+	while (((*textData != FNT_EOB) || (scrollY != renderY)) && !g_engine->quit()) {
 		if ((int32)_mixer->getSoundElapsedTime(bgSound) - relDelay < (SCROLL_TIMING * 2)) { // sync to audio
 			if (scrollY < BUFSIZE_Y - CREDITS_Y)
 				_system->copyRectToScreen(screenBuf + scrollY * CREDITS_X, CREDITS_X, START_X, START_Y, CREDITS_X, CREDITS_Y);
@@ -175,7 +175,7 @@
 	uint8 *revoBuf = credFile.decompressFile(REVO_LOGO);
 	uint8 *revoPal = credFile.fetchFile(REVO_PAL, &_palLen);
 	_palLen /= 3;
-	while ((_mixer->getSoundElapsedTime(bgSound) < LOGO_FADEUP_TIME) && !SwordEngine::_systemVars.engineQuit) {
+	while ((_mixer->getSoundElapsedTime(bgSound) < LOGO_FADEUP_TIME) && !g_engine->quit()) {
 		delay(100);
 	}
 	memset(_palette, 0, 256 * 4);
@@ -184,13 +184,13 @@
 	_system->updateScreen();
 
 	fadePalette(revoPal, true, _palLen);
-	while ((_mixer->getSoundElapsedTime(bgSound) < LOGO_FADEDOWN_TIME) && !SwordEngine::_systemVars.engineQuit) {
+	while ((_mixer->getSoundElapsedTime(bgSound) < LOGO_FADEDOWN_TIME) && !g_engine->quit()) {
 		delay(100);
 	}
 	fadePalette(revoPal, false, _palLen);
 	delay(3000);
 
-	if (SwordEngine::_systemVars.engineQuit)
+	if (g_engine->quit())
 		_mixer->stopAll();
 	free(revoBuf);
 }
@@ -200,7 +200,7 @@
 	int fadeStart = fadeup ? 0 : 12;
 
 	int relDelay = _system->getMillis();
-	for (int fadeStep = fadeStart; (fadeStep >= 0) && (fadeStep <= 12) && !SwordEngine::_systemVars.engineQuit; fadeStep += fadeDir) {
+	for (int fadeStep = fadeStart; (fadeStep >= 0) && (fadeStep <= 12) && !g_engine->quit(); fadeStep += fadeDir) {
 		for (uint16 cnt = 0; cnt < len * 3; cnt++)
 			_palette[(cnt / 3) * 4 + (cnt % 3)] = (srcPal[cnt] * fadeStep) / 12;
 		_system->setPalette(_palette, 0, 256);
@@ -281,9 +281,6 @@
 		Common::EventManager *eventMan = _system->getEventManager();
 		while (eventMan->pollEvent(event)) {
 			switch (event.type) {
-			case Common::EVENT_QUIT:
-				SwordEngine::_systemVars.engineQuit = true;
-				break;
 			default:
 				break;
 			}
@@ -294,7 +291,7 @@
 		if (msecs > 0)
 			_system->delayMillis(10);
 
-	} while ((_system->getMillis() < start + msecs) && !SwordEngine::_systemVars.engineQuit);
+	} while ((_system->getMillis() < start + msecs) && !g_engine->quit());
 }
 
 ArcFile::ArcFile(void) {

Modified: scummvm/trunk/engines/sword1/logic.cpp
===================================================================
--- scummvm/trunk/engines/sword1/logic.cpp	2008-09-01 20:20:57 UTC (rev 34254)
+++ scummvm/trunk/engines/sword1/logic.cpp	2008-09-01 20:21:30 UTC (rev 34255)
@@ -1636,7 +1636,7 @@
 	if (SwordEngine::_systemVars.isDemo) {
 		GUI::MessageDialog dialog("This is the end of the Broken Sword 1 Demo", "OK", NULL);
 		dialog.runModal();
-		SwordEngine::_systemVars.engineQuit = true;
+		g_engine->quitGame();
 	} else
 		error("fnQuitGame() called");
 	return fnQuit(cpt, id, 0, 0, 0, 0, 0, 0);

Modified: scummvm/trunk/engines/sword1/sword1.cpp
===================================================================
--- scummvm/trunk/engines/sword1/sword1.cpp	2008-09-01 20:20:57 UTC (rev 34254)
+++ scummvm/trunk/engines/sword1/sword1.cpp	2008-09-01 20:21:30 UTC (rev 34255)
@@ -32,6 +32,7 @@
 #include "common/fs.h"
 #include "common/timer.h"
 #include "common/events.h"
+#include "common/savefile.h"
 #include "common/system.h"
 
 #include "engines/metaengine.h"
@@ -94,13 +95,22 @@
 		return "Broken Sword Games (C) Revolution";
 	}
 
+	virtual bool hasFeature(MetaEngineFeature f) const;
 	virtual GameList getSupportedGames() const;
 	virtual GameDescriptor findGame(const char *gameid) const;
 	virtual GameList detectGames(const FSList &fslist) const;
+	virtual SaveStateList listSaves(const char *target) const;
 
 	virtual PluginError createInstance(OSystem *syst, Engine **engine) const;
 };
 
+bool SwordMetaEngine::hasFeature(MetaEngineFeature f) const {
+	return
+		(f == kSupportsRTL) ||
+		(f == kSupportsListSaves) ||
+		(f == kSupportsDirectLoad);
+}
+
 GameList SwordMetaEngine::getSupportedGames() const {
 	GameList games;
 	games.push_back(sword1FullSettings);
@@ -187,6 +197,47 @@
 	return kNoError;
 }
 
+SaveStateList SwordMetaEngine::listSaves(const char *target) const {
+	Common::SaveFileManager *saveFileMan = g_system->getSavefileManager();
+	SaveStateList saveList;
+
+	Common::String pattern = "SAVEGAME.???";
+	Common::StringList filenames = saveFileMan->listSavefiles(pattern.c_str());
+	sort(filenames.begin(), filenames.end());
+	Common::StringList::const_iterator file = filenames.begin();
+
+	Common::InSaveFile *in = saveFileMan->openForLoading("SAVEGAME.INF");
+	if (in) {
+		uint8 stop;
+		char saveDesc[32];
+		do {
+			// Obtain the last digit of the filename, since they correspond to the save slot
+			int slotNum = atoi(file->c_str() + file->size() - 1);
+
+			uint pos = 0;
+			do {
+				stop = in->readByte();
+				if (pos < (sizeof(saveDesc) - 1)) { 	
+					if ((stop == 10) || (stop == 255) || (in->eos())) {
+						saveDesc[pos++] = '\0';
+					}
+					else if (stop >= 32) {
+						saveDesc[pos++] = stop;
+					}
+				}
+			} while ((stop != 10) && (stop != 255) && (!in->eos()));
+			if (saveDesc[0] != 0) {
+				saveList.push_back(SaveStateDescriptor(slotNum, saveDesc, *file));
+				file++;
+			}
+		} while ((stop != 255) && (!in->eos()));
+	}
+	
+	delete in;
+		
+	return saveList;
+}
+
 #if PLUGIN_ENABLED_DYNAMIC(SWORD1)
 	REGISTER_PLUGIN_DYNAMIC(SWORD1, PLUGIN_TYPE_ENGINE, SwordMetaEngine);
 #else
@@ -247,8 +298,6 @@
 	_resMan = new ResMan("swordres.rif", _systemVars.isMac);
 	debug(5, "Starting object manager");
 	_objectMan = new ObjectMan(_resMan);
-	_mixer->setVolumeForSoundType(Audio::Mixer::kSFXSoundType, Audio::Mixer::kMaxMixerVolume);
-	_mixer->setVolumeForSoundType(Audio::Mixer::kMusicSoundType, Audio::Mixer::kMaxMixerVolume);
 	_mouse = new Mouse(_system, _resMan, _objectMan);
 	_screen = new Screen(_system, _resMan, _objectMan);
 	_music = new Music(_mixer);
@@ -257,60 +306,13 @@
 	_logic = new Logic(_objectMan, _resMan, _screen, _mouse, _sound, _music, _menu, _system, _mixer);
 	_mouse->useLogicAndMenu(_logic, _menu);
 
-	uint musicVol = ConfMan.getInt("music_volume");
-	uint speechVol = ConfMan.getInt("speech_volume");
-	uint sfxVol = ConfMan.getInt("sfx_volume");
-	uint musicBal = 50;
-	if (ConfMan.hasKey("music_balance")) {
-		musicBal = CLIP(ConfMan.getInt("music_balance"), 0, 100);
-	}
-	uint speechBal = 50;
-	if (ConfMan.hasKey("speech_balance")) {
-		speechBal = CLIP(ConfMan.getInt("speech_balance"), 0, 100);
-	}
-	uint sfxBal = 50;
-	if (ConfMan.hasKey("sfx_balance")) {
-		sfxBal = CLIP(ConfMan.getInt("sfx_balance"), 0, 100);
-	}
+	syncSoundSettings();
 
-	uint musicVolL = 2 * musicVol * musicBal / 100;
-	uint musicVolR = 2 * musicVol - musicVolL;
-
-	uint speechVolL = 2 * speechVol * speechBal / 100;
-	uint speechVolR = 2 * speechVol - speechVolL;
-
-	uint sfxVolL = 2 * sfxVol * sfxBal / 100;
-	uint sfxVolR = 2 * sfxVol - sfxVolL;
-
-	if (musicVolR > 255) {
-		musicVolR = 255;
-	}
-	if (musicVolL > 255) {
-		musicVolL = 255;
-	}
-	if (speechVolR > 255) {
-		speechVolR = 255;
-	}
-	if (speechVolL > 255) {
-		speechVolL = 255;
-	}
-	if (sfxVolR > 255) {
-		sfxVolR = 255;
-	}
-	if (sfxVolL > 255) {
-		sfxVolL = 255;
-	}
-
-	_music->setVolume(musicVolL, musicVolR);
-	_sound->setSpeechVol(speechVolL, speechVolR);
-	_sound->setSfxVol(sfxVolL, sfxVolR);
-
 	_systemVars.justRestoredGame = 0;
 	_systemVars.currentCD = 0;
 	_systemVars.controlPanelMode = CP_NEWGAME;
 	_systemVars.forceRestart = false;
 	_systemVars.wantFade = true;
-	_systemVars.engineQuit = false;
 
 	switch (Common::parseLanguage(ConfMan.get("language"))) {
 	case Common::DE_DEU:
@@ -358,6 +360,62 @@
 	_systemVars.wantFade = true;
 }
 
+void SwordEngine::syncSoundSettings() {
+	uint musicVol = ConfMan.getInt("music_volume");
+	uint sfxVol = ConfMan.getInt("sfx_volume");
+	uint speechVol = ConfMan.getInt("speech_volume");
+
+	uint musicBal = 50;
+	if (ConfMan.hasKey("music_balance")) {
+		musicBal = CLIP(ConfMan.getInt("music_balance"), 0, 100);
+	}
+
+	uint speechBal = 50;
+	if (ConfMan.hasKey("speech_balance")) {
+		speechBal = CLIP(ConfMan.getInt("speech_balance"), 0, 100);
+	}
+	uint sfxBal = 50;
+	if (ConfMan.hasKey("sfx_balance")) {
+		sfxBal = CLIP(ConfMan.getInt("sfx_balance"), 0, 100);
+	}
+
+	uint musicVolL = 2 * musicVol * musicBal / 100;
+	uint musicVolR = 2 * musicVol - musicVolL;
+
+	uint speechVolL = 2 * speechVol * speechBal / 100;
+	uint speechVolR = 2 * speechVol - speechVolL;
+
+	uint sfxVolL = 2 * sfxVol * sfxBal / 100;
+	uint sfxVolR = 2 * sfxVol - sfxVolL;
+
+	if (musicVolR > 255) {
+		musicVolR = 255;
+	}
+	if (musicVolL > 255) {
+		musicVolL = 255;
+	}
+
+	if (speechVolR > 255) {
+		speechVolR = 255;
+	}
+	if (speechVolL > 255) {
+		speechVolL = 255;
+	}
+	if (sfxVolR > 255) {
+		sfxVolR = 255;
+	}
+	if (sfxVolL > 255) {
+		sfxVolL = 255;
+	}
+
+	_music->setVolume(musicVolL, musicVolR);
+	_sound->setSpeechVol(speechVolL, speechVolR);
+	_sound->setSfxVol(sfxVolL, sfxVolR);
+
+	_mixer->setVolumeForSoundType(Audio::Mixer::kSFXSoundType, ConfMan.getInt("sfx_volume"));
+	_mixer->setVolumeForSoundType(Audio::Mixer::kSpeechSoundType, ConfMan.getInt("speech_volume"));
+}
+
 void SwordEngine::flagsToBool(bool *dest, uint8 flags) {
 	uint8 bitPos = 0;
 	while (flags) {
@@ -639,13 +697,13 @@
 		int saveSlot = ConfMan.getInt("save_slot");
 		// Savegames are numbered starting from 1 in the dialog window,
 		// but their filenames are numbered starting from 0.
-		if (saveSlot > 0 && _control->restoreGameFromFile(saveSlot - 1)) {
+		if (saveSlot >= 0 && _control->savegamesExist() && _control->restoreGameFromFile(saveSlot)) {
 			_control->doRestore();
 		} else if (_control->savegamesExist()) {
 			_systemVars.controlPanelMode = CP_NEWGAME;
 			if (_control->runPanel() == CONTROL_GAME_RESTORED)
 				_control->doRestore();
-			else if (!_systemVars.engineQuit)
+			else if (!quit())
 				_logic->startPositions(0);
 		} else {
 			// no savegames, start new game.
@@ -654,10 +712,10 @@
 	}
 	_systemVars.controlPanelMode = CP_NORMAL;
 
-	while (!_systemVars.engineQuit) {
+	while (!quit()) {
 		uint8 action = mainLoop();
 
-		if (!_systemVars.engineQuit) {
+		if (!quit()) {
 			// the mainloop was left, we have to reinitialize.
 			reinitialize();
 			if (action == CONTROL_GAME_RESTORED)
@@ -669,7 +727,7 @@
 		}
 	}
 
-	return 0;
+	return _eventMan->shouldRTL();
 }
 
 void SwordEngine::checkCd(void) {
@@ -698,7 +756,7 @@
 	uint8 retCode = 0;
 	_keyPressed.reset();
 
-	while ((retCode == 0) && (!_systemVars.engineQuit)) {
+	while ((retCode == 0) && (!quit())) {
 		// do we need the section45-hack from sword.c here?
 		checkCd();
 
@@ -747,9 +805,9 @@
 			}
 			_mouseState = 0;
 			_keyPressed.reset();
-		} while ((Logic::_scriptVars[SCREEN] == Logic::_scriptVars[NEW_SCREEN]) && (retCode == 0) && (!_systemVars.engineQuit));
+		} while ((Logic::_scriptVars[SCREEN] == Logic::_scriptVars[NEW_SCREEN]) && (retCode == 0) && (!quit()));
 
-		if ((retCode == 0) && (Logic::_scriptVars[SCREEN] != 53) && _systemVars.wantFade && (!_systemVars.engineQuit)) {
+		if ((retCode == 0) && (Logic::_scriptVars[SCREEN] != 53) && _systemVars.wantFade && (!quit())) {
 			_screen->fadeDownPalette();
 			int32 relDelay = (int32)_system->getMillis();
 			while (_screen->stillFading()) {
@@ -796,9 +854,6 @@
 				_mouseState |= BS1R_BUTTON_UP;
 				_mouseCoord = event.mouse;
 				break;
-			case Common::EVENT_QUIT:
-				_systemVars.engineQuit = true;
-				break;
 			default:
 				break;
 			}

Modified: scummvm/trunk/engines/sword1/sword1.h
===================================================================
--- scummvm/trunk/engines/sword1/sword1.h	2008-09-01 20:20:57 UTC (rev 34254)
+++ scummvm/trunk/engines/sword1/sword1.h	2008-09-01 20:21:30 UTC (rev 34255)
@@ -58,7 +58,6 @@
 	bool	runningFromCd;
 	uint32	currentCD;			// starts at zero, then either 1 or 2 depending on section being played
 	uint32	justRestoredGame;	// see main() in sword.c & New_screen() in gtm_core.c
-	bool	engineQuit;
 
 	uint8	controlPanelMode;	// 1 death screen version of the control panel, 2 = successful end of game, 3 = force restart
 	bool	forceRestart;
@@ -78,6 +77,7 @@
 	virtual ~SwordEngine();
 	static SystemVars _systemVars;
 	void reinitialize(void);
+	virtual void syncSoundSettings();
 
 	uint32 _features;
 protected:


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