Skip to content

Commit

Permalink
dunai-examples: Upgrade example to use SDL2. Refs ivanperez-keera#446
Browse files Browse the repository at this point in the history
SDL 1 is deprecated, and no longer maintained. To keep the example
working with more modern versions of packages in the Haskell ecosystem,
this commit ports bouncingball to use SDL2.
  • Loading branch information
mchav committed Nov 4, 2024
1 parent 85bb794 commit 3511a19
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions dunai-examples/bouncingball/BouncingBall.hs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ main = do

reactimate (return ())
(\_ -> return (0.005, Just ()))
(\_ e -> render e renderer >> return False)
(\_ e -> render e renderer)
sf

sf = bouncingBall (100.0 :: Float) 0.0
Expand Down Expand Up @@ -65,8 +65,12 @@ fallingBall p0 v0 = proc () -> do
-- whenS :: (a -> Bool) -> SF a (Yampa.Event a)
-- whenS p = (((arr p >>> edge) &&& arr id) >>> (arr (uncurry tag)))

render :: RealFrac a => (a, b) -> SDL.Renderer -> IO ()
render :: RealFrac a => (a, b) -> SDL.Renderer -> IO Bool
render (p,_) renderer = do
events <- SDL.pollEvents
let quit = elem SDL.QuitEvent $ map SDL.eventPayload events

-- Set background.
let white = SDL.V4 maxBound maxBound maxBound maxBound
SDL.rendererDrawColor renderer SDL.$= white
SDL.clear renderer
Expand All @@ -80,6 +84,8 @@ render (p,_) renderer = do

threadDelay 1000

return quit

-- * Auxiliary functions

-- | Integrate a linearly changing input.
Expand Down

0 comments on commit 3511a19

Please sign in to comment.