From ae29688a6bcd05daf9154fb5792861723afdb1ed Mon Sep 17 00:00:00 2001
From: 3gg <3gg@shellblade.net>
Date: Thu, 2 Jan 2025 09:58:14 -0800
Subject: Introduce HasState to simplify state programming.

---
 Demos/Pong/Main.hs | 20 +++++---------------
 1 file changed, 5 insertions(+), 15 deletions(-)

(limited to 'Demos/Pong')

diff --git a/Demos/Pong/Main.hs b/Demos/Pong/Main.hs
index 993c0ff..22b1021 100644
--- a/Demos/Pong/Main.hs
+++ b/Demos/Pong/Main.hs
@@ -7,7 +7,7 @@ import           Pong
 import           Spear.App
 import           Spear.Game
 import           Spear.Math.AABB
-import           Spear.Math.Matrix4         as Matrix4 hiding (position)
+import           Spear.Math.Matrix4         as Matrix4
 import           Spear.Math.Spatial
 import           Spear.Math.Spatial2
 import           Spear.Math.Vector
@@ -20,12 +20,10 @@ import           Spear.Sound.State
 import           Spear.Window
 
 import           Control.Monad              (when)
-import           Data.Maybe                 (mapMaybe)
 
 
 data Pong = Pong
-  { immRenderState  :: ImmRenderState
-  , viewProjection  :: Matrix4
+  { viewProjection  :: Matrix4
   , backgroundMusic :: SoundSource
   , world           :: [GameObject]
   }
@@ -43,10 +41,6 @@ main = runApp app
 
 initGame :: Game AppContext Pong
 initGame = do
-  renderCoreState <- contextRenderCoreState <$> get
-  (immRenderState, renderCoreState') <- runSiblingGame renderCoreState newImmRenderer
-  -- TODO: This can work if we use FlexibleContexts and change the function signatures.
-  --immRenderState <- newImmRenderer
   music <- siblingGame $ do
     musicBuffer <- loadAudioFile "/home/jeanne/Casual Tiki Party Main.wav"
     music <- makeSoundSource
@@ -54,13 +48,10 @@ initGame = do
     setSoundLoopMode music Loop
     playSounds [music]
     return music
-  return $ Pong immRenderState Matrix4.id music newWorld
+  return $ Pong Matrix4.id music newWorld
 
 endGame :: Game GameState ()
-endGame = do
-  renderCoreState <- appRenderCoreState <$> get
-  game <- getGameState
-  exec' runSiblingGame renderCoreState (deleteImmRenderer $ immRenderState game)
+endGame = return ()
 
 
 step :: Elapsed -> Dt -> [InputEvent] -> Game GameState Bool
@@ -86,7 +77,7 @@ exitRequested = elem (KeyDown KEY_ESC)
 render :: Game GameState ()
 render = do
   gameState <- getGameState
-  immRenderState' <- exec runSiblingGame (immRenderState gameState) $ do
+  siblingGame $ do
     immStart
     immSetViewProjectionMatrix (viewProjection gameState)
     -- Clear the background to a different colour than the playable area to make
@@ -95,7 +86,6 @@ render = do
     clearBuffers [ColourBuffer]
     render' $ world gameState
     immEnd
-  putGameState $ gameState { immRenderState = immRenderState' }
 
 render' :: [GameObject] -> Game ImmRenderState ()
 render' world = do
-- 
cgit v1.2.3