Cleanup, trying to diagnose space leak in crit update
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
--{-# LANGUAGE TupleSections #-}
|
||||
module Dodge.Creature.Perception
|
||||
( perceptionUpdate
|
||||
, perceptionUpdate'
|
||||
, newSounds
|
||||
)
|
||||
where
|
||||
@@ -29,6 +30,33 @@ perceptionUpdate is cr = basicAttentionUpdate is cr
|
||||
>>= basicAwarenessUpdate
|
||||
>>= rememberSounds
|
||||
|
||||
perceptionUpdate'
|
||||
:: [Int] -- ^ List of creature ids that may direct attention and awareness
|
||||
-> World
|
||||
-> Creature
|
||||
-> Creature
|
||||
perceptionUpdate' is w cr = rememberSounds' w $ basicAwarenessUpdate' $ basicAttentionUpdate' is w cr
|
||||
|
||||
{- | Update a creatures awareness based upon the creatures' current direction
|
||||
of attention -}
|
||||
basicAwarenessUpdate'
|
||||
:: Creature
|
||||
-> Creature
|
||||
basicAwarenessUpdate' cr = case _crAttentionDir $ _crPerception cr of
|
||||
AttentiveTo is -> cr
|
||||
& crPerception . crAwarenessLevel
|
||||
%~ (IM.mapMaybe decreaseAwareness . IM.unionWith combineAwareness is)
|
||||
& maybeBark
|
||||
where
|
||||
oldAwareness = _crAwarenessLevel $ _crPerception cr
|
||||
newAwareness = (IM.mapMaybe decreaseAwareness . IM.unionWith combineAwareness is) oldAwareness
|
||||
becomesCognizant = any isCognizant $ IM.unionWith cogRaised oldAwareness newAwareness
|
||||
maybeBark | becomesCognizant = case vocalizationTest cr of
|
||||
Just sid -> crActionPlan . crImpulse .~ [Bark sid]
|
||||
Nothing -> id
|
||||
| otherwise = id
|
||||
Fixated i -> cr & crPerception . crAwarenessLevel
|
||||
%~ ( IM.insert i (Cognizant 10000) . IM.mapMaybe decreaseAwareness)
|
||||
{- | Update a creatures awareness based upon the creatures' current direction
|
||||
of attention -}
|
||||
basicAwarenessUpdate
|
||||
@@ -84,6 +112,16 @@ basicAttentionUpdate cids cr = do
|
||||
pure $ cr & crPerception . crAttentionDir .~
|
||||
AttentiveTo (IM.mapMaybe (newExtraAwareness cr w) $ IM.fromList $ zip cids cids)
|
||||
|
||||
{- | Given a fixed group of creatures, direct attention to those of them that
|
||||
- are in view. -}
|
||||
basicAttentionUpdate'
|
||||
:: [Int] -- ^ Creatures that may attract this creature's attention
|
||||
-> World
|
||||
-> Creature
|
||||
-> Creature
|
||||
basicAttentionUpdate' cids w cr = cr & crPerception . crAttentionDir .~
|
||||
AttentiveTo (IM.mapMaybe (newExtraAwareness cr w) $ IM.fromList $ zip cids cids)
|
||||
|
||||
newExtraAwareness
|
||||
:: Creature -- ^ source creature
|
||||
-> World
|
||||
@@ -119,6 +157,9 @@ rememberSounds cr = do
|
||||
sList <- asks newSounds
|
||||
return $ cr & crMemory . soundsToInvestigate .~ map fst (filter (soundIsClose cr) sList)
|
||||
-- return $ cr & crMemory . soundsToInvestigate .~ [V2 0 0]
|
||||
--
|
||||
rememberSounds' :: World -> Creature -> Creature
|
||||
rememberSounds' w cr = cr & crMemory . soundsToInvestigate .~ map fst (filter (soundIsClose cr) (newSounds w))
|
||||
|
||||
soundIsClose :: Creature -> (Point2,Float) -> Bool
|
||||
soundIsClose cr (pos,vol) = vol > (_auDist . _crAudition $ _crPerception cr) (dist pos (_crPos cr))
|
||||
|
||||
Reference in New Issue
Block a user