[Scummvm-git-logs] scummvm master -> b617364f453e973135d9b3e52afe4040f405295f

sev- sev at scummvm.org
Sat Aug 28 20:55:16 UTC 2021


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

Summary:
b617364f45 COMMON: improve RandomSource initial seed


Commit: b617364f453e973135d9b3e52afe4040f405295f
    https://github.com/scummvm/scummvm/commit/b617364f453e973135d9b3e52afe4040f405295f
Author: Die4Ever (die4ever2006 at hotmail.com)
Date: 2021-08-28T22:55:13+02:00

Commit Message:
COMMON: improve RandomSource initial seed

This improves the range of seeds compared to using only getMillis (which
is the number of milliseconds since program start) as the seed. This was
especially an issue if you started the game directly from command line,
Steam, or GOG instead of using the ScummVM interface. Previously the
initial seed was just the load time, which can have very small variance
on a fast computer.

Changed paths:
    common/random.cpp


diff --git a/common/random.cpp b/common/random.cpp
index 2b7d140510..5da2f67337 100644
--- a/common/random.cpp
+++ b/common/random.cpp
@@ -37,7 +37,13 @@ RandomSource::RandomSource(const String &name) {
 #ifdef ENABLE_EVENTRECORDER
 	setSeed(g_eventRec.getRandomSeed(name));
 #else
-	setSeed(g_system->getMillis());
+	TimeDate time;
+	g_system->getTimeAndDate(time);
+	uint32 newSeed = time.tm_sec + time.tm_min * 60 + time.tm_hour * 3600;
+	newSeed += time.tm_mday * 86400 + time.tm_mon * 86400 * 31;
+	newSeed += time.tm_year * 86400 * 366;
+	newSeed = newSeed * 1000 + g_system->getMillis();
+	setSeed(newSeed);
 #endif
 }
 




More information about the Scummvm-git-logs mailing list