let animation objects delete themselves after they are not being used anymore
PS:
I don't like that we create new animation objects every single time before a page transition is done, I'm sure that can be done in a nicer way.
But at least we're not keeping those non-reused objects around forever now...
module ServerCore whereimport Control.Concurrentimport Control.Monadimport System.Log.Loggerimport Control.Monad.Readerimport Control.Monad.State.Strictimport Data.Set as Setimport qualified Data.ByteString.Char8 as Bimport Control.DeepSeqimport Data.Uniqueimport Data.Maybe--------------------------------------import CoreTypesimport NetRoutinesimport HWProtoCoreimport Actionsimport OfficialServer.DBInteractionimport ServerStatetimerLoop :: Int -> Chan CoreMessage -> IO ()timerLoop tick messagesChan = threadDelay 30000000 >> writeChan messagesChan (TimerAction tick) >> timerLoop (tick + 1) messagesChanreactCmd :: [B.ByteString] -> StateT ServerState IO ()reactCmd cmd = do (Just ci) <- gets clientIndex rnc <- gets roomsClients actions <- liftIO $ withRoomsAndClients rnc (\irnc -> runReader (handleCmd cmd) (ci, irnc)) forM_ (actions `deepseq` actions) processActionmainLoop :: StateT ServerState IO ()mainLoop = forever $ do -- get >>= \s -> put $! s si <- gets serverInfo r <- liftIO $ readChan $ coreChan si case r of Accept ci -> processAction (AddClient ci) ClientMessage (ci, cmd) -> do liftIO $ debugM "Clients" $ show ci ++ ": " ++ show cmd removed <- gets removedClients unless (ci `Set.member` removed) $ do modify (\s -> s{clientIndex = Just ci}) reactCmd cmd Remove ci -> processAction (DeleteClient ci) ClientAccountInfo ci uid info -> do rnc <- gets roomsClients exists <- liftIO $ clientExists rnc ci when exists $ do modify (\s -> s{clientIndex = Just ci}) uid' <- client's clUID when (uid == hashUnique uid') $ processAction (ProcessAccountInfo info) return () TimerAction tick -> mapM_ processAction $ PingAll : [StatsAction | even tick]startServer :: ServerInfo -> IO ()startServer si = do noticeM "Core" $ "Listening on port " ++ show (listenPort si) _ <- forkIO $ acceptLoop (fromJust $ serverSocket si) (coreChan si) _ <- forkIO $ timerLoop 0 $ coreChan si startDBConnection si rnc <- newRoomsAndClients newRoom evalStateT mainLoop (ServerState Nothing si Set.empty rnc)