I'm at the point in my Traveller I'm trying to handle player-independent updates to the game state. For reference, the project is here (the devel branch is the relevant one for this question).
Libraries/Universe/GameState.hs
has a function, updateGS
that handles all player updates to the game state. The EventNetwork
looks like this right now.
makeNetworkDescription :: AddHandler PlayerCommand ->
AddHandler () ->
TChan GameState ->
IO EventNetwork
makeNetworkDescription addCommandEvent tickHandler gsChannel = compile $ do
eInput <- fromAddHandler addCommandEvent
eTick <- fromAddHandler tickHandler
let bGameState = accumB initialGS $ updateGS <$> eInput
eGameState <- changes bGameState
reactimate $ (\n -> (atomically $ writeTChan gsChannel n)) <$> eGameState
The problem in implementing this timer is that all the examples I have looked at have a use case different from mine, physics simulation. There's no physics involved in this game. I'm trying to use a timer to have the game state evaluated independent of player actions. For now, the only thing I want to manage is hyperspace travel. When completely implemented, moving from one planet to another will change an Agent
's location
to Right Hyperspace
. What needs to happen now, is that when a tick
happens, distanceTraversed
increments by one. Then if distanceTraversed
equals totalDistance
Agent
's location becomes Left Planet
.
So what would that look like from the EventNetwork
's point of view?
let bHyperspace = accumB initialGS $ foo <$> eTick
now to combine behaviors
let bBaz = (++) <$> bGameState <*> bHyperspace
Is this the right track?