Move debug flags to config, various perf improvements
This commit is contained in:
@@ -1,14 +1,16 @@
|
||||
{- | Deals with moving creature wall collisions. -}
|
||||
module Dodge.WallCreatureCollisions where
|
||||
module Dodge.WallCreatureCollisions
|
||||
( colCrsWalls
|
||||
) where
|
||||
import Dodge.Data
|
||||
import Dodge.Data.DamageType
|
||||
import Dodge.Creature.State.Data
|
||||
import Dodge.Debug.Flag.Data
|
||||
import Dodge.Zone
|
||||
import Dodge.Base
|
||||
import Dodge.Config.Data
|
||||
import Geometry
|
||||
|
||||
import Data.List
|
||||
import Data.Monoid
|
||||
import Data.Maybe
|
||||
import Data.Function
|
||||
import Control.Lens
|
||||
@@ -21,9 +23,7 @@ colCrWall :: World -> Creature -> Creature
|
||||
colCrWall w c
|
||||
| noclipIsOn && _crID c == 0 = c -- for noclip
|
||||
| p1 == p2 = pushOrCrush ls c
|
||||
| otherwise = c & crPos %~
|
||||
-- collideCorners rad wallPoints
|
||||
collideWalls rad p1 ls
|
||||
| otherwise = c & crPos %~ pushOutFromWalls rad ls
|
||||
. flip (collidePointWalls p1) wls -- check push throughs
|
||||
where
|
||||
rad = _crRad c + wallBuffer
|
||||
@@ -32,7 +32,7 @@ colCrWall w c
|
||||
ls = IM.elems $ _wlLine <$> wallsNearPoint p2 w
|
||||
wls = wallsNearPoint p2 w
|
||||
--wallPoints = map fst ls
|
||||
noclipIsOn = _noClip $ _debugFlags w
|
||||
noclipIsOn = _debug_noclip $ _config w
|
||||
|
||||
-- the amount to push creatures out from walls, extra to their radius
|
||||
wallBuffer :: Float
|
||||
@@ -41,23 +41,11 @@ wallBuffer = 0
|
||||
-- the following tests whether or not a point is on a wall, and if so pushes it
|
||||
-- out from the wall
|
||||
-- this is then repeated if the point ends up on a new wall
|
||||
collideWalls :: Float -> Point2 -> [(Point2,Point2)] -> Point2 -> Point2
|
||||
collideWalls rad cp1 wls cp2 = case (listToMaybe . mapMaybe (pushOutFromWall rad cp2)) wls of
|
||||
Nothing -> cp2
|
||||
Just cp3 -> case (listToMaybe . reverse . mapMaybe (pushOutFromWall rad cp3)) wls of
|
||||
Nothing -> cp3
|
||||
-- Just cp4 -> 0.5 *.* (cp4 +.+ cp1)
|
||||
Just _ -> cp1
|
||||
|
||||
-- pushes a point out from a list of walls
|
||||
-- if multiple new points occur, chooses the one closest to the orignal point
|
||||
pushOutFromWalls :: Float -> [(Point2,Point2)] -> Point2 -> Point2
|
||||
pushOutFromWalls rad wls p =
|
||||
fromMaybe p
|
||||
. listToMaybe
|
||||
. sortBy (compare `on` dist p)
|
||||
$ mapMaybe (pushOutFromWall rad p)
|
||||
wls
|
||||
pushOutFromWalls rad wls p1 = case (getFirst . foldMap (First . pushOutFromWall rad p1)) wls of
|
||||
Nothing -> p1
|
||||
Just p2 -> fromMaybe p2 $ (getLast . foldMap (Last . pushOutFromWall rad p2)) wls
|
||||
-- possible improvement: choose between the closer of p2 and "p3" to p1
|
||||
|
||||
pushOrCrush :: [(Point2,Point2)] -> Creature -> Creature
|
||||
pushOrCrush wls cr = case mapMaybe (pushOutFromWall (_crRad cr) cpos) wls of
|
||||
@@ -80,18 +68,17 @@ pushOutFromWall rad cp2 (wp1,wp2)
|
||||
newP = errorClosestPointOnLine 5 wp1' wp2' cp2
|
||||
isOnWall = circOnSegNoEndpoints wp1 wp2 cp2 rad
|
||||
|
||||
pushOutFromCorners :: World -> Creature -> Creature
|
||||
pushOutFromCorners w cr = cr & crPos .~ newPos
|
||||
where
|
||||
newPos = foldr (intersectCirclePoint (_crRad cr)) (_crPos cr) ls
|
||||
ls = nub . concatMap (\(x,y) -> [x,y]) . IM.elems $ _wlLine <$> wallsNearPoint (_crPos cr) w
|
||||
--pushOutFromCorners :: World -> Creature -> Creature
|
||||
--pushOutFromCorners w cr = cr & crPos .~ newPos
|
||||
-- where
|
||||
-- newPos = foldr (intersectCirclePoint (_crRad cr)) (_crPos cr) ls
|
||||
-- ls = nub . concatMap (\(x,y) -> [x,y]) . IM.elems $ _wlLine <$> wallsNearPoint (_crPos cr) w
|
||||
|
||||
collideCorners :: Float -> [Point2] -> Point2 -> Point2
|
||||
collideCorners rad ps p2 = foldr (intersectCirclePoint rad) p2 ps
|
||||
|
||||
-- collide circles with points (outer corners)
|
||||
intersectCirclePoint :: Float -> Point2 -> Point2 -> Point2
|
||||
intersectCirclePoint rad p cCen
|
||||
| dist cCen p > rad = cCen
|
||||
| otherwise = p +.+ (rad *.* errorNormalizeV 65 (cCen -.- p))
|
||||
--collideCorners :: Float -> [Point2] -> Point2 -> Point2
|
||||
--collideCorners rad ps p2 = foldr (intersectCirclePoint rad) p2 ps
|
||||
|
||||
---- collide circles with points (outer corners)
|
||||
--intersectCirclePoint :: Float -> Point2 -> Point2 -> Point2
|
||||
--intersectCirclePoint rad p cCen
|
||||
-- | dist cCen p > rad = cCen
|
||||
-- | otherwise = p +.+ (rad *.* errorNormalizeV 65 (cCen -.- p))
|
||||
|
||||
Reference in New Issue
Block a user