Simplify block/wall destruction

This uses a right fold, so might be slower than a strict left fold
This commit is contained in:
2025-11-09 16:00:46 +00:00
parent 6f3632d495
commit cd7a5dcbb5
3 changed files with 48 additions and 25 deletions
+15 -6
View File
@@ -13,14 +13,23 @@ import Dodge.Zoning.Base
import Geometry.Data
import qualified IntMapHelp as IM
--updateWallDamages :: World -> World
--updateWallDamages w =
-- let (is, w') = IM.foldlWithKey' f (mempty, w) (w ^. cWorld . lWorld . wallDamages)
-- in updateEdgesWall is w' & cWorld . lWorld . wallDamages .~ IM.empty
-- where
-- f isw k dams = fromMaybe isw $ do
-- wl <- isw ^? _2 . cWorld . lWorld . walls . ix k
-- return $ foldl' (flip (`damageWall` wl)) isw dams
updateWallDamages :: World -> World
updateWallDamages w =
let (is, w') = IM.foldlWithKey' f (mempty, w) (w ^. cWorld . lWorld . wallDamages)
in updateEdgesWall is w' & cWorld . lWorld . wallDamages .~ IM.empty
updateWallDamages w = set (cWorld . lWorld . wallDamages) mempty
. uncurry updateEdgesWall $ foldrM f w
(IM.toList $ w ^. cWorld . lWorld . wallDamages)
where
f isw k dams = fromMaybe isw $ do
wl <- isw ^? _2 . cWorld . lWorld . walls . ix k
return $ foldl' (flip (`damageWall` wl)) isw dams
f (k,dams) w' = fromMaybe (mempty,w') $ do
wl <- w' ^? cWorld . lWorld . walls . ix k
return $ foldrM (damageWall wl) w' dams
updateEdgesWall :: S.Set Int2 -> World -> World
updateEdgesWall is w =