From 2938675f3836d92eef5e813873065143ca73b02b Mon Sep 17 00:00:00 2001 From: Griffin Smith Date: Fri, 18 Jun 2021 11:51:37 -0400 Subject: fix(xanthous): Wipe memoized vision when the game updates 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 Tested-by: BuildkiteCI --- users/grfn/xanthous/src/Xanthous/App/Time.hs | 2 ++ users/grfn/xanthous/src/Xanthous/Game/Lenses.hs | 10 +++++++--- 2 files changed, 9 insertions(+), 3 deletions(-) (limited to 'users/grfn') diff --git a/users/grfn/xanthous/src/Xanthous/App/Time.hs b/users/grfn/xanthous/src/Xanthous/App/Time.hs index b17348f3853e..cca352858d9c 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 051493192323..f7b4d5fb9fd2 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 -- cgit 1.4.1