From f1939232bec72fffede16a55119bc7c4fb3057cf Mon Sep 17 00:00:00 2001 From: 3gg <3gg@shellblade.net> Date: Mon, 30 Dec 2024 19:14:12 -0800 Subject: Simplify Game monad. --- Demos/Pong/Main.hs | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) (limited to 'Demos/Pong/Main.hs') diff --git a/Demos/Pong/Main.hs b/Demos/Pong/Main.hs index de8e6f2..df90020 100644 --- a/Demos/Pong/Main.hs +++ b/Demos/Pong/Main.hs @@ -41,16 +41,16 @@ initGame window = do endGame :: Game GameState () endGame = do - game <- getGameState + game <- get runSubGame' (deleteImmRenderer $ immRenderState game) (renderCoreState game) step :: Elapsed -> Dt -> [InputEvent] -> Game GameState Bool step elapsed dt inputEvents = do - gs <- getGameState + gs <- get events <- processInput (window gs) - --when (events /= []) $ gameIO . putStrLn $ show events - modifyGameState $ \gs -> + --when (events /= []) $ liftIO . putStrLn $ show events + modify $ \gs -> gs { world = stepWorld (realToFrac elapsed) (realToFrac dt) events (world gs) } @@ -67,18 +67,18 @@ exitRequested = elem (KeyDown KEY_ESC) render :: Game GameState () render = do - gameState <- getGameState + gameState <- get immRenderState' <- flip execSubGame (immRenderState gameState) $ do immStart immSetViewProjectionMatrix (viewProjection gameState) -- Clear the background to a different colour than the playable area to make -- the latter distinguishable. - gameIO $ do + liftIO $ do setClearColour (0.2, 0.2, 0.2, 0.0) clearBuffers [ColourBuffer] render' $ world gameState immEnd - saveGameState $ gameState { immRenderState = immRenderState' } + put $ gameState { immRenderState = immRenderState' } render' :: [GameObject] -> Game ImmRenderState () render' world = do @@ -122,7 +122,7 @@ resize (ResizeEvent w h) = bottom = if r > 1 then 0 else -pad top = if r > 1 then 1 else 1 + pad in do - gameIO $ setViewport 0 0 w h - modifyGameState $ \state -> state { + liftIO $ setViewport 0 0 w h + modify $ \state -> state { viewProjection = Matrix4.ortho left right bottom top (-1) 1 } -- cgit v1.2.3