Improve pathing debugging, work on door pathing

This commit is contained in:
2022-07-03 00:24:25 +01:00
parent 3efd89fa34
commit 67b612fe60
9 changed files with 59 additions and 43 deletions
+11 -8
View File
@@ -23,12 +23,13 @@ import qualified Data.IntSet as IS
import qualified Data.Graph.Inductive as FGL
import qualified Streaming.Prelude as S
plDoor :: Color
-> EdgeObstacle
-> (World -> Bool) -- ^ Opening condition
-> [(Point2,Point2)] -- ^ Door positions, closed to open.
-- Bumped out up and down by 9, not widened
-> World
-> (Int,World)
plDoor col cond pss gw = (drid, addWalls $ gw & doors %~ addDoor) -- carefull with the ordering of addWalls
plDoor col eo cond pss gw = (drid, addWalls $ gw & doors %~ addDoor) -- carefull with the ordering of addWalls
where
drid = IM.newKey $ _doors gw
addDoor = IM.insert drid $ defaultDoor
@@ -40,14 +41,15 @@ plDoor col cond pss gw = (drid, addWalls $ gw & doors %~ addDoor) -- carefull wi
, _drPos = head pss
, _drOpenPos = head pss
, _drClosePos = last pss
, _drObstacleType = eo
}
nsteps = length pss - 1
wlids = take 4 [IM.newKey $ _walls gw ..]
wlps' = uncurry (rectanglePairs 9) $ head pss
addWalls w' = foldl' (addDoorWall drid $ switchWallCol col) w' $ zip wlids wlps'
addWalls w' = foldl' (addDoorWall eo drid $ switchWallCol col) w' $ zip wlids wlps'
addDoorWall :: Int -> Wall -> World -> (Int,(Point2,Point2)) -> World
addDoorWall drid wl w (wlid,wlps) = w'
addDoorWall :: EdgeObstacle -> Int -> Wall -> World -> (Int,(Point2,Point2)) -> World
addDoorWall eo drid wl w (wlid,wlps) = w'
& walls %~ IM.insert wlid wl
{ _wlLine = wlps
, _wlID = wlid
@@ -55,7 +57,7 @@ addDoorWall drid wl w (wlid,wlps) = w'
}
& doors . ix drid . drObstructs .++~ es
where
(w',es) = uncurry (obstructPathsCrossing DoorObstacle) wlps w
(w',es) = uncurry (obstructPathsCrossing eo) wlps w
-- TODO use vector instead of list, perhaps also memoisation of rectanglePairs
-- TODO update _drPos
-- perhaps also remove use of DoorInt in favour of DoorOpen/DoorClosed
@@ -121,12 +123,13 @@ maybeClearDoorPath eo w (x,y,pe)
plSlideDoor
:: Door
-> Wall
-> EdgeObstacle
-> Float
-> Point2
-> Point2
-> World
-> (Int, World)
plSlideDoor dr wl shiftOffset a b gw
plSlideDoor dr wl eo shiftOffset a b gw
= (drid, addDoorWalls $ gw & doors %~ addDoor)
where
drid = IM.newKey $ _doors gw
@@ -138,9 +141,9 @@ plSlideDoor dr wl shiftOffset a b gw
, _drPos = (a,b)
, _drOpenPos = (shiftLeft a,shiftLeft b)
, _drClosePos = (a,b)
, _drObstacleType = DoorObstacle
, _drObstacleType = eo
}
addDoorWalls w' = foldl' (addDoorWall drid wl) w' $ zip wlids pairs
addDoorWalls w' = foldl' (addDoorWall eo drid wl) w' $ zip wlids pairs
pairs = rectanglePairs 9 a b
shiftLeft = (+.+ (a -.- b +.+ shiftOffset *.* normalizeV (b -.- a)))
wlids = take 4 [IM.newKey $ _walls gw ..]