30 lines
589 B
Haskell
30 lines
589 B
Haskell
module Client.Game where
|
|
|
|
import Control.Concurrent
|
|
|
|
import qualified Control.Concurrent.STM as STM
|
|
|
|
import Control.Monad
|
|
|
|
import Control.Monad.Loops
|
|
|
|
import Control.Monad.RWS
|
|
|
|
-- internal imports
|
|
|
|
import Client.Communication
|
|
import Client.Types
|
|
|
|
import Library.Types
|
|
|
|
runGame :: Game ()
|
|
runGame = do
|
|
sock <- asks rcSocket
|
|
queue <- asks rcQueue
|
|
recvThread <- liftIO $ forkIO $ forever $ receiveMessage sock queue
|
|
whileM_
|
|
(not . clientStop <$> (liftIO . STM.atomically . STM.readTMVar =<< gets scClientState))
|
|
(do
|
|
handleMessages
|
|
)
|
|
liftIO $ killThread recvThread
|