only draw visible tiles

This commit is contained in:
nek0 2018-04-22 11:59:14 +02:00
parent a05799cc9f
commit 366b79ecef
2 changed files with 30 additions and 27 deletions

View file

@ -84,7 +84,7 @@ placeNPCs imgmat tilemat rp gr count =
rp rp
updateNPCs updateNPCs
:: MonadIO m :: MonadIO m
=> M.Matrix (Maybe ImgId) => M.Matrix (Maybe ImgId)
-> [ReachPoint] -> [ReachPoint]
-> Double -> Double

View file

@ -120,18 +120,19 @@ drawMap :: Affection UserData ()
drawMap = do drawMap = do
ud <- getAffection ud <- getAffection
dt <- getDelta dt <- getDelta
(_, playerPos) <- yieldSystemT (worldState ud) $ do (_, (playerPos, npcposs)) <- yieldSystemT (worldState ud) $ do
efor $ \_ -> do pc <- efor $ \_ -> do
with player with player
with pos with pos
pos' <- E.get pos pos' <- E.get pos
pure pos' pure pos'
(_, npcposs) <- yieldSystemT (worldState ud) $ do -- (_, npcposs) <- yieldSystemT (worldState ud) $ do
efor $ \_ -> do npcs <- efor $ \_ -> do
with npcState with npcState
with pos with pos
pos' <- E.get pos pos' <- E.get pos
pure pos' pure pos'
return (pc, npcs)
let V2 pr pc = head playerPos let V2 pr pc = head playerPos
mat = imgMat (stateData ud) mat = imgMat (stateData ud)
ctx = nano ud ctx = nano ud
@ -224,27 +225,29 @@ drawTile
-> Maybe ImgId -> Maybe ImgId
-> IO () -> IO ()
drawTile ai ctx pr pc row col img = drawTile ai ctx pr pc row col img =
do when ((realToFrac x > -tileWidth && realToFrac y > -tileHeight) &&
save ctx (realToFrac x < 1280 && realToFrac (y - (74 - realToFrac tileHeight)) < 720)) $
if (isNothing img) do
then drawPlayer save ctx
else do if (isNothing img)
if (Prelude.null mb) then drawPlayer
then do
drawImage
drawPlayer
else do
if (all (\m -> pr > (fromIntegral (floor pr :: Int)) + m) minrs &&
all (\m -> pc < (fromIntegral (floor pc :: Int)) + m) mincs) ||
(all (\m -> pr > (fromIntegral (floor pr :: Int)) + m) minrs &&
all (\m -> pc < (fromIntegral (floor pc :: Int)) + m) maxcs)
then do
drawImage
drawPlayer
else do else do
drawPlayer if (Prelude.null mb)
drawImage then do
restore ctx drawImage
drawPlayer
else do
if (all (\m -> pr > (fromIntegral (floor pr :: Int)) + m) minrs &&
all (\m -> pc < (fromIntegral (floor pc :: Int)) + m) mincs) ||
(all (\m -> pr > (fromIntegral (floor pr :: Int)) + m) minrs &&
all (\m -> pc < (fromIntegral (floor pc :: Int)) + m) maxcs)
then do
drawImage
drawPlayer
else do
drawPlayer
drawImage
restore ctx
where where
tileWidth = 64 :: Double tileWidth = 64 :: Double
tileHeight = 32 :: Double tileHeight = 32 :: Double
@ -253,9 +256,9 @@ drawTile ai ctx pr pc row col img =
mincs = Prelude.map (snd . matmin) mb mincs = Prelude.map (snd . matmin) mb
maxcs = Prelude.map (snd . matmax) mb maxcs = Prelude.map (snd . matmax) mb
x = realToFrac $ 640 + ((fromIntegral col - pc) + x = realToFrac $ 640 + ((fromIntegral col - pc) +
(fromIntegral row - pr)) * (tileWidth / 2) (fromIntegral row - pr)) * (tileWidth / 2) :: CFloat
y = realToFrac $ 360 - (tileHeight / 2) + ((fromIntegral row - pr) - y = realToFrac $ 360 - (tileHeight / 2) + ((fromIntegral row - pr) -
(fromIntegral col - pc)) * (tileHeight / 2) (fromIntegral col - pc)) * (tileHeight / 2) :: CFloat
dist = distance (V2 (fromIntegral row) (fromIntegral col)) dist = distance (V2 (fromIntegral row) (fromIntegral col))
(V2 (realToFrac pr - 1) (realToFrac pc)) / 4 (V2 (realToFrac pr - 1) (realToFrac pc)) / 4
fact = fact =