Skip to content
This repository has been archived by the owner on Jan 17, 2020. It is now read-only.

Change subscriptionsFn to take a model as an argument #125

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion examples/flappy/Main.hs
Original file line number Diff line number Diff line change
Expand Up @@ -398,6 +398,6 @@ main = do
run engine defaultConfig GameLifecycle
{ initialFn = initial
, updateFn = update
, subscriptionsFn = subscriptions
, subscriptionsFn = const subscriptions
, viewFn = view
}
2 changes: 1 addition & 1 deletion examples/hello/Main.hs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,6 @@ main = do
run engine defaultConfig GameLifecycle
{ initialFn = initial
, updateFn = update
, subscriptionsFn = subscriptions
, subscriptionsFn = const subscriptions
, viewFn = view
}
2 changes: 1 addition & 1 deletion helm.cabal
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: helm
version: 2.0.0
version: 3.0.0
Copy link
Owner

@z0w0 z0w0 Oct 15, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should stay at 2.0.0 as that hasn't actually been released yet

synopsis: A functionally reactive game engine.
description: A functionally reactive game engine, with headgear to protect you
from the headache of game development provided.
Expand Down
7 changes: 5 additions & 2 deletions src/Helm.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/Helm/Engine.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down