@@ -153,9 +153,15 @@ module WorldModule =
153153
154154 /// Set whether the world state is advancing.
155155 static member setAdvancing advancing ( world : World ) =
156- if world.ContextImSim.Names.Length = 0
157- then World.defer ( World.mapAmbientState ( AmbientState.setAdvancing advancing)) Game.Handle world
158- else Log.error " Cannot call World.setAdvancing in an ImSim context."
156+ if world.ContextImSim.Names.Length = 0 then
157+ World.defer ( World.mapAmbientState ( AmbientState.setAdvancing advancing)) Game.Handle world
158+ else
159+ // HACK: in order to avoid unintentional interaction with the ImSim hack that clears and restores
160+ // advancement state ImSim contexts, we schedule the advancement change outside of the normal workflow.
161+ // Also note how this hack put type declaration order in a sloppy state (World.addTasklet is defined
162+ // _after_ World.setAdvancing).
163+ let time = if EndFrameProcessingStarted && world.Advancing then GameTime.epsilon else GameTime.zero
164+ World.addTasklet Game.Handle { ScheduledTime = time; ScheduledOp = World.mapAmbientState ( AmbientState.setAdvancing advancing) } world
159165
160166 /// Set whether the world's frame rate is being explicitly paced based on clock progression.
161167 static member setFramePacing clockPacing ( world : World ) =
@@ -400,7 +406,7 @@ module WorldModule =
400406 World.mapAmbientState ( AmbientState.restoreTasklets tasklets) world
401407
402408 /// Add a tasklet to be executed by the engine at the scheduled time.
403- static member addTasklet simulant tasklet world =
409+ static member addTasklet ( simulant : Simulant ) tasklet world =
404410 World.mapAmbientState ( AmbientState.addTasklet simulant tasklet) world
405411
406412 /// Schedule an operation to be executed by the engine with the given delay.
@@ -443,12 +449,7 @@ module WorldModule =
443449 /// When called in an ImSim Process context, will provide the ImSim simulant context and declared values from
444450 /// World that were active in that Process context as well as time and advancement state.
445451 static member defer operation ( simulant : Simulant ) ( world : World ) =
446- let time =
447- if EndFrameProcessingStarted && world.Advancing then
448- match Constants.GameTime.DesiredFrameRate with
449- | StaticFrameRate _ -> UpdateTime 1 L
450- | DynamicFrameRate _ -> TickTime 1 L
451- else GameTime.zero
452+ let time = if EndFrameProcessingStarted && world.Advancing then GameTime.epsilon else GameTime.zero
452453 World.schedule time operation simulant world
453454
454455 /// Attempt to get the window flags.
0 commit comments