diff --git a/examples/flappy/Main.hs b/examples/flappy/Main.hs index cb3078c..f9f08fb 100644 --- a/examples/flappy/Main.hs +++ b/examples/flappy/Main.hs @@ -398,6 +398,6 @@ main = do run engine defaultConfig GameLifecycle { initialFn = initial , updateFn = update - , subscriptionsFn = subscriptions + , subscriptionsFn = const subscriptions , viewFn = view } diff --git a/examples/hello/Main.hs b/examples/hello/Main.hs index ebe574d..2e952b9 100644 --- a/examples/hello/Main.hs +++ b/examples/hello/Main.hs @@ -32,6 +32,6 @@ main = do run engine defaultConfig GameLifecycle { initialFn = initial , updateFn = update - , subscriptionsFn = subscriptions + , subscriptionsFn = const subscriptions , viewFn = view } diff --git a/src/Helm.hs b/src/Helm.hs index 76550e4..1ee93fb 100644 --- a/src/Helm.hs +++ b/src/Helm.hs @@ -45,17 +45,20 @@ run -> GameConfig -> GameLifecycle e m a -- ^ The configuration for running the game. -> IO () -- ^ An IO monad that blocks the main thread until the engine quits. -run engine config lifecycle@GameLifecycle { initialFn, subscriptionsFn = Sub sigGen } = void $ do +run engine config lifecycle@GameLifecycle { initialFn, subscriptionsFn } = void $ do {- The call to 'embed' here is a little bit hacky, but seems necessary to get this working. This is because 'start' actually computes the signal gen passed to it, and all of our signal gens try to fetch the 'input' value within the top layer signal gen (rather than in the contained signal). But we haven't sampled with the input value yet, so it'll be undefined unless we 'embed'. -} + let (initialModel, initialCmds) = initialFn + (Sub sigGen) = subscriptionsFn initialModel + smp <- start $ embed (return engine) sigGen -- Setup the initial engine context and perform the initial game step - ctx@(EngineContext engine_ _) <- flip stepCmd (snd initialFn) $ EngineContext engine Game + ctx@(EngineContext engine_ _) <- flip stepCmd initialCmds $ EngineContext engine Game { gameConfig = config , gameLifecycle = lifecycle , gameModel = fst initialFn diff --git a/src/Helm/Engine.hs b/src/Helm/Engine.hs index 1e2dc84..e3996bc 100644 --- a/src/Helm/Engine.hs +++ b/src/Helm/Engine.hs @@ -148,7 +148,7 @@ data GameLifecycle e m a = GameLifecycle { -- If no subscriptions are required (i.e. no user input is required), -- pass 'Sub.none'. Alternatively, if multiple subscriptions are required -- use 'Sub.batch' to combine them. - subscriptionsFn :: Sub e a, + subscriptionsFn :: m -> Sub e a, -- | Called when the engine is ready to render the game. -- The function is given the current state of the game model