Skip to content

User controlled tick rate #379

Answered by turion
reubenharry asked this question in Q&A
Dec 3, 2024 · 1 comments · 2 replies
Discussion options

You must be logged in to vote

That's a simple but great question! The answer is yes, this should be easily possible. I'd solve this by using a monad to communicate the clock rate to the clock. Something like this:

data VaryingClock = VaryingClock

defaultRate :: Double
defaultRate = 0.1

instance (MonadAccum (Last Double) m, MonadIO m) => Clock m VaryingClock where
  type Time VaryingClock = Double
  type Tag VaryingClock = ()
  initClock _ = return ((constM look >>> arr (getLast >>> fromMaybe defaultRate) >>> sumN) &&& arr (const ()), 0)

setRate :: MonadAccum (Last Double) m => ClSF m cl Double ()
setRate = arrM $ add . Last . Just

This uses the Accum monad to read the last set clock rate. (We can't use StateT becau…

Replies: 1 comment 2 replies

Comment options

You must be logged in to vote
2 replies
@reubenharry
Comment options

@turion
Comment options

Answer selected by reubenharry
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants