Skip to content

Commit

Permalink
guarding against cases in which logical time and clock time diverge i…
Browse files Browse the repository at this point in the history
…n renderer
  • Loading branch information
David Ogborn authored and David Ogborn committed Oct 26, 2018
1 parent fa6699d commit 1890c8c
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 5 deletions.
2 changes: 0 additions & 2 deletions Estuary/Makefile

This file was deleted.

12 changes: 10 additions & 2 deletions Estuary/Renderer.hs
Original file line number Diff line number Diff line change
Expand Up @@ -114,9 +114,17 @@ sleepUntilNextRender = do
s <- get
let next = addUTCTime renderPeriod (logicalTime s)
let diff = diffUTCTime next (renderEndTime s)
let delay = floor $ realToFrac diff * 1000000 - 10000 -- ie. wakeup ~ 10 milliseconds before next logical time
next' <- liftIO $ if diff > 0 then return next else do
putStrLn "*** logical time too far behind clock time - fast forwarding"
return $ addUTCTime (diff * (-1) + 0.01) next -- fast forward so next logical time is 10 milliseconds after clock time
let diff' = diffUTCTime next' (renderEndTime s)
next'' <- liftIO $ if diff' < (renderPeriod*2) then return next' else do -- not allowed to get more than 1 render period ahead
putStrLn "*** logical time too far ahead of clock time - rewinding"
return $ addUTCTime renderPeriod $ renderEndTime s
let diff'' = diffUTCTime next'' (renderEndTime s)
let delay = floor $ realToFrac diff'' * 1000000 - 10000 -- ie. wakeup ~ 10 milliseconds before next logical time
liftIO $ threadDelay delay
put $ s { logicalTime = next }
put $ s { logicalTime = next'' }

calculateRenderTimes :: Renderer
calculateRenderTimes = do
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ releaseClient: # make installClient or prodInstallClient first!

curlReleaseClient: # this uses curl to download and unzip a recent pre-built client from a GitHub release
rm -rf Estuary.jsexe
curl -o temp.zip -L https://github.com/d0kt0r0/estuary/releases/download/20181025/estuary-client-20181025.zip
curl -o temp.zip -L https://github.com/d0kt0r0/estuary/releases/download/20181026/estuary-client-20181026.zip
unzip temp.zip
rm -rf temp.zip
cp -Rf static/Dirt Estuary.jsexe
Expand Down

0 comments on commit 1890c8c

Please sign in to comment.