{-# LANGUAGE Arrows #-}
{-# LANGUAGE RecordWildCards #-}
module FRP.Rhine.Gloss.Pure.Combined where
import FRP.Rhine
import FRP.Rhine.Reactimation.ClockErasure
import FRP.Rhine.Gloss.Common
import FRP.Rhine.Gloss.Pure
type GlossCombinedClock a =
SequentialClock
GlossM
(GlossEventClock a)
GlossSimulationClock
glossSchedule :: Schedule GlossM (GlossEventClock a) GlossSimulationClock
glossSchedule :: forall a. Schedule GlossM (GlossEventClock a) GlossSimulationClock
glossSchedule = forall (m :: * -> *) cl a b.
(Monad m, Semigroup cl, Clock m cl) =>
Schedule m (SelectClock cl a) (SelectClock cl b)
schedSelectClocks
type GlossEventClock a = SelectClock GlossClock a
glossEventSelectClock ::
(Event -> Maybe a) ->
GlossEventClock a
glossEventSelectClock :: forall a. (Event -> Maybe a) -> GlossEventClock a
glossEventSelectClock Event -> Maybe a
selector =
SelectClock
{ mainClock :: GlossClock
mainClock = GlossClock
GlossClock
, select :: Tag GlossClock -> Maybe a
select = (forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= Event -> Maybe a
selector)
}
glossEventClock :: GlossEventClock Event
glossEventClock :: GlossEventClock Event
glossEventClock = forall a. (Event -> Maybe a) -> GlossEventClock a
glossEventSelectClock forall a. a -> Maybe a
Just
type GlossSimulationClock = SelectClock GlossClock ()
glossSimulationClock :: GlossSimulationClock
glossSimulationClock :: GlossSimulationClock
glossSimulationClock = SelectClock {GlossClock
forall {a}. Maybe a -> Maybe ()
select :: forall {a}. Maybe a -> Maybe ()
mainClock :: GlossClock
select :: Tag GlossClock -> Maybe ()
mainClock :: GlossClock
..}
where
mainClock :: GlossClock
mainClock = GlossClock
GlossClock
select :: Maybe a -> Maybe ()
select (Just a
_event) = forall a. Maybe a
Nothing
select Maybe a
Nothing = forall a. a -> Maybe a
Just ()
type GlossRhine a = Rhine GlossM (GlossCombinedClock a) () ()
buildGlossRhine ::
(Event -> Maybe a) ->
ClSF GlossM GlossSimulationClock [a] () ->
GlossRhine a
buildGlossRhine :: forall a.
(Event -> Maybe a)
-> ClSF GlossM GlossSimulationClock [a] () -> GlossRhine a
buildGlossRhine Event -> Maybe a
selector ClSF GlossM GlossSimulationClock [a] ()
clsfSim =
forall (m :: * -> *) cl b a.
Monad m =>
(TimeInfo cl -> b) -> ClSF m cl a b
timeInfoOf forall cl. TimeInfo cl -> Tag cl
tag forall cl (m :: * -> *) a b.
(cl ~ In cl, cl ~ Out cl) =>
ClSF m cl a b -> cl -> Rhine m cl a b
@@ forall a. (Event -> Maybe a) -> GlossEventClock a
glossEventSelectClock Event -> Maybe a
selector
forall (m :: * -> *) cl1 a b cl2 c.
Rhine m cl1 a b
-> ResamplingPoint m cl1 cl2 b c
-> RhineAndResamplingPoint m cl1 cl2 a c
>-- forall (m :: * -> *) cl1 cl2 a.
Monad m =>
ResamplingBuffer m cl1 cl2 a [a]
collect forall (m :: * -> *) cl1 cl2 a b.
ResamplingBuffer m (Out cl1) (In cl2) a b
-> Schedule m cl1 cl2 -> ResamplingPoint m cl1 cl2 a b
-@- forall a. Schedule GlossM (GlossEventClock a) GlossSimulationClock
glossSchedule
forall (m :: * -> *) cl1 cl2 a b c.
(Clock m cl1, Clock m cl2, Time cl1 ~ Time cl2,
Time (Out cl1) ~ Time cl1, Time (In cl2) ~ Time cl2,
Clock m (Out cl1), Clock m (Out cl2), Clock m (In cl1),
Clock m (In cl2), GetClockProxy cl1, GetClockProxy cl2) =>
RhineAndResamplingPoint m cl1 cl2 a b
-> Rhine m cl2 b c -> Rhine m (SequentialClock m cl1 cl2) a c
--> ClSF GlossM GlossSimulationClock [a] ()
clsfSim forall cl (m :: * -> *) a b.
(cl ~ In cl, cl ~ Out cl) =>
ClSF m cl a b -> cl -> Rhine m cl a b
@@ GlossSimulationClock
glossSimulationClock
flowGlossCombined ::
GlossSettings ->
GlossRhine a ->
IO ()
flowGlossCombined :: forall a. GlossSettings -> GlossRhine a -> IO ()
flowGlossCombined GlossSettings
settings Rhine {SN GlossM (GlossCombinedClock a) () ()
GlossCombinedClock a
sn :: forall (m :: * -> *) cl a b. Rhine m cl a b -> SN m cl a b
clock :: forall (m :: * -> *) cl a b. Rhine m cl a b -> cl
clock :: GlossCombinedClock a
sn :: SN GlossM (GlossCombinedClock a) () ()
..} = forall {cl} {b}.
Clock GlossM cl =>
GlossSettings -> cl -> MSF GlossM (Time cl, Tag cl) b -> IO ()
flowGlossWithWorldMSF GlossSettings
settings GlossCombinedClock a
clock forall a b. (a -> b) -> a -> b
$ proc (Time (GlossCombinedClock a), Tag (GlossCombinedClock a))
tick -> do
forall (m :: * -> *) cl a b.
(Monad m, Clock m cl, GetClockProxy cl) =>
Time cl
-> SN m cl a b -> MSF m (Time cl, Tag cl, Maybe a) (Maybe b)
eraseClockSN Float
0 SN GlossM (GlossCombinedClock a) () ()
sn
-< case (Time (GlossCombinedClock a), Tag (GlossCombinedClock a))
tick of
(Time (GlossCombinedClock a)
_, Left a
event) -> (Float
0, forall a b. a -> Either a b
Left a
event, forall a. a -> Maybe a
Just ())
(Time (GlossCombinedClock a)
diffTime, Right ()) -> (Time (GlossCombinedClock a)
diffTime, forall a b. b -> Either a b
Right (), forall a. Maybe a
Nothing)