gore-and-ash-sync-1.2.0.1: Gore&Ash module for high level network synchronization

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

Game.GoreAndAsh.Sync.Remote.Sync

Contents

Description

 

Synopsis

Remote actor API

data Sync m i s a where Source #

Special monad that keeps info about synchronization logic between client and server for type a. Remote collection uses the description to generate special code to automatic synchronization of shared actor state.

m
means underlying game monad, that will be used during synchronization
i
means actor unique id type
s
means actor state that is beeing syncing. As soon as you crafted 'Sync i s s' it means you defined full description how to sync actor state.
a
is actual value type that the Sync value is describing synchronization for. As soon as you crafted 'Sync i s s' it means you defined full description how to sync actor state.

Constructors

SyncPure :: a -> Sync m i s a 
SyncNone :: (s -> a) -> Sync m i s a 
SyncClient :: Dict (Eq a, Serialize a, RemoteActor i s) -> Peer -> !Word64 -> (s -> a) -> Sync m i s a 
SyncServer :: Dict (Serialize a, RemoteActor i s) -> !Word64 -> (s -> a) -> Sync m i s a 
SyncCond :: GameWire m s (Event ()) -> (s -> a) -> Sync m i s a -> Sync m i s a 
SyncReject :: Dict (Serialize a, RemoteActor i s) -> GameWire m (s, a) (Event a) -> !Word64 -> Sync m i s a -> Sync m i s a 
SyncApp :: Sync m i s (a -> b) -> Sync m i s a -> Sync m i s b 

Instances

Functor (Sync m i s) Source # 

Methods

fmap :: (a -> b) -> Sync m i s a -> Sync m i s b #

(<$) :: a -> Sync m i s b -> Sync m i s a #

Applicative (Sync m i s) Source # 

Methods

pure :: a -> Sync m i s a #

(<*>) :: Sync m i s (a -> b) -> Sync m i s a -> Sync m i s b #

(*>) :: Sync m i s a -> Sync m i s b -> Sync m i s b #

(<*) :: Sync m i s a -> Sync m i s b -> Sync m i s a #

type FullSync m i s = Sync m i s s Source #

Type synonim for those Sync DSL programs that defines full synchronization of actor state

class NetworkMessage i => RemoteActor i a | i -> a, a -> i Source #

API to support automatic synchronization of actors between client and server

Associated Types

type RemoteActorState i :: * Source #

State of remote actor (should be equal a)

type RemoteActorId a :: * Source #

Id of remote actor (should be equal i)

noSync Source #

Arguments

:: (s -> a)

Getter of the field

-> Sync m i s a 

Perphoms no synchronization, the sync primitive returns local value of field

clientSide Source #

Arguments

:: (Eq a, Serialize a, RemoteActor i s) 
=> Peer

Which peer controls the field, sync messages from other peers are not processed

-> Word64

Field id, other side actor should define clientSide with matching id

-> (s -> a)

Field getter

-> Sync m i s a 

Declares that state field is client side, i.e. it is produced in client actor and then sent to server. For peers that are not equal to specified (owner of the field) the sync behavior acts as serverSide.

If server side changes the value manually, client is forced to new server side value.

serverSide Source #

Arguments

:: (Serialize a, RemoteActor i s) 
=> Word64

Field id, other side actor should define serverSide with matching id

-> (s -> a)

Field getter

-> Sync m i s a 

Declares that state field is server side, i.e. it is produced in server actor and then sent to all clients.

Clients cannot change the value manually.

condSync Source #

Arguments

:: Monad m 
=> GameWire m s (Event b)

Wire that produces events when sync should be done

-> (s -> a)

Field getter

-> Sync m i s a

Sub action that should be done when sync event is produced

-> Sync m i s a 

Makes synchronization appear only when given wire produces an event.

Note: intended to use with serverSide

syncReject Source #

Arguments

:: (Serialize a, RemoteActor i s) 
=> GameWire m (s, a) (Event a)

Fires event when the synced value is invalid, event carries new value that should be placed and sended to remote peer

-> Word64

Id of field to resync at remote host when failed

-> Sync m i s a

Sub action that produces synced values for first argument

-> Sync m i s a 

There are sometimes net errors or malicios data change in remote actor, the action provides you ability to reject incorrect values and resync remote actor to fallback value.

Note: intended to use with serverSide

Helpers for conditional synchronization

fieldChanges Source #

Arguments

:: Eq a 
=> (s -> a)

Field getter

-> GameWire m s (Event a) 

Produces event when given field is changed

fieldChangesWithin Source #

Arguments

:: (Num a, Ord a) 
=> (s -> a)

Field getter

-> a

Delta, variation greater than the value is treated as change

-> GameWire m s (Event a) 

Produces event when given field is changed

Dictionary utils

data Dict ctxt where Source #

Reify typeclass to dictionary

Constructors

Dict :: ctxt => Dict ctxt 

encodish :: Dict (Serialize a) -> a -> ByteString Source #

Use serialize dictionary to call encode

decodish :: Dict (Serialize a) -> ByteString -> Either String a Source #

Use serialize dictionary to call decode