Thread random generate through creature update
This commit is contained in:
+12
-3
@@ -31,7 +31,8 @@ import qualified Data.IntMap.Lazy as IM
|
|||||||
import qualified Data.Map as M
|
import qualified Data.Map as M
|
||||||
import Control.Lens
|
import Control.Lens
|
||||||
import Data.Monoid
|
import Data.Monoid
|
||||||
--import System.Random
|
import System.Random
|
||||||
|
--import Data.Bifunctor
|
||||||
|
|
||||||
update :: World -> World
|
update :: World -> World
|
||||||
update = functionalUpdate . pushSideEffects
|
update = functionalUpdate . pushSideEffects
|
||||||
@@ -136,10 +137,18 @@ updateParticles w = set particles (catMaybes ps) w'
|
|||||||
where
|
where
|
||||||
(w',ps) = mapAccumR (\a b -> _ptUpdate' b a b) w $ _particles w
|
(w',ps) = mapAccumR (\a b -> _ptUpdate' b a b) w $ _particles w
|
||||||
|
|
||||||
|
-- Note that this updates the randgen
|
||||||
updateCreatures :: World -> World
|
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
|
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. -}
|
Apply door mechanisms. -}
|
||||||
|
|||||||
Reference in New Issue
Block a user