gameServer/RoomsAndClients.hs
branchsdl2transition
changeset 11362 ed5a6478e710
parent 11046 47a8c19ecb60
equal deleted inserted replaced
11361:31570b766315 11362:ed5a6478e710
       
     1 {-
       
     2  * Hedgewars, a free turn based strategy game
       
     3  * Copyright (c) 2004-2015 Andrey Korotaev <unC0Rr@gmail.com>
       
     4  *
       
     5  * This program is free software; you can redistribute it and/or modify
       
     6  * it under the terms of the GNU General Public License as published by
       
     7  * the Free Software Foundation; version 2 of the License
       
     8  *
       
     9  * This program is distributed in the hope that it will be useful,
       
    10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
       
    11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
       
    12  * GNU General Public License for more details.
       
    13  *
       
    14  * You should have received a copy of the GNU General Public License
       
    15  * along with this program; if not, write to the Free Software
       
    16  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
       
    17  \-}
       
    18 
     1 {-# LANGUAGE BangPatterns, GeneralizedNewtypeDeriving #-}
    19 {-# LANGUAGE BangPatterns, GeneralizedNewtypeDeriving #-}
     2 
    20 
     3 module RoomsAndClients(
    21 module RoomsAndClients(
     4     RoomIndex(),
    22     RoomIndex(),
     5     ClientIndex(),
    23     ClientIndex(),
    20     client,
    38     client,
    21     room,
    39     room,
    22     client'sM,
    40     client'sM,
    23     room'sM,
    41     room'sM,
    24     allClientsM,
    42     allClientsM,
       
    43     allRoomsM,
    25     clientsM,
    44     clientsM,
    26     roomsM,
    45     roomsM,
    27     roomClientsM,
    46     roomClientsM,
    28     roomClientsIndicesM,
    47     roomClientsIndicesM,
    29     withRoomsAndClients,
    48     withRoomsAndClients,
   156 room'sM (MRoomsAndClients (rooms, _)) f (RoomIndex ri) = liftM (f . room') (rooms `readElem` ri)
   175 room'sM (MRoomsAndClients (rooms, _)) f (RoomIndex ri) = liftM (f . room') (rooms `readElem` ri)
   157 
   176 
   158 allClientsM :: MRoomsAndClients r c -> IO [ClientIndex]
   177 allClientsM :: MRoomsAndClients r c -> IO [ClientIndex]
   159 allClientsM (MRoomsAndClients (_, clients)) = liftM (map ClientIndex) $ indicesM clients
   178 allClientsM (MRoomsAndClients (_, clients)) = liftM (map ClientIndex) $ indicesM clients
   160 
   179 
       
   180 allRoomsM :: MRoomsAndClients r c -> IO [RoomIndex]
       
   181 allRoomsM (MRoomsAndClients (rooms, _)) = liftM (map RoomIndex) $ indicesM rooms
       
   182 
   161 clientsM :: MRoomsAndClients r c -> IO [c]
   183 clientsM :: MRoomsAndClients r c -> IO [c]
   162 clientsM (MRoomsAndClients (_, clients)) = indicesM clients >>= mapM (liftM client' . readElem clients)
   184 clientsM (MRoomsAndClients (_, clients)) = indicesM clients >>= mapM (liftM client' . readElem clients)
   163 
   185 
   164 roomsM :: MRoomsAndClients r c -> IO [r]
   186 roomsM :: MRoomsAndClients r c -> IO [r]
   165 roomsM (MRoomsAndClients (rooms, _)) = indicesM rooms >>= mapM (liftM room' . readElem rooms)
   187 roomsM (MRoomsAndClients (rooms, _)) = indicesM rooms >>= mapM (liftM room' . readElem rooms)