[Scummvm-git-logs] scummvm master -> 0b53d3c1159d269d716628553279be629cac1373

sev- noreply at scummvm.org
Sun Sep 10 19:56:54 UTC 2023


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

Summary:
da98116a44 HPL1: Simplify check for support of extended save files
b7b7808b37 WAGE: Support extended save states
9aa16fa5d9 WAGE: Remove now redundant info from the saves
41386aa5c4 WAGE: Implemented "Save" command
14eb8e339c WAGE: Implemented Quit command
745b3e3124 WAGE: Implemented saving on exit
d40bf2ce6c WAGE: Implemented the rest of menu commands
0b53d3c115 WAGE: Implemented periodic scene sounds


Commit: da98116a44639f150924ecc900b3d87641cc6f3d
    https://github.com/scummvm/scummvm/commit/da98116a44639f150924ecc900b3d87641cc6f3d
Author: Eugene Sandulenko (sev at scummvm.org)
Date: 2023-09-10T14:15:49+02:00

Commit Message:
HPL1: Simplify check for support of extended save files

Changed paths:
    engines/hpl1/metaengine.cpp


diff --git a/engines/hpl1/metaengine.cpp b/engines/hpl1/metaengine.cpp
index af83226f91f..819e542f0a9 100644
--- a/engines/hpl1/metaengine.cpp
+++ b/engines/hpl1/metaengine.cpp
@@ -41,12 +41,7 @@ Common::Error Hpl1MetaEngine::createInstance(OSystem *syst, Engine **engine, con
 }
 
 bool Hpl1MetaEngine::hasFeature(MetaEngineFeature f) const {
-	return (f == kSavesUseExtendedFormat) ||
-		   (f == kSimpleSavesNames) ||
-		   (f == kSupportsListSaves) ||
-		   (f == kSupportsDeleteSave) ||
-		   (f == kSavesSupportMetaInfo) ||
-		   (f == kSavesSupportThumbnail) ||
+	return checkExtendedSaves(f) ||
 		   (f == kSupportsLoadingDuringStartup);
 }
 


Commit: b7b7808b37c1f39a6e30a9b3777b392a30effdca
    https://github.com/scummvm/scummvm/commit/b7b7808b37c1f39a6e30a9b3777b392a30effdca
Author: Eugene Sandulenko (sev at scummvm.org)
Date: 2023-09-10T14:18:14+02:00

Commit Message:
WAGE: Support extended save states

Changed paths:
    engines/wage/metaengine.cpp
    engines/wage/saveload.cpp


diff --git a/engines/wage/metaengine.cpp b/engines/wage/metaengine.cpp
index 0dc7f3964f1..f2c72f72300 100644
--- a/engines/wage/metaengine.cpp
+++ b/engines/wage/metaengine.cpp
@@ -29,7 +29,7 @@
 #include "wage/wage.h"
 
 namespace Wage {
-	
+
 uint32 WageEngine::getFeatures() {
 	return _gameDescription->flags;
 }
@@ -55,11 +55,8 @@ public:
 };
 
 bool WageMetaEngine::hasFeature(MetaEngineFeature f) const {
-	return
-		(f == kSupportsListSaves) ||
-		(f == kSupportsLoadingDuringStartup) ||
-		(f == kSupportsDeleteSave) ||
-		(f == kSimpleSavesNames);
+	return checkExtendedSaves(f) ||
+		(f == kSupportsLoadingDuringStartup);
 }
 
 bool Wage::WageEngine::hasFeature(EngineFeature f) const {
diff --git a/engines/wage/saveload.cpp b/engines/wage/saveload.cpp
index 4921e416767..6c16c382d51 100644
--- a/engines/wage/saveload.cpp
+++ b/engines/wage/saveload.cpp
@@ -363,6 +363,8 @@ int WageEngine::saveGame(const Common::String &fileName, const Common::String &d
 	// so these would be the last 4 bytes of the file
 	out->writeUint32BE(WAGEflag);
 
+	g_engine->getMetaEngine()->appendExtendedSave(out, g_engine->getTotalPlayTime(), description, fileName.contains("auto"));
+
 	out->finalize();
 	if (out->err()) {
 		warning("Can't write file '%s'. (Disk full?)", fileName.c_str());


Commit: 9aa16fa5d9d84b9be272b40e38865ec73124e26f
    https://github.com/scummvm/scummvm/commit/9aa16fa5d9d84b9be272b40e38865ec73124e26f
Author: Eugene Sandulenko (sev at scummvm.org)
Date: 2023-09-10T15:01:55+02:00

Commit Message:
WAGE: Remove now redundant info from the saves

Changed paths:
    engines/wage/metaengine.cpp
    engines/wage/saveload.cpp


diff --git a/engines/wage/metaengine.cpp b/engines/wage/metaengine.cpp
index f2c72f72300..81808b3b83e 100644
--- a/engines/wage/metaengine.cpp
+++ b/engines/wage/metaengine.cpp
@@ -49,9 +49,7 @@ public:
 	Common::Error createInstance(OSystem *syst, Engine **engine, const ADGameDescription *desc) const override;
 
 	bool hasFeature(MetaEngineFeature f) const override;
-	SaveStateList listSaves(const char *target) const override;
 	int getMaximumSaveSlot() const override;
-	void removeSaveState(const char *target, int slot) const override;
 };
 
 bool WageMetaEngine::hasFeature(MetaEngineFeature f) const {
@@ -71,53 +69,8 @@ Common::Error WageMetaEngine::createInstance(OSystem *syst, Engine **engine, con
 	return Common::kNoError;
 }
 
-SaveStateList WageMetaEngine::listSaves(const char *target) const {
-	const uint32 WAGEflag = MKTAG('W','A','G','E');
-	Common::SaveFileManager *saveFileMan = g_system->getSavefileManager();
-	Common::StringArray filenames;
-	char saveDesc[128] = {0};
-	Common::String pattern = target;
-	pattern += ".###";
-
-	filenames = saveFileMan->listSavefiles(pattern);
-
-	SaveStateList saveList;
-	for (Common::StringArray::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);
-			if (in) {
-				saveDesc[0] = 0;
-				in->seek(in->size() - 8);
-				uint32 offset = in->readUint32BE();
-				uint32 type = in->readUint32BE();
-				if (type == WAGEflag) {
-					in->seek(offset);
-
-					type = in->readUint32BE();
-					if (type == WAGEflag) {
-						in->read(saveDesc, 127);
-					}
-				}
-				saveList.push_back(SaveStateDescriptor(this, slotNum, saveDesc));
-				delete in;
-			}
-		}
-	}
-
-	// Sort saves based on slot number.
-	Common::sort(saveList.begin(), saveList.end(), SaveStateDescriptorSlotComparator());
-	return saveList;
-}
-
 int WageMetaEngine::getMaximumSaveSlot() const { return 999; }
 
-void WageMetaEngine::removeSaveState(const char *target, int slot) const {
-	g_system->getSavefileManager()->removeSavefile(Common::String::format("%s.%03d", target, slot));
-}
-
 #if PLUGIN_ENABLED_DYNAMIC(WAGE)
 	REGISTER_PLUGIN_DYNAMIC(WAGE, PLUGIN_TYPE_ENGINE, WageMetaEngine);
 #else
diff --git a/engines/wage/saveload.cpp b/engines/wage/saveload.cpp
index 6c16c382d51..7a6a6d8996d 100644
--- a/engines/wage/saveload.cpp
+++ b/engines/wage/saveload.cpp
@@ -74,8 +74,6 @@
 
 namespace Wage {
 
-static const uint32 WAGEflag = MKTAG('W', 'A', 'G', 'E');
-
 //TODO: make sure these are calculated right: (we add flag, description, etc)
 #define VARS_INDEX 0x005E
 #define SCENES_INDEX 0x0232
@@ -334,36 +332,7 @@ int WageEngine::saveGame(const Common::String &fileName, const Common::String &d
 	}
 
 	// the following is appended by ScummVM
-	int32 appendixOffset = out->pos();
-	if (appendixOffset < 0) {
-		warning("OutSaveFile::pos() failed");
-	}
-	out->writeUint32BE(WAGEflag);
-
-	// Write description of saved game, limited to WAGE_SAVEDGAME_DESCRIPTION_LEN characters + terminating NUL
-	const int WAGE_SAVEDGAME_DESCRIPTION_LEN = 127;
-	char description[WAGE_SAVEDGAME_DESCRIPTION_LEN + 1];
-
-	memset(description, 0, sizeof(description));
-	strncpy(description, descriptionString.c_str(), WAGE_SAVEDGAME_DESCRIPTION_LEN);
-	assert(WAGE_SAVEDGAME_DESCRIPTION_LEN + 1 == 128); // safety
-	out->write(description, 128);
-
-	out->writeByte(SAVEGAME_CURRENT_VERSION);
-	debug(9, "Writing save game version (%d)", SAVEGAME_CURRENT_VERSION);
-
-	// Thumbnail
-	Graphics::saveThumbnail(*out);
-
-	out->writeUint32BE(appendixOffset);
-
-	// this one to make checking easier:
-	// it couldn't be added to the beginning
-	// and we won't be able to find it in the middle,
-	// so these would be the last 4 bytes of the file
-	out->writeUint32BE(WAGEflag);
-
-	g_engine->getMetaEngine()->appendExtendedSave(out, g_engine->getTotalPlayTime(), description, fileName.contains("auto"));
+	g_engine->getMetaEngine()->appendExtendedSave(out, g_engine->getTotalPlayTime(), descriptionString, fileName.contains("auto"));
 
 	out->finalize();
 	if (out->err()) {


Commit: 41386aa5c4163b7f6e7804b2fd63fc644a5ee5b2
    https://github.com/scummvm/scummvm/commit/41386aa5c4163b7f6e7804b2fd63fc644a5ee5b2
Author: Eugene Sandulenko (sev at scummvm.org)
Date: 2023-09-10T15:40:14+02:00

Commit Message:
WAGE: Implemented "Save" command

Changed paths:
    engines/wage/gui.cpp
    engines/wage/gui.h
    engines/wage/saveload.cpp
    engines/wage/wage.h


diff --git a/engines/wage/gui.cpp b/engines/wage/gui.cpp
index ac2550cff6d..c32e233344c 100644
--- a/engines/wage/gui.cpp
+++ b/engines/wage/gui.cpp
@@ -67,7 +67,7 @@ static const Graphics::MacMenuData menuSubItems[] = {
 	{ kMenuFile, "New",			kMenuActionNew, 0, false },
 	{ kMenuFile, "Open...",		kMenuActionOpen, 0, true },
 	{ kMenuFile, "Close",		kMenuActionClose, 0, true },
-	{ kMenuFile, "Save",		kMenuActionSave, 0, true },
+	{ kMenuFile, "Save",		kMenuActionSave, 0, false },
 	{ kMenuFile, "Save as...",	kMenuActionSaveAs, 0, true },
 	{ kMenuFile, "Revert",		kMenuActionRevert, 0, false },
 	{ kMenuFile, "Quit",		kMenuActionQuit, 0, true },
@@ -278,6 +278,12 @@ void Gui::executeMenuCommand(int action, Common::String &text) {
 		break;
 
 	case kMenuActionSave:
+		if (_engine->_defaultSaveSlot != -1 && _engine->_defaultSaveSlot != _engine->getAutosaveSlot()) {
+			_engine->saveGameState(_engine->_defaultSaveSlot, _engine->_defaultSaveDescritpion, false);
+			break;
+		}
+		// falltrhough
+
 	case kMenuActionSaveAs:
 		_engine->scummVMSaveLoadDialog(true);
 		break;
@@ -400,4 +406,8 @@ void Gui::enableNewGameMenus() {
 	_menu->enableCommand(kMenuFile, kMenuActionQuit, true);
 }
 
+void Gui::enableSave() {
+	_menu->enableCommand(kMenuFile, kMenuActionSave, true);
+}
+
 } // End of namespace Wage
diff --git a/engines/wage/gui.h b/engines/wage/gui.h
index ac622b234f7..c5371393c49 100644
--- a/engines/wage/gui.h
+++ b/engines/wage/gui.h
@@ -136,6 +136,7 @@ public:
 	void disableUndo();
 	void disableAllMenus();
 	void enableNewGameMenus();
+	void enableSave();
 
 	bool processSceneEvents(WindowClick click, Common::Event &event);
 	void executeMenuCommand(int action, Common::String &text);
diff --git a/engines/wage/saveload.cpp b/engines/wage/saveload.cpp
index 7a6a6d8996d..31d7d3c6770 100644
--- a/engines/wage/saveload.cpp
+++ b/engines/wage/saveload.cpp
@@ -61,6 +61,7 @@
 #include "wage/wage.h"
 #include "wage/world.h"
 #include "wage/entities.h"
+#include "wage/gui.h"
 
 #define SAVEGAME_CURRENT_VERSION 1
 
@@ -687,23 +688,45 @@ int WageEngine::loadGame(int slotId) {
 	_aim = aim;
 	_opponentAim = opponentAim;
 
+	// Load the savaegame header
+	ExtendedSavegameHeader header;
+	if (!MetaEngine::readSavegameHeader(data, &header, true))
+		error("Invalid savegame");
+
+	_defaultSaveDescritpion = header.description;
+
 	delete data;
 	return 0;
 }
 
 Common::Error WageEngine::loadGameState(int slot) {
-	if (loadGame(slot) == 0)
+	if (loadGame(slot) == 0) {
+		if (slot != getAutosaveSlot()) {
+			_defaultSaveSlot = slot;
+			// save description is set inside of loadGame()
+			_gui->enableSave();
+		}
+
 		return Common::kNoError;
-	else
+	} else {
 		return Common::kUnknownError;
+	}
 }
 
 Common::Error WageEngine::saveGameState(int slot, const Common::String &description, bool isAutosave) {
 	Common::String saveLoadSlot = getSaveStateName(slot);
-	if (saveGame(saveLoadSlot, description) == 0)
+	if (saveGame(saveLoadSlot, description) == 0) {
+		if (slot != getAutosaveSlot()) {
+			_defaultSaveSlot = slot;
+			_defaultSaveDescritpion = description;
+
+			_gui->enableSave();
+		}
+
 		return Common::kNoError;
-	else
+	} else {
 		return Common::kUnknownError;
+	}
 }
 
 bool WageEngine::scummVMSaveLoadDialog(bool isSave) {
diff --git a/engines/wage/wage.h b/engines/wage/wage.h
index 1e332bb66b6..48a93e66cbd 100644
--- a/engines/wage/wage.h
+++ b/engines/wage/wage.h
@@ -206,6 +206,8 @@ public:
 	bool _commandWasQuick;
 
 	bool _shouldQuit;
+	int _defaultSaveSlot = -1;
+	Common::String _defaultSaveDescritpion;
 
 	Common::String _inputText;
 


Commit: 14eb8e339cc526bc73fee438add56abea19bd0dc
    https://github.com/scummvm/scummvm/commit/14eb8e339cc526bc73fee438add56abea19bd0dc
Author: Eugene Sandulenko (sev at scummvm.org)
Date: 2023-09-10T15:43:08+02:00

Commit Message:
WAGE: Implemented Quit command

Changed paths:
    engines/wage/gui.cpp


diff --git a/engines/wage/gui.cpp b/engines/wage/gui.cpp
index c32e233344c..d2ca14e47f1 100644
--- a/engines/wage/gui.cpp
+++ b/engines/wage/gui.cpp
@@ -269,7 +269,6 @@ void Gui::executeMenuCommand(int action, Common::String &text) {
 	case kMenuActionNew:
 	case kMenuActionClose:
 	case kMenuActionRevert:
-	case kMenuActionQuit:
 		warning("STUB: executeMenuCommand: action: %d", action);
 		break;
 
@@ -277,6 +276,10 @@ void Gui::executeMenuCommand(int action, Common::String &text) {
 		_engine->scummVMSaveLoadDialog(false);
 		break;
 
+	case kMenuActionQuit:
+		_engine->saveDialog();
+		break;
+
 	case kMenuActionSave:
 		if (_engine->_defaultSaveSlot != -1 && _engine->_defaultSaveSlot != _engine->getAutosaveSlot()) {
 			_engine->saveGameState(_engine->_defaultSaveSlot, _engine->_defaultSaveDescritpion, false);


Commit: 745b3e31246fcb467d459bc13e75f13af78aa66b
    https://github.com/scummvm/scummvm/commit/745b3e31246fcb467d459bc13e75f13af78aa66b
Author: Eugene Sandulenko (sev at scummvm.org)
Date: 2023-09-10T17:03:30+02:00

Commit Message:
WAGE: Implemented saving on exit

Changed paths:
    engines/wage/gui.cpp
    engines/wage/wage.cpp


diff --git a/engines/wage/gui.cpp b/engines/wage/gui.cpp
index d2ca14e47f1..384d0778c09 100644
--- a/engines/wage/gui.cpp
+++ b/engines/wage/gui.cpp
@@ -281,11 +281,8 @@ void Gui::executeMenuCommand(int action, Common::String &text) {
 		break;
 
 	case kMenuActionSave:
-		if (_engine->_defaultSaveSlot != -1 && _engine->_defaultSaveSlot != _engine->getAutosaveSlot()) {
-			_engine->saveGameState(_engine->_defaultSaveSlot, _engine->_defaultSaveDescritpion, false);
-			break;
-		}
-		// falltrhough
+		_engine->saveGame();
+		break;
 
 	case kMenuActionSaveAs:
 		_engine->scummVMSaveLoadDialog(true);
diff --git a/engines/wage/wage.cpp b/engines/wage/wage.cpp
index 5fec12182c8..1e7e8a8d596 100644
--- a/engines/wage/wage.cpp
+++ b/engines/wage/wage.cpp
@@ -102,7 +102,7 @@ WageEngine::~WageEngine() {
 
 bool WageEngine::pollEvent(Common::Event &event) {
 	return _eventMan->pollEvent(event);
-} 
+}
 
 Common::Error WageEngine::run() {
 	debug("WageEngine::init");
@@ -248,7 +248,7 @@ bool WageEngine::saveDialog() {
 	buttons.push_back(new Graphics::MacDialogButton("Yes", 112, 67, 68, 28));
 	buttons.push_back(new Graphics::MacDialogButton("Cancel", 205, 67, 68, 28));
 
-	Graphics::MacFont font; 
+	Graphics::MacFont font;
 
 	Graphics::MacText saveBeforeCloseMessage(*_world->_saveBeforeCloseMessage, _gui->_wm, &font, Graphics::kColorBlack,
 									  Graphics::kColorWhite, 291, Graphics::kTextAlignCenter);
@@ -290,7 +290,10 @@ void WageEngine::aboutDialog() {
 }
 
 void WageEngine::saveGame() {
-	warning("STUB: saveGame()");
+	if (_defaultSaveSlot != -1 && _defaultSaveSlot != getAutosaveSlot())
+		saveGameState(_defaultSaveSlot, _defaultSaveDescritpion, false);
+	else
+		scummVMSaveLoadDialog(true);
 }
 
 void WageEngine::performInitialSetup() {


Commit: d40bf2ce6cd0baebc375aff4068a24a847224e92
    https://github.com/scummvm/scummvm/commit/d40bf2ce6cd0baebc375aff4068a24a847224e92
Author: Eugene Sandulenko (sev at scummvm.org)
Date: 2023-09-10T18:09:43+02:00

Commit Message:
WAGE: Implemented the rest of menu commands

Changed paths:
    engines/wage/entities.cpp
    engines/wage/gui.cpp
    engines/wage/gui.h
    engines/wage/saveload.cpp
    engines/wage/wage.cpp
    engines/wage/wage.h


diff --git a/engines/wage/entities.cpp b/engines/wage/entities.cpp
index 35930e65610..f897a156da2 100644
--- a/engines/wage/entities.cpp
+++ b/engines/wage/entities.cpp
@@ -268,6 +268,8 @@ Designed *Obj::removeFromCharOrScene() {
 }
 
 void Obj::resetState(Chr *owner, Scene *scene) {
+	removeFromCharOrScene();
+
 	warning("STUB: Obj::resetState()");
 }
 
diff --git a/engines/wage/gui.cpp b/engines/wage/gui.cpp
index 384d0778c09..d6627e37c1e 100644
--- a/engines/wage/gui.cpp
+++ b/engines/wage/gui.cpp
@@ -64,9 +64,9 @@ namespace Wage {
 static const Graphics::MacMenuData menuSubItems[] = {
 	{ kMenuHighLevel, "File",	0, 0, false },
 	{ kMenuHighLevel, "Edit",	0, 0, false },
-	{ kMenuFile, "New",			kMenuActionNew, 0, false },
+	{ kMenuFile, "New",			kMenuActionNew, 0, true },
 	{ kMenuFile, "Open...",		kMenuActionOpen, 0, true },
-	{ kMenuFile, "Close",		kMenuActionClose, 0, true },
+	{ kMenuFile, "Close",		kMenuActionClose, 0, false },
 	{ kMenuFile, "Save",		kMenuActionSave, 0, false },
 	{ kMenuFile, "Save as...",	kMenuActionSaveAs, 0, true },
 	{ kMenuFile, "Revert",		kMenuActionRevert, 0, false },
@@ -266,10 +266,20 @@ void Gui::executeMenuCommand(int action, Common::String &text) {
 	case kMenuActionAbout:
 		_engine->aboutDialog();
 		break;
+
 	case kMenuActionNew:
+		_engine->_restartRequested = true;
+		break;
+
 	case kMenuActionClose:
+		// This is a no-op as we do not let new game to be opened
+		break;
+
 	case kMenuActionRevert:
-		warning("STUB: executeMenuCommand: action: %d", action);
+		if (_engine->_defaultSaveSlot != -1) {
+			_engine->_isGameOver = false;
+			_engine->loadGameState(_engine->_defaultSaveSlot);
+		}
 		break;
 
 	case kMenuActionOpen:
@@ -410,4 +420,8 @@ void Gui::enableSave() {
 	_menu->enableCommand(kMenuFile, kMenuActionSave, true);
 }
 
+void Gui::enableRevert() {
+	_menu->enableCommand(kMenuFile, kMenuActionRevert, true);
+}
+
 } // End of namespace Wage
diff --git a/engines/wage/gui.h b/engines/wage/gui.h
index c5371393c49..88e0626608c 100644
--- a/engines/wage/gui.h
+++ b/engines/wage/gui.h
@@ -137,6 +137,7 @@ public:
 	void disableAllMenus();
 	void enableNewGameMenus();
 	void enableSave();
+	void enableRevert();
 
 	bool processSceneEvents(WindowClick click, Common::Event &event);
 	void executeMenuCommand(int action, Common::String &text);
diff --git a/engines/wage/saveload.cpp b/engines/wage/saveload.cpp
index 31d7d3c6770..714441d70d5 100644
--- a/engines/wage/saveload.cpp
+++ b/engines/wage/saveload.cpp
@@ -700,6 +700,7 @@ int WageEngine::loadGame(int slotId) {
 }
 
 Common::Error WageEngine::loadGameState(int slot) {
+	warning("LOADING %d", slot);
 	if (loadGame(slot) == 0) {
 		if (slot != getAutosaveSlot()) {
 			_defaultSaveSlot = slot;
diff --git a/engines/wage/wage.cpp b/engines/wage/wage.cpp
index 1e7e8a8d596..dce43bc204e 100644
--- a/engines/wage/wage.cpp
+++ b/engines/wage/wage.cpp
@@ -154,6 +154,9 @@ Common::Error WageEngine::run() {
 	while (!_shouldQuit) {
 		processEvents();
 
+		if (_restartRequested)
+			restart();
+
 		_gui->draw();
 		g_system->updateScreen();
 		g_system->delayMillis(50);
@@ -162,6 +165,27 @@ Common::Error WageEngine::run() {
 	return Common::kNoError;
 }
 
+void WageEngine::restart() {
+	_restartRequested = false;
+	delete _gui;
+	delete _world;
+
+	_world = new World(this);
+
+	if (!_world->loadWorld(_resManager))
+		return;
+
+	_shouldQuit = false;
+
+	_gui = new Gui(this);
+
+	_temporarilyHidden = true;
+	performInitialSetup();
+
+	Common::String input("look");
+	processTurn(&input, NULL);
+}
+
 void WageEngine::processEvents() {
 	Common::Event event;
 
@@ -189,6 +213,7 @@ void WageEngine::processEvents() {
 
 					processTurn(&_inputText, NULL);
 					_gui->disableUndo();
+					_gui->enableRevert();
 					break;
 				}
 			default:
@@ -365,7 +390,7 @@ void WageEngine::wearObjs(Chr* chr) {
 }
 
 void WageEngine::doClose() {
-	warning("STUB: doClose()");
+	// No op on ScummVM since we do not allow to load arbitrary games
 }
 
 Scene *WageEngine::getSceneByName(Common::String &location) {
diff --git a/engines/wage/wage.h b/engines/wage/wage.h
index 48a93e66cbd..5c52fa033b8 100644
--- a/engines/wage/wage.h
+++ b/engines/wage/wage.h
@@ -204,6 +204,7 @@ public:
 	bool _temporarilyHidden;
 	bool _isGameOver;
 	bool _commandWasQuick;
+	bool _restartRequested = false;
 
 	bool _shouldQuit;
 	int _defaultSaveSlot = -1;
@@ -242,6 +243,8 @@ private:
 	int saveGame(const Common::String &fileName, const Common::String &descriptionString);
 	int loadGame(int slotId);
 
+	void restart();
+
 private:
 	const ADGameDescription *_gameDescription;
 


Commit: 0b53d3c1159d269d716628553279be629cac1373
    https://github.com/scummvm/scummvm/commit/0b53d3c1159d269d716628553279be629cac1373
Author: Eugene Sandulenko (sev at scummvm.org)
Date: 2023-09-10T21:38:58+02:00

Commit Message:
WAGE: Implemented periodic scene sounds

Changed paths:
    engines/wage/sound.cpp
    engines/wage/wage.cpp
    engines/wage/wage.h


diff --git a/engines/wage/sound.cpp b/engines/wage/sound.cpp
index d9d5583d85e..027c12d6ae3 100644
--- a/engines/wage/sound.cpp
+++ b/engines/wage/sound.cpp
@@ -113,8 +113,45 @@ void WageEngine::playSound(Common::String soundName) {
 	}
 }
 
+static void soundTimer(void *refCon) {
+	Scene *scene = (Scene *)refCon;
+	WageEngine *engine = (WageEngine *)g_engine;
+
+	g_system->getTimerManager()->removeTimerProc(&soundTimer);
+
+	if (engine->_world->_player->_currentScene != scene)
+		return;
+
+	if (engine->_soundQueue.empty()) {
+		if (scene->_soundType == Scene::PERIODIC && 0) {
+			engine->_soundToPlay = scene->_soundName; // We cannot play sound here because that goes recursively
+
+			uint32 nextRun = 60000 / scene->_soundFrequency;
+			g_system->getTimerManager()->installTimerProc(&soundTimer, nextRun * 1000, scene, "WageEngine::soundTimer");
+		} else if (scene->_soundType == Scene::RANDOM || 1) {
+			for (int i = 0; i < scene->_soundFrequency * 5; i++)
+				engine->_soundQueue.push_back(g_system->getMillis() + engine->_rnd->getRandomNumber(60000));
+
+			Common::sort(engine->_soundQueue.begin(), engine->_soundQueue.end());
+
+			int nextRun = engine->_soundQueue.front();
+			engine->_soundQueue.pop_front();
+
+			g_system->getTimerManager()->installTimerProc(&soundTimer, (nextRun - g_system->getMillis()) * 1000, scene, "WageEngine::soundTimer");
+		} else {
+			warning("updateSoundTimerForScene: Unknown sound type %d", scene->_soundType);
+		}
+	} else {
+		int nextRun = engine->_soundQueue.front();
+		engine->_soundQueue.pop_front();
+
+		g_system->getTimerManager()->installTimerProc(&soundTimer, (nextRun - g_system->getMillis()) * 1000, scene, "WageEngine::soundTimer");
+
+		engine->_soundToPlay = scene->_soundName; // We cannot play sound here because that goes recursively
+	}
+}
+
 void WageEngine::updateSoundTimerForScene(Scene *scene, bool firstTime) {
-	//warning("STUB: WageEngine::updateSoundTimerForScene()");
 	if (_world->_player->_currentScene != scene)
 			return;
 
@@ -128,26 +165,8 @@ void WageEngine::updateSoundTimerForScene(Scene *scene, bool firstTime) {
 			return;
 		}
 
-		warning("STUB: updateSoundTimerForScene: sound: '%s', %s", soundName.c_str(),
-				scene->_soundType == Scene::PERIODIC ? "PERIODIC" : "RANDOM");
-
-#if 0
-		soundTimer = new Timer();
-		switch (scene.getSoundType()) {
-		case Scene.PERIODIC:
-			if (firstTime)
-				soundTimer.schedule(new PlaySoundTask(scene, sound), 0);
-			int delay = 60000 / scene.getSoundFrequency();
-			soundTimer.schedule(new PlaySoundTask(scene, sound), delay);
-			soundTimer.schedule(new UpdateSoundTimerTask(scene), delay + 1);
-			break;
-		case Scene.RANDOM:
-			for (int i = 0; i < scene.getSoundFrequency(); i++)
-				soundTimer.schedule(new PlaySoundTask(scene, sound), (int)(Math.random() * 60000));
-			soundTimer.schedule(new UpdateSoundTimerTask(scene), 60000);
-			break;
-		}
-#endif
+		// Launch the process
+		soundTimer(scene);
 	}
 
 }
diff --git a/engines/wage/wage.cpp b/engines/wage/wage.cpp
index dce43bc204e..b37a630edc0 100644
--- a/engines/wage/wage.cpp
+++ b/engines/wage/wage.cpp
@@ -160,6 +160,11 @@ Common::Error WageEngine::run() {
 		_gui->draw();
 		g_system->updateScreen();
 		g_system->delayMillis(50);
+
+		if (!_soundToPlay.empty()) {
+			playSound(_soundToPlay);
+			_soundToPlay.clear();
+		}
 	}
 
 	return Common::kNoError;
diff --git a/engines/wage/wage.h b/engines/wage/wage.h
index 5c52fa033b8..eb4e12afcb1 100644
--- a/engines/wage/wage.h
+++ b/engines/wage/wage.h
@@ -54,6 +54,7 @@
 #include "common/rect.h"
 #include "common/macresman.h"
 #include "common/random.h"
+#include "common/timer.h"
 
 #include "wage/debugger.h"
 
@@ -159,7 +160,6 @@ private:
 	void performHealingMagic(Chr *chr, Obj *magicalObject);
 
 	void doClose();
-	void updateSoundTimerForScene(Scene *scene, bool firstTime);
 
 public:
 	void takeObj(Obj *obj);
@@ -212,7 +212,11 @@ public:
 
 	Common::String _inputText;
 
+	Common::List<int> _soundQueue;
+	Common::String _soundToPlay;
+
 	void playSound(Common::String soundName);
+	void updateSoundTimerForScene(Scene *scene, bool firstTime);
 	void setMenu(Common::String soundName);
 	void appendText(const char *str);
 	void gameOver();




More information about the Scummvm-git-logs mailing list