From 156a338d48ecc26eb0bed223ca4d0ba54e030c12 Mon Sep 17 00:00:00 2001 From: kiana-S Date: Tue, 28 Dec 2021 16:38:15 -0500 Subject: [PATCH] Reformat Graphics.Engine --- Graphics/Engine.hs | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/Graphics/Engine.hs b/Graphics/Engine.hs index f284a9a..f5382c0 100644 --- a/Graphics/Engine.hs +++ b/Graphics/Engine.hs @@ -1,3 +1,4 @@ +{-# LANGUAGE LambdaCase #-} module Graphics.Engine where import Control.Arrow @@ -5,13 +6,26 @@ import Control.Monad.Representable.Reader import FRP.Yampa import GOL.Engine import GOL.Space +import Graphics.Config +import Graphics.Gloss import Graphics.GlossUtils (InputEvent) +import Graphics.Gloss.Interface.IO.Game hiding (Event) +import qualified Graphics.Gloss.Interface.IO.Game as G -tickEvent :: SF a (Event ()) -tickEvent = repeatedly 1.0 () +data Tick = Tick initialSpace :: Space f => f Bool initialSpace = tabulate $ const False -engine :: Space f => GOL f Bool -> SF a (GOL f Bool) -engine start = tickEvent >>> accumHoldBy (\s _ -> tick s) start \ No newline at end of file +engine :: Space f => GOL f Bool -> SF (Event Tick) (GOL f Bool) +engine = accumHoldBy (\s _ -> tick s) + +defaultPeriod = 0.5 + +repeatTick :: Time -> SF a (Event Tick) +repeatTick t = repeatedly t Tick + +tickSignal :: SF (Event Time) (Event Tick) +tickSignal = + arr (\ev -> ((), fmap repeatTick ev)) + >>> drSwitch (repeatTick defaultPeriod)