gore-and-ash-actor-1.1.0.0: Gore&Ash engine extension that implements actor style of programming

Copyright(c) Anton Gushcha, 2015-2016
LicenseBSD3
Maintainerncrashed@gmail.com
Stabilityexperimental
PortabilityPOSIX
Safe HaskellNone
LanguageHaskell2010

Game.GoreAndAsh.Actor.API

Contents

Description

Module that contains monadic and arrow API of actor module.

Synopsis

Documentation

class MonadThrow m => ActorMonad m where Source

Low level monadic API for module.

Methods

actorRegisterM :: ActorMessage i => m i Source

Registers new actor in message system

actorRegisterFixedM :: ActorMessage i => i -> m () Source

Registers specific id, throws ActorException if there is id clash

actorDeleteM :: ActorMessage i => i -> m () Source

Deletes actor with given id

actorRegisteredM :: ActorMessage i => i -> m Bool Source

Checks if given id is already taken

actorSendM :: (ActorMessage i, Typeable (ActorMessageType i)) => i -> ActorMessageType i -> m () Source

Sends typed message to actor with given id

actorGetMessagesM :: (ActorMessage i, Typeable (ActorMessageType i)) => i -> m (Seq (ActorMessageType i)) Source

Get all messages that were collected for given actor's id

Note: Doesn't clears the queue

findActorTypeRepM :: String -> m (Maybe HashableTypeRep) Source

Find type representation of actor by it type name

registerActorTypeRepM :: forall proxy i. ActorMessage i => proxy i -> m () Source

Register type representation for actor (sometimes this should be done before any actor is registered)

Instances

data ActorException Source

Exceptions thrown by ActorMonad

Constructors

ActorIdConflict TypeRep Int

Tried to register already presented actor

Message API

actorSend :: (ActorMonad m, ActorMessage i, Typeable (ActorMessageType i)) => i -> GameWire m (Event (ActorMessageType i)) (Event ()) Source

Sends message to statically known actor

actorSendMany :: (ActorMonad m, ActorMessage i, Typeable (ActorMessageType i), Foldable t) => i -> GameWire m (Event (t (ActorMessageType i))) (Event ()) Source

Sends many messages to statically known actor

actorSendDyn :: (ActorMonad m, ActorMessage i, Typeable (ActorMessageType i)) => GameWire m (Event (i, ActorMessageType i)) (Event ()) Source

Sends message to actor with incoming id

actorSendManyDyn :: (ActorMonad m, ActorMessage i, Typeable (ActorMessageType i), Foldable t) => GameWire m (Event (t (i, ActorMessageType i))) (Event ()) Source

Sends many messages, dynamic version of actorSendMany which takes actor id as arrow input

actorProcessMessages Source

Arguments

:: (ActorMonad m, ActorMessage i, Typeable (ActorMessageType i)) 
=> i

Actor id known statically

-> (a -> ActorMessageType i -> a)

Action that modifies accumulator

-> GameWire m a a

Wire that updates input value using supplied function

Helper to process all messages from message queue and update a state

actorProcessMessagesM Source

Arguments

:: (ActorMonad m, ActorMessage i, Typeable (ActorMessageType i)) 
=> i

Actor id known statically

-> (a -> ActorMessageType i -> GameMonadT m a)

Monadic action that modifies accumulator

-> GameWire m a a

Wire that updates input value using supplied function

Helper to process all messages from message queue and update a state (monadic version)

actorMessages Source

Arguments

:: (ActorMonad m, ActorMessage i, Typeable (ActorMessageType i)) 
=> i

Actor id which messages we look for

-> (ActorMessageType i -> Bool)

Filter function, leaves only with True return value

-> GameWire m a (Event (Seq (ActorMessageType i))) 

Non-centric style of subscribing to messages

Actor API

makeActor Source

Arguments

:: (ActorMonad m, ActorMessage i) 
=> (i -> GameWire m a b)

Body wire

-> GameActor m i a b

Operation that makes actual actor

Registers new index for wire and makes an actor wire

makeFixedActor Source

Arguments

:: (ActorMonad m, ActorMessage i) 
=> i

Manual id of actor

-> GameWire m a b

Body wire

-> GameActor m i a b

Operation that makes actual actor

Registers new actor with fixed id, can fail with ActorException if there is already registered actor for that id

runActor Source

Arguments

:: ActorMonad m 
=> GameActor m i a b

Actor creator

-> GameWire m a (b, i)

Usual wire that also returns id of inner indexed wire

If need no dynamic switching, you can use the function to embed index wire just at time

runActor' Source

Arguments

:: ActorMonad m 
=> GameActor m i a b

Actor creator

-> GameWire m a b

Usual wire

Same as runActor, but doesn't return id of actor

Helpers for libraries

getActorFingerprint :: forall i. ActorMessage i => i -> HashableTypeRep Source

Helper to get actor fingerprint from id value