[Scummvm-git-logs] scummvm master -> 4791bb0646d369168dac9c1a59cdad26f7b02804

antoniou79 noreply at scummvm.org
Fri Aug 9 17:41:31 UTC 2024


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

Summary:
4e553baca9 BLADERUNNER: Move bootparm management outside initChapterAndScene()
4791bb0646 BLADERUNNER: Fix random seed generation for new game


Commit: 4e553baca92d5b31d15e5d5cb47c62315096ce6a
    https://github.com/scummvm/scummvm/commit/4e553baca92d5b31d15e5d5cb47c62315096ce6a
Author: antoniou79 (a.antoniou79 at gmail.com)
Date: 2024-08-09T20:30:18+03:00

Commit Message:
BLADERUNNER: Move bootparm management outside initChapterAndScene()

This fixes a (potential) crash when launching ScummVM with boot params and then starting a NEW GAME from KIA menu

Example of cmd line that would lead to crash in the above scenario: scummvm -d0 -b 4021004 bladerunner-win

Changed paths:
    engines/bladerunner/bladerunner.cpp


diff --git a/engines/bladerunner/bladerunner.cpp b/engines/bladerunner/bladerunner.cpp
index 93151e39b3f..9e11f0f8b89 100644
--- a/engines/bladerunner/bladerunner.cpp
+++ b/engines/bladerunner/bladerunner.cpp
@@ -498,12 +498,14 @@ Common::Error BladeRunnerEngine::run() {
 			} else if (hasSavegames) {
 				_kia->_forceOpen = true;
 				_kia->open(kKIASectionLoad);
+			} else {
+				// Despite the redundancy (wrt initializations done in startup()),
+				// newGame() also does some additional setting up explicitly,
+				// so better to keep this here (helps with code readability too
+				// and with using the proper seed for randomization).
+				newGame(kGameDifficultyMedium);
 			}
 		}
-		// TODO: why is the game starting a new game here when everything is done in startup?
-		//  else {
-		// 	newGame(kGameDifficultyMedium);
-		// }
 		gameLoop();
 
 		_mouse->disable();
@@ -839,6 +841,36 @@ bool BladeRunnerEngine::startup(bool hasSavegames) {
 		_aiScripts = new AIScripts(this, actorCount);
 
 		initChapterAndScene();
+
+		// Handle Boot Params here:
+		// If this process (loading an explicit set of Chapter, Set and Scene) fails,
+		// then the game will keep with the default Chapter, Set and Scene for a New Game
+		// as set in the initChapterAndScene() above.
+		// If the process succeeds (_bootParam will be true), then in run()
+		// we skip auto-starting a New Game proper or showing the KIA to load a saved game / start new game,
+		// and go directly to gameLoop() to start the game with the custom settings for Chapter, Set and Scene.
+		if (ConfMan.hasKey("boot_param")) {
+			int param = ConfMan.getInt("boot_param"); // CTTTSSS
+			if (param < 1000000 || param >= 6000000) {
+				debug("Invalid boot parameter. Valid format is: CTTTSSS");
+			} else {
+				int chapter = param / 1000000;
+				param -= chapter * 1000000;
+				int set = param / 1000;
+				param -= set * 1000;
+				int scene = param;
+
+				// init chapter to default first chapter (required by dbgAttemptToLoadChapterSetScene())
+				_settings->setChapter(1);
+				_validBootParam = _debugger->dbgAttemptToLoadChapterSetScene(chapter, set, scene);
+				if (_validBootParam) {
+					debug("Explicitly loading Chapter: %d Set: %d Scene: %d", chapter, set, scene);
+				} else {
+					debug("Invalid combination of Chapter Set and Scene ids as boot parameters");
+				}
+			}
+		}
+
 	}
 	return true;
 }
@@ -856,32 +888,8 @@ void BladeRunnerEngine::initChapterAndScene() {
 		_actors[i]->movementTrackNext(true);
 	}
 
-	if (ConfMan.hasKey("boot_param")) {
-		int param = ConfMan.getInt("boot_param"); // CTTTSSS
-		if (param < 1000000 || param >= 6000000) {
-			debug("Invalid boot parameter. Valid format is: CTTTSSS");
-		} else {
-			int chapter = param / 1000000;
-			param -= chapter * 1000000;
-			int set = param / 1000;
-			param -= set * 1000;
-			int scene = param;
-
-			// init chapter to default first chapter (required by dbgAttemptToLoadChapterSetScene())
-			_settings->setChapter(1);
-			_validBootParam = _debugger->dbgAttemptToLoadChapterSetScene(chapter, set, scene);
-			if (_validBootParam) {
-				debug("Explicitly loading Chapter: %d Set: %d Scene: %d", chapter, set, scene);
-			} else {
-				debug("Invalid combination of Chapter Set and Scene ids");
-			}
-		}
-	}
-
-	if (!_validBootParam) {
-		_settings->setChapter(1);
-		_settings->setNewSetAndScene(_gameInfo->getInitialSetId(), _gameInfo->getInitialSceneId());
-	}
+	_settings->setChapter(1);
+	_settings->setNewSetAndScene(_gameInfo->getInitialSetId(), _gameInfo->getInitialSceneId());
 }
 
 void BladeRunnerEngine::shutdown() {


Commit: 4791bb0646d369168dac9c1a59cdad26f7b02804
    https://github.com/scummvm/scummvm/commit/4791bb0646d369168dac9c1a59cdad26f7b02804
Author: antoniou79 (a.antoniou79 at gmail.com)
Date: 2024-08-09T20:33:19+03:00

Commit Message:
BLADERUNNER: Fix random seed generation for new game

Generates a new seed for random numbers at the exact point when a new game starts to initialize

Additionally, this command will use a custom seed, if any (set from ScummVM Global Options), for the new game.
And, this avoids the issue of intermediate calculations of random numbers, during setup() initializations
(via initScript.SCRIPT_Initialize_Game()) or in KIA menu, eg. when adjusting speech volume, before starting a new game,
which would result in the new game starting with a different seed than the one set from ScummVM Global Options.

Changed paths:
    engines/bladerunner/bladerunner.cpp


diff --git a/engines/bladerunner/bladerunner.cpp b/engines/bladerunner/bladerunner.cpp
index 9e11f0f8b89..06a582cd24b 100644
--- a/engines/bladerunner/bladerunner.cpp
+++ b/engines/bladerunner/bladerunner.cpp
@@ -2808,6 +2808,12 @@ bool BladeRunnerEngine::loadGame(Common::SeekableReadStream &stream, int version
 }
 
 void BladeRunnerEngine::newGame(int difficulty) {
+	// Set a (new) seed for randomness when starting a new game.
+	// This also makes sure that if there's a custom random seed set in ScummVM's configuration,
+	// that's the one that will be used.
+	_rnd.setSeed(Common::RandomSource::generateNewSeed());
+	//debug("Random seed for the New Game is: %u", _rnd.getSeed());
+
 	_settings->reset();
 	_combat->reset();
 




More information about the Scummvm-git-logs mailing list