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

@ -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,6 +225,8 @@ drawTile
-> Maybe ImgId -> Maybe ImgId
-> IO () -> IO ()
drawTile ai ctx pr pc row col img = drawTile ai ctx pr pc row col img =
when ((realToFrac x > -tileWidth && realToFrac y > -tileHeight) &&
(realToFrac x < 1280 && realToFrac (y - (74 - realToFrac tileHeight)) < 720)) $
do do
save ctx save ctx
if (isNothing img) if (isNothing img)
@ -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 =