@@ -158,6 +158,11 @@ static bool get_native_app(void* userdata) {
158158 return static_cast <Context*>(userdata)->NativeApp ();
159159}
160160
161+ static void set_mixer_seed (void * userdata, int v) {
162+ return static_cast <Context*>(userdata)->SetMixerSeed (
163+ static_cast <std::uint32_t >(v));
164+ }
165+
161166static void set_actions (void * userdata, double look_down_up,
162167 double look_left_right, signed char move_back_forward,
163168 signed char strafe_left_right, signed char crouch_jump,
@@ -480,7 +485,7 @@ lua::NResultsOr MapMakerModule(lua_State* L) {
480485 LuaTextLevelMaker::CreateObject (
481486 L, ctx->ExecutableRunfiles (), ctx->TempDirectory (),
482487 ctx->UseLocalLevelCache (), ctx->UseGlobalLevelCache (),
483- ctx->LevelCacheParams ());
488+ ctx->LevelCacheParams (), ctx-> MixerSeed () );
484489 return 1 ;
485490 } else {
486491 return " Missing context!" ;
@@ -507,6 +512,7 @@ Context::Context(lua::Vm lua_vm, const char* executable_runfiles,
507512 : lua_vm_(std::move(lua_vm)),
508513 native_app_(false ),
509514 actions_{},
515+ mixer_seed_ (0 ),
510516 level_cache_params_{},
511517 game_ (executable_runfiles, calls, file_reader_override,
512518 temp_folder != nullptr ? temp_folder : " " ),
@@ -528,6 +534,7 @@ Context::Context(lua::Vm lua_vm, const char* executable_runfiles,
528534 hooks->run_lua_snippet = run_lua_snippet;
529535 hooks->set_native_app = set_native_app;
530536 hooks->get_native_app = get_native_app;
537+ hooks->set_mixer_seed = set_mixer_seed;
531538 hooks->set_actions = set_actions;
532539 hooks->get_actions = get_actions;
533540 hooks->find_model = find_model;
@@ -652,7 +659,8 @@ int Context::Init() {
652659 lua_vm_.AddCModuleToSearchers (
653660 " dmlab.system.tensor" , tensor::LuaTensorConstructors);
654661 lua_vm_.AddCModuleToSearchers (
655- " dmlab.system.maze_generation" , LuaMazeGeneration::Require);
662+ " dmlab.system.maze_generation" , &lua::Bind<LuaMazeGeneration::Require>,
663+ {reinterpret_cast <void *>(static_cast <std::uintptr_t >(mixer_seed_))});
656664 lua_vm_.AddCModuleToSearchers (
657665 " dmlab.system.map_maker" , &lua::Bind<MapMakerModule>, {this });
658666 lua_vm_.AddCModuleToSearchers (
@@ -668,7 +676,9 @@ int Context::Init() {
668676 &lua::Bind<ContextPickups::Module>,
669677 {MutablePickups ()});
670678 lua_vm_.AddCModuleToSearchers (
671- " dmlab.system.random" , &lua::Bind<LuaRandom::Require>, {UserPrbg ()});
679+ " dmlab.system.random" , &lua::Bind<LuaRandom::Require>,
680+ {UserPrbg (),
681+ reinterpret_cast <void *>(static_cast <std::uintptr_t >(mixer_seed_))});
672682 lua_vm_.AddCModuleToSearchers (
673683 " dmlab.system.model" , &lua::Bind<ModelModule>,
674684 {const_cast <DeepmindCalls*>(Game ().Calls ())});
@@ -704,7 +714,8 @@ int Context::Init() {
704714}
705715
706716int Context::Start (int episode, int seed) {
707- EnginePrbg ()->seed (seed);
717+ EnginePrbg ()->seed (static_cast <std::uint64_t >(seed) ^
718+ (static_cast <std::uint64_t >(mixer_seed_) << 32 ));
708719 MutableGame ()->NextMap ();
709720 lua_State* L = lua_vm_.get ();
710721 script_table_ref_.PushMemberFunction (" start" );
0 commit comments