diff --git a/src/MainGame/WorldMap.hs b/src/MainGame/WorldMap.hs index 04ba5f6..ea1a7db 100644 --- a/src/MainGame/WorldMap.hs +++ b/src/MainGame/WorldMap.hs @@ -520,18 +520,22 @@ drawTile ud ctx posanims pr pc row col img = updateMap :: Double -> Affection UserData () updateMap dt = do ud <- getAffection - if stateData ud == None + -- empty <- liftIO $ isEmptyMVar (stateMVar ud) + if stateData ud == None -- && empty then do - liftIO $ logIO A.Debug "Loaded game data" - (nws, mendat) <- liftIO $ takeMVar (stateMVar ud) - putAffection ud - { worldState = nws - , stateData = mendat - } - updateMap 0.1 - updateMap 0.1 - updateMap 0.1 - updateMap 19 + mstart <- liftIO $ tryTakeMVar (stateMVar ud) + case mstart of + Just (nws, mendat) -> do + putAffection ud + { worldState = nws + , stateData = mendat + } + updateMap 0.1 + updateMap 0.1 + updateMap 0.1 + updateMap 19 + liftIO $ logIO A.Debug "Loaded game data" + Nothing -> return () else do (nws, _) <- yieldSystemT (worldState ud) $ do emap allEnts $ do diff --git a/src/Util.hs b/src/Util.hs index fc236b3..fa39b11 100644 --- a/src/Util.hs +++ b/src/Util.hs @@ -11,6 +11,8 @@ import Data.Graph.AStar import Data.Maybe import qualified Data.Text as T +import Control.Monad (join) + import qualified SDL import qualified Graphics.Rendering.OpenGL as GL hiding (get) @@ -164,7 +166,8 @@ naviGraph imgmat animBounds (V2 r c) = (\acc (rr, cc) -> if null (maybe [] collisionObstacle - (M.safeGet (r + rr) (c + cc) imgmat) ++ + (join $ M.safeGet (r + rr) (c + cc) imgmat) + ++ map snd (filter (\(V2 br bc, _) -> floor br == r + rr && floor bc == c + cc) animBounds)) @@ -177,14 +180,15 @@ naviGraph imgmat animBounds (V2 r c) = foldl (\acc (rr, cc) -> if null - (maybe [] (collisionObstacle <$>) - ([M.safeGet (r + rr) (c + cc) imgmat] ++ - map snd (filter (\(V2 br bc, _) -> floor br == r + rr && floor bc == c + cc) - animBounds))) + (maybe [] collisionObstacle + (join $ M.safeGet (r + rr) (c + cc) imgmat) + ++ + map snd (filter (\(V2 br bc, _) -> floor br == r + rr && floor bc == c + cc) + animBounds)) && all null (map (\(oor, ooc) -> (maybe [] collisionObstacle - (M.safeGet (r + oor) (c + ooc) imgmat)) ++ + (join $ M.safeGet (r + oor) (c + ooc) imgmat)) ++ map snd (filter (\(V2 br bc, _) -> floor br == r + oor && floor bc == c + ooc) animBounds))