{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE NamedFieldPuns #-}
{-# LANGUAGE RecordWildCards #-}
{-# LANGUAGE TypeFamilies #-}
module FRP.Rhine.Gloss
( module FRP.Rhine.Gloss
, module X
)
where
import Data.Functor.Identity (Identity, runIdentity)
import qualified Control.Arrow as X
import Graphics.Gloss.Interface.Pure.Game
import qualified Graphics.Gloss as X
import FRP.Rhine hiding (trivialResamplingBuffer)
import FRP.Rhine.Reactimation.Tick
import qualified FRP.Rhine as X
import qualified FRP.Rhine.ClSF as X
import FRP.Rhine.Gloss.Internals
type GlossClock a
= SequentialClock Identity
(SelectClock GlossEventClock a)
GlossSimulationClock_
type GlossRhine a = Rhine Identity (GlossClock a) () Picture
type GlossClSF a = ClSF Identity GlossSimulationClock [a] Picture
buildGlossRhine
:: (Event -> Maybe a)
-> GlossClSF a
-> GlossRhine a
buildGlossRhine select clsfSim
= timeInfoOf tag @@ SelectClock { mainClock = GlossEventClock, .. }
>-- collect -@- glossSchedule
--> withProperSimClock clsfSim @@ GlossSimulationClock_
flowGloss
:: Display
-> Color
-> Int
-> GlossRhine a
-> IO ()
flowGloss display color n Rhine {..}
= play display color n world getPic handleEvent simStep
where
graphicsBuffer
:: ResamplingBuffer Identity
GlossSimulationClock_ GlossGraphicsClock
Picture Picture
graphicsBuffer = keepLast Blank
world = createTickable (trivialResamplingBuffer clock) sn graphicsBuffer ()
getPic Tickable { buffer2 } = fst $ runIdentity $ get buffer2 $ TimeInfo () () () ()
handleEvent event tickable = case select (sequentialCl1 clock) event of
Just a -> runIdentity $ tick tickable () $ Left a
Nothing -> tickable
simStep diff tickable = runIdentity $ tick tickable () $ Right diff