From 13b07b53ce7a4b9dac2d3d825e5251d6cdf8cef1 Mon Sep 17 00:00:00 2001 From: justin Date: Wed, 24 Aug 2022 10:08:55 +0100 Subject: [PATCH] Fix space leak (non-strict data fields) --- src/Dodge/Creature/State.hs | 22 +++++++++++----------- src/Dodge/Data/Item.hs | 6 +++--- src/Dodge/Humanoid.hs | 8 ++++++-- 3 files changed, 20 insertions(+), 16 deletions(-) diff --git a/src/Dodge/Creature/State.hs b/src/Dodge/Creature/State.hs index d1c18b047..135f94e4c 100644 --- a/src/Dodge/Creature/State.hs +++ b/src/Dodge/Creature/State.hs @@ -34,8 +34,7 @@ foldCr :: Creature -> World -> World ---foldCr xs cr w = foldr ($ cr) w xs -foldCr xs cr w = foldl' f w $ reverse xs +foldCr xs cr w = foldl' f w xs where f w' g = case w' ^? cWorld . creatures . ix (_crID cr) of Just cr' -> g cr' w' @@ -51,15 +50,15 @@ foldCr xs cr w = foldl' f w $ reverse xs stateUpdate :: (Creature -> World -> World) -> Creature -> World -> World stateUpdate f = foldCr - [ equipmentEffects - , invSideEff - , upInv -- upInv must be called before invSideEff 22.05.23 - , movementSideEff - , f - , internalUpdate - , clearDamage -- these three + [ doDamage -- these three , checkDeath -- must be in - , doDamage -- this order 22/06/05 + , clearDamage -- this order 24/7/22 + , internalUpdate + , f + , movementSideEff + , upInv -- upInv must be called before invSideEff 22.05.23 + , invSideEff + , equipmentEffects ] checkDeath :: Creature -> World -> World @@ -245,7 +244,8 @@ itemUpdate cr i | otherwise = baseupdate False where baseupdate bool = - updateAutoRecharge . (itUse %~ useUpdate) + updateAutoRecharge + . (itUse %~ useUpdate) . (itLocation .~ InInv (_crID cr) i) . (itIsHeld .~ bool) diff --git a/src/Dodge/Data/Item.hs b/src/Dodge/Data/Item.hs index e6d47b609..4426ca70e 100644 --- a/src/Dodge/Data/Item.hs +++ b/src/Dodge/Data/Item.hs @@ -1,6 +1,6 @@ -{-# LANGUAGE DeriveGeneric #-} -{-# LANGUAGE DeriveAnyClass #-} ---{-# LANGUAGE StrictData #-} +--{-# LANGUAGE DeriveGeneric #-} +--{-# LANGUAGE DeriveAnyClass #-} +{-# LANGUAGE StrictData #-} {-# LANGUAGE TemplateHaskell #-} module Dodge.Data.Item ( diff --git a/src/Dodge/Humanoid.hs b/src/Dodge/Humanoid.hs index 458b09da7..7c5045276 100644 --- a/src/Dodge/Humanoid.hs +++ b/src/Dodge/Humanoid.hs @@ -187,8 +187,12 @@ defaultImpulsive :: Creature -> World -> World -defaultImpulsive fs cr = updateRandGen -- . stateUpdate (const id) cr - --fmap (fmap updateRandGen) . stateUpdate . impulsiveAIBefore . chainCreatureUpdates +defaultImpulsive + --xs cr = id + -- updateRandGen -- . stateUpdate (const id) cr + = fmap (fmap updateRandGen) . stateUpdate . impulsiveAIBefore . chainCreatureUpdates + --xs cr = updateRandGen . stateUpdate (const id) cr + --xs cr = stateUpdate (const id) cr where updateRandGen w = let (_, g) = randomR (0, 1 :: Int) (_randGen w)