This commit is contained in:
2025-10-03 20:14:41 +01:00
parent 2d44809900
commit cba3ca784a
13 changed files with 181 additions and 193 deletions
+6 -16
View File
@@ -1,6 +1,6 @@
module Dodge.Room.Path (
gridPoints,
linksAndPath',
linksGridToPath,
makeGrid,
createPathGrid,
gridPoints'',
@@ -14,17 +14,14 @@ import Data.Maybe
import qualified Data.Set as S
import Dodge.Data.GenWorld
import Dodge.LevelGen.StaticWalls
import Dodge.RoomLink
import Geometry
import Grid
createPathGrid :: Room -> Room
createPathGrid rm =
rm
{ _rmPath = linksAndPath' (_rmLinks rm) filterGrid
}
createPathGrid rm = rm & rmPath .~ linksGridToPath (_rmLinks rm) filterGrid
where
filterGrid = filter (\p -> pairInPolys (_rmPolys rm) p && testCrossWalls outerWalls p) grid
filterGrid = filter
(\p -> pairInPolys (_rmPolys rm) p && testCrossWalls outerWalls p) grid
grid = fromMaybe [] $ shiftedGrid <$> minx <*> maxx <*> miny <*> maxy
outerWalls = foldr cutPoly [] $ _rmPolys rm
outerPoints = map fst outerWalls
@@ -36,17 +33,10 @@ createPathGrid rm =
<*> L.premap sndV2 L.minimum
<*> L.premap sndV2 L.maximum
--linksAndPath :: [(Point2, Float)] -> [(Point2, Point2)] -> S.Set (Point2, Point2)
--linksAndPath lnks subpth = S.fromList subpth <> foldMap linkClosest lnks
-- where
-- linkClosest (p, _) = doublePairSet (p, minimumBy (compare `on` dist p) $ map fst subpth)
linksAndPath' :: [RoomLink] -> [(Point2, Point2)] -> S.Set (Point2, Point2)
linksAndPath' lnks subpth = S.fromList subpth
<> foldMap (linkClosest . (^. rlPos) ) lnks
linksGridToPath :: [RoomLink] -> [(Point2, Point2)] -> S.Set (Point2, Point2)
linksGridToPath lnks subpth = S.fromList subpth <> foldMap (linkClosest . (^. rlPos)) lnks
where
linkClosest p = doublePairSet (p, minimumBy (compare `on` dist p) $ map fst subpth)
--linksAndPath' = linksAndPath . map lnkPosDir
testCrossWalls :: [(Point2, Point2)] -> (Point2, Point2) -> Bool
testCrossWalls wls (a, b) = not $ any (isJust . uncurry (intersectSegSeg a b)) wls