Improve machines, tweak wall ids

This commit is contained in:
2021-11-01 15:21:21 +00:00
parent 7692421112
commit 7ddbbdda14
11 changed files with 76 additions and 28 deletions
+11 -9
View File
@@ -15,6 +15,7 @@ import Dodge.Update.Camera
import Dodge.SoundLogic
import Dodge.Inventory
import Dodge.WorldEvent.Sound
import Dodge.Wall.Delete
import Geometry
import Geometry.ConvexPoly
import Geometry.Vector3D
@@ -24,6 +25,7 @@ import Data.List
import Data.Maybe
import Data.Function
import qualified Data.Set as S
import qualified Data.IntSet as IS
import qualified Data.IntMap.Strict as IM
import Control.Lens
import Data.Monoid
@@ -63,6 +65,7 @@ functionalUpdate w = case _menuLayers w of
. updateLightSources
. updateClouds
. zoneClouds
. updateMachines
. updateCreatures
. updateCreatureGroups
. updateBlocks
@@ -86,7 +89,7 @@ splinterBlock bl w = foldr unshadowBlock w (_blShadows bl) -- foldr shiftTowardC
& blocks . ix (_blID bl) . blHPs %~ tail
& theSoundEffect cen
where
wls = map (_walls w IM.!) (_blWallIDs bl)
wls = map (_walls w IM.!) (IS.toList $ _blWallIDs bl)
ps = map (fst . _wlLine) wls
cen = centroid ps
theSoundEffect
@@ -112,18 +115,12 @@ updateBlocks w = foldr f w $ _blocks w
destroyBlock :: Block -> World -> World
destroyBlock bl w = w
& walls %~ removeIDs wlids
& flip (foldr removeFromZone) wlids
& deleteWallIDs wlids
& blocks %~ IM.delete (_blID bl)
& mkSoundBreakGlass pos
where
wlids = _blWallIDs bl
pos = fst . _wlLine $ _walls w IM.! head wlids
removeIDs is wls = foldr IM.delete wls is
removeFromZone wlid w' = over (wallsZone . znObjects . ix x . ix y) (IM.delete (_wlID wl)) w'
where
(x,y) = zoneOfPoint $ uncurry pHalf (_wlLine wl)
wl = _walls w IM.! wlid -- note the use of w not w'
pos = fst . _wlLine $ _walls w IM.! IS.findMin wlids
-- | Note the explict use of record syntax. Using lens created a space leak.
resetWorldEvents :: World -> World
@@ -158,6 +155,11 @@ updateParticles w = set particles (catMaybes ps) w'
where
(w',ps) = mapAccumR (\a b -> _ptUpdate b a b) w $ _particles w
updateMachines :: World -> World
updateMachines w = foldr f w (_machines w)
where
f mc = _mcUpdate mc mc
-- Note that this updates the randgen
updateCreatures :: World -> World
updateCreatures w = appEndo f $ w