Thread random generate through creature update

This commit is contained in:
2021-09-05 12:46:19 +01:00
parent c16c09a9ce
commit 68ba11aa91
+12 -3
View File
@@ -31,7 +31,8 @@ import qualified Data.IntMap.Lazy as IM
import qualified Data.Map as M
import Control.Lens
import Data.Monoid
--import System.Random
import System.Random
--import Data.Bifunctor
update :: World -> World
update = functionalUpdate . pushSideEffects
@@ -136,10 +137,18 @@ updateParticles w = set particles (catMaybes ps) w'
where
(w',ps) = mapAccumR (\a b -> _ptUpdate' b a b) w $ _particles w
-- Note that this updates the randgen
updateCreatures :: World -> World
updateCreatures w = appEndo f $ w & creatures .~ IM.mapMaybe id m
updateCreatures w = appEndo f $ w
& creatures .~ IM.mapMaybe id m
& randGen .~ newg
where
(f,m) = traverse (\cr -> _crUpdate cr cr w) (_creatures w)
((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
{- |
Apply door mechanisms. -}