[Scummvm-git-logs] scummvm master -> 7a683300c89cffc2a2337250d2db46fcff6cc9c9
sev-
noreply at scummvm.org
Mon Jan 2 15:13:07 UTC 2023
This automated email contains information about 6 new commits which have been
pushed to the 'scummvm' repo located at https://github.com/scummvm/scummvm .
Summary:
41da1de090 COMMON: Sync RNG seed initialising between common and event recorder
0fb25d7734 COMMON: Allow specify random seed via scummvm.ini
b07baf493b ALL: Make sure we always allow to override random seed
49a0a54e9d BASE: Added --random-seed command line option
e4686897d4 GUI: Added setting for global RNG seed in the Misc tab
7a683300c8 NEWS: Mention new RNG seed setting
Commit: 41da1de090eb5e0212f3d1a80f3e36a6d8978320
https://github.com/scummvm/scummvm/commit/41da1de090eb5e0212f3d1a80f3e36a6d8978320
Author: Eugene Sandulenko (sev at scummvm.org)
Date: 2023-01-02T16:12:44+01:00
Commit Message:
COMMON: Sync RNG seed initialising between common and event recorder
Changed paths:
common/random.cpp
common/random.h
gui/EventRecorder.cpp
diff --git a/common/random.cpp b/common/random.cpp
index 79009542e7c..8456e692b28 100644
--- a/common/random.cpp
+++ b/common/random.cpp
@@ -34,14 +34,19 @@ RandomSource::RandomSource(const String &name) {
#ifdef ENABLE_EVENTRECORDER
setSeed(g_eventRec.getRandomSeed(name));
#else
+ setSeed(generateNewSeed());
+#endif
+}
+
+uint32 RandomSource::generateNewSeed() {
TimeDate time;
g_system->getTimeAndDate(time);
uint32 newSeed = time.tm_sec + time.tm_min * 60U + time.tm_hour * 3600U;
newSeed += time.tm_mday * 86400U + time.tm_mon * 86400U * 31U;
newSeed += time.tm_year * 86400U * 366U;
newSeed = newSeed * 1000U + g_system->getMillis();
- setSeed(newSeed);
-#endif
+
+ return newSeed;
}
void RandomSource::setSeed(uint32 seed) {
@@ -69,7 +74,7 @@ uint RandomSource::getRandomNumberRng(uint min, uint max) {
int RandomSource::getRandomNumberRngSigned(int min, int max) {
return getRandomNumber(max - min) + min;
}
-
+
inline void RandomSource::scrambleSeed() {
//marsaglia's paper says that any of 81 triplets are feasible
//(11,21,13) was chosen, with (cba) and (>>,<<,>>)
diff --git a/common/random.h b/common/random.h
index 9780717237e..f5b69a738af 100644
--- a/common/random.h
+++ b/common/random.h
@@ -54,6 +54,11 @@ public:
*/
RandomSource(const String &name);
+ /**
+ * Generates new seed based on the current date/time
+ */
+ static uint32 generateNewSeed();
+
void setSeed(uint32 seed); /*!< Set the seed used to initialize the RNG. */
uint32 getSeed() const { /*!< Get a random seed that can be used to initialize the RNG. */
@@ -89,7 +94,7 @@ public:
* @return a random number in the interval [min, max]
*/
int getRandomNumberRngSigned(int min, int max);
-
+
/**
* Scrambles the seed in order to get a new result.
* Code is shared between getRandomNumber and getRandomBit,
diff --git a/gui/EventRecorder.cpp b/gui/EventRecorder.cpp
index d38d3834927..1e3b73d0657 100644
--- a/gui/EventRecorder.cpp
+++ b/gui/EventRecorder.cpp
@@ -359,7 +359,7 @@ uint32 EventRecorder::getRandomSeed(const Common::String &name) {
if (_recordMode == kRecorderPlayback) {
return _playbackFile->getHeader().randomSourceRecords[name];
}
- uint32 result = g_system->getMillis();
+ uint32 result = Common::RandomSource::generateNewSeed();
if (_recordMode == kRecorderRecord) {
_recordFile->getHeader().randomSourceRecords[name] = result;
}
Commit: 0fb25d7734d94aa459e6ca0755ea4dd4c69047c6
https://github.com/scummvm/scummvm/commit/0fb25d7734d94aa459e6ca0755ea4dd4c69047c6
Author: Eugene Sandulenko (sev at scummvm.org)
Date: 2023-01-02T16:12:44+01:00
Commit Message:
COMMON: Allow specify random seed via scummvm.ini
Changed paths:
common/random.cpp
diff --git a/common/random.cpp b/common/random.cpp
index 8456e692b28..f67afbab63c 100644
--- a/common/random.cpp
+++ b/common/random.cpp
@@ -21,6 +21,7 @@
#include "common/random.h"
#include "common/system.h"
+#include "common/config-manager.h"
#include "gui/EventRecorder.h"
@@ -39,6 +40,9 @@ RandomSource::RandomSource(const String &name) {
}
uint32 RandomSource::generateNewSeed() {
+ if (ConfMan.hasKey("random_seed"))
+ return ConfMan.getInt("random_seed");
+
TimeDate time;
g_system->getTimeAndDate(time);
uint32 newSeed = time.tm_sec + time.tm_min * 60U + time.tm_hour * 3600U;
Commit: b07baf493b8a099245b067878d362a732811e351
https://github.com/scummvm/scummvm/commit/b07baf493b8a099245b067878d362a732811e351
Author: Eugene Sandulenko (sev at scummvm.org)
Date: 2023-01-02T16:12:44+01:00
Commit Message:
ALL: Make sure we always allow to override random seed
Changed paths:
engines/drascula/talk.cpp
engines/glk/hugo/herun.cpp
engines/made/script.cpp
diff --git a/engines/drascula/talk.cpp b/engines/drascula/talk.cpp
index 73309044e46..3d6f34774cd 100644
--- a/engines/drascula/talk.cpp
+++ b/engines/drascula/talk.cpp
@@ -27,7 +27,7 @@ static const int x_talk_dch[6] = {1, 25, 49, 73, 97, 121};
static const int x_talk_izq[6] = {145, 169, 193, 217, 241, 265};
void DrasculaEngine::talkInit(const char *filename) {
- _rnd->setSeed((unsigned int)_system->getMillis() / 2);
+ _rnd->setSeed(Common::RandomSource::generateNewSeed());
playFile(filename);
}
diff --git a/engines/glk/hugo/herun.cpp b/engines/glk/hugo/herun.cpp
index 79861bd7ea5..855f497308b 100644
--- a/engines/glk/hugo/herun.cpp
+++ b/engines/glk/hugo/herun.cpp
@@ -2317,7 +2317,7 @@ int Hugo::RunSystem() {
case 22: /* INIT_RANDOM */
{
#if !defined (RANDOM)
- _random.setSeed(g_system->getMillis());
+ _random.setSeed(Common::RandomSource::generateNewSeed());
#else
time_t seed;
SRANDOM((unsigned int)time((time_t *)&seed));
diff --git a/engines/made/script.cpp b/engines/made/script.cpp
index d7cdea2fcb0..2dd82738d6b 100644
--- a/engines/made/script.cpp
+++ b/engines/made/script.cpp
@@ -512,7 +512,7 @@ void ScriptInterpreter::cmd_rand() {
}
void ScriptInterpreter::cmd_randomize() {
- _vm->_rnd->setSeed(g_system->getMillis());
+ _vm->_rnd->setSeed(Common::RandomSource::generateNewSeed());
_stack.setTop(0);
}
Commit: 49a0a54e9d93d5f056de1fc731516bfd508d8358
https://github.com/scummvm/scummvm/commit/49a0a54e9d93d5f056de1fc731516bfd508d8358
Author: Eugene Sandulenko (sev at scummvm.org)
Date: 2023-01-02T16:12:44+01:00
Commit Message:
BASE: Added --random-seed command line option
Changed paths:
base/commandLine.cpp
diff --git a/base/commandLine.cpp b/base/commandLine.cpp
index 7cf968d245d..bda58ccc6b2 100644
--- a/base/commandLine.cpp
+++ b/base/commandLine.cpp
@@ -175,6 +175,7 @@ static const char HELP_STRING4[] =
")\n"
" --show-fps Set the turn on display FPS info in 3D games\n"
" --no-show-fps Set the turn off display FPS info in 3D games\n"
+ " --random-seed=SEED Set the random seed used to initialize entropy\n"
" --renderer=RENDERER Select 3D renderer (software, opengl, opengl_shaders)\n"
" --aspect-ratio Enable aspect ratio correction\n"
" --[no-]dirtyrects Enable dirty rectangles optimisation in software renderer\n"
@@ -865,6 +866,9 @@ Common::String parseCommandLine(Common::StringMap &settings, int argc, const cha
DO_LONG_OPTION_INT("talkspeed")
END_OPTION
+ DO_LONG_OPTION_INT("random-seed")
+ END_OPTION
+
DO_LONG_OPTION_BOOL("copy-protection")
END_OPTION
@@ -1904,6 +1908,7 @@ bool processSettings(Common::String &command, Common::StringMap &settings, Commo
"opl-driver",
"talkspeed",
"render-mode",
+ "random-seed",
nullptr
};
Commit: e4686897d4be6a2ba03ba051aca0be96e0a7717f
https://github.com/scummvm/scummvm/commit/e4686897d4be6a2ba03ba051aca0be96e0a7717f
Author: Eugene Sandulenko (sev at scummvm.org)
Date: 2023-01-02T16:12:44+01:00
Commit Message:
GUI: Added setting for global RNG seed in the Misc tab
Changed paths:
gui/options.cpp
gui/options.h
diff --git a/gui/options.cpp b/gui/options.cpp
index 7e72a66dbf6..ad1d68cdd2b 100644
--- a/gui/options.cpp
+++ b/gui/options.cpp
@@ -103,6 +103,7 @@ enum {
kGraphicsTabContainerReflowCmd = 'gtcr',
kScalerPopUpCmd = 'scPU',
kFullscreenToggled = 'oful',
+ kRandomSeedClearCmd = 'rndc',
};
enum {
@@ -2526,6 +2527,18 @@ void GlobalOptionsDialog::addMiscControls(GuiObject *boss, const Common::String
_autosavePeriodPopUp->appendEntry(_(savePeriodLabels[i]), savePeriodValues[i]);
}
+ Common::String seed;
+ if (ConfMan.hasKey("random_seed"))
+ seed = Common::String::format("%u", ConfMan.getInt("random_seed"));
+
+ _randomSeedDesc = new StaticTextWidget(boss, prefix + "RandomSeedDesc", _("Random seed:"), _("Seed for initializing all random number generators"));
+
+ if (ConfMan.isKeyTemporary("random_seed"))
+ _randomSeedDesc->setFontColor(ThemeEngine::FontColor::kFontColorOverride);
+
+ _randomSeed = new EditTextWidget(boss, prefix + "RandomSeedEditText", seed, Common::U32String());
+ _randomSeedClearButton = addClearButton(boss, prefix + "RandomSeedClearButton", kRandomSeedClearCmd);
+
#ifdef USE_DISCORD
_discordRpcCheckbox = new CheckboxWidget(boss, prefix + "DiscordRpc",
_("Enable Discord integration"),
@@ -2901,6 +2914,27 @@ void GlobalOptionsDialog::apply() {
}
#endif // USE_DISCORD
+ bool differs = false;
+ if (ConfMan.hasKey("random_seed")) {
+ if (_randomSeed->getEditString().empty()) {
+ differs = true;
+ } else if ((uint32)_randomSeed->getEditString().asUint64() != ConfMan.getInt("random_seed")) {
+ differs = true;
+ }
+ } else {
+ if (!_randomSeed->getEditString().empty())
+ differs = true;
+ }
+
+ if (differs) {
+ if (_randomSeed->getEditString().empty())
+ ConfMan.removeKey("random_seed", _domain);
+ else
+ ConfMan.setInt("random_seed", (uint32)_randomSeed->getEditString().asUint64());
+
+ _randomSeedDesc->setFontColor(ThemeEngine::FontColor::kFontColorNormal);
+ }
+
GUI::ThemeEngine::GraphicsMode gfxMode = (GUI::ThemeEngine::GraphicsMode)_rendererPopUp->getSelectedTag();
Common::String oldGfxConfig = ConfMan.get("gui_renderer");
Common::String newGfxConfig = GUI::ThemeEngine::findModeConfigName(gfxMode);
@@ -3133,6 +3167,13 @@ void GlobalOptionsDialog::handleCommand(CommandSender *sender, uint32 cmd, uint3
}
break;
}
+ case kRandomSeedClearCmd: {
+ if (_randomSeed) {
+ _randomSeed->setEditString(Common::U32String());
+ }
+ g_gui.scheduleTopDialogRedraw();
+ break;
+ }
#ifdef USE_CLOUD
#ifdef USE_LIBCURL
case kCloudTabContainerReflowCmd: {
diff --git a/gui/options.h b/gui/options.h
index 5fa7838122f..19fc5122190 100644
--- a/gui/options.h
+++ b/gui/options.h
@@ -311,6 +311,9 @@ protected:
//
StaticTextWidget *_autosavePeriodPopUpDesc;
PopUpWidget *_autosavePeriodPopUp;
+ StaticTextWidget *_randomSeedDesc;
+ EditTextWidget *_randomSeed;
+ ButtonWidget *_randomSeedClearButton;
#ifdef USE_UPDATES
StaticTextWidget *_updatesPopUpDesc;
Commit: 7a683300c89cffc2a2337250d2db46fcff6cc9c9
https://github.com/scummvm/scummvm/commit/7a683300c89cffc2a2337250d2db46fcff6cc9c9
Author: Eugene Sandulenko (sev at scummvm.org)
Date: 2023-01-02T16:12:44+01:00
Commit Message:
NEWS: Mention new RNG seed setting
Changed paths:
NEWS.md
diff --git a/NEWS.md b/NEWS.md
index ff3a9b09609..e4b9a589ef8 100644
--- a/NEWS.md
+++ b/NEWS.md
@@ -21,6 +21,7 @@ For a more comprehensive changelog of the latest experimental code, see:
line option).
- Improved cursor scaling in OpenGL mode.
- Fix crash when browsing folders containing files with \1 in the names.
+ - Added possibility to specify RNG seed via GUI or command line option.
AGI:
- Improved support for French translations.
More information about the Scummvm-git-logs
mailing list