{-# 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
import FRP.Rhine.Clock.Select
import FRP.Rhine.Reactimation.Tick
import FRP.Rhine.ResamplingBuffer.Collect
import FRP.Rhine.ResamplingBuffer.KeepLast
import qualified FRP.Rhine as X
import qualified FRP.Rhine.SyncSF 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 GlossSyncSF a = SyncSF Identity GlossSimulationClock [a] Picture
buildGlossRhine
:: (Event -> Maybe a)
-> GlossSyncSF a
-> GlossRhine a
buildGlossRhine select syncsfSim
= timeInfoOf tag @@ SelectClock { mainClock = GlossEventClock, .. }
>-- collect -@- glossSchedule
--> withProperSimClock syncsfSim @@ 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) sf 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