Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix docs and make GlossEnv available to users
Browse files Browse the repository at this point in the history
turion committed May 14, 2024
1 parent d04f01f commit 0e26505
Showing 1 changed file with 12 additions and 9 deletions.
21 changes: 12 additions & 9 deletions rhine-gloss/src/FRP/Rhine/Gloss/IO.hs
Original file line number Diff line number Diff line change
@@ -8,12 +8,14 @@

-- | Wrapper to write @gloss@ applications in Rhine, using concurrency.
module FRP.Rhine.Gloss.IO (
GlossConcT,
GlossEnv (..),
GlossConcT (..),
paintIO,
clearIO,
paintAllIO,
GlossEventClockIO (..),
GlossSimClockIO (..),
makeGlossEnv,
launchInGlossThread,
launchGlossThread,
flowGlossIO,
@@ -119,21 +121,22 @@ instance GetClockProxy GlossSimClockIO

-- * Reactimation

{- | Apply this to supply the 'GlossConcT' effect.
Creates a new thread in which @gloss@ is run,
and feeds the clocks 'GlossEventClockIO' and 'GlossSimClockIO'.
-- | Create the concurrent variables to communicate with the @gloss@ backend.
makeGlossEnv ::
(MonadIO m) =>
m GlossEnv
makeGlossEnv = liftIO $ GlossEnv <$> newEmptyMVar <*> newEmptyMVar <*> newIORef Blank <*> newIORef 0

Usually, this function is applied to the result of 'flow',
so you can handle all occurring effects as needed.
If you only use @gloss@ in your whole signal network,
you can use 'flowGlossIO' instead.
{- | Helper function for 'launchInGlossThread'.
Creates concurrent variables and launches the @gloss@ backend in a separate thread.
-}
launchGlossThread ::
(MonadIO m) =>
GlossSettings ->
m GlossEnv
launchGlossThread GlossSettings {..} = do
vars <- liftIO $ GlossEnv <$> newEmptyMVar <*> newEmptyMVar <*> newIORef Blank <*> newIORef 0
vars <- makeGlossEnv
let
getPic GlossEnv {picRef} = readIORef picRef
-- Only try to put so this doesn't hang in case noone is listening for events or ticks

0 comments on commit 0e26505

Please sign in to comment.