24 lines
622 B
Haskell
24 lines
622 B
Haskell
{-# LANGUAGE ExistentialQuantification #-}
|
|
module Scenes.SceneClass where
|
|
|
|
import qualified SDL
|
|
|
|
class SceneClass a where
|
|
|
|
-- | Perform initialization.
|
|
initScene :: IO a
|
|
|
|
-- | Run updates on the data given the time elapsed since last frame
|
|
update :: a -> Float -> IO ()
|
|
|
|
-- | Handle input events
|
|
onEvents :: a -> [SDL.Event] -> IO ()
|
|
|
|
-- | perform the drawing
|
|
render :: a -> IO ()
|
|
|
|
-- Existential type wrapper to make all Scenes implementing SceneClass
|
|
-- homogenous.
|
|
-- See more at https://wiki.haskell.org/Existential_type#Dynamic_dispatch_mechanism_of_OOP
|
|
data Scene = forall a. SceneClass a => Scene a
|