[Scummvm-git-logs] scummvm master -> 3a8bcd751f1bf05575e70e2c64361983e3c8cf3e

sev- noreply at scummvm.org
Sun Jun 21 13:10:14 UTC 2026


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

Summary:
3a8bcd751f DIRECTOR: Seed RNG from system time instead of a fixed value


Commit: 3a8bcd751f1bf05575e70e2c64361983e3c8cf3e
    https://github.com/scummvm/scummvm/commit/3a8bcd751f1bf05575e70e2c64361983e3c8cf3e
Author: Zachary Berry (zberry92 at gmail.com)
Date: 2026-06-21T15:10:09+02:00

Commit Message:
DIRECTOR: Seed RNG from system time instead of a fixed value

Director seeds its RNG by time from the classic MacOS epoch. Use
this instead of the hard coded 1 orginally implemented unless
the seed is set in the GUI.

This fixes RNG in games that do not explicitly call
`set the randomSeed`

Changed paths:
    engines/director/util.cpp
    engines/director/util.h


diff --git a/engines/director/util.cpp b/engines/director/util.cpp
index c65c3ee66c7..6aaa3001db0 100644
--- a/engines/director/util.cpp
+++ b/engines/director/util.cpp
@@ -25,7 +25,9 @@
 #include "common/memstream.h"
 #include "common/punycode.h"
 #include "common/str-array.h"
+#include "common/system.h"
 #include "common/tokenizer.h"
+#include "common/util.h"
 #include "common/xpfloat.h"
 #include "common/compression/deflate.h"
 
@@ -1203,7 +1205,19 @@ Common::Path dumpFactoryName(const char *prefix, const char *name, const char *e
 	return Common::Path(Common::String::format("./dumps/%s-factory-%s.%s", prefix, name, ext), '/');
 }
 
-void RandomState::setSeed(int seed, bool runInit) {
+// Seconds between the classic Mac OS epoch and the Unix epoch.
+static const uint32 kMacEpochOffset = 2082844800U;
+
+uint32 macTimeSeed() {
+	// Director seeds its RNG with the local wall-clock time in seconds since
+	// the classic Mac OS epoch.
+	TimeDate td;
+	g_system->getTimeAndDate(td);
+
+	return (uint32)(Common::DateTime::dateTimeToInt64(td) + kMacEpochOffset);
+}
+
+void RandomState::setSeed(uint32 seed, bool runInit) {
 	if (runInit)
 		init(32);
 
@@ -1245,9 +1259,7 @@ void RandomState::init(int len) {
 		_len = (1 << len) - 1;
 	}
 
-	// The original is _always_ initalized with a seed of 1. It is hardcoded and is by design
-	// The developers were offered to use `set the randomSeed` Lingo
-	setSeed(1, false);
+	setSeed(macTimeSeed(), false);
 	_mask = masks[len - 2];
 }
 
diff --git a/engines/director/util.h b/engines/director/util.h
index 8d5e746c6e9..661346710df 100644
--- a/engines/director/util.h
+++ b/engines/director/util.h
@@ -71,6 +71,8 @@ Common::Path dumpFactoryName(const char *prefix, const char *name, const char *e
 
 bool isButtonSprite(SpriteType spriteType);
 
+uint32 macTimeSeed();
+
 class RandomState {
 public:
 	uint32 _seed;
@@ -81,7 +83,7 @@ public:
 		_seed = _mask = _len = 0;
 	}
 
-	void setSeed(int seed, bool runInit = true);
+	void setSeed(uint32 seed, bool runInit = true);
 	uint32 getSeed() { return _seed; }
 	int32 getRandom(int32 range);
 




More information about the Scummvm-git-logs mailing list