-
Notifications
You must be signed in to change notification settings - Fork 2
/
sample_scheduler.hs
51 lines (38 loc) · 1.16 KB
/
sample_scheduler.hs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
{-# LANGUAGE TemplateHaskell #-}
{-# LANGUAGE FlexibleContexts #-}
import Hate
import Hate.Graphics.Api.Shapes
import Hate.Common.Scheduler
import Control.Lens
data SampleState = SampleState {
_radius :: Float,
_sched :: Scheduler SampleState,
_firstRun :: Bool
}
makeLenses ''SampleState
sampleLoad :: LoadFn SampleState
sampleLoad = return $ SampleState 0 emptyScheduler True
sampleDraw :: DrawFn SampleState
sampleDraw p = [translate (Vec2 150 150) $ circle (p ^. radius)]
schedule' evt = sched %= (flip schedule) evt
every' t evt = every t evt >>= schedule'
after' t evt = after t evt >>= schedule'
sampleUpdate :: UpdateFn SampleState
sampleUpdate _ = do
-- repeated action
use firstRun >>= \p -> when p $ do
every' 1 $ radius += 50
firstRun .= False
use sched >>= process >>= assign sched
-- queue a waiting action
whenKeyPressed Key'Space $ after' 2 $ radius += 20
-- continuous action
radius *= 0.95
config :: Config
config =
Config
{ windowTitle = "Sample - Scheduler"
, windowSize = (1024, 768)
}
main :: IO ()
main = runApp config sampleLoad sampleUpdate sampleDraw