Skip to content

Commit

Permalink
libretro: serialize random seed, so games don't diverge when restored.
Browse files Browse the repository at this point in the history
  • Loading branch information
icculus committed Aug 14, 2023
1 parent 5900186 commit 89832e3
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 4 deletions.
5 changes: 2 additions & 3 deletions mojozork-libretro.c
Expand Up @@ -1489,10 +1489,8 @@ bool retro_load_game_special(unsigned type, const struct retro_game_info *info,
}


// !!! FIXME: random seeds aren't serialized, so future game state can diverge in small (or not so small) ways when restoring. Maybe that's okay...?

#define MOJOZORK_SERIALIZATION_MAGIC 0x6B5A6A4D // littleendian number is "MjZk" in ASCII.
#define MOJOZORK_SERIALIZATION_CURRENT_VERSION 2
#define MOJOZORK_SERIALIZATION_CURRENT_VERSION 3

/* MAKE SURE THESE STAY IN ORDER: 64-bit first, 32 second, then 16, then BUFFER.
This will make sure memory accesses stay aligned. */
Expand Down Expand Up @@ -1526,6 +1524,7 @@ bool retro_load_game_special(unsigned type, const struct retro_game_info *info,
MOJOZORK_SERIALIZE_BUFFER(GState->stack, 256) /* hopefully 256 is enough */ \
MOJOZORK_SERIALIZE_BUFFER(scrollback, sizeof (scrollback)) \
if (version >= 2) { MOJOZORK_SERIALIZE_BUFFER(upper_window, sizeof (upper_window)) } \
if (version >= 3) { MOJOZORK_SERIALIZE_SINT32(random_seed) } \
}

size_t retro_serialize_size(void)
Expand Down
2 changes: 1 addition & 1 deletion mojozork.c
Expand Up @@ -1134,7 +1134,7 @@ static void opcode_print_paddr(void)
} // opcode_print_paddr


static int random_seed = 0;
static sint32 random_seed = 0;
static int randomNumber(void)
{
// this is POSIX.1-2001's potentially bad suggestion, but we're not exactly doing cryptography here.
Expand Down

0 comments on commit 89832e3

Please sign in to comment.