Use system sleep functions as threadDelay sleep to long without -threaded
This commit is contained in:
parent
c0d2d54ea1
commit
d6b28723a2
5 changed files with 17 additions and 4 deletions
|
@ -21,6 +21,9 @@ import qualified Data.Map as M
|
|||
import qualified Data.Set as S
|
||||
import Data.Time
|
||||
|
||||
import Foreign.C.Types
|
||||
|
||||
|
||||
main :: IO ()
|
||||
main = do
|
||||
let theLevel = testLevel
|
||||
|
@ -45,7 +48,7 @@ main = do
|
|||
deinitGL gl
|
||||
|
||||
minFrameTime :: NominalDiffTime
|
||||
minFrameTime = 0.01
|
||||
minFrameTime = 0.02
|
||||
|
||||
mainLoop :: Main ()
|
||||
mainLoop = do
|
||||
|
@ -60,9 +63,10 @@ mainLoop = do
|
|||
rtime <- liftIO getCurrentTime
|
||||
let drender = diffUTCTime rtime t
|
||||
when (drender < minFrameTime) $
|
||||
liftIO $ threadDelay $ truncate $ 1e6*(minFrameTime - drender)
|
||||
liftIO $ usleep gl $ truncate $ 1e6*(minFrameTime - drender)
|
||||
|
||||
currenttime <- liftIO getCurrentTime
|
||||
liftIO $ print $ diffUTCTime currenttime rtime
|
||||
let d = round $ 1e2*(diffUTCTime currenttime t)
|
||||
|
||||
replicateM_ d simulationStep
|
||||
|
@ -74,7 +78,6 @@ mainLoop = do
|
|||
runnext <- gets run
|
||||
when runnext mainLoop
|
||||
|
||||
|
||||
handleEvents :: Main ()
|
||||
handleEvents = do
|
||||
(newgl, event) <- gets driver >>= liftIO . nextEvent
|
||||
|
|
Reference in a new issue