Move towards a simplified creature update

This commit is contained in:
2021-12-09 18:16:31 +00:00
parent e1a9327c06
commit bd94044445
14 changed files with 50 additions and 39 deletions
+14 -13
View File
@@ -25,8 +25,8 @@ import qualified Data.IntMap.Strict as IM
import qualified Data.Map.Strict as M
--import qualified Data.Set as S
import Control.Lens
import Data.Monoid
import System.Random
--import Data.Monoid
--import System.Random
{- For most menus the only way to change the world is using event handling. -}
updateUniverse :: Universe -> Universe
@@ -65,7 +65,8 @@ functionalUpdate cfig w = checkEndGame
. zoneClouds
. updateMIM magnets _mgUpdate
. updateIMl _machines _mcUpdate
. updateCreatures
. updateIMl _creatures _crUpdate
-- . updateCreatures
. updateCreatureGroups
. updateBlocks
. updateSeenWalls
@@ -144,16 +145,16 @@ updateMIM :: ASetter' World (IM.IntMap a) -> (a -> a -> Maybe a) -> World -> Wor
updateMIM f up w = w & f %~ IM.mapMaybe (dbArg up)
-- Note that this updates the randgen
updateCreatures :: World -> World
updateCreatures w = appEndo f $ w
& creatures .~ IM.mapMaybe id m
& randGen .~ newg
where
((f,newg),m) = mapAccumR crUp (Endo id,_randGen w) (_creatures w)
crUp (f',g) cr = ((f' <> f'',g'), cr')
where
(f'',cr') = _crUpdate cr cr (w & randGen .~ g)
(_,g') = genWord8 g
--updateCreatures :: World -> World
--updateCreatures w = appEndo f $ w
-- & creatures .~ IM.mapMaybe id m
-- & randGen .~ newg
-- where
-- ((f,newg),m) = mapAccumR crUp (Endo id,_randGen w) (_creatures w)
-- crUp (f',g) cr = ((f' <> f'',g'), cr')
-- where
-- (f'',cr') = _crUpdate cr cr (w & randGen .~ g)
-- (_,g') = genWord8 g
ppEvents :: World -> World
ppEvents w = IM.foldl' (flip $ \pp -> _ppEvent pp pp) w $ _pressPlates w