Fix bug in line zoning by using less ambitious algorithm

This commit is contained in:
2022-02-13 09:24:27 +00:00
parent 0a860e6f68
commit 9af636aa83
10 changed files with 65 additions and 22 deletions
+6 -3
View File
@@ -143,7 +143,7 @@ updateInstantParticles w = case _instantParticles w of
in updateInstantParticles $ w' & particles %~ (catMaybes ps' ++)
updateMIM :: ASetter' World (IM.IntMap a) -> (a -> a -> Maybe a) -> World -> World
updateMIM f up w = w & f %~ IM.mapMaybe (dbArg up)
updateMIM f up = f %~ IM.mapMaybe (dbArg up)
-- Note that this updates the randgen
--updateCreatures :: World -> World
@@ -160,12 +160,15 @@ updateMIM f up w = w & f %~ IM.mapMaybe (dbArg up)
ppEvents :: World -> World
ppEvents w = IM.foldl' (flip $ \pp -> _ppEvent pp pp) w $ _pressPlates w
-- this is not working correctly, maybe a problem with wallsAlongLine
updateSeenWalls :: World -> World
updateSeenWalls w = foldl' markWallSeen w wallsToUpdate
where
vPos = _cameraViewFrom w
wallsToUpdate = concatMap (\p -> visibleWalls vPos (vPos +.+p) $ wallsAlongLine vPos (vPos +.+ p) w)
$ nRays 20
-- wallsToUpdate = concatMap (\p -> visibleWalls vPos (vPos +.+p) $ _walls w)
-- $ nRays 20
markWallSeen :: World -> Wall -> World
markWallSeen w wl = w { _walls = IM.adjust mw (_wlID wl) $ _walls w }
@@ -269,7 +272,7 @@ crCrSpring c1 c2 w
{- Finds the visible walls from a point to another point. -}
visibleWalls :: Point2 -> Point2 -> IM.IntMap Wall -> [Wall]
visibleWalls p1 p2 ws
= takeUntil theTest
= takeUntil isOpaque
. map snd
. sortOn (dist p1 . fromJust . fst)
. filter (isJust . fst)
@@ -277,7 +280,7 @@ visibleWalls p1 p2 ws
$ IM.elems ws
where
f wl = (uncurry intersectSegSeg (_wlLine wl) p1 p2, wl)
theTest wl = _wlOpacity wl /= Opaque
isOpaque wl = _wlOpacity wl == Opaque
updateDelayedEvents :: World -> World
updateDelayedEvents w = let (neww,newde) = mapAccumR f w (_delayedEvents w)
+4 -2
View File
@@ -81,11 +81,13 @@ pushOrCrush wls cr = case mapMaybe (pushOutFromWall (_crRad cr) cpos) wls of
-- note the inclusion of endpoints in circOnSeg
crOnWall :: Creature -> World -> Bool
crOnWall cr w = any (\(a,b) -> circOnSeg a b p r) wls
crOnWall cr = any (\(a,b) -> circOnSeg a b p r)
. fmap _wlLine
. IM.filter (not . _wlWalkable)
. wallsNearPoint p
where
p = _crPos cr
r = _crRad cr
wls = fmap _wlLine . IM.filter (not . _wlWalkable) $ wallsNearPoint p w
-- assumes that the wall is orientated
-- assumes wall points are different
-5
View File
@@ -1,5 +0,0 @@
{- |
Placeholder... not sure of its purpose, but might deal with pure world change functions.
The world datatype itself is very intertwined with the creature, weapon, etc datatypes.
-}
module Dodge.World where
+8 -2
View File
@@ -29,6 +29,9 @@ import Data.List
import qualified Data.IntMap.Strict as IM
import qualified Data.IntSet as IS
--flattenZones :: Zone (IM.IntMap a) -> IM.IntMap a
--flattenZones = flattenIMIMIM . _znObjects
zoneSize :: Float
zoneSize = 50
@@ -68,10 +71,12 @@ zoneOfLine (V2 aa ab) (V2 ba bb)
$ digitalLine (zoneOfPoint (V2 aa ab)) (zoneOfPoint (V2 ba bb))
where
f (x,y) = [(p,r) | p <-[x-1,x,x+1] , r<-[y-1,y,y+1]]
--f (x,y) = [(p,r) | p <-[x-2..x+2] , r<-[y-2..y+2]]
zoneOfLineIntMap :: Point2 -> Point2 -> IM.IntMap IS.IntSet
--{-# INLINE zoneOfLineIntMap #-}
zoneOfLineIntMap = ddaExt zoneSize
--zoneOfLineIntMap = ddaExt zoneSize
zoneOfLineIntMap = ddaSq zoneSize
zoneOfCircle :: Point2 -> Float -> [(Int,Int)]
zoneOfCircle p r = concatMap zoneNearPoint $ divideCircle (1.5 * zoneSize) p r
@@ -148,7 +153,8 @@ cloudsNearPoint p w = f (IM.lookup x (_znObjects $ _cloudsZone w) >>= IM.lookup
-- within this function
wallsAlongLine :: Point2 -> Point2 -> World -> IM.IntMap Wall
--{-# INLINE wallsAlongLine #-}
wallsAlongLine a b w = IM.foldlWithKey' g IM.empty kps
wallsAlongLine a b w =
IM.foldlWithKey' g IM.empty kps
where
g m x s = IM.union (IM.unions (IM.restrictKeys (f x $ _znObjects $ _wallsZone w) s)) m
kps = zoneOfLineIntMap a b