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 <grfn@gws.fyi> Tested-by: BuildkiteCI
This commit is contained in:
parent
91c71b3808
commit
2938675f38
2 changed files with 9 additions and 3 deletions
|
@ -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)
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue