Safe Haskell | None |
---|---|
Language | Haskell2010 |
This module forms the apecs Prelude. It selectively re-exports the user-facing functions from the submodules.
- module Data.Proxy
- newtype System w a = System {}
- class Elem (Storage c) ~ c => Component c where
- type Storage c
- newtype Entity = Entity {}
- class Component c => Has w c where
- data Not a = Not
- data Map c
- data Unique c
- data Global c
- data Cache (n :: Nat) s
- explInit :: ExplInit s => IO s
- get :: forall w c. Get w c => Entity -> System w c
- set :: forall w c. Set w c => Entity -> c -> System w ()
- getAll :: forall w c. (Get w c, Members w c) => System w [c]
- cmap :: forall w cx cy. (Get w cx, Members w cx, Set w cy) => (cx -> cy) -> System w ()
- cmapM :: forall w cx cy. (Get w cx, Set w cy, Members w cx) => (cx -> System w cy) -> System w ()
- cmapM_ :: forall w c a. (Get w c, Members w c) => (c -> System w a) -> System w ()
- modify :: forall w c. (Get w c, Set w c) => Entity -> (c -> c) -> System w ()
- destroy :: forall w c. Destroy w c => Entity -> Proxy c -> System w ()
- exists :: forall w c. Get w c => Entity -> Proxy c -> System w Bool
- runSystem :: System w a -> w -> IO a
- runWith :: w -> System w a -> IO a
- runGC :: System w ()
- data EntityCounter
- newEntity :: (Set w c, Get w EntityCounter, Set w EntityCounter) => c -> System w 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 => forall a. IO a -> m a
- lift :: MonadTrans t => forall (m :: * -> *) a. Monad m => m a -> t m a
Documentation
module Data.Proxy
Core types
A System is a newtype around `ReaderT w IO a`, where w
is the game world variable.
class Elem (Storage c) ~ c => Component c Source #
A component is defined by the type of its storage The storage in turn supplies runtime types for the component. For the component to be valid, its Storage must be an instance of Store.
An Entity is just an integer, used to index into a component store.
class Component c => Has w c where Source #
A world Has
a component if it can produce its Storage
Has w Entity Source # | |
Has w c => Has w (Identity c) Source # | |
Has w c => Has w (Filter c) Source # | |
Has w c => Has w (Maybe c) Source # | |
Has w c => Has w (Not c) Source # | |
(Has w t_0, Has w t_1) => Has w (t_0, t_1) Source # | |
(Has w t_0, Has w t_1, Has w t_2) => Has w (t_0, t_1, t_2) Source # | |
(Has w t_0, Has w t_1, Has w t_2, Has w t_3) => Has w (t_0, t_1, t_2, t_3) Source # | |
(Has w t_0, Has w t_1, Has w t_2, Has w t_3, Has w t_4) => Has w (t_0, t_1, t_2, t_3, t_4) Source # | |
(Has w t_0, Has w t_1, Has w t_2, Has w t_3, Has w t_4, Has w t_5) => Has w (t_0, t_1, t_2, t_3, t_4, t_5) Source # | |
(Has w t_0, Has w t_1, Has w t_2, Has w t_3, Has w t_4, Has w t_5, Has w t_6) => Has w (t_0, t_1, t_2, t_3, t_4, t_5, t_6) Source # | |
(Has w t_0, Has w t_1, Has w t_2, Has w t_3, Has w t_4, Has w t_5, Has w t_6, Has w t_7) => Has w (t_0, t_1, t_2, t_3, t_4, t_5, t_6, t_7) Source # | |
Psuedocomponent indicating the absence of a
.
Stores
A map based on Data.Intmap.Strict
. O(log(n)) for most operations.
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.
A Global contains exactly one component.
Initialized with mempty
The store will return true for every existence check, but only ever gives (-1) as its inhabitant.
The entity argument is ignored when setting/getting a global.
data Cache (n :: Nat) s Source #
A cache around another store. Note that iterating over a cache is linear in cache size, so sparsely populated caches might actually decrease performance.
ExplMembers s => ExplMembers (Cache n s) Source # | |
ExplDestroy s => ExplDestroy (Cache n s) Source # | |
ExplSet s => ExplSet (Cache n s) Source # | |
ExplGet s => ExplGet (Cache n s) Source # | |
(ExplInit s, KnownNat n, Cachable s) => ExplInit (Cache n s) Source # | |
(KnownNat n, Cachable s) => Cachable (Cache n s) Source # | |
type Elem (Cache n s) Source # | |
Systems
set :: forall w c. Set w c => Entity -> c -> System w () Source #
Writes a component to a given entity. Will overwrite existing components. The type was originally 'Entity c -> c -> System w ()', but is relaxed to 'Entity e' so you don't always have to write 'set . cast'
getAll :: forall w c. (Get w c, Members w c) => System w [c] Source #
Get all components c
.
Call as [(c,Entity)]
to read the entity/index.
cmap :: forall w cx cy. (Get w cx, Members w cx, Set w cy) => (cx -> cy) -> System w () Source #
Maps a function over all entities with a cx
, and writes their cy
cmapM :: forall w cx cy. (Get w cx, Set w cy, Members w cx) => (cx -> System w cy) -> System w () Source #
Monadically iterates over all entites with a cx, and writes their cy
cmapM_ :: forall w c a. (Get w c, Members w c) => (c -> System w a) -> System w () Source #
Monadically iterates over all entites with a cx
modify :: forall w c. (Get w c, Set w c) => Entity -> (c -> c) -> System w () Source #
Applies a function, if possible.
destroy :: forall w c. Destroy w c => Entity -> Proxy c -> System w () Source #
Destroys component c
for the given entity.
Note that c
is a phantom argument, used only to convey the type of the entity to be destroyed.
exists :: forall w c. Get w c => Entity -> Proxy c -> System w Bool Source #
Returns whether the given entity has component c
Note that c
is a phantom argument, used only to convey the type of the entity to be queried.
Other
data EntityCounter Source #
Component used by newEntity to track the number of issued entities.
Automatically added to any world created with makeWorld
newEntity :: (Set w c, Get w EntityCounter, Set w EntityCounter) => c -> System w Entity Source #
Writes the given components to a new entity, and yields that entity. The return value is often ignored.
Convenience entity (-1), used in places where the exact 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 makes a component instance:
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.