Safe Haskell | None |
---|---|
Language | Haskell2010 |
This module re-exports the apecs prelude with STM versions.
Synopsis
- type System w a = SystemT w STM a
- module Apecs.STM
- data KProxy t = KProxy
- data Proxy (t :: k) :: forall k. k -> Type = Proxy
- asProxyTypeOf :: a -> proxy a -> a
- makeWorldAndComponents :: String -> [Name] -> Q [Dec]
- runGC :: System w ()
- global :: Entity
- cfoldM_ :: (Members w m c, Get w m c) => (a -> c -> SystemT w m a) -> a -> SystemT w m ()
- cfoldM :: (Members w m c, Get w m c) => (a -> c -> SystemT w m a) -> a -> SystemT w m a
- cfold :: (Members w m c, Get w m c) => (a -> c -> a) -> a -> SystemT w m a
- cmapM_ :: (Get w m c, Members w m c) => (c -> SystemT w m a) -> SystemT w m ()
- cmapM :: (Get w m cx, Set w m cy, Members w m cx) => (cx -> SystemT w m cy) -> SystemT w m ()
- cmap :: (Get w m cx, Members w m cx, Set w m cy) => (cx -> cy) -> SystemT w m ()
- ($~) :: (Get w m c, Set w m c) => Entity -> (c -> c) -> SystemT w m ()
- modify :: (Get w m c, Set w m c) => Entity -> (c -> c) -> SystemT w m ()
- destroy :: Destroy w m c => Entity -> Proxy c -> SystemT w m ()
- exists :: Get w m c => Entity -> Proxy c -> SystemT w m Bool
- ($=) :: Set w m c => Entity -> c -> SystemT w m ()
- set :: Set w m c => Entity -> c -> SystemT w m ()
- get :: Get w m c => Entity -> SystemT w m c
- runWith :: w -> SystemT w m a -> m a
- runSystem :: SystemT w m a -> w -> m a
- data Not a = Not
- data Cache (n :: Nat) s
- newtype Entity = Entity {}
- newtype SystemT w (m :: Type -> Type) a = SystemT {}
- class Elem (Storage c) ~ c => Component c where
- class (Monad m, Component c) => Has w (m :: Type -> Type) c where
- explInit :: ExplInit m s => m s
- type Get w (m :: Type -> Type) c = (Has w m c, ExplGet m (Storage c))
- type Set w (m :: Type -> Type) c = (Has w m c, ExplSet m (Storage c))
- type Members w (m :: Type -> Type) c = (Has w m c, ExplMembers m (Storage c))
- type Destroy w (m :: Type -> Type) c = (Has w m c, ExplDestroy m (Storage c))
- asks :: MonadReader r m => (r -> a) -> m a
- liftIO :: MonadIO m => IO a -> m a
- lift :: (MonadTrans t, Monad m) => m a -> t m a
- ask :: MonadReader r m => m r
Documentation
module Apecs.STM
A concrete, promotable proxy type, for use at the kind level There are no instances for this because it is intended at the kind level only
data Proxy (t :: k) :: forall k. k -> Type #
Proxy
is a type that holds no data, but has a phantom parameter of
arbitrary type (or even kind). Its use is to provide type information, even
though there is no value available of that type (or it may be too costly to
create one).
Historically,
is a safer alternative to the
Proxy
:: Proxy
a'undefined :: a'
idiom.
>>>
Proxy :: Proxy (Void, Int -> Int)
Proxy
Proxy can even hold types of higher kinds,
>>>
Proxy :: Proxy Either
Proxy
>>>
Proxy :: Proxy Functor
Proxy
>>>
Proxy :: Proxy complicatedStructure
Proxy
Instances
Generic1 (Proxy :: k -> Type) | |
Monad (Proxy :: Type -> Type) | Since: base-4.7.0.0 |
Functor (Proxy :: Type -> Type) | Since: base-4.7.0.0 |
Applicative (Proxy :: Type -> Type) | Since: base-4.7.0.0 |
Foldable (Proxy :: Type -> Type) | Since: base-4.7.0.0 |
Defined in Data.Foldable fold :: Monoid m => Proxy m -> m # foldMap :: Monoid m => (a -> m) -> Proxy a -> m # foldr :: (a -> b -> b) -> b -> Proxy a -> b # foldr' :: (a -> b -> b) -> b -> Proxy a -> b # foldl :: (b -> a -> b) -> b -> Proxy a -> b # foldl' :: (b -> a -> b) -> b -> Proxy a -> b # foldr1 :: (a -> a -> a) -> Proxy a -> a # foldl1 :: (a -> a -> a) -> Proxy a -> a # elem :: Eq a => a -> Proxy a -> Bool # maximum :: Ord a => Proxy a -> a # minimum :: Ord a => Proxy a -> a # | |
Traversable (Proxy :: Type -> Type) | Since: base-4.7.0.0 |
Alternative (Proxy :: Type -> Type) | Since: base-4.9.0.0 |
MonadPlus (Proxy :: Type -> Type) | Since: base-4.9.0.0 |
Hashable1 (Proxy :: Type -> Type) | |
Defined in Data.Hashable.Class | |
Bounded (Proxy t) | Since: base-4.7.0.0 |
Enum (Proxy s) | Since: base-4.7.0.0 |
Eq (Proxy s) | Since: base-4.7.0.0 |
Ord (Proxy s) | Since: base-4.7.0.0 |
Read (Proxy t) | Since: base-4.7.0.0 |
Show (Proxy s) | Since: base-4.7.0.0 |
Ix (Proxy s) | Since: base-4.7.0.0 |
Generic (Proxy t) | |
Semigroup (Proxy s) | Since: base-4.9.0.0 |
Monoid (Proxy s) | Since: base-4.7.0.0 |
Hashable (Proxy a) | |
Defined in Data.Hashable.Class | |
type Rep1 (Proxy :: k -> Type) | Since: base-4.6.0.0 |
type Rep (Proxy t) | Since: base-4.6.0.0 |
asProxyTypeOf :: a -> proxy a -> a #
asProxyTypeOf
is a type-restricted version of const
.
It is usually used as an infix operator, and its typing forces its first
argument (which is usually overloaded) to have the same type as the tag
of the second.
>>>
import Data.Word
>>>
:type asProxyTypeOf 123 (Proxy :: Proxy Word8)
asProxyTypeOf 123 (Proxy :: Proxy Word8) :: Word8
Note the lower-case proxy
in the definition. This allows any type
constructor with just one argument to be passed to the function, for example
we could also write
>>>
import Data.Word
>>>
:type asProxyTypeOf 123 (Just (undefined :: Word8))
asProxyTypeOf 123 (Just (undefined :: Word8)) :: Word8
makeWorldAndComponents :: String -> [Name] -> Q [Dec] #
Same as makeWorld, but also defines Component
instances with a Map
store.
Convenience entity, for use in places where the entity value does not matter, i.e. a global store.
cfoldM_ :: (Members w m c, Get w m c) => (a -> c -> SystemT w m a) -> a -> SystemT w m () #
Monadically fold over the game world. Strict in the accumulator.
cfoldM :: (Members w m c, Get w m c) => (a -> c -> SystemT w m a) -> a -> SystemT w m a #
Monadically fold over the game world. Strict in the accumulator.
cfold :: (Members w m c, Get w m c) => (a -> c -> a) -> a -> SystemT w m a #
Fold over the game world; for example, cfold max (minBound :: Foo)
will find the maximum value of Foo
.
Strict in the accumulator.
cmapM_ :: (Get w m c, Members w m c) => (c -> SystemT w m a) -> SystemT w m () #
Monadically iterates over all entites with a cx
cmapM :: (Get w m cx, Set w m cy, Members w m cx) => (cx -> SystemT w m cy) -> SystemT w m () #
Monadically iterates over all entites with a cx
, and writes their cy
.
cmap :: (Get w m cx, Members w m cx, Set w m cy) => (cx -> cy) -> SystemT w m () #
Maps a function over all entities with a cx
, and writes their cy
.
($~) :: (Get w m c, Set w m c) => Entity -> (c -> c) -> SystemT w m () infixr 2 #
modify
operator
Applies a function, if possible.
modify :: (Get w m c, Set w m c) => Entity -> (c -> c) -> SystemT w m () #
Applies a function, if possible.
destroy :: Destroy w m c => Entity -> Proxy c -> SystemT w m () #
Destroys component c
for the given entity.
exists :: Get w m c => Entity -> Proxy c -> SystemT w m Bool #
Returns whether the given entity has component c
($=) :: Set w m c => Entity -> c -> SystemT w m () infixr 2 #
set
operator
Writes a Component to a given Entity. Will overwrite existing Components.
set :: Set w m c => Entity -> c -> SystemT w m () #
Writes a Component to a given Entity. Will overwrite existing Components.
Psuedocomponent indicating the absence of a
.
Mainly used as e.g. cmap $ (a, Not b) -> c
to iterate over entities with an a
but no b
.
Can also be used to delete components, like cmap $ a -> (Not :: Not a)
to delete every a
component.
A cache around another store. Caches store their members in a fixed-size vector, so operations run in O(1). Caches can provide huge performance boosts, especially for large numbers of components. The cache size is given as a type-level argument.
Note that iterating over a cache is linear in cache size, so sparsely populated caches might actually decrease performance. In general, the exact size of the cache does not matter as long as it reasonably approximates the number of components present.
The cache uses entity (-2) to internally represent missing entities, so be wary when manually manipulating entities.
Instances
(MonadIO m, ExplInit m s, KnownNat n, Cachable s) => ExplInit m (Cache n s) | |
Defined in Apecs.Stores | |
(MonadIO m, ExplGet m s) => ExplGet m (Cache n s) | |
(MonadIO m, ExplSet m s) => ExplSet m (Cache n s) | |
(MonadIO m, ExplDestroy m s) => ExplDestroy m (Cache n s) | |
Defined in Apecs.Stores explDestroy :: Cache n s -> Int -> m () # | |
(MonadIO m, ExplMembers m s) => ExplMembers m (Cache n s) | |
Defined in Apecs.Stores explMembers :: Cache n s -> m (Vector Int) # | |
(KnownNat n, Cachable s) => Cachable (Cache n s) | |
Defined in Apecs.Stores | |
type Elem (Cache n s) | |
Defined in Apecs.Stores |
An Entity is just an integer, used to index into a component store.
In general, use newEntity
, cmap
, and component tags instead of manipulating these directly.
For performance reasons, negative values like (-1) are reserved for stores to represent special values, so avoid using these.
newtype SystemT w (m :: Type -> Type) a #
A SystemT is a newtype around `ReaderT w m a`, where w
is the game world variable.
Systems serve to
- Allow type-based lookup of a component's store through
getStore
. - Lift side effects into their host Monad.
Instances
Monad m => MonadReader w (SystemT w m) | |
MonadTrans (SystemT w) | |
Defined in Apecs.Core | |
Monad m => Monad (SystemT w m) | |
Functor m => Functor (SystemT w m) | |
Applicative m => Applicative (SystemT w m) | |
Defined in Apecs.Core | |
MonadIO m => MonadIO (SystemT w m) | |
Defined in Apecs.Core |
class Elem (Storage c) ~ c => Component c #
A component is defined by specifying how it is stored. The constraint ensures that stores and components are mapped one-to-one.
Instances
Component EntityCounter | |
Defined in Apecs.Util type Storage EntityCounter :: Type # | |
Component EntityCounter Source # | |
Defined in Apecs.STM type Storage EntityCounter :: Type # | |
Component c => Component (Not c) | |
Defined in Apecs.Components | |
Component c => Component (Filter c) | |
Defined in Apecs.Components | |
Component c => Component (Redirect c) | |
Defined in Apecs.Components | |
(Storage c ~ Pushdown s c, Component c) => Component (Stack c) | |
Defined in Apecs.Stores.Extra |
class (Monad m, Component c) => Has w (m :: Type -> Type) c where #
Has w m c
means that world w
can produce a Storage c
.
:: MonadReader r m | |
=> (r -> a) | The selector function to apply to the environment. |
-> m a |
Retrieves a function of the current environment.
lift :: (MonadTrans t, Monad m) => m a -> t m a #
Lift a computation from the argument monad to the constructed monad.
ask :: MonadReader r m => m r #
Retrieves the monad environment.