c19e3dae5f
Memoize the return value of characterVisiblePositions to a new, semi-abstracted "memo" field on the GameState, recalcuclated if the character position ever changes. I'm 90% sure that the perf issues we were encountering were actually caused by characterVisiblePositions getting called once for *every tile* on draw, but this slightly larger change also makes the game perform relatively-usably again. Since this is only recalculated if the character position changes, if we ever get non-transparent entities moving around without the characters influence (maybe something building or knocking down walls?) we'll have an issue there where the vision won't be updated as a result of those changes if they happen while the character is taking a non-moving action - but we can cross that bridge when we come to it. Change-Id: I3fc745ddf0014d6f164f735ad7e5080da779b92a Reviewed-on: https://cl.tvl.fyi/c/depot/+/3185 Reviewed-by: grfn <grfn@gws.fyi> Tested-by: BuildkiteCI
48 lines
1.3 KiB
Haskell
48 lines
1.3 KiB
Haskell
--------------------------------------------------------------------------------
|
|
module Xanthous.Prelude
|
|
( module ClassyPrelude
|
|
, Type
|
|
, Constraint
|
|
, module GHC.TypeLits
|
|
, module Control.Lens
|
|
, module Data.Void
|
|
, module Control.Comonad
|
|
, module Witherable
|
|
, fail
|
|
|
|
, (&!)
|
|
|
|
-- * Classy-Prelude addons
|
|
, ninsertSet
|
|
, ndeleteSet
|
|
, toVector
|
|
) where
|
|
--------------------------------------------------------------------------------
|
|
import ClassyPrelude hiding
|
|
( return, (<|), unsnoc, uncons, cons, snoc, index, (<.>), Index, say
|
|
, catMaybes, filter, mapMaybe, hashNub, ordNub
|
|
, Memoized, runMemoized
|
|
)
|
|
import Data.Kind
|
|
import GHC.TypeLits hiding (Text)
|
|
import Control.Lens hiding (levels, Level)
|
|
import Data.Void
|
|
import Control.Comonad
|
|
import Witherable
|
|
import Control.Monad.Fail (fail)
|
|
--------------------------------------------------------------------------------
|
|
|
|
ninsertSet
|
|
:: (IsSet set, MonoPointed set)
|
|
=> Element set -> NonNull set -> NonNull set
|
|
ninsertSet x xs = impureNonNull $ opoint x `union` toNullable xs
|
|
|
|
ndeleteSet :: IsSet b => Element b -> NonNull b -> b
|
|
ndeleteSet x = deleteSet x . toNullable
|
|
|
|
toVector :: (MonoFoldable (f a), Element (f a) ~ a) => f a -> Vector a
|
|
toVector = fromList . toList
|
|
|
|
infixl 1 &!
|
|
(&!) :: a -> (a -> b) -> b
|
|
(&!) = flip ($!)
|