module Game.GoreAndAsh.Sync.State(
SyncState(..)
, SyncRole(..)
, NetworkMessage(..)
, SyncServiceMsg(..)
, emptySyncState
) where
import Control.DeepSeq
import Data.Serialize
import Data.Word
import GHC.Generics
import qualified Data.HashMap.Strict as H
import qualified Data.Sequence as S
import Game.GoreAndAsh.Actor
import Game.GoreAndAsh.Actor.TypeRep
import Game.GoreAndAsh.Network
data SyncRole =
SyncMaster
| SyncSlave
deriving (Generic, Eq, Show, Enum)
instance NFData SyncRole
class ActorMessage i => NetworkMessage i where
type NetworkMessageType i :: *
data SyncServiceMsg =
SyncServiceRequestId !String
| SyncServiceResponseId !String !Word64
| SyncServiceResponseNotRegistered !String
deriving (Generic)
instance Serialize SyncServiceMsg
data SyncState s = SyncState {
syncNextState :: !s
, syncIdMap :: !(H.HashMap HashableTypeRep Word64)
, syncIdMapRev :: !(H.HashMap Word64 HashableTypeRep)
, syncNextId :: !Word64
, syncScheduledMessages :: !(H.HashMap Peer (S.Seq (String, ChannelID, Word64 -> Message)))
, syncLogging :: !Bool
, syncRole :: !SyncRole
} deriving (Generic)
instance NFData s => NFData (SyncState s)
emptySyncState :: s -> SyncState s
emptySyncState s = SyncState {
syncNextState = s
, syncIdMap = H.empty
, syncIdMapRev = H.empty
, syncNextId = 1
, syncScheduledMessages = H.empty
, syncLogging = False
, syncRole = SyncMaster
}