This commit is contained in:
2025-10-12 21:13:06 +01:00
parent 408b39f160
commit 8b44538048
11 changed files with 23 additions and 137 deletions
+23 -23
View File
@@ -1,4 +1,5 @@
{-# LANGUAGE LambdaCase #-}
module Dodge.Update (updateUniverse) where
import Color
@@ -32,7 +33,6 @@ import Dodge.LinearShockwave.Update
import Dodge.ListDisplayParams
import Dodge.Machine.Update
import Dodge.ModificationEffect
import Dodge.PressPlate
import Dodge.Projectile.Update
import Dodge.Prop.Moving
import Dodge.Prop.Update
@@ -161,7 +161,7 @@ updateUniverseMid u = case _uvScreenLayers u of
. updateUseInputInGame
$ over
uvWorld
(updateMouseInGame (u ^. uvConfig) . updateCamera (u ^. uvConfig))
(updateMouseInGame (u ^. uvConfig) . updateCamera (u ^. uvConfig))
u
timeFlowUpdate :: Universe -> Universe
@@ -237,13 +237,12 @@ scrollTimeForward w = case w ^? timeFlow . futureWorlds . _head of
-- | The update step.
functionalUpdate :: Universe -> Universe
functionalUpdate u =
functionalUpdate =
checkEndGame
. over (uvWorld . cWorld . lWorld) updateMagnets
. over uvWorld (cWorld . lWorld . lClock +~ 1)
. over uvWorld updateDistortions
. over uvWorld updateCreatureSoundPositions
. over uvWorld ppEvents
. colCrsWalls
. over uvWorld simpleCrSprings
. over uvWorld (updateIMl' (_doors . _lWorld . _cWorld) updateDoor)
@@ -270,7 +269,9 @@ functionalUpdate u =
. over uvWorld updatePulseLasers
. over uvWorld updateTeslaArcs
. over uvWorld updateTractorBeams
. over uvWorld (updateIMl' (_linearShockwaves . _lWorld . _cWorld) updateLinearShockwave)
. over
uvWorld
(updateIMl' (_linearShockwaves . _lWorld . _cWorld) updateLinearShockwave)
. over uvWorld (updateIMl' (_props . _lWorld . _cWorld) updateProp)
. over uvWorld (updateIMl' (_projectiles . _lWorld . _cWorld) updateProjectile)
. over uvWorld updateClouds
@@ -297,7 +298,7 @@ functionalUpdate u =
. set (uvWorld . cWorld . lWorld . flares) []
. set (uvWorld . cWorld . lWorld . lights) []
. updateAimPos
$ over uvWorld updatePastWorlds u
. over uvWorld updatePastWorlds
updateAimPos :: Universe -> Universe
updateAimPos u =
@@ -317,7 +318,7 @@ checkTermDist w = fromMaybe w $ do
tmid <- w ^? hud . subInventory . termID
btid <- w ^? cWorld . lWorld . terminals . ix tmid . tmButtonID
btpos <- w ^? cWorld . lWorld . buttons . ix btid . btPos
guard $ dist btpos ( you w ^. crPos . _xy) > 40
guard $ dist btpos (you w ^. crPos . _xy) > 40
return $ w & hud . subInventory .~ NoSubInventory
updateMouseContext :: Config -> Universe -> Universe
@@ -327,7 +328,7 @@ updateMouseContext cfig u = case u ^? uvScreenLayers . ix 0 of
updateMouseContextGame :: Config -> Universe -> MouseContext -> MouseContext
updateMouseContextGame cfig u = \case
OverInvDrag i _ -> OverInvDrag i (inverseSelNumPos cfig invDP mpos disss)
OverInvDrag i _ -> OverInvDrag i (inverseSelNumPos cfig invDP mpos disss)
x@OverInvDragSelect{} -> x
_ -> fromMaybe aimcontext (isrotatedrag <|> overterm <|> overinv <|> overcomb)
where
@@ -458,8 +459,8 @@ pbFlicker pt =
d = 4 * fromIntegral (10 + abs ((_pbTimer pt `mod` 20) - 10))
zoneClouds :: World -> World
zoneClouds w = w
& clZoning .~ foldl' (flip zoneCloud) mempty (w ^. cWorld . lWorld . clouds)
zoneClouds w =
w & clZoning .~ foldl' (flip zoneCloud) mempty (w ^. cWorld . lWorld . clouds)
zoneDusts :: World -> World
zoneDusts w = w & dsZoning .~ foldl' (flip zoneDust) mempty (w ^. cWorld . lWorld . dusts)
@@ -495,8 +496,7 @@ setOldPos cr = cr & crOldPos .~ _crPos cr
zoneCreatures :: World -> World
zoneCreatures w =
w & crZoning
.~ foldl' zoneCreature mempty (w ^. cWorld . lWorld . creatures)
w & crZoning .~ foldl' zoneCreature mempty (w ^. cWorld . lWorld . creatures)
updateCreatureSoundPositions :: World -> World
updateCreatureSoundPositions w =
@@ -505,9 +505,10 @@ updateCreatureSoundPositions w =
$ _playingSounds w
where
insertSound w' k s = w' & toPlaySounds %~ M.insertWith (const id) k s
updateSound (CrMouth cid) s = case w ^? cWorld . lWorld . creatures . ix cid . crPos . _xy of
Just p -> Just s{_soundPos = p, _soundAngDist = Just (soundAngle p w, 0)}
Nothing -> Just s{_soundTime = Just 0}
updateSound (CrMouth cid) s =
case w ^? cWorld . lWorld . creatures . ix cid . crPos . _xy of
Just p -> Just s{_soundPos = p, _soundAngDist = Just (soundAngle p w, 0)}
Nothing -> Just s{_soundTime = Just 0}
updateSound _ _ = Nothing
--updateIMr :: (World -> IM.IntMap a) -> (a -> a -> World -> World) -> World -> World
@@ -599,7 +600,8 @@ updatePulseLaser pz = case pz ^. pzTimer of
5 -> (Endo f, [pz & pzTimer -~ 1])
_ -> (Endo g, [pz & pzTimer -~ 1])
where
f w = dodam thHit w
f w =
dodam thHit w
& cWorld . lWorld . flares <>~ drawLaser cyan (sp : ps)
where
(thHit, ps) = reflectPulseLaserAlong phasev sp xp w
@@ -730,9 +732,6 @@ updateDusts w = updateObjMapMaybe dusts (updateDust w) w
-- (intersectSegSegss x y ass)
--intersectSegsSegss _ _ = Nothing
ppEvents :: World -> World
ppEvents w = IM.foldl' (flip $ \pp -> doPressPlateEvent (_ppEvent pp) pp) w $ w ^. cWorld . lWorld . pressPlates
--updateSeenWalls :: World -> World
--updateSeenWalls w = alaf Endo foldMap (markWallSeen . _wlID . snd) (allVisibleWalls w) w
@@ -845,8 +844,9 @@ dustSpringVel a v b
radDist = 10
simpleCrSprings :: World -> World
simpleCrSprings w = IM.foldl' (flip crSpring) w
$ IM.filter (\cr -> cr ^. crPos . _z >= 0) $ w ^. cWorld . lWorld . creatures
simpleCrSprings w =
IM.foldl' (flip crSpring) w $
IM.filter (\cr -> cr ^. crPos . _z >= 0) $ w ^. cWorld . lWorld . creatures
-- note that this may in rare cases not push creatures away from each other
crSpring :: Creature -> World -> World
@@ -868,8 +868,8 @@ crCrSpring c1 c2
vec = c1 ^. crPos . _xy - c2 ^. crPos . _xy
diff = magV vec
comRad = crRad (c1 ^. crType) + crRad (c2 ^. crType)
overlap1 = ((comRad - diff) * crMass (_crType c2) * 0.5 / massT) *.* errorNormalizeV 55 vec
overlap2 = ((comRad - diff) * crMass (_crType c1) * 0.5 / massT) *.* errorNormalizeV 56 vec
overlap1 = ((comRad - diff) * crMass (_crType c2) * 0.5 / massT) *^ signorm vec
overlap2 = ((comRad - diff) * crMass (_crType c1) * 0.5 / massT) *^ signorm vec
massT = crMass (_crType c1) + crMass (_crType c2)
updateDelayedEvents :: World -> World