rhine-gloss-0.8.1.1: Gloss backend for Rhine
Safe HaskellSafe-Inferred
LanguageHaskell2010

FRP.Rhine.Gloss.Pure.Combined

Description

A pure gloss backend for Rhine, with separated event and simulation loop.

To run pure Rhine apps with gloss, write a signal network (SN) in the GlossCombinedClock and use flowGlossCombined. As an easy starter, you can use the helper function buildGlossRhine.

Synopsis

Documentation

type GlossCombinedClock a = SequentialClock GlossM (GlossEventClock a) GlossSimulationClock Source #

The overall clock of a pure rhine SN that can be run by gloss. It is combined of two subsystems, the event part and the simulation part. a is the type of subevents that are selected.

Events

type GlossEventClock a = SelectClock GlossClock a Source #

The clock that ticks whenever a specific gloss event occurs.

glossEventSelectClock :: (Event -> Maybe a) -> GlossEventClock a Source #

Select the relevant events by converting them to Just a, and the irrelevant ones to Nothing.

Simulation

type GlossSimulationClock = SelectClock GlossClock () Source #

The clock that ticks for every gloss simulation step.

Signal networks

type GlossRhine a = Rhine GlossM (GlossCombinedClock a) () () Source #

The type of a valid Rhine that can be run by gloss, if you chose to separate events and simulation into two subsystems. a is the type of subevents that are selected.

All painting has to be done in GlossM, e.g. via the paint method.

Typically, such a Rhine is built something like this:

-- | Select only key press events
myEventClock :: GlossEventClock Key
myEventClock = glossEventSelectClock selector
  where
    selector (EventKey key _ _ _) = Just key
    selector _ = Nothing

myEventSubsystem :: ClSF GlossM GlossEventClock () MyType
myEventSubsystem = ...

mySim :: ClSF GlossM GlossSimulationClock [MyType] ()
mySim = ...

myGlossRhine :: GlossRhine a
myGlossRhine
  = myEventSubsystem @ myEventClock >-- collect -- glossSchedule --> mySim @@ glossSimulationClock

buildGlossRhine Source #

Arguments

:: (Event -> Maybe a)

The event selector

-> ClSF GlossM GlossSimulationClock [a] ()

The ClSF representing the game loop.

-> GlossRhine a 

For most applications, it is sufficient to implement a single signal function that is called with a list of all relevant events that occurred in the last tick.

Reactimation

flowGlossCombined Source #

Arguments

:: GlossSettings 
-> GlossRhine a

The gloss-compatible Rhine.

-> IO () 

The main function that will start the gloss backend and run the SN.