Module

Game.Aff

Package
purescript-game
Repository
artemisSystem/purescript-game

#_dt Source

_dt :: SProxy "dt"

#_end Source

_end :: SProxy "end"

#_stateRef Source

_stateRef :: SProxy "stateRef"

#_env Source

_env :: SProxy "env"

#OnStartExecIn Source

type OnStartExecIn e s a r = (aff :: AFF, effect :: EFFECT, end :: EXCEPT a, env :: READER e, state :: STATE s | r)

The execIn effects that are used for the onStart update

#LoopExecIn Source

type LoopExecIn e s a r = (aff :: AFF, dt :: READER Seconds, effect :: EFFECT, end :: EXCEPT a, env :: READER e, state :: STATE s | r)

The execIn effects that are used for most loop updates

#ExecOut Source

type ExecOut e s a = (aff :: AFF, effect :: EFFECT, end :: EXCEPT a, env :: READER e, stateRef :: READER (Ref s))

The execOut effects for TemplateAffGame

#Interpreted Source

type Interpreted e s = (aff :: AFF, effect :: EFFECT, env :: READER e, stateRef :: READER (Ref s))

The effects in an interpreted TemplateAffGame

#Req Source

type Req = (aff :: AFF, effect :: EFFECT)

The effect and aff effects are required to be supported by every AffGameUpdate. Reducers for AffGame can interpret the extra effects in terms of them.

#AffGame Source

newtype AffGame extra a

An AffGame is an Aff that takes a Reducer as an argument. Can be constructed from a TemplateAffGame using mkAffGame.

Constructors

Instances

#ParAffGame Source

newtype ParAffGame extra a

A variant of AffGame that composes effects in parallel

Instances

#simpleAffGame Source

simpleAffGame :: forall a extra. Run (aff :: AFF, effect :: EFFECT | extra) a -> AffGame extra a

Construct a simple AffGame using a Run whose effect row includes the AffGame's extra row

#AffGameUpdate Source

type AffGameUpdate extra e s a = GameUpdate extra Req (ExecOut e s a) Unit

#TemplateAffGame Source

type TemplateAffGame extra e s a = { init :: Run (aff :: AFF, effect :: EFFECT) { env :: e, initState :: s }, updates :: Array (AffGameUpdate extra e s a) }

#interpretAffGame Source

interpretAffGame :: forall a s e. Run (ExecOut e s a) Unit -> Run (Interpreted e s) a

#parallelizeAffGame Source

parallelizeAffGame :: forall a s e. Array (Run (Interpreted e s) a) -> Run (Interpreted e s) a

#mkAffGame Source

mkAffGame :: forall a s e extra. TemplateAffGame extra e s a -> AffGame extra a

Make an AffGame from a TemplateAffGame

#runGame Source

runGame :: forall r a extra. Reducer extra Req -> AffGame extra a -> Run (aff :: AFF | r) a

Run an AffGame in Run

#runGameAff Source

runGameAff :: forall a extra. Reducer extra Req -> AffGame extra a -> Aff a

Run an AffGame in Aff

#launchGame Source

launchGame :: forall a extra. Reducer extra Req -> AffGame extra a -> Effect (Fiber a)

Launch an AffGame in Effect, returning the Fiber.

#launchGame_ Source

launchGame_ :: forall a extra. Reducer extra Req -> AffGame extra a -> Effect Unit

Launch an AffGame in Effect. Discards the result value.

#onStart Source

onStart :: forall a s e extra. Run (OnStartExecIn e s a extra) Unit -> AffGameUpdate extra e s a

An AffGameUpdate that runs once when the AffGame starts

#loopUpdate Source

loopUpdate :: forall b a s e extra. Aff Unit -> Run (LoopExecIn e s a extra) b -> (b -> Run (LoopExecIn e s a extra) b) -> AffGameUpdate extra e s a

Create an AffGameUpdate that runs in loops, using the Aff Unit as a waiting action inbetween

#loopUpdate' Source

loopUpdate' :: forall a s e extra. Aff Unit -> Run (LoopExecIn e s a extra) Unit -> AffGameUpdate extra e s a

Create a simple loop update that runs the same action repeatedly, using the Aff Unit as a waiting action inbetween

#matchInterval Source

matchInterval :: forall d a s e extra. Duration d => Aff Unit -> Run (LoopExecIn e s a extra) d -> Run (LoopExecIn e s a extra) Unit -> AffGameUpdate extra e s a

Create a loop that on every iteration (distinguished by the Aff Unit) tries to match the interval returned by the first Run action. It will not run the second Run action (the "update") when looping if the given duration has not passed since the last update was run.

It compensates for lost time, so that if the duration is a pure (Milliseconds 10.0), and the waiting action alternates between resolving after 12ms and 8ms, when the update is first run after 12ms, matchInterval will remember that it is 2ms behind, and run the update again when the waiting action resolves after another 8ms. Also, if the waiting action is long enough that 3 times the returned duration has passed since the last update, it will clear the accumulated time difference and run the update once. This is so that if the waiting action takes a lot longer to resolve one time, a bunch of updates won't pile up and run in quick succession (otherwise, this can happen if you switch away from a tab when using delayFrame as your waiting action, as it will stop updating until the tab becomes active again).

#FPS Source

newtype FPS

A newtype with a Duration instance, where the stored number describes an amount of frames per second. Running fromDuration will return the amount of milliseconds a frame will take at that framerate. fromDuration (FPS 0.0) is Milliseconds 0.0.

Constructors

Instances

Re-exports from Game

#Reducer Source

data Reducer (extra :: Row Type) (req :: Row Type)

#GameUpdate Source

newtype GameUpdate (extra :: Row Type) (req :: Row Type) (execOut :: Row Type) a

Constructors

#runReducer Source

runReducer :: forall a req_execIn req extra nubExecIn execIn update. Union execIn extra update => Union req execIn req_execIn => Nub execIn nubExecIn => Nub req_execIn nubExecIn => Reducer extra req -> (Run update a -> Run execIn a)

Turn a Reducer into a function that acts on a specific effect row

#mkReducer Source

mkReducer :: forall extra_req req extra. Union extra req extra_req => ((Run (Anything + extra_req)) ~> (Run (Anything + req))) -> Reducer extra req

Create a Reducer. Note: doing mkReducer $ f will raise an EscapedSkolem error. Use parentheses or do instead of $.