--- a/gameServer/RoomsAndClients.hs Wed Mar 21 00:05:46 2012 -0400
+++ b/gameServer/RoomsAndClients.hs Thu Mar 22 22:55:38 2012 +0400
@@ -1,3 +1,5 @@
+{-# LANGUAGE BangPatterns, GeneralizedNewtypeDeriving #-}
+
module RoomsAndClients(
RoomIndex(),
ClientIndex(),
@@ -34,24 +36,25 @@
import Store
import Control.Monad
+import Control.DeepSeq
data Room r = Room {
- roomClients' :: [ClientIndex],
- room' :: r
+ roomClients' :: ![ClientIndex],
+ room' :: !r
}
data Client c = Client {
- clientRoom' :: RoomIndex,
- client' :: c
+ clientRoom' :: !RoomIndex,
+ client' :: !c
}
newtype RoomIndex = RoomIndex ElemIndex
- deriving (Eq)
+ deriving (Eq, NFData)
newtype ClientIndex = ClientIndex ElemIndex
- deriving (Eq, Show, Read, Ord)
+ deriving (Eq, Show, Read, Ord, NFData)
instance Show RoomIndex where
show (RoomIndex i) = 'r' : show i
@@ -82,10 +85,10 @@
roomAddClient :: ClientIndex -> Room r -> Room r
-roomAddClient cl rm = let cls = cl : roomClients' rm; nr = rm{roomClients' = cls} in cls `seq` nr
+roomAddClient cl rm = let cls = cl : roomClients' rm; nr = rm{roomClients' = cls} in cls `deepseq` nr
roomRemoveClient :: ClientIndex -> Room r -> Room r
-roomRemoveClient cl rm = let cls = filter (/= cl) $ roomClients' rm; nr = rm{roomClients' = cls} in cls `seq` nr
+roomRemoveClient cl rm = let cls = filter (/= cl) $ roomClients' rm; nr = rm{roomClients' = cls} in cls `deepseq` nr
addRoom :: MRoomsAndClients r c -> r -> IO RoomIndex