Cleanup
This commit is contained in:
+17
-16
@@ -18,7 +18,6 @@ module Dodge.Base.Collide (
|
|||||||
collideCircWalls,
|
collideCircWalls,
|
||||||
overlapSegWalls,
|
overlapSegWalls,
|
||||||
overlapSegCrs,
|
overlapSegCrs,
|
||||||
-- bounceBall,
|
|
||||||
bouncePoint,
|
bouncePoint,
|
||||||
circOnSomeWall,
|
circOnSomeWall,
|
||||||
circOnAnyCr,
|
circOnAnyCr,
|
||||||
@@ -37,12 +36,12 @@ module Dodge.Base.Collide (
|
|||||||
collide3,
|
collide3,
|
||||||
) where
|
) where
|
||||||
|
|
||||||
import Data.Monoid
|
|
||||||
import Control.Lens
|
import Control.Lens
|
||||||
import Control.Monad
|
import Control.Monad
|
||||||
import qualified Data.IntSet as IS
|
import qualified Data.IntSet as IS
|
||||||
import Data.List (sortOn)
|
import Data.List (sortOn)
|
||||||
import Data.Maybe
|
import Data.Maybe
|
||||||
|
import Data.Monoid
|
||||||
import Dodge.Base.Wall
|
import Dodge.Base.Wall
|
||||||
import Dodge.Creature.Radius
|
import Dodge.Creature.Radius
|
||||||
import Dodge.Data.Object
|
import Dodge.Data.Object
|
||||||
@@ -261,10 +260,6 @@ collideCircWalls sp ep rad = foldl' findPoint (ep, Nothing)
|
|||||||
. shiftbyrad
|
. shiftbyrad
|
||||||
. _wlLine
|
. _wlLine
|
||||||
$ wl
|
$ wl
|
||||||
-- shiftbyrad (a, b) =
|
|
||||||
-- ( a +.+ rad *.* normalizeV (a -.- b)
|
|
||||||
-- , b +.+ rad *.* normalizeV (b -.- a)
|
|
||||||
-- )
|
|
||||||
shiftbyrad (a, b) =
|
shiftbyrad (a, b) =
|
||||||
bimap
|
bimap
|
||||||
f
|
f
|
||||||
@@ -299,7 +294,12 @@ circOnAnyCr :: Point2 -> Float -> World -> Bool
|
|||||||
{-# INLINE circOnAnyCr #-}
|
{-# INLINE circOnAnyCr #-}
|
||||||
circOnAnyCr p r w = IS.foldr f False $ crIXsNearPoint p w
|
circOnAnyCr p r w = IS.foldr f False $ crIXsNearPoint p w
|
||||||
where
|
where
|
||||||
f cid bl = maybe False (\cr -> dist p (cr ^. crPos . _xy) < r + crRad (cr ^. crType)) (w ^? cWorld . lWorld . creatures . ix cid) || bl
|
f cid bl =
|
||||||
|
maybe
|
||||||
|
False
|
||||||
|
(\cr -> dist p (cr ^. crPos . _xy) < r + crRad (cr ^. crType))
|
||||||
|
(w ^? cWorld . lWorld . creatures . ix cid)
|
||||||
|
|| bl
|
||||||
|
|
||||||
-- | More general collision tests follow
|
-- | More general collision tests follow
|
||||||
hasLOS :: Point2 -> Point2 -> World -> Bool
|
hasLOS :: Point2 -> Point2 -> World -> Bool
|
||||||
@@ -325,13 +325,16 @@ hasLOSIndirect p1 p2 =
|
|||||||
. collidePointTestFilter wlIsOpaque p1 p2
|
. collidePointTestFilter wlIsOpaque p1 p2
|
||||||
. wlsNearSeg p1 p2
|
. wlsNearSeg p1 p2
|
||||||
|
|
||||||
|
isFlyable :: Point2 -> Point2 -> World -> Bool
|
||||||
|
{-# INLINE isFlyable #-}
|
||||||
|
isFlyable p1 p2 =
|
||||||
|
not
|
||||||
|
. collidePointTestFilter (not . (^?! wlPathable)) p1 p2
|
||||||
|
. wlsNearSeg p1 p2
|
||||||
|
|
||||||
isWalkable :: Point2 -> Point2 -> World -> Bool
|
isWalkable :: Point2 -> Point2 -> World -> Bool
|
||||||
{-# INLINE isWalkable #-}
|
{-# INLINE isWalkable #-}
|
||||||
isWalkable p1 p2 w =
|
isWalkable p1 p2 w = isFlyable p1 p2 w && not (getAny $ foldMap f (w ^. cWorld . chasms))
|
||||||
(not
|
|
||||||
. collidePointTestFilter (not . (^?! wlPathable)) p1 p2
|
|
||||||
. wlsNearSeg p1 p2 $ w)
|
|
||||||
&& not (getAny $ foldMap f (w ^. cWorld . chasms))
|
|
||||||
where
|
where
|
||||||
f = foldMap (Any . isJust . uncurry (intersectSegSeg p1 p2)) . loopPairs
|
f = foldMap (Any . isJust . uncurry (intersectSegSeg p1 p2)) . loopPairs
|
||||||
|
|
||||||
@@ -339,8 +342,8 @@ canSee :: Int -> Int -> World -> Bool
|
|||||||
{-# INLINE canSee #-}
|
{-# INLINE canSee #-}
|
||||||
canSee i j w = hasLOS p1 p2 w
|
canSee i j w = hasLOS p1 p2 w
|
||||||
where
|
where
|
||||||
p1 = w ^?! cWorld . lWorld . creatures . ix i . crPos . _xy -- _crPos (_creatures (_cWorld w) IM.! i)
|
p1 = w ^?! cWorld . lWorld . creatures . ix i . crPos . _xy
|
||||||
p2 = w ^?! cWorld . lWorld . creatures . ix j . crPos . _xy -- _crPos (_creatures (_cWorld w) IM.! j) -- unsafe
|
p2 = w ^?! cWorld . lWorld . creatures . ix j . crPos . _xy
|
||||||
|
|
||||||
canSeeIndirect :: Int -> Int -> World -> Bool
|
canSeeIndirect :: Int -> Int -> World -> Bool
|
||||||
{-# INLINE canSeeIndirect #-}
|
{-# INLINE canSeeIndirect #-}
|
||||||
@@ -362,5 +365,3 @@ anythingHitCirc rad sp ep w = hitCr || circHitWall sp ep rad w
|
|||||||
(\cr -> intersectCircSegTest (cr ^. crPos . _xy) (rad + crRad (cr ^. crType)) sp ep)
|
(\cr -> intersectCircSegTest (cr ^. crPos . _xy) (rad + crRad (cr ^. crType)) sp ep)
|
||||||
(w ^? cWorld . lWorld . creatures . ix cid)
|
(w ^? cWorld . lWorld . creatures . ix cid)
|
||||||
|| bl
|
|| bl
|
||||||
|
|
||||||
-- this should probably be wallsOnLine or something
|
|
||||||
|
|||||||
Reference in New Issue
Block a user