From 8ec9f9cb6fa619e8538105336560e3ec3cbb4dc5 Mon Sep 17 00:00:00 2001 From: nek0 Date: Thu, 7 Mar 2019 15:13:40 +0100 Subject: [PATCH] prefilter drawing elements --- src/MainGame/WorldMap.hs | 67 +++++++++++++++++++++++++++------------- 1 file changed, 45 insertions(+), 22 deletions(-) diff --git a/src/MainGame/WorldMap.hs b/src/MainGame/WorldMap.hs index 93f9c25..df111b7 100644 --- a/src/MainGame/WorldMap.hs +++ b/src/MainGame/WorldMap.hs @@ -615,10 +615,36 @@ drawMap = do closePath ctx fillColor ctx (rgb 255 255 255) fill ctx - void $ sequence $ parMap rpar (\(i, ls) -> void $ sequence $ parMap rpar - (\(j, t) -> drawTile ud ctx (partposanims M.! (i, j)) pr pc i j t) - (reverse $ zip [1..] ls)) - (zip [1..] (toLists mat)) + let coordList = concatMap + (\(i, ls) -> Prelude.map + (\(j, t) -> ((i, j), t)) + (reverse $ zip [1..] ls) + ) + (zip [1..] (toLists mat)) + filterList = Prelude.filter + (\((frow, fcol), tile) -> + ((realToFrac (sx frow fcol) > -tileWidth && + realToFrac (sy frow fcol) > -tileHeight) && + ((realToFrac (sx frow fcol) :: Double) < 1280 && + (realToFrac ((sy frow fcol)- (74 - (realToFrac tileHeight :: CFloat))) :: Double) < 720)) + ) + coordList + !posanimList = Prelude.map + (\((row, col), tile) -> ((row, col), tile, partposanims M.! (row, col))) + filterList + sx row col = realToFrac $ 640 + ((fromIntegral col - pc) + + (fromIntegral row - pr)) * (tileWidth / 2) :: CFloat + sy row col = realToFrac $ 360 - (tileHeight / 2) + ((fromIntegral row - pr) - + (fromIntegral col - pc)) * (tileHeight / 2) :: CFloat + void $ sequence $ parMap rpar + (\((row, col), tile, posanim) -> + drawTile ud ctx posanim pr pc row col tile + ) + posanimList + -- void $ sequence $ parMap rpar (\(i, ls) -> void $ sequence $ parMap rpar + -- (\(j, t) -> drawTile ud ctx (partposanims M.! (i, j)) pr pc i j t) + -- (reverse $ zip [1..] ls)) + -- (zip [1..] (toLists mat)) mapM_ (\(V2 sr sc, pa, perc) -> when pa $ do let lx = realToFrac $ 640 + ((sc - pc) + (sr - pr)) * (tileWidth / 2) :: CFloat @@ -658,24 +684,21 @@ drawTile -> Maybe ImgId -> IO () drawTile ud ctx posanims pr pc row col img = - when ((realToFrac x > -tileWidth && realToFrac y > -tileHeight) && - ((realToFrac x :: Double) < 1280 && - (realToFrac (y - (74 - (realToFrac tileHeight :: CFloat))) :: Double) < 720)) $ - do - let (bef, beh) = L.partition delimiter sorted - save ctx - mapM_ drawAnim beh - maybe (return ()) (draw ud x (y - 42) 64 74 fact) - ((assetImages ud Map.!) <$> case img of - Just ImgEmpty -> Nothing - _ -> img - ) - mapM_ drawAnim bef - restore ctx - -- when (floor pr == row && floor pc == col) $ do - -- A.logIO A.Debug ("sorted: " ++ show sorted) - -- A.logIO A.Debug ("beh: " ++ show beh) - -- A.logIO A.Debug ("bef: " ++ show bef) + do + let (bef, beh) = L.partition delimiter sorted + save ctx + mapM_ drawAnim beh + maybe (return ()) (draw ud x (y - 42) 64 74 fact) + ((assetImages ud Map.!) <$> case img of + Just ImgEmpty -> Nothing + _ -> img + ) + mapM_ drawAnim bef + restore ctx + -- when (floor pr == row && floor pc == col) $ do + -- A.logIO A.Debug ("sorted: " ++ show sorted) + -- A.logIO A.Debug ("beh: " ++ show beh) + -- A.logIO A.Debug ("bef: " ++ show bef) where delimiter (V2 nr nc, as, mbnds) = animFloats (asId as) ||