Refactor world events

This commit is contained in:
2022-07-22 14:30:53 +01:00
parent 7fdb70dd1c
commit 43e7d20b21
14 changed files with 95 additions and 40 deletions
+7 -8
View File
@@ -4,6 +4,7 @@ Module : Dodge.Update
Description : Simulation update
-}
module Dodge.Update ( updateUniverse ) where
import Dodge.WorldEffect
import Dodge.Data
import Dodge.Beam
import Dodge.LightSource.Update
@@ -47,7 +48,7 @@ import SDL
updateUniverse :: Universe -> Universe
updateUniverse u = case _menuLayers u of
(WaitScreen s i : _)
| i < 1 -> u & over uvWorld (dbArg _worldEvents)
| i < 1 -> u & over uvWorld doWorldEvents
| otherwise -> u & menuLayers %~ ( (WaitScreen s (i-1) :) . tail )
(OptionScreen {_scOptionFlag = GameOverOptions} : _) -> u & uvWorld %~
( updateParticles
@@ -75,9 +76,8 @@ functionalUpdate w = over uvWorld checkEndGame
. over uvWorld (simpleCrSprings )
. over uvWorld (zoneCreatures )
. over uvWorld (updateIMl _doors _drMech )
. over uvWorld doWorldEvents
. over uvWorld (updateDelayedEvents )
. over uvWorld (resetWorldEvents )
. over uvWorld (dbArg _worldEvents )
. over uvWorld (updateIMl _modifications _mdUpdate )
. over uvWorld (updateSparks )
. over uvWorld (updateRadarSweeps )
@@ -110,6 +110,9 @@ functionalUpdate w = over uvWorld checkEndGame
. updateBounds -- where should this go? next to update camera?
$ over uvWorld updateCloseObjects w
doWorldEvents :: World -> World
doWorldEvents w = foldr doWorldEffect (w & worldEvents .~ []) (_worldEvents w)
zoneClouds :: World -> World
zoneClouds w = w
& clZoning . znObjects .~ mempty
@@ -194,10 +197,6 @@ updateIMl fim fup w = foldl' (flip $ dbArg fup) w (fim w)
updateIMl' :: (World -> IM.IntMap a) -> (a -> World -> World) -> World -> World
updateIMl' fim fup w = foldl' (flip fup) w (fim w)
-- | Note the explict use of record syntax. Using lens created a space leak.
resetWorldEvents :: World -> World
resetWorldEvents w = w {_worldEvents = id}
updateCreatureGroups :: World -> World
updateCreatureGroups w = w & creatureGroups %~
IM.mapMaybe (\cgp -> _crGroupUpdate cgp w cgp)
@@ -457,5 +456,5 @@ updateDelayedEvents w = let (neww,newde) = mapAccumR f w (_delayedEvents w)
in neww & delayedEvents .~ catMaybes newde
where
f w' (i,g)
| i <= 0 = (g w', Nothing)
| i <= 0 = (w' & worldEvents .:~ g, Nothing)
| otherwise = (w', Just (i-1,g))