{-# LANGUAGE Arrows #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE NamedFieldPuns #-}
{-# LANGUAGE RecordWildCards #-}
{-# LANGUAGE TypeFamilies #-}
module FRP.Rhine.Gloss.Internals where
import qualified Control.Category as Category
import Data.Functor.Identity (Identity)
import Control.Monad.Trans.MSF.Reader (readerS, runReaderS)
import Graphics.Gloss.Interface.Pure.Game
import FRP.Rhine
import FRP.Rhine.Clock.Select
errMsg :: String
errMsg = "You cannot start gloss apps with FRP.Rhine.flow. "
++ "Use FRP.Rhine.Gloss.flowGloss instead."
data GlossEventClock = GlossEventClock
instance Clock m GlossEventClock where
type TimeDomainOf GlossEventClock = ()
type Tag GlossEventClock = Event
startClock _ = error errMsg
data GlossSimulationClock_ = GlossSimulationClock_
instance Clock m GlossSimulationClock_ where
type TimeDomainOf GlossSimulationClock_ = ()
type Tag GlossSimulationClock_ = Float
startClock _ = error errMsg
data GlossSimulationClock = GlossSimulationClock
instance Clock m GlossSimulationClock where
type TimeDomainOf GlossSimulationClock = Float
type Tag GlossSimulationClock = ()
startClock _ = error errMsg
withProperSimClock
:: Monad m
=> SyncSF m GlossSimulationClock a b
-> SyncSF m GlossSimulationClock_ a b
withProperSimClock syncsf = readerS
$ (intermingle *** Category.id) >>> runReaderS syncsf
where
intermingle :: Monad m => MSF m (TimeInfo GlossSimulationClock_) (TimeInfo GlossSimulationClock)
intermingle = proc TimeInfo {tag} -> do
let sinceTick = tag
absolute <- sumS -< sinceTick
let sinceStart = absolute
returnA -< TimeInfo { tag = (), .. }
data GlossGraphicsClock = GlossGraphicsClock
instance Clock m GlossGraphicsClock where
type TimeDomainOf GlossGraphicsClock = ()
type Tag GlossGraphicsClock = ()
startClock _ = error errMsg
glossSchedule :: Schedule Identity (SelectClock GlossEventClock a) GlossSimulationClock_
glossSchedule = error errMsg