Safe Haskell | None |
---|---|
Language | Haskell2010 |
This module forms the apecs Prelude. It selectively re-exports the user-facing functions from the submodules.
- newtype System w a = System {}
- class (Elem (Storage c) ~ c, Store (Storage c)) => Component c where
- type Storage c
- newtype Entity = Entity Int
- class Component c => Has w c where
- data Not a = Not
- data Map c
- data Unique c
- data Global c
- initStore :: Store s => IO s
- get :: forall w c. Has w c => Entity -> System w c
- set :: forall w c. Has w c => Entity -> c -> System w ()
- cmap :: forall world cx cy. (Has world cx, Has world cy) => (cx -> cy) -> System world ()
- cmapM :: forall world c a. Has world c => (c -> System world a) -> System world [a]
- cmapM_ :: forall world c a. Has world c => (c -> System world a) -> System world ()
- modify :: forall w c. Has w c => Entity -> (c -> c) -> System w ()
- destroy :: forall w c. Has w c => Entity -> c -> System w ()
- exists :: forall w c. Has w c => Entity -> c -> System w Bool
- runSystem :: System w a -> w -> IO a
- runWith :: w -> System w a -> IO a
- runGC :: System w ()
- data EntityCounter
- newEntity :: (Store (Storage c), Has w c, Has w EntityCounter) => c -> System w Entity
- global :: Entity
- proxy :: forall t. t
- makeWorld :: 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
Types
A system is a newtype around `ReaderT w IO a`, where w
is the game world variable.
class (Elem (Storage c) ~ c, Store (Storage 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 really just an Int in a newtype.
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 p, Has w q) => Has w (Either p q) 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
.
A map from Data.Intmap.Strict. O(log(n)) for most operations.
Yields safe runtime representations of type Maybe c
.
A Unique contains at most one component. Writing to it overwrites both the previous component and its owner.
A Global contains exactly one component.
Initialized with mempty
Store wrapper functions
set :: forall w c. Has 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'
cmap :: forall world cx cy. (Has world cx, Has world cy) => (cx -> cy) -> System world () Source #
Maps a function over all entities with a cx
, and writes their cy
cmapM :: forall world c a. Has world c => (c -> System world a) -> System world [a] Source #
Monadically iterates over all entites with a cx
cmapM_ :: forall world c a. Has world c => (c -> System world a) -> System world () Source #
Monadically iterates over all entites with a cx
modify :: forall w c. Has w c => Entity -> (c -> c) -> System w () Source #
Applies a function, if possible.
destroy :: forall w c. Has w c => Entity -> 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. Has w c => Entity -> 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 #
Secretly just an int in a newtype
newEntity :: (Store (Storage c), Has w c, Has w EntityCounter) => c -> System w Entity Source #
Writes the given components to a new entity, and yields that entity
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
|
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.