module FranTime where
import BaseTypes
import IOExts

-- we want access to the current time in Fran, so use another
-- of these unpleasant global variables

franTime :: IORef Time
franTime = unsafePerformIO $ newIORef 0

{-# NOINLINE franTime #-}

resetFranTime :: Time -> IO ()
resetFranTime t = writeIORef franTime t

getFranTime :: IO Time
getFranTime = readIORef franTime

getTime = getFranTime

-- time MUST INCREASE every time we run this, for cached behaviors
-- to work

setFranTime :: Time -> IO Time
setFranTime t = do
 v <- getFranTime 
 let t' = (if t <= v then v + tickRunDelay else t)
 t' `seq` resetFranTime t'
 return t'

tickRunDelay :: DTime
tickRunDelay = 0.001
