apecs-0.2.1.0: A fast ECS for game engine programming

Safe HaskellNone
LanguageHaskell2010

Apecs.Types

Synopsis

Documentation

newtype Entity c Source #

An Entity is really just an Int. The type variable is used to keep track of reads and writes, but can be freely cast.

Constructors

Entity Int 

Instances

Eq (Entity c) Source # 

Methods

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

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

Ord (Entity c) Source # 

Methods

compare :: Entity c -> Entity c -> Ordering #

(<) :: Entity c -> Entity c -> Bool #

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

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

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

max :: Entity c -> Entity c -> Entity c #

min :: Entity c -> Entity c -> Entity c #

Show (Entity c) Source # 

Methods

showsPrec :: Int -> Entity c -> ShowS #

show :: Entity c -> String #

showList :: [Entity c] -> ShowS #

Cast (Entity a) (Entity b) Source # 

Methods

cast :: Entity a -> Entity b Source #

newtype Slice c Source #

A slice is a list of entities, represented by a Data.Unbox.Vector of Ints.

Constructors

Slice 

Fields

Instances

Show (Slice c) Source # 

Methods

showsPrec :: Int -> Slice c -> ShowS #

show :: Slice c -> String #

showList :: [Slice c] -> ShowS #

Monoid (Slice c) Source # 

Methods

mempty :: Slice c #

mappend :: Slice c -> Slice c -> Slice c #

mconcat :: [Slice c] -> Slice c #

Cast (Slice a) (Slice b) Source # 

Methods

cast :: Slice a -> Slice b Source #

newtype System w a Source #

A system is a newtype around `ReaderT w IO a`, where w is the game world variable.

Constructors

System 

Fields

Instances

Monad (System w) Source # 

Methods

(>>=) :: System w a -> (a -> System w b) -> System w b #

(>>) :: System w a -> System w b -> System w b #

return :: a -> System w a #

fail :: String -> System w a #

Functor (System w) Source # 

Methods

fmap :: (a -> b) -> System w a -> System w b #

(<$) :: a -> System w b -> System w a #

Applicative (System w) Source # 

Methods

pure :: a -> System w a #

(<*>) :: System w (a -> b) -> System w a -> System w b #

(*>) :: System w a -> System w b -> System w b #

(<*) :: System w a -> System w b -> System w a #

MonadIO (System w) Source # 

Methods

liftIO :: IO a -> System w a #

class Initializable (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 in instance of Initializable.

Associated Types

type Storage c = s | s -> c Source #

Instances

Component EntityCounter Source # 

Associated Types

type Storage EntityCounter = (s :: *) Source #

(Component a, Component b) => Component (a, b) Source # 

Associated Types

type Storage (a, b) = (s :: *) Source #

(Component a, Component b, Component c) => Component (a, b, c) Source # 

Associated Types

type Storage (a, b, c) = (s :: *) Source #

class Component c => Has w c where Source #

A world Has a component if it can produce its Storage

Minimal complete definition

getStore

Methods

getStore :: System w (Storage c) Source #

Instances

(Has w a, Has w b) => Has w (a, b) Source # 

Methods

getStore :: System w (Storage (a, b)) Source #

(Has w a, Has w b, Has w c) => Has w (a, b, c) Source # 

Methods

getStore :: System w (Storage (a, b, c)) Source #

class Initializable s where Source #

Common for every storage. Represents a container that can be initialized.

Minimal complete definition

initStoreWith

Associated Types

type InitArgs s Source #

The initialization argument required by this store

Methods

initStoreWith :: InitArgs s -> IO s Source #

Instances

Initializable (Global c) Source # 

Associated Types

type InitArgs (Global c) :: * Source #

Initializable (Unique c) Source # 

Associated Types

type InitArgs (Unique c) :: * Source #

Initializable (Set c) Source # 

Associated Types

type InitArgs (Set c) :: * Source #

Methods

initStoreWith :: InitArgs (Set c) -> IO (Set c) Source #

Initializable (Map c) Source # 

Associated Types

type InitArgs (Map c) :: * Source #

Methods

initStoreWith :: InitArgs (Map c) -> IO (Map c) Source #

(Initializable a, Initializable b) => Initializable (a, b) Source # 

Associated Types

type InitArgs (a, b) :: * Source #

Methods

initStoreWith :: InitArgs (a, b) -> IO (a, b) Source #

(KnownNat n, Cachable s) => Initializable (Cache n s) Source # 

Associated Types

type InitArgs (Cache n s) :: * Source #

Methods

initStoreWith :: InitArgs (Cache n s) -> IO (Cache n s) Source #

(Log l (Stores s), Cachable s) => Initializable (Logger l s) Source # 

Associated Types

type InitArgs (Logger l s) :: * Source #

Methods

initStoreWith :: InitArgs (Logger l s) -> IO (Logger l s) Source #

(Initializable a, Initializable b, Initializable c) => Initializable (a, b, c) Source # 

Associated Types

type InitArgs (a, b, c) :: * Source #

Methods

initStoreWith :: InitArgs (a, b, c) -> IO (a, b, c) Source #

class HasMembers s where Source #

A store that is indexed by entities.

Minimal complete definition

explDestroy, explExists, explMembers

Methods

explDestroy :: s -> Int -> IO () Source #

Destroys the component for the given index.

explExists :: s -> Int -> IO Bool Source #

Returns whether there is a component for the given index

explMembers :: s -> IO (Vector Int) Source #

Returns an unboxed vector of member indices

explReset :: s -> IO () Source #

Removes all components. Equivalent to calling explDestroy on each member

explImapM_ :: MonadIO m => s -> (Int -> m a) -> m () Source #

Monadically iterates over member indices

explImapM :: MonadIO m => s -> (Int -> m a) -> m [a] Source #

Monadically iterates over member indices

Instances

HasMembers (Unique c) Source # 

Methods

explDestroy :: Unique c -> Int -> IO () Source #

explExists :: Unique c -> Int -> IO Bool Source #

explMembers :: Unique c -> IO (Vector Int) Source #

explReset :: Unique c -> IO () Source #

explImapM_ :: MonadIO m => Unique c -> (Int -> m a) -> m () Source #

explImapM :: MonadIO m => Unique c -> (Int -> m a) -> m [a] Source #

HasMembers (Set c) Source # 

Methods

explDestroy :: Set c -> Int -> IO () Source #

explExists :: Set c -> Int -> IO Bool Source #

explMembers :: Set c -> IO (Vector Int) Source #

explReset :: Set c -> IO () Source #

explImapM_ :: MonadIO m => Set c -> (Int -> m a) -> m () Source #

explImapM :: MonadIO m => Set c -> (Int -> m a) -> m [a] Source #

HasMembers (Map c) Source # 

Methods

explDestroy :: Map c -> Int -> IO () Source #

explExists :: Map c -> Int -> IO Bool Source #

explMembers :: Map c -> IO (Vector Int) Source #

explReset :: Map c -> IO () Source #

explImapM_ :: MonadIO m => Map c -> (Int -> m a) -> m () Source #

explImapM :: MonadIO m => Map c -> (Int -> m a) -> m [a] Source #

(HasMembers a, HasMembers b) => HasMembers (a, b) Source # 

Methods

explDestroy :: (a, b) -> Int -> IO () Source #

explExists :: (a, b) -> Int -> IO Bool Source #

explMembers :: (a, b) -> IO (Vector Int) Source #

explReset :: (a, b) -> IO () Source #

explImapM_ :: MonadIO m => (a, b) -> (Int -> m a) -> m () Source #

explImapM :: MonadIO m => (a, b) -> (Int -> m a) -> m [a] Source #

Cachable s => HasMembers (Cache n s) Source # 

Methods

explDestroy :: Cache n s -> Int -> IO () Source #

explExists :: Cache n s -> Int -> IO Bool Source #

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

explReset :: Cache n s -> IO () Source #

explImapM_ :: MonadIO m => Cache n s -> (Int -> m a) -> m () Source #

explImapM :: MonadIO m => Cache n s -> (Int -> m a) -> m [a] Source #

(Log l (Stores s), Cachable s) => HasMembers (Logger l s) Source # 

Methods

explDestroy :: Logger l s -> Int -> IO () Source #

explExists :: Logger l s -> Int -> IO Bool Source #

explMembers :: Logger l s -> IO (Vector Int) Source #

explReset :: Logger l s -> IO () Source #

explImapM_ :: MonadIO m => Logger l s -> (Int -> m a) -> m () Source #

explImapM :: MonadIO m => Logger l s -> (Int -> m a) -> m [a] Source #

(HasMembers a, HasMembers b, HasMembers c) => HasMembers (a, b, c) Source # 

Methods

explDestroy :: (a, b, c) -> Int -> IO () Source #

explExists :: (a, b, c) -> Int -> IO Bool Source #

explMembers :: (a, b, c) -> IO (Vector Int) Source #

explReset :: (a, b, c) -> IO () Source #

explImapM_ :: MonadIO m => (a, b, c) -> (Int -> m a) -> m () Source #

explImapM :: MonadIO m => (a, b, c) -> (Int -> m a) -> m [a] Source #

newtype Safe c Source #

Represents a safe access to c. A safe access is either a read that might fail, or a write that might delete.

Constructors

Safe 

Fields

class HasMembers s => Store s where Source #

Class of storages that associates components with entities.

Minimal complete definition

explGetUnsafe, explGet, explSet, explSetMaybe

Associated Types

type SafeRW s Source #

Return type for safe reads writes to the store

type Stores s Source #

The type of components stored by this Store

Methods

explGetUnsafe :: s -> Int -> IO (Stores s) Source #

Unsafe index to the store. Undefined if the component does not exist

explGet :: s -> Int -> IO (SafeRW s) Source #

Retrieves a component from the store

explSet :: s -> Int -> Stores s -> IO () Source #

Writes a component

explSetMaybe :: s -> Int -> SafeRW s -> IO () Source #

Either writes or deletes a component

explModify :: s -> Int -> (Stores s -> Stores s) -> IO () Source #

Modifies an element in the store. Equivalent to reading a value, and then writing the result of the function application.

explCmap :: s -> (Stores s -> Stores s) -> IO () Source #

Maps over all elements of this store. Equivalent to getting a list of all entities with this component, and then explModifying each of them.

explCmapM_ :: MonadIO m => s -> (Stores s -> m a) -> m () Source #

explCimapM_ :: MonadIO m => s -> ((Int, Stores s) -> m a) -> m () Source #

explCmapM :: MonadIO m => s -> (Stores s -> m a) -> m [a] Source #

explCimapM :: MonadIO m => s -> ((Int, Stores s) -> m a) -> m [a] Source #

Instances

Store (Unique c) Source # 

Associated Types

type SafeRW (Unique c) :: * Source #

type Stores (Unique c) :: * Source #

Methods

explGetUnsafe :: Unique c -> Int -> IO (Stores (Unique c)) Source #

explGet :: Unique c -> Int -> IO (SafeRW (Unique c)) Source #

explSet :: Unique c -> Int -> Stores (Unique c) -> IO () Source #

explSetMaybe :: Unique c -> Int -> SafeRW (Unique c) -> IO () Source #

explModify :: Unique c -> Int -> (Stores (Unique c) -> Stores (Unique c)) -> IO () Source #

explCmap :: Unique c -> (Stores (Unique c) -> Stores (Unique c)) -> IO () Source #

explCmapM_ :: MonadIO m => Unique c -> (Stores (Unique c) -> m a) -> m () Source #

explCimapM_ :: MonadIO m => Unique c -> ((Int, Stores (Unique c)) -> m a) -> m () Source #

explCmapM :: MonadIO m => Unique c -> (Stores (Unique c) -> m a) -> m [a] Source #

explCimapM :: MonadIO m => Unique c -> ((Int, Stores (Unique c)) -> m a) -> m [a] Source #

Flag c => Store (Set c) Source # 

Associated Types

type SafeRW (Set c) :: * Source #

type Stores (Set c) :: * Source #

Methods

explGetUnsafe :: Set c -> Int -> IO (Stores (Set c)) Source #

explGet :: Set c -> Int -> IO (SafeRW (Set c)) Source #

explSet :: Set c -> Int -> Stores (Set c) -> IO () Source #

explSetMaybe :: Set c -> Int -> SafeRW (Set c) -> IO () Source #

explModify :: Set c -> Int -> (Stores (Set c) -> Stores (Set c)) -> IO () Source #

explCmap :: Set c -> (Stores (Set c) -> Stores (Set c)) -> IO () Source #

explCmapM_ :: MonadIO m => Set c -> (Stores (Set c) -> m a) -> m () Source #

explCimapM_ :: MonadIO m => Set c -> ((Int, Stores (Set c)) -> m a) -> m () Source #

explCmapM :: MonadIO m => Set c -> (Stores (Set c) -> m a) -> m [a] Source #

explCimapM :: MonadIO m => Set c -> ((Int, Stores (Set c)) -> m a) -> m [a] Source #

Store (Map c) Source # 

Associated Types

type SafeRW (Map c) :: * Source #

type Stores (Map c) :: * Source #

Methods

explGetUnsafe :: Map c -> Int -> IO (Stores (Map c)) Source #

explGet :: Map c -> Int -> IO (SafeRW (Map c)) Source #

explSet :: Map c -> Int -> Stores (Map c) -> IO () Source #

explSetMaybe :: Map c -> Int -> SafeRW (Map c) -> IO () Source #

explModify :: Map c -> Int -> (Stores (Map c) -> Stores (Map c)) -> IO () Source #

explCmap :: Map c -> (Stores (Map c) -> Stores (Map c)) -> IO () Source #

explCmapM_ :: MonadIO m => Map c -> (Stores (Map c) -> m a) -> m () Source #

explCimapM_ :: MonadIO m => Map c -> ((Int, Stores (Map c)) -> m a) -> m () Source #

explCmapM :: MonadIO m => Map c -> (Stores (Map c) -> m a) -> m [a] Source #

explCimapM :: MonadIO m => Map c -> ((Int, Stores (Map c)) -> m a) -> m [a] Source #

(Store a, Store b) => Store (a, b) Source # 

Associated Types

type SafeRW (a, b) :: * Source #

type Stores (a, b) :: * Source #

Methods

explGetUnsafe :: (a, b) -> Int -> IO (Stores (a, b)) Source #

explGet :: (a, b) -> Int -> IO (SafeRW (a, b)) Source #

explSet :: (a, b) -> Int -> Stores (a, b) -> IO () Source #

explSetMaybe :: (a, b) -> Int -> SafeRW (a, b) -> IO () Source #

explModify :: (a, b) -> Int -> (Stores (a, b) -> Stores (a, b)) -> IO () Source #

explCmap :: (a, b) -> (Stores (a, b) -> Stores (a, b)) -> IO () Source #

explCmapM_ :: MonadIO m => (a, b) -> (Stores (a, b) -> m a) -> m () Source #

explCimapM_ :: MonadIO m => (a, b) -> ((Int, Stores (a, b)) -> m a) -> m () Source #

explCmapM :: MonadIO m => (a, b) -> (Stores (a, b) -> m a) -> m [a] Source #

explCimapM :: MonadIO m => (a, b) -> ((Int, Stores (a, b)) -> m a) -> m [a] Source #

Cachable s => Store (Cache n s) Source # 

Associated Types

type SafeRW (Cache n s) :: * Source #

type Stores (Cache n s) :: * Source #

Methods

explGetUnsafe :: Cache n s -> Int -> IO (Stores (Cache n s)) Source #

explGet :: Cache n s -> Int -> IO (SafeRW (Cache n s)) Source #

explSet :: Cache n s -> Int -> Stores (Cache n s) -> IO () Source #

explSetMaybe :: Cache n s -> Int -> SafeRW (Cache n s) -> IO () Source #

explModify :: Cache n s -> Int -> (Stores (Cache n s) -> Stores (Cache n s)) -> IO () Source #

explCmap :: Cache n s -> (Stores (Cache n s) -> Stores (Cache n s)) -> IO () Source #

explCmapM_ :: MonadIO m => Cache n s -> (Stores (Cache n s) -> m a) -> m () Source #

explCimapM_ :: MonadIO m => Cache n s -> ((Int, Stores (Cache n s)) -> m a) -> m () Source #

explCmapM :: MonadIO m => Cache n s -> (Stores (Cache n s) -> m a) -> m [a] Source #

explCimapM :: MonadIO m => Cache n s -> ((Int, Stores (Cache n s)) -> m a) -> m [a] Source #

(Log l (Stores s), Cachable s) => Store (Logger l s) Source # 

Associated Types

type SafeRW (Logger l s) :: * Source #

type Stores (Logger l s) :: * Source #

Methods

explGetUnsafe :: Logger l s -> Int -> IO (Stores (Logger l s)) Source #

explGet :: Logger l s -> Int -> IO (SafeRW (Logger l s)) Source #

explSet :: Logger l s -> Int -> Stores (Logger l s) -> IO () Source #

explSetMaybe :: Logger l s -> Int -> SafeRW (Logger l s) -> IO () Source #

explModify :: Logger l s -> Int -> (Stores (Logger l s) -> Stores (Logger l s)) -> IO () Source #

explCmap :: Logger l s -> (Stores (Logger l s) -> Stores (Logger l s)) -> IO () Source #

explCmapM_ :: MonadIO m => Logger l s -> (Stores (Logger l s) -> m a) -> m () Source #

explCimapM_ :: MonadIO m => Logger l s -> ((Int, Stores (Logger l s)) -> m a) -> m () Source #

explCmapM :: MonadIO m => Logger l s -> (Stores (Logger l s) -> m a) -> m [a] Source #

explCimapM :: MonadIO m => Logger l s -> ((Int, Stores (Logger l s)) -> m a) -> m [a] Source #

(Store a, Store b, Store c) => Store (a, b, c) Source # 

Associated Types

type SafeRW (a, b, c) :: * Source #

type Stores (a, b, c) :: * Source #

Methods

explGetUnsafe :: (a, b, c) -> Int -> IO (Stores (a, b, c)) Source #

explGet :: (a, b, c) -> Int -> IO (SafeRW (a, b, c)) Source #

explSet :: (a, b, c) -> Int -> Stores (a, b, c) -> IO () Source #

explSetMaybe :: (a, b, c) -> Int -> SafeRW (a, b, c) -> IO () Source #

explModify :: (a, b, c) -> Int -> (Stores (a, b, c) -> Stores (a, b, c)) -> IO () Source #

explCmap :: (a, b, c) -> (Stores (a, b, c) -> Stores (a, b, c)) -> IO () Source #

explCmapM_ :: MonadIO m => (a, b, c) -> (Stores (a, b, c) -> m a) -> m () Source #

explCimapM_ :: MonadIO m => (a, b, c) -> ((Int, Stores (a, b, c)) -> m a) -> m () Source #

explCmapM :: MonadIO m => (a, b, c) -> (Stores (a, b, c) -> m a) -> m [a] Source #

explCimapM :: MonadIO m => (a, b, c) -> ((Int, Stores (a, b, c)) -> m a) -> m [a] Source #

type IsRuntime c = (Store (Storage c), Stores (Storage c) ~ c) Source #

A constraint that indicates that the runtime representation of c is c This will almost always be the case, but it _might_ not be so we need this constraint.

class GlobalRW s c where Source #

Class of storages for global values

Minimal complete definition

explGlobalRead, explGlobalWrite

Methods

explGlobalRead :: s -> IO c Source #

explGlobalWrite :: s -> c -> IO () Source #

explGlobalModify :: s -> (c -> c) -> IO () Source #

Instances

GlobalRW (Global c) c Source # 

Methods

explGlobalRead :: Global c -> IO c Source #

explGlobalWrite :: Global c -> c -> IO () Source #

explGlobalModify :: Global c -> (c -> c) -> IO () Source #

(GlobalRW a ca, GlobalRW b cb) => GlobalRW (a, b) (ca, cb) Source # 

Methods

explGlobalRead :: (a, b) -> IO (ca, cb) Source #

explGlobalWrite :: (a, b) -> (ca, cb) -> IO () Source #

explGlobalModify :: (a, b) -> ((ca, cb) -> (ca, cb)) -> IO () Source #

(GlobalRW a ca, GlobalRW b cb, GlobalRW c cc) => GlobalRW (a, b, c) (ca, cb, cc) Source # 

Methods

explGlobalRead :: (a, b, c) -> IO (ca, cb, cc) Source #

explGlobalWrite :: (a, b, c) -> (ca, cb, cc) -> IO () Source #

explGlobalModify :: (a, b, c) -> ((ca, cb, cc) -> (ca, cb, cc)) -> IO () Source #

class Cast a b where Source #

Casts for entities and slices

Minimal complete definition

cast

Methods

cast :: a -> b Source #

Instances

Cast (Slice a) (Slice b) Source # 

Methods

cast :: Slice a -> Slice b Source #

Cast (Entity a) (Entity b) Source # 

Methods

cast :: Entity a -> Entity b Source #