Skip to content

Commit ad11273

Browse files
committed
Replacing ImSim setAdvancing log with workaround hack.
1 parent d85455f commit ad11273

File tree

4 files changed

+32
-26
lines changed

4 files changed

+32
-26
lines changed

Nu/Nu/Core/GameTime.fs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,7 @@ and [<Struct; CustomEquality; CustomComparison; TypeConverter (typeof<GameTimeCo
166166
static member isZero time = GameTime.unary isZero isZero time
167167
static member notZero time = GameTime.unary notZero notZero time
168168
static member zero = GameTime.ofSeconds 0.0f
169+
static member epsilon = match Constants.GameTime.DesiredFrameRate with StaticFrameRate _ -> UpdateTime 1L | DynamicFrameRate _ -> TickTime 1L
169170
static member min (left : GameTime) right = if left <= right then left else right
170171
static member max (left : GameTime) right = if left >= right then left else right
171172
static member MinValue = GameTime.make Int64.MinValue Single.MinValue

Nu/Nu/World/WorldModule.fs

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -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 1L
450-
| DynamicFrameRate _ -> TickTime 1L
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.

Nu/Nu/World/WorldModule2.fs

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -275,6 +275,19 @@ module WorldModule2 =
275275
| DesireNone -> ()
276276
| DesireIgnore -> ()
277277

278+
static member private updateScreenTransition world =
279+
match World.getSelectedScreenOpt world with
280+
| Some selectedScreen ->
281+
match selectedScreen.GetTransitionState world with
282+
| IncomingState transitionTime -> World.updateScreenIncoming transitionTime selectedScreen world
283+
| IdlingState transitionTime -> World.updateScreenIdling transitionTime selectedScreen world
284+
| OutgoingState transitionTime -> World.updateScreenOutgoing transitionTime selectedScreen world
285+
| None ->
286+
match World.getDesiredScreen world with
287+
| Desire desiredScreen -> World.transitionScreen desiredScreen world
288+
| DesireNone -> ()
289+
| DesireIgnore -> ()
290+
278291
static member private updateScreenRequestedSong world =
279292
match World.getSelectedScreenOpt world with
280293
| Some selectedScreen ->
@@ -296,18 +309,9 @@ module WorldModule2 =
296309
| RequestIgnore -> ()
297310
| None -> ()
298311

299-
static member private updateScreenTransition world =
300-
match World.getSelectedScreenOpt world with
301-
| Some selectedScreen ->
302-
match selectedScreen.GetTransitionState world with
303-
| IncomingState transitionTime -> World.updateScreenIncoming transitionTime selectedScreen world
304-
| IdlingState transitionTime -> World.updateScreenIdling transitionTime selectedScreen world
305-
| OutgoingState transitionTime -> World.updateScreenOutgoing transitionTime selectedScreen world
306-
| None ->
307-
match World.getDesiredScreen world with
308-
| Desire desiredScreen -> World.transitionScreen desiredScreen world
309-
| DesireNone -> ()
310-
| DesireIgnore -> ()
312+
static member private processScreenTransitioning world =
313+
World.updateScreenTransition world
314+
World.updateScreenRequestedSong world
311315

312316
/// Try to transition to the given screen if no other transition is in progress.
313317
static member tryTransitionScreen destination world =
@@ -1867,9 +1871,9 @@ module WorldModule2 =
18671871
world.Timers.PreProcessTimer.Stop ()
18681872
if world.Alive then
18691873

1870-
// update screen transitioning process
1871-
World.updateScreenTransition world
1872-
World.updateScreenRequestedSong world
1874+
// process screen transitioning
1875+
// NOTE: not bothering to do timing on this.
1876+
World.processScreenTransitioning world
18731877
if world.Alive then
18741878

18751879
// process HID inputs

Nu/Nu/World/WorldPrelude.fs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -641,7 +641,7 @@ module internal AmbientState =
641641
let internal restoreTasklets tasklets state =
642642
{ state with Tasklets = tasklets }
643643

644-
let internal addTasklet simulant tasklet state =
644+
let internal addTasklet (simulant : Simulant) tasklet state =
645645
{ state with
646646
Tasklets =
647647
match state.Tasklets.TryGetValue simulant with

0 commit comments

Comments
 (0)