apecs is a fast, type-driven Entity-Component-System library for game programming.


Keywords
control, data, game, library, Propose Tags, Skip to Readme, , Index, Quick Jump, Apecs, Apecs.Components, Apecs.Core, Apecs.Experimental.Children, Apecs.Experimental.Components, Apecs.Experimental.Reactive, Apecs.Experimental.Stores, Apecs.Experimental.Util, Apecs.Stores, Apecs.System, Apecs.TH, Apecs.Util, apecs-0.9.6.tar.gz, browse, Package description, Package maintainers, AlexanderBondarenko, jship, jonascarpay, edit package information , Entity Component System, documentation on hackage, tutorial, examples, #apecs on the haskell gamedev discord, #haskell-game:matrix.org, Notakto, associated blog post/apecs tutorial, @Ashe, mallRL, @nmaehlmann, An implementation of the Unity tutorial project using apecs, @mewhhaha, SpaceMar, @dpwiz, Achtung die haskell, (Your game here), apecs-physics, Chipmunk2D, apecs-gloss, gloss, apecs-stm, entity-component-system, game-development, haskell
License
BSD-3-Clause
Install
cabal install apecs-0.9.6

Documentation

apecs

apecs is an Entity Component System (ECS) library for game development.

apecs aims to be

  • Fast - Performance is competitive with Rust ECS libraries (see benchmark results below)
  • Safe - Completely hides the dangers of the low-level machinery
  • Concise - Game logic is expressed using a small number of powerful combinators
  • Flexible - Easily add new modules or backends
  • Cool

Benchmarks

Links

Games/articles
Packages

Example

{-# LANGUAGE FlexibleInstances     #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE ScopedTypeVariables   #-}
{-# LANGUAGE TemplateHaskell       #-}
{-# LANGUAGE TypeFamilies          #-}

import Apecs
import Linear (V2 (..))

newtype Position = Position (V2 Double) deriving Show
newtype Velocity = Velocity (V2 Double) deriving Show
data Flying = Flying

makeWorldAndComponents "World" [''Position, ''Velocity, ''Flying]

game :: System World ()
game = do
  newEntity (Position 0, Velocity 1)
  newEntity (Position 2, Velocity 1)
  newEntity (Position 1, Velocity 2, Flying)

  -- 1. Add velocity to position
  -- 2. Apply gravity to non-flying entities
  -- 3. Print a list of entities and their positions
  cmap $ \(Position p, Velocity v) -> Position (v+p)
  cmap $ \(Velocity v, _ :: Not Flying) -> Velocity (v - V2 0 1)
  cmapM_ $ \(Position p, Entity e) -> liftIO . print $ (e, p)

main :: IO ()
main = initWorld >>= runSystem game