Finish replacement of sortOn with safeMinimumBy, regress door space leak

This commit is contained in:
2021-07-20 05:40:57 +02:00
parent 8bc5b49a3c
commit 40ee81aff9
4 changed files with 10 additions and 16 deletions
+2 -5
View File
@@ -1,16 +1,13 @@
module Dodge.Creature.Action.Flee module Dodge.Creature.Action.Flee
where where
import Dodge.Data import Dodge.Data
import Dodge.Base.Collide
import Geometry import Geometry
import Data.List
import Data.Maybe
retreatPointForFrom retreatPointForFrom
:: Float -> World -> Creature -> Point2 -> Maybe Point2 :: Float -> World -> Creature -> Point2 -> Maybe Point2
retreatPointForFrom d _ cr p retreatPointForFrom d _ cr p
= listToMaybe = safeMinimumOn (dist cpos)
. sortOn (dist cpos)
$ divideCircle 10 p d $ divideCircle 10 p d
where where
cpos = _crPos cr cpos = _crPos cr
+1 -2
View File
@@ -17,7 +17,6 @@ import Picture
import Geometry import Geometry
import Data.Maybe import Data.Maybe
import Data.List
import qualified Data.IntMap.Strict as IM import qualified Data.IntMap.Strict as IM
import Control.Lens import Control.Lens
import Control.Monad.Reader import Control.Monad.Reader
@@ -59,7 +58,7 @@ mFlockACC cr w = do
&& dist (_crPos cr') tpos > dist cpos tpos && dist (_crPos cr') tpos > dist cpos tpos
-- && circOnSeg (_crPos cr') tpos cpos (_crRad cr + _crRad cr') -- && circOnSeg (_crPos cr') tpos cpos (_crRad cr + _crRad cr')
nearACCs = IM.filter isFarACC $ creaturesNearPointI 3 cpos w nearACCs = IM.filter isFarACC $ creaturesNearPointI 3 cpos w
acr <- listToMaybe $ sortOn (dist cpos . _crPos) $ IM.elems nearACCs acr <- safeMinimumOn (dist cpos . _crPos) nearACCs
let r = _crRad acr + _crRad cr + 10 let r = _crRad acr + _crRad cr + 10
horDir = normalizeV (vNormal (cpos -.- tpos)) horDir = normalizeV (vNormal (cpos -.- tpos))
horShift = if isLHS tpos cpos (_crPos acr) horShift = if isLHS tpos cpos (_crPos acr)
+2 -2
View File
@@ -4,7 +4,7 @@ import Dodge.Data
import Dodge.Base import Dodge.Base
import Geometry import Geometry
import Data.Maybe --import Data.Maybe
import Data.List import Data.List
import qualified Data.IntMap.Strict as IM import qualified Data.IntMap.Strict as IM
--import System.Random --import System.Random
@@ -52,7 +52,7 @@ rmSelectedInvItem
rmSelectedInvItem cid w = rmInvItem cid (_crInvSel (_creatures w IM.! cid)) w rmSelectedInvItem cid w = rmInvItem cid (_crInvSel (_creatures w IM.! cid)) w
-- for now, left are floor items, right are buttons -- for now, left are floor items, right are buttons
closestActiveObject :: World -> Maybe (Either FloorItem Button) closestActiveObject :: World -> Maybe (Either FloorItem Button)
closestActiveObject w = listToMaybe $ sortOn (dist ypos . pos) actObjs closestActiveObject w = safeMinimumOn (dist ypos . pos) actObjs
where where
ypos = _crPos $ you w ypos = _crPos $ you w
actObjs = filter (\obj -> dist ypos (pos obj) < 40 && hasLOS ypos (pos obj) w) actObjs = filter (\obj -> dist ypos (pos obj) < 40 && hasLOS ypos (pos obj) w)
+5 -7
View File
@@ -5,6 +5,7 @@ Description : Concerns carving out of static walls to create the general room pl
module Dodge.LevelGen.StaticWalls module Dodge.LevelGen.StaticWalls
where where
import Dodge.Data import Dodge.Data
import Dodge.Base.Collide
import Geometry import Geometry
--import Control.Lens --import Control.Lens
@@ -180,8 +181,7 @@ addPolyWall (p1,p2) wls =
else (p1,p2) : wls else (p1,p2) : wls
Nothing -> (p1,p2) : wls Nothing -> (p1,p2) : wls
where where
maybeWs = listToMaybe hitWls maybeWs = safeMinimumOn (dist p3 . fromJust . f) $ filter (isJust . f) wls
hitWls = sortOn (dist p3 . fromJust . f) $ filter (isJust . f) wls
p3 = 0.5 *.* (p1 +.+ p2) p3 = 0.5 *.* (p1 +.+ p2)
p4 = p3 +.+ 10000 *.* vNormal (p2 -.- p1) p4 = p3 +.+ 10000 *.* vNormal (p2 -.- p1)
f = uncurry $ myIntersectSegSeg p3 p4 f = uncurry $ myIntersectSegSeg p3 p4
@@ -289,19 +289,18 @@ brokenAdd :: WallP
brokenAdd = head brokenAddedWalls brokenAdd = head brokenAddedWalls
findShadowWall :: WallP -> [WallP] -> Maybe WallP findShadowWall :: WallP -> [WallP] -> Maybe WallP
findShadowWall (p1,p2) wls = listToMaybe hitWls findShadowWall (p1,p2) wls = safeMinimumOn (dist p3 . fromJust . f) $ filter (isJust . f) wls
where where
p3 = 0.5 *.* (p1 +.+ p2) p3 = 0.5 *.* (p1 +.+ p2)
p4 = p3 +.+ 10000 *.* rotateV (negate $ pi/4) (vNormal (p2 -.- p1)) p4 = p3 +.+ 10000 *.* rotateV (negate $ pi/4) (vNormal (p2 -.- p1))
hitWls = sortOn (dist p3 . fromJust . f) $ filter (isJust . f) wls
f = uncurry $ myIntersectSegSeg p3 p4 f = uncurry $ myIntersectSegSeg p3 p4
findShadowWalls :: WallP -> [WallP] -> [WallP] findShadowWalls :: WallP -> [WallP] -> [WallP]
findShadowWalls (p1,p2) wls = hitWls findShadowWalls (p1,p2) wls = hitWls
where where
hitWls = sortOn (dist p3 . fromJust . f) $ filter (isJust . f) wls
p3 = 0.5 *.* (p1 +.+ p2) p3 = 0.5 *.* (p1 +.+ p2)
p4 = p3 +.+ 10000 *.* vNormal (p2 -.- p1) p4 = p3 +.+ 10000 *.* vNormal (p2 -.- p1)
hitWls = sortOn (dist p3 . fromJust . f) $ filter (isJust . f) wls
f = uncurry $ myIntersectSegSeg p3 p4 f = uncurry $ myIntersectSegSeg p3 p4
addWallDebug :: WallP -> [WallP] -> [WallP] addWallDebug :: WallP -> [WallP] -> [WallP]
@@ -312,8 +311,7 @@ addWallDebug (p1,p2) wls =
else (p1,p2) : wls else (p1,p2) : wls
Nothing -> (p1,p2) : wls Nothing -> (p1,p2) : wls
where where
maybeWs = listToMaybe hitWls maybeWs = safeMinimumOn (dist p3 . fromJust . f) $ filter (isJust . f) wls
hitWls = sortOn (dist p3 . fromJust . f) $ filter (isJust . f) wls
p3 = 0.5 *.* (p1 +.+ p2) p3 = 0.5 *.* (p1 +.+ p2)
p4 = p3 +.+ 10000 *.* vNormal (p2 -.- p1) p4 = p3 +.+ 10000 *.* vNormal (p2 -.- p1)
f = uncurry $ myIntersectSegSeg p3 p4 f = uncurry $ myIntersectSegSeg p3 p4