Copyright | (c) Anton Gushcha, 2015-2016 |
---|---|
License | BSD3 |
Maintainer | ncrashed@gmail.com |
Stability | experimental |
Portability | POSIX |
Safe Haskell | None |
Language | Haskell2010 |
- data Sync m i s a where
- 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
- type FullSync m i s = Sync m i s s
- class NetworkMessage i => RemoteActor i a | i -> a, a -> i where
- type RemoteActorState i :: *
- type RemoteActorId a :: *
- noSync :: (s -> a) -> Sync m i s a
- clientSide :: (Eq a, Serialize a, RemoteActor i s) => Peer -> Word64 -> (s -> a) -> Sync m i s a
- serverSide :: (Serialize a, RemoteActor i s) => Word64 -> (s -> a) -> Sync m i s a
- condSync :: Monad m => GameWire m s (Event b) -> (s -> a) -> Sync m i s a -> Sync m i s a
- syncReject :: (Serialize a, RemoteActor i s) => GameWire m (s, a) (Event a) -> Word64 -> Sync m i s a -> Sync m i s a
- fieldChanges :: Eq a => (s -> a) -> GameWire m s (Event a)
- fieldChangesWithin :: (Num a, Ord a) => (s -> a) -> a -> GameWire m s (Event a)
- data Dict ctxt where
- encodish :: Dict (Serialize a) -> a -> ByteString
- decodish :: Dict (Serialize a) -> ByteString -> Either String a
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.
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 |
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
type RemoteActorState i :: * Source #
State of remote actor (should be equal a)
type RemoteActorId a :: * Source #
Id of remote actor (should be equal i)
:: (s -> a) | Getter of the field |
-> Sync m i s a |
Perphoms no synchronization, the sync primitive returns local value of field
:: (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 |
-> (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.
:: (Serialize a, RemoteActor i s) | |
=> Word64 | Field id, other side actor should define |
-> (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.
:: 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
:: (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
:: Eq a | |
=> (s -> a) | Field getter |
-> GameWire m s (Event a) |
Produces event when given field is changed
:: (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
encodish :: Dict (Serialize a) -> a -> ByteString Source #
Use serialize dictionary to call encode