-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
352 additions
and
309 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
{-# LANGUAGE LambdaCase #-} | ||
{-# LANGUAGE RankNTypes #-} | ||
{-# LANGUAGE TemplateHaskell #-} | ||
|
||
module EffectfulQML where | ||
|
||
import Data.Typeable | ||
import Effectful | ||
import Effectful.Dispatch.Dynamic (interpret) | ||
import Effectful.State.Static.Shared (State, get) | ||
import Effectful.TH | ||
import Graphics.QML hiding (fireSignal, runEngineLoop) | ||
import Graphics.QML qualified as QML | ||
|
||
-- | Data type to hold a signal key and object reference | ||
data SignalUpdate | ||
= forall tt. | ||
( Typeable tt | ||
) => | ||
SignalUpdate | ||
{ signalKey :: SignalKey (IO ()), | ||
object :: ObjRef tt | ||
} | ||
|
||
-- | Define the effects for QML operations. | ||
data EffectfulQML :: Effect where | ||
RunEngineLoop :: EngineConfig -> EffectfulQML m () | ||
FireSignal :: EffectfulQML m () | ||
|
||
type instance DispatchOf EffectfulQML = Dynamic | ||
|
||
makeEffect ''EffectfulQML | ||
|
||
-- | Handler for the QML effects. | ||
runEffectfulQML :: (IOE :> es, State SignalUpdate :> es) => Eff (EffectfulQML : es) a -> Eff es a | ||
runEffectfulQML = interpret $ \_ -> \case | ||
RunEngineLoop config -> do | ||
liftIO $ QML.runEngineLoop config | ||
FireSignal -> do | ||
SignalUpdate key obj <- get | ||
liftIO $ QML.fireSignal key obj |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.