@@ -19,13 +19,26 @@ EngineConfig normalizeConfig(EngineConfig config) {
1919 return config;
2020}
2121
22+ EngineStepContext makeStepContext (const DeterministicRng& rng, std::uint64_t frameIndex,
23+ std::uint64_t fixedStepIndex, double alpha,
24+ std::uint64_t runIndex) {
25+ return EngineStepContext{
26+ .frameIndex = frameIndex,
27+ .fixedStepIndex = fixedStepIndex,
28+ .alpha = alpha,
29+ .runIndex = runIndex,
30+ .derivedSeed = rng.derive (runIndex, fixedStepIndex),
31+ };
32+ }
33+
2234} // namespace
2335
2436EngineRuntime::EngineRuntime (EngineConfig config)
2537 : config_(normalizeConfig(config)),
2638 scheduler_ (core_, buffer_),
2739 world_(EngineWorld::ConstructionToken{}, core_, resources_, buffer_),
28- frameClock_(config_) {
40+ frameClock_(config_),
41+ rng_(config_.baseSeed) {
2942}
3043
3144void EngineRuntime::addSystem (std::unique_ptr<EngineSystem> system,
@@ -39,19 +52,15 @@ void EngineRuntime::initialize() {
3952 resources_ = ResourceStore{};
4053 buffer_ = CommandBuffer{};
4154 scheduler_.resetCadenceState ();
55+ rng_.reseed (config_.baseSeed );
4256 stats_ = {};
4357 stats_.state = EngineState::Ready;
4458 ++runIndex_;
4559
4660 scheduler_.configure (world_);
4761
48- const EngineStepContext startupCtx{
49- .frameIndex = stats_.frameIndex ,
50- .fixedStepIndex = stats_.fixedStepIndex ,
51- .alpha = 0.0 ,
52- .runIndex = runIndex_,
53- .derivedSeed = 0 ,
54- };
62+ const EngineStepContext startupCtx = makeStepContext (
63+ rng_, stats_.frameIndex , stats_.fixedStepIndex , 0.0 , runIndex_);
5564 scheduler_.executeStartup (world_, startupCtx);
5665}
5766
@@ -75,6 +84,7 @@ void EngineRuntime::stop() {
7584 resources_ = ResourceStore{};
7685 buffer_ = CommandBuffer{};
7786 scheduler_.resetCadenceState ();
87+ rng_.reseed (config_.baseSeed );
7888 stats_ = {};
7989 stats_.state = EngineState::Stopped;
8090}
@@ -94,13 +104,8 @@ void EngineRuntime::stepFrame(double deltaSeconds) {
94104 ++stats_.frameIndex ;
95105 stats_.fixedStepsThisFrame = 0 ;
96106
97- EngineStepContext ctx{
98- .frameIndex = stats_.frameIndex ,
99- .fixedStepIndex = stats_.fixedStepIndex ,
100- .alpha = frameClock_.alpha (),
101- .runIndex = runIndex_,
102- .derivedSeed = 0 ,
103- };
107+ auto ctx = makeStepContext (rng_, stats_.frameIndex , stats_.fixedStepIndex ,
108+ frameClock_.alpha (), runIndex_);
104109
105110 scheduler_.executePhase (UpdatePhase::PreSimulation, world_, ctx);
106111
@@ -109,13 +114,8 @@ void EngineRuntime::stepFrame(double deltaSeconds) {
109114 ++stats_.fixedStepIndex ;
110115 ++stats_.fixedStepsThisFrame ;
111116
112- ctx = EngineStepContext{
113- .frameIndex = stats_.frameIndex ,
114- .fixedStepIndex = stats_.fixedStepIndex ,
115- .alpha = frameClock_.alpha (),
116- .runIndex = runIndex_,
117- .derivedSeed = 0 ,
118- };
117+ ctx = makeStepContext (rng_, stats_.frameIndex , stats_.fixedStepIndex ,
118+ frameClock_.alpha (), runIndex_);
119119
120120 scheduler_.executePhase (UpdatePhase::FixedSimulation, world_, ctx);
121121 }
0 commit comments