From a8c86c54cafffb9426600eba145b7d16a97de2e7 Mon Sep 17 00:00:00 2001 From: Aleksey Pirogov Date: Sun, 15 Oct 2017 22:24:11 +0300 Subject: [PATCH 1/2] Change `subscriptionsFn` to take a model as an argument --- examples/flappy/Main.hs | 2 +- examples/hello/Main.hs | 2 +- helm.cabal | 2 +- src/Helm.hs | 7 +++++-- src/Helm/Engine.hs | 2 +- 5 files changed, 9 insertions(+), 6 deletions(-) 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/helm.cabal b/helm.cabal index 22adb27..0b037de 100644 --- a/helm.cabal +++ b/helm.cabal @@ -1,5 +1,5 @@ name: helm -version: 2.0.0 +version: 3.0.0 synopsis: A functionally reactive game engine. description: A functionally reactive game engine, with headgear to protect you from the headache of game development provided. 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 From 3b335c20b7b9da6b656fdbde2f51902b8726043f Mon Sep 17 00:00:00 2001 From: Aleksey Pirogov Date: Mon, 16 Oct 2017 07:45:25 +0300 Subject: [PATCH 2/2] return version back --- helm.cabal | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/helm.cabal b/helm.cabal index 0b037de..22adb27 100644 --- a/helm.cabal +++ b/helm.cabal @@ -1,5 +1,5 @@ name: helm -version: 3.0.0 +version: 2.0.0 synopsis: A functionally reactive game engine. description: A functionally reactive game engine, with headgear to protect you from the headache of game development provided.