Cleanup, improve auto wall rotate
This commit is contained in:
+20
-32
@@ -21,7 +21,6 @@ module Dodge.Base.Collide (
|
||||
bouncePoint,
|
||||
circOnSomeWall,
|
||||
circOnAnyCr,
|
||||
overlapCircWalls,
|
||||
overlapCircWallsClosest,
|
||||
crsNearPoint,
|
||||
allVisibleWalls,
|
||||
@@ -73,15 +72,15 @@ doBounce x sp ep (p, mwl) = fmap f mwl
|
||||
, reflVelWallDamp x wl (ep -.- sp)
|
||||
)
|
||||
|
||||
--bounceBall ::
|
||||
-- bounceBall ::
|
||||
-- Float ->
|
||||
-- Point2 ->
|
||||
-- Point2 ->
|
||||
-- Float ->
|
||||
-- [Wall] ->
|
||||
-- Maybe (Point2, Point2)
|
||||
--{-# INLINE bounceBall #-}
|
||||
--bounceBall x sp ep r = doBounce x sp ep . collideCircWalls sp ep r
|
||||
-- {-# INLINE bounceBall #-}
|
||||
-- bounceBall x sp ep r = doBounce x sp ep . collideCircWalls sp ep r
|
||||
|
||||
bouncePoint ::
|
||||
(Wall -> Bool) ->
|
||||
@@ -106,7 +105,7 @@ collide3Chasms sp w m =
|
||||
foldl'
|
||||
(flip (collide3Chasm sp))
|
||||
m
|
||||
--(foldMap loopPairs $ w ^. cWorld . chasms)
|
||||
-- (foldMap loopPairs $ w ^. cWorld . chasms)
|
||||
(w ^. cWorld . cliffs)
|
||||
|
||||
collide3Chasm :: Point3 -> (Point2, Point2) -> (Point3, MPO) -> (Point3, MPO)
|
||||
@@ -194,9 +193,9 @@ collidePointTestFilter t sp ep =
|
||||
|
||||
---- this COULD be written in terms of collidePointWallsFilterStream, TODO test
|
||||
---- whether this is actually faster
|
||||
--collidePointTestFilter :: (Wall -> Bool) -> Point2 -> Point2 -> StreamOf Wall -> Bool
|
||||
--{-# INLINE collidePointTestFilter #-}
|
||||
--collidePointTestFilter t sp ep = runIdentity
|
||||
-- collidePointTestFilter :: (Wall -> Bool) -> Point2 -> Point2 -> StreamOf Wall -> Bool
|
||||
-- {-# INLINE collidePointTestFilter #-}
|
||||
-- collidePointTestFilter t sp ep = runIdentity
|
||||
-- . S.any_ (isJust . uncurry (intersectSegSeg sp ep) . _wlLine)
|
||||
-- . S.filter t
|
||||
|
||||
@@ -204,15 +203,15 @@ collidePointWallsFilter :: (Wall -> Bool) -> Point2 -> Point2 -> World -> (Point
|
||||
{-# INLINE collidePointWallsFilter #-}
|
||||
collidePointWallsFilter t sp ep = collidePoint sp ep . filter t . wlsNearSeg sp ep
|
||||
|
||||
--overlapSegWalls :: Point2 -> Point2 -> StreamOf Wall
|
||||
-- overlapSegWalls :: Point2 -> Point2 -> StreamOf Wall
|
||||
-- -> StreamOf (Point2,Wall)
|
||||
--{-# INLINE overlapSegWalls #-}
|
||||
--overlapSegWalls sp ep = S.mapMaybe $ \wl -> uncurry (intersectSegSeg sp ep) (_wlLine wl) <&> (,wl)
|
||||
-- {-# INLINE overlapSegWalls #-}
|
||||
-- overlapSegWalls sp ep = S.mapMaybe $ \wl -> uncurry (intersectSegSeg sp ep) (_wlLine wl) <&> (,wl)
|
||||
|
||||
overlapSegWalls :: Point2 -> Point2 -> [Wall] -> [(Point2, Wall)]
|
||||
{-# INLINE overlapSegWalls #-}
|
||||
overlapSegWalls sp ep = mapMaybe
|
||||
$ \wl -> uncurry (intersectSegSeg sp ep) (_wlLine wl) <&> (,wl)
|
||||
overlapSegWalls sp ep = mapMaybe $
|
||||
\wl -> uncurry (intersectSegSeg sp ep) (_wlLine wl) <&> (,wl)
|
||||
|
||||
visibleWalls :: Point2 -> Point2 -> World -> [(Point2, Wall)]
|
||||
{-# INLINE visibleWalls #-}
|
||||
@@ -228,16 +227,12 @@ allVisibleWalls w = concatMap (flip (visibleWalls vPos) w . (+.+ vPos)) $ nRays
|
||||
where
|
||||
vPos = w ^. wCam . camViewFrom
|
||||
|
||||
overlapCircWalls ::
|
||||
Point2 ->
|
||||
Float ->
|
||||
[Wall] ->
|
||||
[(Point2, Wall)]
|
||||
overlapCircWalls :: Point2 -> Float -> [Wall] -> [(Point2, Wall)]
|
||||
{-# INLINE overlapCircWalls #-}
|
||||
overlapCircWalls p r = mapMaybe dointersect
|
||||
overlapCircWalls p r = mapMaybe g
|
||||
where
|
||||
dointersect wl = f (_wlLine wl) <&> (,wl)
|
||||
f (a, b) = intersectSegSeg p (p +.+ r *.* normalizeV ((0.5 *.* (a +.+ b)) -.- p)) a b
|
||||
g wl = f (_wlLine wl) <&> (,wl)
|
||||
f (a, b) = intersectSegSeg p (p + r *^ vNormal (normalizeV (b - a))) a b
|
||||
|
||||
circHitWall :: Point2 -> Point2 -> Float -> World -> Bool
|
||||
circHitWall sp ep r w =
|
||||
@@ -256,7 +251,8 @@ collideCircWalls :: Point2 -> Point2 -> Float -> [Wall] -> (Point2, Maybe Wall)
|
||||
collideCircWalls sp ep rad = foldl' findPoint (ep, Nothing)
|
||||
where
|
||||
findPoint (p, mwl) wl =
|
||||
maybe (p, mwl) (,Just wl) . uncurry (intersectSegSeg sp p)
|
||||
maybe (p, mwl) (,Just wl)
|
||||
. uncurry (intersectSegSeg sp p)
|
||||
. shiftbyrad
|
||||
. _wlLine
|
||||
$ wl
|
||||
@@ -272,14 +268,7 @@ collideCircWalls sp ep rad = foldl' findPoint (ep, Nothing)
|
||||
|
||||
overlapCircWallsClosest :: Point2 -> Float -> [Wall] -> Maybe (Point2, Wall)
|
||||
{-# INLINE overlapCircWallsClosest #-}
|
||||
overlapCircWallsClosest p r =
|
||||
safeMinimumOn (dist p . fst)
|
||||
. overlapCircWalls p r
|
||||
|
||||
--overlapCircWallsClosest :: Point2 -> Float -> StreamOf Wall -> Maybe (Point2,Wall)
|
||||
--{-# INLINE overlapCircWallsClosest #-}
|
||||
--overlapCircWallsClosest p r = minStreamOn (dist p . fst)
|
||||
-- . overlapCircWalls p r
|
||||
overlapCircWallsClosest p r = safeMinimumOn (dist p . fst) . overlapCircWalls p r
|
||||
|
||||
{- | Test if a circle collides with any wall.
|
||||
- Note no check on whether the wall is walkable.
|
||||
@@ -313,7 +302,7 @@ hasButtonLOS :: Point2 -> Point2 -> World -> Bool
|
||||
{-# INLINE hasButtonLOS #-}
|
||||
hasButtonLOS _ _ = const True
|
||||
|
||||
--hasButtonLOS p1 p2 =
|
||||
-- hasButtonLOS p1 p2 =
|
||||
-- not
|
||||
-- . collidePointTestFilter (not . _wlTouchThrough) p1 p2
|
||||
-- . wlsNearSeg p1 p2
|
||||
@@ -325,7 +314,6 @@ hasLOSIndirect p1 p2 =
|
||||
. collidePointTestFilter wlIsOpaque p1 p2
|
||||
. wlsNearSeg p1 p2
|
||||
|
||||
|
||||
canSee :: Int -> Int -> World -> Bool
|
||||
{-# INLINE canSee #-}
|
||||
canSee i j w = hasLOS p1 p2 w
|
||||
|
||||
Reference in New Issue
Block a user