From d6af8dc352f2f87bcbeda11f932a6fbc574fe883 Mon Sep 17 00:00:00 2001 From: Edward Richardson Date: Sat, 3 May 2014 02:11:16 +1200 Subject: [PATCH 1/3] Added static RNGseed control --- src/d_main.cpp | 9 ++++++++- src/g_level.cpp | 6 +++++- src/m_random.cpp | 36 ++++++++++++++++++++++++++++++++++++ src/m_random.h | 4 ++++ 4 files changed, 53 insertions(+), 2 deletions(-) diff --git a/src/d_main.cpp b/src/d_main.cpp index 6c938ef53..f677f88b3 100644 --- a/src/d_main.cpp +++ b/src/d_main.cpp @@ -1993,7 +1993,14 @@ static void D_DoomInit() SetLanguageIDs (); - rngseed = I_MakeRNGSeed(); + const char *v = Args->CheckValue("-rngseed"); + if (v) + { + rngseed = staticrngseed = atoi(v); + use_staticrng = true; + } + else + rngseed = I_MakeRNGSeed(); FRandom::StaticClearRandom (); Printf ("M_LoadDefaults: Load system defaults.\n"); diff --git a/src/g_level.cpp b/src/g_level.cpp index 65bde08d8..c721be4e1 100644 --- a/src/g_level.cpp +++ b/src/g_level.cpp @@ -408,7 +408,11 @@ void G_InitNew (const char *mapname, bool bTitleLevel) if (!savegamerestore) { - if (!netgame) + if (use_staticrng) + { + rngseed = staticrngseed; + } + else if (!netgame) { // [RH] Change the random seed for each new single player game rngseed = rngseed + 1; } diff --git a/src/m_random.cpp b/src/m_random.cpp index 763410111..f1e39faf9 100644 --- a/src/m_random.cpp +++ b/src/m_random.cpp @@ -96,6 +96,42 @@ FRandom M_Random; // Global seed. This is modified predictably to initialize every RNG. DWORD rngseed; +// Static RNG marker. This is only used when the RNG is set for each new game. +DWORD staticrngseed; +bool use_staticrng; + +// Allows checking or staticly setting the global seed. +CCMD(rngseed) +{ + if (argv.argc() == 1) + { + Printf("Usage: rngseed get|set|clear\n"); + return; + } + if (stricmp(argv[1], "get") == 0) + { + Printf("rngseed is %d\n", rngseed); + } + else if (stricmp(argv[1], "set") == 0) + { + if (argv.argc() == 2) + { + Printf("You need to specify a value to set\n"); + } + else + { + staticrngseed = atoi(argv[2]); + use_staticrng = true; + Printf("Static rngseed %d will be set for next game\n", staticrngseed); + } + } + else if (stricmp(argv[1], "clear") == 0) + { + use_staticrng = false; + Printf("Static rngseed cleared\n"); + } +} + // PRIVATE DATA DEFINITIONS ------------------------------------------------ FRandom *FRandom::RNGList; diff --git a/src/m_random.h b/src/m_random.h index 5b124c50e..b5e21c63c 100644 --- a/src/m_random.h +++ b/src/m_random.h @@ -215,6 +215,10 @@ private: extern DWORD rngseed; // The starting seed (not part of state) +extern DWORD staticrngseed; // Static rngseed that can be set by the user +extern bool use_staticrng; + + // M_Random can be used for numbers that do not affect gameplay extern FRandom M_Random; From 6183f8125fa4dc00db087b683bc08b8deb68e3d2 Mon Sep 17 00:00:00 2001 From: Edward Richardson Date: Sat, 3 May 2014 02:48:52 +1200 Subject: [PATCH 2/3] Don't change RNG in demos incase they are static --- src/d_main.cpp | 1 + src/g_level.cpp | 10 ++++------ 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/src/d_main.cpp b/src/d_main.cpp index f677f88b3..5d36459db 100644 --- a/src/d_main.cpp +++ b/src/d_main.cpp @@ -1998,6 +1998,7 @@ static void D_DoomInit() { rngseed = staticrngseed = atoi(v); use_staticrng = true; + Printf("D_DoomInit: Static RNGseed %d set.\n", rngseed); } else rngseed = I_MakeRNGSeed(); diff --git a/src/g_level.cpp b/src/g_level.cpp index c721be4e1..7b37ad471 100644 --- a/src/g_level.cpp +++ b/src/g_level.cpp @@ -408,13 +408,11 @@ void G_InitNew (const char *mapname, bool bTitleLevel) if (!savegamerestore) { - if (use_staticrng) + if (!netgame && !demorecording && !demoplayback) { - rngseed = staticrngseed; - } - else if (!netgame) - { // [RH] Change the random seed for each new single player game - rngseed = rngseed + 1; + // [RH] Change the random seed for each new single player game + // [ED850] The demo already sets the RNG. + rngseed = use_staticrng ? staticrngseed : (rngseed + 1); } FRandom::StaticClearRandom (); P_ClearACSVars(true); From 104a07d461bd8f75622a8674a7cb390174c41b9b Mon Sep 17 00:00:00 2001 From: Edward Richardson Date: Sat, 3 May 2014 03:24:51 +1200 Subject: [PATCH 3/3] Make sure use_staticrng is false if not needed --- src/d_main.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/d_main.cpp b/src/d_main.cpp index 5d36459db..29049b10f 100644 --- a/src/d_main.cpp +++ b/src/d_main.cpp @@ -2001,7 +2001,11 @@ static void D_DoomInit() Printf("D_DoomInit: Static RNGseed %d set.\n", rngseed); } else + { rngseed = I_MakeRNGSeed(); + use_staticrng = false; + } + FRandom::StaticClearRandom (); Printf ("M_LoadDefaults: Load system defaults.\n");