Safe Haskell | None |
---|---|
Language | Haskell2010 |
This module forms the apecs Prelude. It selectively re-exports the user-facing functions from the submodules.
Synopsis
- module Data.Proxy
- newtype SystemT w m a = SystemT {}
- type System w a = SystemT w IO a
- class Elem (Storage c) ~ c => Component c where
- type Storage c
- newtype Entity = Entity {}
- class (Monad m, Component c) => Has w m c where
- data Not a = Not
- type Get w m c = (Has w m c, ExplGet m (Storage c))
- type Set w m c = (Has w m c, ExplSet m (Storage c))
- type Destroy w m c = (Has w m c, ExplDestroy m (Storage c))
- type Members w m c = (Has w m c, ExplMembers m (Storage c))
- data Map c
- data Unique c
- data Global c
- data Cache (n :: Nat) s
- explInit :: ExplInit m s => m s
- get :: forall w m c. Get w m c => Entity -> SystemT w m c
- set :: forall w m c. Set w m c => Entity -> c -> SystemT w m ()
- ($=) :: forall w m c. Set w m c => Entity -> c -> SystemT w m ()
- destroy :: forall w m c. Destroy w m c => Entity -> Proxy c -> SystemT w m ()
- exists :: forall w m c. Get w m c => Entity -> Proxy c -> SystemT w m Bool
- modify :: forall w m c. (Get w m c, Set w m c) => Entity -> (c -> c) -> SystemT w m ()
- ($~) :: forall w m c. (Get w m c, Set w m c) => Entity -> (c -> c) -> SystemT w m ()
- cmap :: forall w m cx cy. (Get w m cx, Members w m cx, Set w m cy) => (cx -> cy) -> SystemT w m ()
- cmapM :: forall w m cx cy. (Get w m cx, Set w m cy, Members w m cx) => (cx -> SystemT w m cy) -> SystemT w m ()
- cmapM_ :: forall w m c a. (Get w m c, Members w m c) => (c -> SystemT w m a) -> SystemT w m ()
- cfold :: forall w m c a. (Members w m c, Get w m c) => (a -> c -> a) -> a -> SystemT w m a
- cfoldM :: forall w m c a. (Members w m c, Get w m c) => (a -> c -> SystemT w m a) -> a -> SystemT w m a
- cfoldM_ :: forall w m c a. (Members w m c, Get w m c) => (a -> c -> SystemT w m a) -> a -> SystemT w m ()
- runSystem :: SystemT w m a -> w -> m a
- runWith :: w -> SystemT w m a -> m a
- runGC :: System w ()
- data EntityCounter
- newEntity :: (MonadIO m, Set w m c, Get w m EntityCounter) => c -> SystemT w m Entity
- global :: Entity
- makeWorld :: String -> [Name] -> Q [Dec]
- makeWorldAndComponents :: String -> [Name] -> Q [Dec]
- asks :: MonadReader r m => (r -> a) -> m a
- ask :: MonadReader r m => m r
- liftIO :: MonadIO m => IO a -> m a
- lift :: (MonadTrans t, Monad m) => m a -> t m a
Documentation
module Data.Proxy
Core types
newtype SystemT w m a Source #
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) Source # | |
MonadTrans (SystemT w) Source # | |
Defined in Apecs.Core | |
Monad m => Monad (SystemT w m) Source # | |
Functor m => Functor (SystemT w m) Source # | |
Applicative m => Applicative (SystemT w m) Source # | |
Defined in Apecs.Core | |
MonadIO m => MonadIO (SystemT w m) Source # | |
Defined in Apecs.Core |
class Elem (Storage c) ~ c => Component c Source #
A component is defined by specifying how it is stored. The constraint ensures that stores and components are mapped one-to-one.
Instances
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.
class (Monad m, Component c) => Has w m c where Source #
Has w m c
means that world w
can produce a Storage c
.
Instances
Monad m => Has w m Entity Source # | |
Monad m => Has w m () Source # | |
(Storage c ~ Pushdown s c, Has w m c) => Has w m (Stack c) Source # | |
Has w m c => Has w m (Identity c) Source # | |
Has w m c => Has w m (Redirect c) Source # | |
Has w m c => Has w m (Filter c) Source # | |
Has w m c => Has w m (Maybe c) Source # | |
Has w m c => Has w m (Not c) Source # | |
(Has w m ca, Has w m cb) => Has w m (Either ca cb) Source # | |
(Has w m t_0, Has w m t_1) => Has w m (t_0, t_1) Source # | |
(Has w m t_0, Has w m t_1, Has w m t_2) => Has w m (t_0, t_1, t_2) Source # | |
(Has w m t_0, Has w m t_1, Has w m t_2, Has w m t_3) => Has w m (t_0, t_1, t_2, t_3) Source # | |
(Has w m t_0, Has w m t_1, Has w m t_2, Has w m t_3, Has w m t_4) => Has w m (t_0, t_1, t_2, t_3, t_4) Source # | |
(Has w m t_0, Has w m t_1, Has w m t_2, Has w m t_3, Has w m t_4, Has w m t_5) => Has w m (t_0, t_1, t_2, t_3, t_4, t_5) Source # | |
(Has w m t_0, Has w m t_1, Has w m t_2, Has w m t_3, Has w m t_4, Has w m t_5, Has w m t_6) => Has w m (t_0, t_1, t_2, t_3, t_4, t_5, t_6) Source # | |
(Has w m t_0, Has w m t_1, Has w m t_2, Has w m t_3, Has w m t_4, Has w m t_5, Has w m t_6, Has w m t_7) => Has w m (t_0, t_1, t_2, t_3, t_4, t_5, t_6, t_7) Source # | |
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.
Stores
A map based on Data.IntMap.Strict
. O(log(n)) for most operations.
Instances
MonadIO m => ExplMembers m (Map c) Source # | |
Defined in Apecs.Stores | |
MonadIO m => ExplDestroy m (Map c) Source # | |
Defined in Apecs.Stores explDestroy :: Map c -> Int -> m () Source # | |
MonadIO m => ExplSet m (Map c) Source # | |
MonadIO m => ExplGet m (Map c) Source # | |
MonadIO m => ExplInit m (Map c) Source # | |
Defined in Apecs.Stores | |
Cachable (Map s) Source # | |
Defined in Apecs.Stores | |
type Elem (Map c) Source # | |
Defined in Apecs.Stores |
A Unique contains zero or one component.
Writing to it overwrites both the previous component and its owner.
Its main purpose is to be a Map
optimized for when only ever one component inhabits it.
Instances
MonadIO m => ExplMembers m (Unique c) Source # | |
Defined in Apecs.Stores | |
MonadIO m => ExplDestroy m (Unique c) Source # | |
Defined in Apecs.Stores explDestroy :: Unique c -> Int -> m () Source # | |
MonadIO m => ExplSet m (Unique c) Source # | |
MonadIO m => ExplGet m (Unique c) Source # | |
MonadIO m => ExplInit m (Unique c) Source # | |
Defined in Apecs.Stores | |
type Elem (Unique c) Source # | |
Defined in Apecs.Stores |
A Global
contains exactly one component.
The initial value is mempty
from the component's Monoid
instance.
When operating on a Global, any entity arguments are ignored.
A Global component can be read with get 0
or get 1
or even get undefined
.
This means that you can read and write Globals while cmap
ping over other components.
The integer global
is defined as -1, and can be used to make operations on a global explicit, i.e. 'Time t <- get global'.
data Cache (n :: Nat) s Source #
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, ExplMembers m s) => ExplMembers m (Cache n s) Source # | |
Defined in Apecs.Stores | |
(MonadIO m, ExplDestroy m s) => ExplDestroy m (Cache n s) Source # | |
Defined in Apecs.Stores explDestroy :: Cache n s -> Int -> m () Source # | |
(MonadIO m, ExplSet m s) => ExplSet m (Cache n s) Source # | |
(MonadIO m, ExplGet m s) => ExplGet m (Cache n s) Source # | |
(MonadIO m, ExplInit m s, KnownNat n, Cachable s) => ExplInit m (Cache n s) Source # | |
Defined in Apecs.Stores | |
(KnownNat n, Cachable s) => Cachable (Cache n s) Source # | |
Defined in Apecs.Stores | |
type Elem (Cache n s) Source # | |
Defined in Apecs.Stores |
Systems
set :: forall w m c. Set w m c => Entity -> c -> SystemT w m () Source #
Writes a Component to a given Entity. Will overwrite existing Components.
($=) :: forall w m c. Set w m c => Entity -> c -> SystemT w m () infixr 2 Source #
set
operator
Writes a Component to a given Entity. Will overwrite existing Components.
destroy :: forall w m c. Destroy w m c => Entity -> Proxy c -> SystemT w m () Source #
Destroys component c
for the given entity.
exists :: forall w m c. Get w m c => Entity -> Proxy c -> SystemT w m Bool Source #
Returns whether the given entity has component c
modify :: forall w m c. (Get w m c, Set w m c) => Entity -> (c -> c) -> SystemT w m () Source #
Applies a function, if possible.
($~) :: forall w m c. (Get w m c, Set w m c) => Entity -> (c -> c) -> SystemT w m () infixr 2 Source #
modify
operator
Applies a function, if possible.
cmap :: forall w m cx cy. (Get w m cx, Members w m cx, Set w m cy) => (cx -> cy) -> SystemT w m () Source #
Maps a function over all entities with a cx
, and writes their cy
.
cmapM :: forall w m cx cy. (Get w m cx, Set w m cy, Members w m cx) => (cx -> SystemT w m cy) -> SystemT w m () Source #
Monadically iterates over all entites with a cx
, and writes their cy
.
cmapM_ :: forall w m c a. (Get w m c, Members w m c) => (c -> SystemT w m a) -> SystemT w m () Source #
Monadically iterates over all entites with a cx
cfold :: forall w m c a. (Members w m c, Get w m c) => (a -> c -> a) -> a -> SystemT w m a Source #
Fold over the game world; for example, cfold max (minBound :: Foo)
will find the maximum value of Foo
.
Strict in the accumulator.
cfoldM :: forall w m c a. (Members w m c, Get w m c) => (a -> c -> SystemT w m a) -> a -> SystemT w m a Source #
Monadically fold over the game world. Strict in the accumulator.
cfoldM_ :: forall w m c a. (Members w m c, Get w m c) => (a -> c -> SystemT w m a) -> a -> SystemT w m () Source #
Monadically fold over the game world. Strict in the accumulator.
Other
data EntityCounter Source #
Component used by newEntity to track the number of issued entities.
Automatically added to any world created with makeWorld
Instances
Eq EntityCounter Source # | |
Defined in Apecs.Util (==) :: EntityCounter -> EntityCounter -> Bool # (/=) :: EntityCounter -> EntityCounter -> Bool # | |
Show EntityCounter Source # | |
Defined in Apecs.Util showsPrec :: Int -> EntityCounter -> ShowS # show :: EntityCounter -> String # showList :: [EntityCounter] -> ShowS # | |
Semigroup EntityCounter Source # | |
Defined in Apecs.Util (<>) :: EntityCounter -> EntityCounter -> EntityCounter # sconcat :: NonEmpty EntityCounter -> EntityCounter # stimes :: Integral b => b -> EntityCounter -> EntityCounter # | |
Monoid EntityCounter Source # | |
Defined in Apecs.Util mempty :: EntityCounter # mappend :: EntityCounter -> EntityCounter -> EntityCounter # mconcat :: [EntityCounter] -> EntityCounter # | |
Component EntityCounter Source # | |
Defined in Apecs.Util type Storage EntityCounter :: Type Source # | |
type Storage EntityCounter Source # | |
Defined in Apecs.Util |
newEntity :: (MonadIO m, Set w m c, Get w m EntityCounter) => c -> SystemT w m Entity Source #
Writes the given components to a new entity, and yields that entity. The return value is often ignored.
Convenience entity, for use in places where the entity value does not matter, i.e. a global store.
makeWorld :: String -> [Name] -> Q [Dec] Source #
makeWorld "WorldName" [''Component1, ''Component2, ...]
turns into
data WorldName = WorldName Component1 Component2 ... EntityCounter instance WorldName `Has` Component1 where ... instance WorldName `Has` Component2 where ... ... instance WorldName `Has` EntityCounter where ... initWorldName :: IO WorldName initWorldName = WorldName <$> initStore <*> initStore <*> ... <*> initStore
|
makeWorldAndComponents :: String -> [Name] -> Q [Dec] Source #
Same as makeWorld, but also defines Component
instances with a Map
store.
Re-exports
:: MonadReader r m | |
=> (r -> a) | The selector function to apply to the environment. |
-> m a |
Retrieves a function of the current environment.
ask :: MonadReader r m => m r #
Retrieves the monad environment.
lift :: (MonadTrans t, Monad m) => m a -> t m a #
Lift a computation from the argument monad to the constructed monad.