followup on randomization vs movies fix:

1. Save/load RAMInitSeed in config so FCEUX doesn't always start up with the same first seed.
2. Moved seeding to PowerNES (FCEU_MemoryRand can be called multiple times, reseeding causes duplication.)
3. Increased bit depth of seed randomization from 15 to 31 bits for more possibilities.
This commit is contained in:
rainwarrior 2018-01-17 04:40:15 +00:00
parent 3a1d872a6d
commit ad3797655e
2 changed files with 12 additions and 8 deletions

View File

@ -74,6 +74,7 @@ extern int palcontrast;
extern int palbrightness;
extern bool paldeemphswap;
extern int RAMInitOption;
extern int RAMInitSeed;
extern TASEDITOR_CONFIG taseditorConfig;
extern char* recentProjectsArray[];
@ -188,6 +189,7 @@ static CFGSTRUCT fceuconfig[] =
AC(force_grayscale),
AC(dendy),
AC(RAMInitOption),
AC(RAMInitSeed),
AC(postrenderscanlines),
AC(vblankscanlines),
AC(overclock_enabled),

View File

@ -845,14 +845,6 @@ u64 xoroshiro128plus_next() {
void FCEU_MemoryRand(uint8 *ptr, uint32 size) {
int x = 0;
//reseed random, unless we're in a movie
extern int disableBatteryLoading;
if(FCEUMOV_Mode(MOVIEMODE_INACTIVE) && !disableBatteryLoading)
RAMInitSeed = rand()&0x7FFF;
//always reseed the PRNG with the current seed, for deterministic results (for that seed)
xoroshiro128plus_seed(RAMInitSeed);
while (size) {
uint8 v = 0;
switch (RAMInitOption)
@ -888,6 +880,16 @@ void PowerNES(void) {
FCEUMOV_AddCommand(FCEUNPCMD_POWER);
if (!GameInfo) return;
//reseed random, unless we're in a movie
extern int disableBatteryLoading;
if(FCEUMOV_Mode(MOVIEMODE_INACTIVE) && !disableBatteryLoading)
{
RAMInitSeed = (RAMInitSeed + (u32)(xoroshiro128plus_next())) | 1;
}
//always reseed the PRNG with the current seed, for deterministic results (for that seed)
xoroshiro128plus_seed(RAMInitSeed);
FCEU_CheatResetRAM();
FCEU_CheatAddRAM(2, 0, RAM);