Simplify grid/lattice creation
This commit is contained in:
@@ -18,12 +18,13 @@ import LensHelp
|
||||
import RandomHelp
|
||||
import Control.Monad
|
||||
|
||||
-- pathing needs to be done
|
||||
roomGlassOctogon ::
|
||||
-- | Size
|
||||
Float ->
|
||||
Room
|
||||
roomGlassOctogon x =
|
||||
createPathGrid $
|
||||
-- createPathGrid $
|
||||
defaultRoom
|
||||
{ _rmPolys =
|
||||
[ rectNSWE x (- x) (- x) x
|
||||
|
||||
+2
-28
@@ -1,39 +1,20 @@
|
||||
module Dodge.Room.Path (
|
||||
gridPoints,
|
||||
linksGridToPath,
|
||||
makeGrid,
|
||||
createPathGrid,
|
||||
-- makeGrid,
|
||||
-- createPathGrid,
|
||||
gridPoints'',
|
||||
linksGridToPath',
|
||||
) where
|
||||
|
||||
import Control.Lens
|
||||
import qualified Control.Foldl as L
|
||||
import Data.Function (on)
|
||||
import Data.List
|
||||
import Data.Maybe
|
||||
import qualified Data.Set as S
|
||||
import Dodge.Data.GenWorld
|
||||
import Dodge.LevelGen.StaticWalls
|
||||
import Geometry
|
||||
import Grid
|
||||
|
||||
createPathGrid :: Room -> Room
|
||||
createPathGrid rm = rm & rmPath .~ linksGridToPath (_rmLinks rm) filterGrid
|
||||
where
|
||||
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
|
||||
(minx, maxx, miny, maxy) = L.fold theFold outerPoints
|
||||
theFold =
|
||||
(,,,)
|
||||
<$> L.premap fstV2 L.minimum
|
||||
<*> L.premap fstV2 L.maximum
|
||||
<*> L.premap sndV2 L.minimum
|
||||
<*> L.premap sndV2 L.maximum
|
||||
|
||||
-- assumes subpth is symmetric
|
||||
linksGridToPath :: [RoomLink] -> [(Point2, Point2)] -> S.Set (Point2, Point2)
|
||||
linksGridToPath lnks subpth = S.fromList subpth <> foldMap (linkClosest . (^. rlPos)) lnks
|
||||
@@ -45,10 +26,3 @@ linksGridToPath' lnks subpth' = subpth <> foldMap (linkClosest . (^. rlPos)) lnk
|
||||
where
|
||||
subpth = foldMap doublePairSet subpth'
|
||||
linkClosest p = doublePairSet (p, minimumBy (compare `on` dist p) $ S.map fst subpth)
|
||||
|
||||
testCrossWalls :: [(Point2, Point2)] -> (Point2, Point2) -> Bool
|
||||
testCrossWalls wls (a, b) = not $ any (isJust . uncurry (intersectSegSeg a b)) wls
|
||||
|
||||
--extra test whether both members of the path edge are in some poly
|
||||
pairInPolys :: [[Point2]] -> (Point2, Point2) -> Bool
|
||||
pairInPolys polys (a, b) = any (pointInPoly a) polys && any (pointInPoly b) polys
|
||||
|
||||
@@ -7,9 +7,10 @@ module Dodge.Room.Procedural (
|
||||
centerVaultRoom,
|
||||
combineRooms,
|
||||
-- linksAndPath,
|
||||
makeGrid,
|
||||
-- makeGrid,
|
||||
) where
|
||||
|
||||
import Grid
|
||||
import Dodge.Door.PutSlideDoor
|
||||
import Dodge.Default.Wall
|
||||
import Control.Monad
|
||||
@@ -37,16 +38,7 @@ import RandomHelp
|
||||
-- This will need a cleanup, but it might change a bit first
|
||||
{- A simple rectangular room with a light in the center.
|
||||
Creates links and pathfinding graph. -}
|
||||
roomRect ::
|
||||
-- | Width
|
||||
Float ->
|
||||
-- | Height
|
||||
Float ->
|
||||
-- | Number of links on vertical walls
|
||||
Int ->
|
||||
-- | Number of links on horizontal walls
|
||||
Int ->
|
||||
Room
|
||||
roomRect :: Float -> Float -> Int -> Int -> Room
|
||||
roomRect x y xn yn =
|
||||
defaultRoom
|
||||
{ _rmPolys = [rectNSWE y 0 0 x]
|
||||
@@ -82,8 +74,14 @@ roomRect x y xn yn =
|
||||
}
|
||||
}
|
||||
where
|
||||
xs = take (xn + 1) [0,xd..] & each +~ 20
|
||||
ys = take (yn + 1) [0,yd..] & each +~ 20
|
||||
yd = (y - 40) / fromIntegral yn
|
||||
xd = (x - 40) / fromIntegral xn
|
||||
pth = linksGridToPath lnks
|
||||
$ latticeXsYs xs ys
|
||||
--pth = linksGridToPath lnks
|
||||
-- $ map (bimap (+.+ V2 20 20) (+.+ V2 20 20)) (makeGrid xd xn yd yn)
|
||||
somelnks poffset ps a = zip (map (+.+ poffset) ps) (repeat a)
|
||||
wlnks = somelnks (V2 0 20) (gridPoints 0 1 yd (yn + 1)) (pi / 2)
|
||||
elnks = somelnks (V2 x 20) (gridPoints 0 1 yd (yn + 1)) (- pi / 2)
|
||||
@@ -97,8 +95,6 @@ roomRect x y xn yn =
|
||||
m edge edgefrom1 edgefrom2 =
|
||||
zipWith (lnkBothAnd (OnEdge edge) edgefrom1 edgefrom2) [0 ..]
|
||||
. zipCountDown
|
||||
pth = linksGridToPath lnks
|
||||
$ map (bimap (+.+ V2 20 20) (+.+ V2 20 20)) (makeGrid xd xn yd yn)
|
||||
makeonpos (p, a) = RoomPos p 0 (S.singleton $ RoomPosOnGrid $ makerpedges a)
|
||||
(NotLink True) mempty
|
||||
makerpedges (a, b) =
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
{-# OPTIONS_GHC -Wno-unused-imports #-}
|
||||
module Dodge.Room.Tutorial where
|
||||
|
||||
import Dodge.Room.Boss
|
||||
import Dodge.Room.Tanks
|
||||
import Dodge.Room.LongDoor
|
||||
import Dodge.Layout
|
||||
@@ -46,7 +47,7 @@ tutAnoTree = do
|
||||
[ tToBTree "TutStartRez" . return . cleatOnward <$> tutRezBox
|
||||
, corDoor
|
||||
-- , return $ tToBTree "cor" $ return $ cleatOnward $ corridor & rmPmnts .~ mempty
|
||||
-- , return $ tToBTree "cor" $ return $ cleatOnward airlock90
|
||||
, return $ tToBTree "cor" $ return $ cleatOnward $ roomGlassOctogon 200
|
||||
-- , corDoor
|
||||
-- , return $ tToBTree "cor" $ return $ cleatOnward (twinSlowDoorRoom 80 200 40)
|
||||
-- , return $ tToBTree "cor" $ return $ cleatOnward corridor
|
||||
|
||||
Reference in New Issue
Block a user