about summary refs log tree commit diff
diff options
context:
space:
mode:
authorGriffin Smith <grfn@gws.fyi>2021-06-18T15·51-0400
committergrfn <grfn@gws.fyi>2021-06-18T17·51+0000
commit2938675f3836d92eef5e813873065143ca73b02b (patch)
tree42dbd118dc7a9cf07f4a6082421e96dd9fa55011
parent91c71b380808c4e1c673e1ee96fe9b7bcf743b72 (diff)
fix(xanthous): Wipe memoized vision when the game updates r/2669
If the game steps forward, entities could be moving around, so we need
to wipe the memoized character vision.

Change-Id: If6ea6a8c4bed7aefef90a0a2ab17eff0af9b9bbe
Reviewed-on: https://cl.tvl.fyi/c/depot/+/3215
Reviewed-by: grfn <grfn@gws.fyi>
Tested-by: BuildkiteCI
-rw-r--r--users/grfn/xanthous/src/Xanthous/App/Time.hs2
-rw-r--r--users/grfn/xanthous/src/Xanthous/Game/Lenses.hs10
2 files changed, 9 insertions, 3 deletions
diff --git a/users/grfn/xanthous/src/Xanthous/App/Time.hs b/users/grfn/xanthous/src/Xanthous/App/Time.hs
index b17348f385..cca352858d 100644
--- a/users/grfn/xanthous/src/Xanthous/App/Time.hs
+++ b/users/grfn/xanthous/src/Xanthous/App/Time.hs
@@ -16,6 +16,7 @@ import           Xanthous.Game.State
 import           Xanthous.Game.Prompt
 import           Xanthous.Game.Lenses
 import           Control.Monad.State (modify)
+import qualified Xanthous.Game.Memo as Memo
 --------------------------------------------------------------------------------
 
 
@@ -26,6 +27,7 @@ stepGameBy ticks = do
     pEntity' <- step ticks pEntity
     entities . ix eid .= pEntity'
 
+  clearMemo Memo.characterVisiblePositions
   modify updateCharacterVision
 
   whenM (uses character isDead)
diff --git a/users/grfn/xanthous/src/Xanthous/Game/Lenses.hs b/users/grfn/xanthous/src/Xanthous/Game/Lenses.hs
index 0514931923..f7b4d5fb9f 100644
--- a/users/grfn/xanthous/src/Xanthous/Game/Lenses.hs
+++ b/users/grfn/xanthous/src/Xanthous/Game/Lenses.hs
@@ -3,7 +3,8 @@
 {-# LANGUAGE AllowAmbiguousTypes #-}
 --------------------------------------------------------------------------------
 module Xanthous.Game.Lenses
-  ( positionedCharacter
+  ( clearMemo
+  , positionedCharacter
   , character
   , characterPosition
   , updateCharacterVision
@@ -38,8 +39,8 @@ import           Xanthous.Data.EntityMap.Graphics
 import           Xanthous.Data.VectorBag
 import           Xanthous.Entities.Character (Character, mkCharacter)
 import           {-# SOURCE #-} Xanthous.Entities.Entities ()
-import Xanthous.Game.Memo (emptyMemoState)
-import Xanthous.Data.Memo (fillWithM)
+import           Xanthous.Game.Memo (emptyMemoState, MemoState)
+import           Xanthous.Data.Memo (fillWithM, Memoized)
 --------------------------------------------------------------------------------
 
 getInitialState :: IO GameState
@@ -68,6 +69,9 @@ initialStateFromSeed seed =
       _memo = emptyMemoState
   in GameState {..}
 
+clearMemo :: MonadState GameState m => Lens' MemoState (Memoized k v) -> m ()
+clearMemo l = memo %= Memo.clear l
+
 positionedCharacter :: Lens' GameState (Positioned Character)
 positionedCharacter = lens getPositionedCharacter setPositionedCharacter
   where