mischief-ecs
Safe HaskellNone
LanguageGHC2024

Mischief.ECS.World

Synopsis

World

data World Source #

The World is the main data structure storing the entities, components, archetypes, and everything else that lives in our app.

Constructors

World 

Fields

newWorld :: SystemTools -> IO World Source #

Create a new World in IO.

setSystemId :: SystemId -> World -> World Source #

Change the current SystemId of the World.

setDeferred :: IORef [System ()] -> World -> World Source #

Set the list of deferred systems of the World.

newtype Frame Source #

Constructors

Frame Int 

Instances

Instances details
Show Frame Source # 
Instance details

Defined in Mischief.ECS.World

Methods

showsPrec :: Int -> Frame -> ShowS #

show :: Frame -> String #

showList :: [Frame] -> ShowS #

Eq Frame Source # 
Instance details

Defined in Mischief.ECS.World

Methods

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

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

Ord Frame Source # 
Instance details

Defined in Mischief.ECS.World

Methods

compare :: Frame -> Frame -> Ordering #

(<) :: Frame -> Frame -> Bool #

(<=) :: Frame -> Frame -> Bool #

(>) :: Frame -> Frame -> Bool #

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

max :: Frame -> Frame -> Frame #

min :: Frame -> Frame -> Frame #

data SystemTools Source #

Constructors

SystemTools 

Fields

worldGet :: forall c m w. (MonadSystem w m, Component c) => Proxy c -> Entity -> m (Maybe c) Source #

worldGetRAny :: forall c m w. (Component c, MonadSystem w m, IsExclusiveRel c ~ 'False) => Proxy c -> Entity -> m (Maybe [Rel c]) Source #

worldSet :: Bundle c => c -> Entity -> System () Source #

Prefs

class (Typeable a, Typeable b) => PrefType (a :: k) (b :: k1) | a -> b Source #

Instances

Instances details
PrefType TimeTypePref TimeTag Source # 
Instance details

Defined in Mischief.ECS.Time

PrefType SupressEventsPref Bool Source # 
Instance details

Defined in Mischief.ECS.World

setPref :: forall {k} (a :: k) b c. PrefType a b => b -> System c -> System c Source #

getPref :: forall {k} (a :: k) m b w. (PrefType a b, MonadSystem w m) => m (Maybe b) Source #

data SupressEventsPref Source #

Instances

Instances details
PrefType SupressEventsPref Bool Source # 
Instance details

Defined in Mischief.ECS.World

Systems

newtype System a Source #

A System is a monad that mutates the World.

It can be added to a certain schedule and ordered with other systems. It also offers IO access via liftIO.

Read the tutorial on systems for more details.

Constructors

System (ReaderT (Hidden World) IO a) 

Instances

Instances details
MonadThrow System Source # 
Instance details

Defined in Mischief.ECS.World

Methods

throwM :: (HasCallStack, Exception e) => e -> System a #

Applicative System Source # 
Instance details

Defined in Mischief.ECS.World

Methods

pure :: a -> System a #

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

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

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

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

Functor System Source # 
Instance details

Defined in Mischief.ECS.World

Methods

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

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

Monad System Source # 
Instance details

Defined in Mischief.ECS.World

Methods

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

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

return :: a -> System a #

MonadFail System Source # 
Instance details

Defined in Mischief.ECS.World

Methods

fail :: String -> System a #

MonadIO System Source # 
Instance details

Defined in Mischief.ECS.World

Methods

liftIO :: IO a -> System a #

SystemAny System Source # 
Instance details

Defined in Mischief.ECS.World

Methods

systemAny :: System a -> ParSystem a -> System a Source #

PrimMonad System Source # 
Instance details

Defined in Mischief.ECS.World

Associated Types

type PrimState System 
Instance details

Defined in Mischief.ECS.World

Methods

primitive :: (State# (PrimState System) -> (# State# (PrimState System), a #)) -> System a #

EraseIntoStorage (System ()) Systems Source # 
Instance details

Defined in Mischief.ECS.Systems

Methods

erase :: System () -> Systems Source #

EraseIntoStorage (System ()) [System ()] Source # 
Instance details

Defined in Mischief.ECS.World

Methods

erase :: System () -> [System ()] Source #

type PrimState System Source # 
Instance details

Defined in Mischief.ECS.World

newtype SystemId Source #

Unique id assigned to each system that's added to a schedule. Just a wrapper around Entity.

Constructors

SystemId 

Fields

Instances

Instances details
Show SystemId Source # 
Instance details

Defined in Mischief.ECS.World

Eq SystemId Source # 
Instance details

Defined in Mischief.ECS.World

Ord SystemId Source # 
Instance details

Defined in Mischief.ECS.World

runWhen :: Typeable a => System (Maybe a) -> (a -> System b) -> System () Source #

Primitive that allows you to set a system to run at every sync point until it returns a Just a, at which point it will run the second system with the obtained a and stop running.

It will run once on the spot, meaning it has no overhead if the first system immediately succeed.

You should only use this in one-time logic, such as Events or the Startup schedule. You should not use it in logic that runs continuously, such as in Update, as it will keep queueing up a new system to check without removing the old one.

runSystem :: System a -> World -> IO a Source #

Run a System with the given World inside IO

class (GetWorld w, MonadReader w a, Applicative a, MonadFail a, Functor a, Monad a, MonadIO a, PrimMonad a, PrimState a ~ RealWorld, MonadThrow a, SystemAny a) => MonadSystem w (a :: Type -> Type) Source #

Typeclass that can be used to generalize systems to both System and ParSystem.

Used mainly by queries and other operations which don't mutate the World.

Instances

Instances details
MonadSystem ParWorld ParSystem Source # 
Instance details

Defined in Mischief.ECS.World

class SystemAny (m :: Type -> Type) where Source #

Methods

systemAny :: System a -> ParSystem a -> m a Source #

Instances

Instances details
SystemAny ParSystem Source # 
Instance details

Defined in Mischief.ECS.World

Methods

systemAny :: System a -> ParSystem a -> ParSystem a Source #

SystemAny System Source # 
Instance details

Defined in Mischief.ECS.World

Methods

systemAny :: System a -> ParSystem a -> System a Source #

Parallel

newtype ParSystem a Source #

A variant of System that contains a ParWorld instead of World.

Parallel systems will only be able to run systems that are either specifically intended for them or are made to work with any MonadSystem (such as queries).

To run a normal System (), you need to defer!

Constructors

ParSystem (ReaderT ParWorld IO a) 

Instances

Instances details
MonadThrow ParSystem Source # 
Instance details

Defined in Mischief.ECS.World

Methods

throwM :: (HasCallStack, Exception e) => e -> ParSystem a #

Applicative ParSystem Source # 
Instance details

Defined in Mischief.ECS.World

Methods

pure :: a -> ParSystem a #

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

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

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

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

Functor ParSystem Source # 
Instance details

Defined in Mischief.ECS.World

Methods

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

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

Monad ParSystem Source # 
Instance details

Defined in Mischief.ECS.World

Methods

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

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

return :: a -> ParSystem a #

MonadFail ParSystem Source # 
Instance details

Defined in Mischief.ECS.World

Methods

fail :: String -> ParSystem a #

MonadIO ParSystem Source # 
Instance details

Defined in Mischief.ECS.World

Methods

liftIO :: IO a -> ParSystem a #

SystemAny ParSystem Source # 
Instance details

Defined in Mischief.ECS.World

Methods

systemAny :: System a -> ParSystem a -> ParSystem a Source #

PrimMonad ParSystem Source # 
Instance details

Defined in Mischief.ECS.World

Associated Types

type PrimState ParSystem 
Instance details

Defined in Mischief.ECS.World

MonadSystem ParWorld ParSystem Source # 
Instance details

Defined in Mischief.ECS.World

MonadReader ParWorld ParSystem Source # 
Instance details

Defined in Mischief.ECS.World

type PrimState ParSystem Source # 
Instance details

Defined in Mischief.ECS.World

data ParWorld Source #

Special wrapper around World given to ParSystems.

Constructors

ParWorld 

Fields

  • world :: Hidden World

    Hidden ensures users cannot access and mutate the World.

  • parDeferred :: IORef [System ()]

    Deferred systems will be collected in this dedicated list and then merged back into the main deferred list once the parallel systems are joined.

Instances

Instances details
MonadSystem ParWorld ParSystem Source # 
Instance details

Defined in Mischief.ECS.World

MonadReader ParWorld ParSystem Source # 
Instance details

Defined in Mischief.ECS.World

parLift :: ParSystem a -> System a Source #

Lift a ParSystem into a System. Doesn't flush the deferred queue!