| Safe Haskell | None |
|---|---|
| Language | Haskell2010 |
Aztecs.ECS
Description
Aztecs is a type-safe and friendly ECS for games and more.
An ECS is a modern approach to organizing your application state as a database, providing patterns for data-oriented design and parallel processing.
The ECS architecture is composed of three main concepts:
Entities
An entity is an object comprised of zero or more components.
In Aztecs, entities are represented by their EntityID, a unique identifier.
Components
A Component holds the data for a particular aspect of an entity.
For example, a zombie entity might have a Health and a Transform component.
newtype Position = Position Int deriving (Show) instance Component Position newtype Velocity = Velocity Int deriving (Show) instance Component Velocity
Systems
A System is a pipeline that processes entities and their components.
Systems in Aztecs either run in sequence or in parallel automatically based on the components they access.
Systems can access game state in two ways:
Access
An Access can be queued for full access to the World, after a system is complete.
Access allows for spawning, inserting, and removing components.
setup :: System () () setup = S.queue . const . A.spawn_ $ bundle (Position 0) <> bundle (Velocity 1)
Queries
A Query can read and write matching components.
move :: System () ()
move =
S.map
( proc () -> do
Velocity v <- Q.query -< ()
Position p <- Q.query -< ()
Q.set -< Position $ p + v
)
>>> S.run printFinally, systems can be run on a World to produce a result.
main :: IO () main = runSystem_ $ setup >>> S.forever move
Synopsis
- module Aztecs.ECS.Access
- module Aztecs.ECS.System
- type Bundle = BundleT Identity
- data BundleT (m :: Type -> Type)
- bundle :: forall (m :: Type -> Type) a. Component m a => a -> BundleT m
- data DynamicBundle (m :: Type -> Type)
- class MonoidDynamicBundle (m :: Type -> Type) a where
- dynBundle :: Component m c => ComponentID -> c -> a
- dynBundleUntracked :: Component m c => ComponentID -> c -> a
- class (Monad m, Typeable a, Storage a (StorageT a)) => Component (m :: Type -> Type) a where
- type StorageT a
- componentOnInsert :: EntityID -> a -> Access m ()
- componentOnChange :: EntityID -> a -> Access m ()
- componentOnRemove :: EntityID -> a -> Access m ()
- data EntityID
- data Query (m :: Type -> Type) a
- query :: forall (m :: Type -> Type) a. (Monad m, Component m a) => Query m a
- queryMaybe :: forall (m :: Type -> Type) a. (Monad m, Component m a) => Query m (Maybe a)
- queryMap :: forall (m :: Type -> Type) a. (Monad m, Component m a) => (a -> a) -> Query m a
- queryMapM :: (Monad m, Component m a) => (a -> m a) -> Query m a
- queryMapWith :: forall (m :: Type -> Type) a b. (Monad m, Component m b) => (a -> b -> b) -> Query m a -> Query m b
- queryMapWith_ :: forall (m :: Type -> Type) a b. (Monad m, Component m b) => (a -> b -> b) -> Query m a -> Query m ()
- queryMapWithM :: forall m a b. (Monad m, Component m b) => (a -> b -> m b) -> Query m a -> Query m b
- class (Monad m, Functor f) => DynamicQueryF (m :: Type -> Type) (f :: Type -> Type) | f -> m
- data QueryFilter
- with :: forall (m :: Type -> Type) a. Component m a => QueryFilter
- without :: forall (m :: Type -> Type) a. Component m a => QueryFilter
- data World (m :: Type -> Type)
- class Typeable e => Event e
- newtype OnInsert a = OnInsert {
- unOnInsert :: a
- newtype OnChange a = OnChange {
- unOnChange :: a
- newtype OnRemove a = OnRemove {
- unOnRemove :: a
- data Observer (m :: Type -> Type) e
- observer :: forall (m :: Type -> Type) e. Event e => EntityID -> (EntityID -> e -> Access m ()) -> Observer m e
- observerFor :: forall (m :: Type -> Type) e. Event e => Set EntityID -> (EntityID -> e -> Access m ()) -> Observer m e
- observerGlobal :: forall (m :: Type -> Type) e. Event e => (e -> Access m ()) -> Observer m e
Documentation
module Aztecs.ECS.Access
module Aztecs.ECS.System
data BundleT (m :: Type -> Type) Source #
Bundle of components.
Instances
| Monad m => MonoidDynamicBundle m (BundleT m) Source # | |
Defined in Aztecs.ECS.World.Bundle Methods dynBundle :: Component m c => ComponentID -> c -> BundleT m Source # dynBundleUntracked :: Component m c => ComponentID -> c -> BundleT m Source # | |
| Monad m => Monoid (BundleT m) Source # | |
| Monad m => Semigroup (BundleT m) Source # | |
data DynamicBundle (m :: Type -> Type) Source #
Dynamic bundle of components.
Instances
| Monad m => MonoidDynamicBundle m (DynamicBundle m) Source # | |
Defined in Aztecs.ECS.World.Bundle.Dynamic Methods dynBundle :: Component m c => ComponentID -> c -> DynamicBundle m Source # dynBundleUntracked :: Component m c => ComponentID -> c -> DynamicBundle m Source # | |
| Monad m => Monoid (DynamicBundle m) Source # | |
Defined in Aztecs.ECS.World.Bundle.Dynamic Methods mempty :: DynamicBundle m # mappend :: DynamicBundle m -> DynamicBundle m -> DynamicBundle m # mconcat :: [DynamicBundle m] -> DynamicBundle m # | |
| Monad m => Semigroup (DynamicBundle m) Source # | |
Defined in Aztecs.ECS.World.Bundle.Dynamic Methods (<>) :: DynamicBundle m -> DynamicBundle m -> DynamicBundle m # sconcat :: NonEmpty (DynamicBundle m) -> DynamicBundle m # stimes :: Integral b => b -> DynamicBundle m -> DynamicBundle m # | |
class MonoidDynamicBundle (m :: Type -> Type) a where Source #
Monoid bundle of dynamic components.
Methods
dynBundle :: Component m c => ComponentID -> c -> a Source #
Add a component to the bundle by its ComponentID.
dynBundleUntracked :: Component m c => ComponentID -> c -> a Source #
Add a component to the bundle by its ComponentID without running lifecycle hooks.
Instances
| Monad m => MonoidDynamicBundle m (BundleT m) Source # | |
Defined in Aztecs.ECS.World.Bundle Methods dynBundle :: Component m c => ComponentID -> c -> BundleT m Source # dynBundleUntracked :: Component m c => ComponentID -> c -> BundleT m Source # | |
| Monad m => MonoidDynamicBundle m (DynamicBundle m) Source # | |
Defined in Aztecs.ECS.World.Bundle.Dynamic Methods dynBundle :: Component m c => ComponentID -> c -> DynamicBundle m Source # dynBundleUntracked :: Component m c => ComponentID -> c -> DynamicBundle m Source # | |
class (Monad m, Typeable a, Storage a (StorageT a)) => Component (m :: Type -> Type) a where Source #
Component that can be stored in the World.
Minimal complete definition
Nothing
Methods
componentOnInsert :: EntityID -> a -> Access m () Source #
Lifecycle hook called when a component is inserted.
componentOnChange :: EntityID -> a -> Access m () Source #
Lifecycle hook called when a component is changed.
componentOnRemove :: EntityID -> a -> Access m () Source #
Lifecycle hook called when a component is removed.
Instances
Unique entity identifier.
data Query (m :: Type -> Type) a Source #
Query for matching entities.
Instances
| Monad m => DynamicQueryF m (Query m) Source # | |
Defined in Aztecs.ECS.Query Methods entity :: Query m EntityID Source # queryDyn :: Component m a => ComponentID -> Query m a Source # queryMaybeDyn :: Component m a => ComponentID -> Query m (Maybe a) Source # queryMapDyn :: Component m a => (a -> a) -> ComponentID -> Query m a Source # queryMapDyn_ :: Component m a => (a -> a) -> ComponentID -> Query m () Source # queryMapDynM :: (Monad m, Component m a) => (a -> m a) -> ComponentID -> Query m a Source # queryMapDynWith :: Component m b => (a -> b -> b) -> ComponentID -> Query m a -> Query m b Source # queryMapDynWith_ :: Component m b => (a -> b -> b) -> ComponentID -> Query m a -> Query m () Source # queryMapDynWithM :: (Monad m, Component m b) => (a -> b -> m b) -> ComponentID -> Query m a -> Query m b Source # queryMapDynWithAccum :: Component m c => (b -> c -> (a, c)) -> ComponentID -> Query m b -> Query m (a, c) Source # queryMapDynWithAccumM :: (Monad m, Component m c) => (b -> c -> m (a, c)) -> ComponentID -> Query m b -> Query m (a, c) Source # queryFilterMap :: (a -> Maybe b) -> Query m a -> Query m b Source # queryFilter :: (a -> Bool) -> Query m a -> Query m a Source # queryUntracked :: Query m a -> Query m a Source # | |
| Monad m => Applicative (Query m) Source # | |
| Functor m => Functor (Query m) Source # | |
query :: forall (m :: Type -> Type) a. (Monad m, Component m a) => Query m a Source #
Query a component.
queryMaybe :: forall (m :: Type -> Type) a. (Monad m, Component m a) => Query m (Maybe a) Source #
Optionally query a component, returning Nothing if it does not exist.
queryMap :: forall (m :: Type -> Type) a. (Monad m, Component m a) => (a -> a) -> Query m a Source #
Query a component and update it.
queryMapM :: (Monad m, Component m a) => (a -> m a) -> Query m a Source #
Query a component and update it with a monadic action.
queryMapWith :: forall (m :: Type -> Type) a b. (Monad m, Component m b) => (a -> b -> b) -> Query m a -> Query m b Source #
Query a component with input and update it.
queryMapWith_ :: forall (m :: Type -> Type) a b. (Monad m, Component m b) => (a -> b -> b) -> Query m a -> Query m () Source #
Query a component with input and update it, ignoring any output.
queryMapWithM :: forall m a b. (Monad m, Component m b) => (a -> b -> m b) -> Query m a -> Query m b Source #
Query a component with input and update it with a monadic action.
class (Monad m, Functor f) => DynamicQueryF (m :: Type -> Type) (f :: Type -> Type) | f -> m Source #
Dynamic query functor.
Minimal complete definition
entity, queryDyn, queryMapDyn, queryMapDynM, queryMapDynWith, queryMapDynWithM, queryMapDynWithAccum, queryMapDynWithAccumM, queryFilterMap, queryUntracked
Instances
| Monad m => DynamicQueryF m (Query m) Source # | |
Defined in Aztecs.ECS.Query Methods entity :: Query m EntityID Source # queryDyn :: Component m a => ComponentID -> Query m a Source # queryMaybeDyn :: Component m a => ComponentID -> Query m (Maybe a) Source # queryMapDyn :: Component m a => (a -> a) -> ComponentID -> Query m a Source # queryMapDyn_ :: Component m a => (a -> a) -> ComponentID -> Query m () Source # queryMapDynM :: (Monad m, Component m a) => (a -> m a) -> ComponentID -> Query m a Source # queryMapDynWith :: Component m b => (a -> b -> b) -> ComponentID -> Query m a -> Query m b Source # queryMapDynWith_ :: Component m b => (a -> b -> b) -> ComponentID -> Query m a -> Query m () Source # queryMapDynWithM :: (Monad m, Component m b) => (a -> b -> m b) -> ComponentID -> Query m a -> Query m b Source # queryMapDynWithAccum :: Component m c => (b -> c -> (a, c)) -> ComponentID -> Query m b -> Query m (a, c) Source # queryMapDynWithAccumM :: (Monad m, Component m c) => (b -> c -> m (a, c)) -> ComponentID -> Query m b -> Query m (a, c) Source # queryFilterMap :: (a -> Maybe b) -> Query m a -> Query m b Source # queryFilter :: (a -> Bool) -> Query m a -> Query m a Source # queryUntracked :: Query m a -> Query m a Source # | |
| Monad m => DynamicQueryF m (DynamicQuery m) Source # | |
Defined in Aztecs.ECS.Query.Dynamic Methods entity :: DynamicQuery m EntityID Source # queryDyn :: Component m a => ComponentID -> DynamicQuery m a Source # queryMaybeDyn :: Component m a => ComponentID -> DynamicQuery m (Maybe a) Source # queryMapDyn :: Component m a => (a -> a) -> ComponentID -> DynamicQuery m a Source # queryMapDyn_ :: Component m a => (a -> a) -> ComponentID -> DynamicQuery m () Source # queryMapDynM :: (Monad m, Component m a) => (a -> m a) -> ComponentID -> DynamicQuery m a Source # queryMapDynWith :: Component m b => (a -> b -> b) -> ComponentID -> DynamicQuery m a -> DynamicQuery m b Source # queryMapDynWith_ :: Component m b => (a -> b -> b) -> ComponentID -> DynamicQuery m a -> DynamicQuery m () Source # queryMapDynWithM :: (Monad m, Component m b) => (a -> b -> m b) -> ComponentID -> DynamicQuery m a -> DynamicQuery m b Source # queryMapDynWithAccum :: Component m c => (b -> c -> (a, c)) -> ComponentID -> DynamicQuery m b -> DynamicQuery m (a, c) Source # queryMapDynWithAccumM :: (Monad m, Component m c) => (b -> c -> m (a, c)) -> ComponentID -> DynamicQuery m b -> DynamicQuery m (a, c) Source # queryFilterMap :: (a -> Maybe b) -> DynamicQuery m a -> DynamicQuery m b Source # queryFilter :: (a -> Bool) -> DynamicQuery m a -> DynamicQuery m a Source # queryUntracked :: DynamicQuery m a -> DynamicQuery m a Source # | |
data QueryFilter Source #
Filter for a Query.
Instances
| Monoid QueryFilter Source # | |
Defined in Aztecs.ECS.Query Methods mempty :: QueryFilter # mappend :: QueryFilter -> QueryFilter -> QueryFilter # mconcat :: [QueryFilter] -> QueryFilter # | |
| Semigroup QueryFilter Source # | |
Defined in Aztecs.ECS.Query Methods (<>) :: QueryFilter -> QueryFilter -> QueryFilter # sconcat :: NonEmpty QueryFilter -> QueryFilter # stimes :: Integral b => b -> QueryFilter -> QueryFilter # | |
with :: forall (m :: Type -> Type) a. Component m a => QueryFilter Source #
Filter for entities containing this component.
without :: forall (m :: Type -> Type) a. Component m a => QueryFilter Source #
Filter out entities containing this component.
Events
Event triggered when a component is inserted.
Constructors
| OnInsert | |
Fields
| |
Instances
| Typeable a => Event (OnInsert a) Source # | |||||
Defined in Aztecs.ECS.Event | |||||
| Generic (OnInsert a) Source # | |||||
Defined in Aztecs.ECS.Event Associated Types
| |||||
| Show a => Show (OnInsert a) Source # | |||||
| Eq a => Eq (OnInsert a) Source # | |||||
| type Rep (OnInsert a) Source # | |||||
Defined in Aztecs.ECS.Event | |||||
Event triggered when a component is changed.
Constructors
| OnChange | |
Fields
| |
Instances
| Typeable a => Event (OnChange a) Source # | |||||
Defined in Aztecs.ECS.Event | |||||
| Generic (OnChange a) Source # | |||||
Defined in Aztecs.ECS.Event Associated Types
| |||||
| Show a => Show (OnChange a) Source # | |||||
| Eq a => Eq (OnChange a) Source # | |||||
| type Rep (OnChange a) Source # | |||||
Defined in Aztecs.ECS.Event | |||||
Event triggered when a component is removed.
Constructors
| OnRemove | |
Fields
| |
Instances
| Typeable a => Event (OnRemove a) Source # | |||||
Defined in Aztecs.ECS.Event | |||||
| Generic (OnRemove a) Source # | |||||
Defined in Aztecs.ECS.Event Associated Types
| |||||
| Show a => Show (OnRemove a) Source # | |||||
| Eq a => Eq (OnRemove a) Source # | |||||
| type Rep (OnRemove a) Source # | |||||
Defined in Aztecs.ECS.Event | |||||
Observers
data Observer (m :: Type -> Type) e Source #
Observer component
observer :: forall (m :: Type -> Type) e. Event e => EntityID -> (EntityID -> e -> Access m ()) -> Observer m e Source #
Create an observer for a single entity.