apecs-stm-0.1.3: STM stores for apecs

Safe HaskellNone
LanguageHaskell2010

Apecs.STM.Prelude

Description

This module re-exports the apecs prelude with STM versions.

Synopsis

Documentation

type System w a = SystemT w STM a Source #

module Apecs.STM

makeWorldAndComponents :: String -> [Name] -> Q [Dec] #

Calls makeWorld and makeMapComponents, i.e. makes a world and also defines Component instances with a Map store.

runGC :: System w () #

Explicitly invoke the garbage collector

global :: Entity #

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 ()) -> 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 cx, Set w m cy) => Entity -> (cx -> cy) -> SystemT w m () infixr 2 #

modify operator

Applies a function, if possible.

modify :: (Get w m cx, Set w m cy) => Entity -> (cx -> cy) -> 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.

get :: Get w m c => Entity -> SystemT w m c #

Read a Component

runWith :: w -> SystemT w m a -> m a #

Run a system in a game world

runSystem :: SystemT w m a -> w -> m a #

Run a system in a game world

data Not a #

Pseudocomponent 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.

Constructors

Not 
Instances
Has w m c => Has w m (Not c) 
Instance details

Defined in Apecs.Components

Methods

getStore :: SystemT w m (Storage (Not c)) #

Component c => Component (Not c) 
Instance details

Defined in Apecs.Components

Associated Types

type Storage (Not c) :: Type #

type Storage (Not c) 
Instance details

Defined in Apecs.Components

type Storage (Not c) = NotStore (Storage c)

data Cache (n :: Nat) s #

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) 
Instance details

Defined in Apecs.Stores

Methods

explInit :: m (Cache n s) #

(MonadIO m, ExplGet m s) => ExplGet m (Cache n s) 
Instance details

Defined in Apecs.Stores

Methods

explGet :: Cache n s -> Int -> m (Elem (Cache n s)) #

explExists :: Cache n s -> Int -> m Bool #

(MonadIO m, ExplSet m s) => ExplSet m (Cache n s) 
Instance details

Defined in Apecs.Stores

Methods

explSet :: Cache n s -> Int -> Elem (Cache n s) -> m () #

(MonadIO m, ExplDestroy m s) => ExplDestroy m (Cache n s) 
Instance details

Defined in Apecs.Stores

Methods

explDestroy :: Cache n s -> Int -> m () #

(MonadIO m, ExplMembers m s) => ExplMembers m (Cache n s) 
Instance details

Defined in Apecs.Stores

Methods

explMembers :: Cache n s -> m (Vector Int) #

(KnownNat n, Cachable s) => Cachable (Cache n s) 
Instance details

Defined in Apecs.Stores

type Elem (Cache n s) 
Instance details

Defined in Apecs.Stores

type Elem (Cache n s) = Elem s

newtype Entity #

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.

Constructors

Entity 

Fields

Instances
Enum Entity 
Instance details

Defined in Apecs.Core

Eq Entity 
Instance details

Defined in Apecs.Core

Methods

(==) :: Entity -> Entity -> Bool #

(/=) :: Entity -> Entity -> Bool #

Num Entity 
Instance details

Defined in Apecs.Core

Ord Entity 
Instance details

Defined in Apecs.Core

Show Entity 
Instance details

Defined in Apecs.Core

type Storage Entity 
Instance details

Defined in Apecs.Components

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.

Constructors

SystemT 

Fields

Instances
Monad m => MonadReader w (SystemT w m) 
Instance details

Defined in Apecs.Core

Methods

ask :: SystemT w m w #

local :: (w -> w) -> SystemT w m a -> SystemT w m a #

reader :: (w -> a) -> SystemT w m a #

MonadTrans (SystemT w) 
Instance details

Defined in Apecs.Core

Methods

lift :: Monad m => m a -> SystemT w m a #

Monad m => Monad (SystemT w m) 
Instance details

Defined in Apecs.Core

Methods

(>>=) :: SystemT w m a -> (a -> SystemT w m b) -> SystemT w m b #

(>>) :: SystemT w m a -> SystemT w m b -> SystemT w m b #

return :: a -> SystemT w m a #

fail :: String -> SystemT w m a #

Functor m => Functor (SystemT w m) 
Instance details

Defined in Apecs.Core

Methods

fmap :: (a -> b) -> SystemT w m a -> SystemT w m b #

(<$) :: a -> SystemT w m b -> SystemT w m a #

Applicative m => Applicative (SystemT w m) 
Instance details

Defined in Apecs.Core

Methods

pure :: a -> SystemT w m a #

(<*>) :: SystemT w m (a -> b) -> SystemT w m a -> SystemT w m b #

liftA2 :: (a -> b -> c) -> SystemT w m a -> SystemT w m b -> SystemT w m c #

(*>) :: SystemT w m a -> SystemT w m b -> SystemT w m b #

(<*) :: SystemT w m a -> SystemT w m b -> SystemT w m a #

MonadIO m => MonadIO (SystemT w m) 
Instance details

Defined in Apecs.Core

Methods

liftIO :: IO a -> SystemT w m a #

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.

Associated Types

type Storage c :: Type #

Instances
Component EntityCounter 
Instance details

Defined in Apecs.Util

Associated Types

type Storage EntityCounter :: Type #

Component EntityCounter Source # 
Instance details

Defined in Apecs.STM

Associated Types

type Storage EntityCounter :: Type #

Component c => Component (Not c) 
Instance details

Defined in Apecs.Components

Associated Types

type Storage (Not c) :: Type #

Component c => Component (Filter c) 
Instance details

Defined in Apecs.Components

Associated Types

type Storage (Filter c) :: Type #

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.

Methods

getStore :: SystemT w m (Storage c) #

Instances
Has w m c => Has w m (Not c) 
Instance details

Defined in Apecs.Components

Methods

getStore :: SystemT w m (Storage (Not c)) #

Has w m c => Has w m (Filter c) 
Instance details

Defined in Apecs.Components

Methods

getStore :: SystemT w m (Storage (Filter c)) #

explInit :: ExplInit m s => m s #

Initialize a new empty store.

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 #

Arguments

:: MonadReader r m 
=> (r -> a)

The selector function to apply to the environment.

-> m a 

Retrieves a function of the current environment.

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, Proxy :: Proxy a is a safer alternative to the '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

Constructors

Proxy 
Instances
Generic1 (Proxy :: k -> Type) 
Instance details

Defined in GHC.Generics

Associated Types

type Rep1 Proxy :: k -> Type #

Methods

from1 :: Proxy a -> Rep1 Proxy a #

to1 :: Rep1 Proxy a -> Proxy a #

Monad (Proxy :: Type -> Type)

Since: base-4.7.0.0

Instance details

Defined in Data.Proxy

Methods

(>>=) :: Proxy a -> (a -> Proxy b) -> Proxy b #

(>>) :: Proxy a -> Proxy b -> Proxy b #

return :: a -> Proxy a #

fail :: String -> Proxy a #

Functor (Proxy :: Type -> Type)

Since: base-4.7.0.0

Instance details

Defined in Data.Proxy

Methods

fmap :: (a -> b) -> Proxy a -> Proxy b #

(<$) :: a -> Proxy b -> Proxy a #

Applicative (Proxy :: Type -> Type)

Since: base-4.7.0.0

Instance details

Defined in Data.Proxy

Methods

pure :: a -> Proxy a #

(<*>) :: Proxy (a -> b) -> Proxy a -> Proxy b #

liftA2 :: (a -> b -> c) -> Proxy a -> Proxy b -> Proxy c #

(*>) :: Proxy a -> Proxy b -> Proxy b #

(<*) :: Proxy a -> Proxy b -> Proxy a #

Foldable (Proxy :: Type -> Type)

Since: base-4.7.0.0

Instance details

Defined in Data.Foldable

Methods

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 #

toList :: Proxy a -> [a] #

null :: Proxy a -> Bool #

length :: Proxy a -> Int #

elem :: Eq a => a -> Proxy a -> Bool #

maximum :: Ord a => Proxy a -> a #

minimum :: Ord a => Proxy a -> a #

sum :: Num a => Proxy a -> a #

product :: Num a => Proxy a -> a #

Traversable (Proxy :: Type -> Type)

Since: base-4.7.0.0

Instance details

Defined in Data.Traversable

Methods

traverse :: Applicative f => (a -> f b) -> Proxy a -> f (Proxy b) #

sequenceA :: Applicative f => Proxy (f a) -> f (Proxy a) #

mapM :: Monad m => (a -> m b) -> Proxy a -> m (Proxy b) #

sequence :: Monad m => Proxy (m a) -> m (Proxy a) #

Alternative (Proxy :: Type -> Type)

Since: base-4.9.0.0

Instance details

Defined in Data.Proxy

Methods

empty :: Proxy a #

(<|>) :: Proxy a -> Proxy a -> Proxy a #

some :: Proxy a -> Proxy [a] #

many :: Proxy a -> Proxy [a] #

MonadPlus (Proxy :: Type -> Type)

Since: base-4.9.0.0

Instance details

Defined in Data.Proxy

Methods

mzero :: Proxy a #

mplus :: Proxy a -> Proxy a -> Proxy a #

Hashable1 (Proxy :: Type -> Type) 
Instance details

Defined in Data.Hashable.Class

Methods

liftHashWithSalt :: (Int -> a -> Int) -> Int -> Proxy a -> Int #

Bounded (Proxy t)

Since: base-4.7.0.0

Instance details

Defined in Data.Proxy

Methods

minBound :: Proxy t #

maxBound :: Proxy t #

Enum (Proxy s)

Since: base-4.7.0.0

Instance details

Defined in Data.Proxy

Methods

succ :: Proxy s -> Proxy s #

pred :: Proxy s -> Proxy s #

toEnum :: Int -> Proxy s #

fromEnum :: Proxy s -> Int #

enumFrom :: Proxy s -> [Proxy s] #

enumFromThen :: Proxy s -> Proxy s -> [Proxy s] #

enumFromTo :: Proxy s -> Proxy s -> [Proxy s] #

enumFromThenTo :: Proxy s -> Proxy s -> Proxy s -> [Proxy s] #

Eq (Proxy s)

Since: base-4.7.0.0

Instance details

Defined in Data.Proxy

Methods

(==) :: Proxy s -> Proxy s -> Bool #

(/=) :: Proxy s -> Proxy s -> Bool #

Ord (Proxy s)

Since: base-4.7.0.0

Instance details

Defined in Data.Proxy

Methods

compare :: Proxy s -> Proxy s -> Ordering #

(<) :: Proxy s -> Proxy s -> Bool #

(<=) :: Proxy s -> Proxy s -> Bool #

(>) :: Proxy s -> Proxy s -> Bool #

(>=) :: Proxy s -> Proxy s -> Bool #

max :: Proxy s -> Proxy s -> Proxy s #

min :: Proxy s -> Proxy s -> Proxy s #

Read (Proxy t)

Since: base-4.7.0.0

Instance details

Defined in Data.Proxy

Show (Proxy s)

Since: base-4.7.0.0

Instance details

Defined in Data.Proxy

Methods

showsPrec :: Int -> Proxy s -> ShowS #

show :: Proxy s -> String #

showList :: [Proxy s] -> ShowS #

Ix (Proxy s)

Since: base-4.7.0.0

Instance details

Defined in Data.Proxy

Methods

range :: (Proxy s, Proxy s) -> [Proxy s] #

index :: (Proxy s, Proxy s) -> Proxy s -> Int #

unsafeIndex :: (Proxy s, Proxy s) -> Proxy s -> Int

inRange :: (Proxy s, Proxy s) -> Proxy s -> Bool #

rangeSize :: (Proxy s, Proxy s) -> Int #

unsafeRangeSize :: (Proxy s, Proxy s) -> Int

Generic (Proxy t) 
Instance details

Defined in GHC.Generics

Associated Types

type Rep (Proxy t) :: Type -> Type #

Methods

from :: Proxy t -> Rep (Proxy t) x #

to :: Rep (Proxy t) x -> Proxy t #

Semigroup (Proxy s)

Since: base-4.9.0.0

Instance details

Defined in Data.Proxy

Methods

(<>) :: Proxy s -> Proxy s -> Proxy s #

sconcat :: NonEmpty (Proxy s) -> Proxy s #

stimes :: Integral b => b -> Proxy s -> Proxy s #

Monoid (Proxy s)

Since: base-4.7.0.0

Instance details

Defined in Data.Proxy

Methods

mempty :: Proxy s #

mappend :: Proxy s -> Proxy s -> Proxy s #

mconcat :: [Proxy s] -> Proxy s #

Hashable (Proxy a) 
Instance details

Defined in Data.Hashable.Class

Methods

hashWithSalt :: Int -> Proxy a -> Int #

hash :: Proxy a -> Int #

type Rep1 (Proxy :: k -> Type)

Since: base-4.6.0.0

Instance details

Defined in GHC.Generics

type Rep1 (Proxy :: k -> Type) = D1 (MetaData "Proxy" "Data.Proxy" "base" False) (C1 (MetaCons "Proxy" PrefixI False) (U1 :: k -> Type))
type Rep (Proxy t)

Since: base-4.6.0.0

Instance details

Defined in GHC.Generics

type Rep (Proxy t) = D1 (MetaData "Proxy" "Data.Proxy" "base" False) (C1 (MetaCons "Proxy" PrefixI False) (U1 :: Type -> Type))

liftIO :: MonadIO m => IO a -> m a #

Lift a computation from the IO monad.

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.