apecs: Fast ECS framework for game programming

[ bsd3, control, data, game, library, program ] [ Propose Tags ]

Entity-Component-System frameworks provide a game programming paradigm that tackles many of the shortcomings of a more OO-oriented approach. apecs is a type-driven ECS, that leverages strong typing for an expressive DSL that turns into fast game code.

[Skip to Readme]
Versions [faq],,,,,,,,,,,,,,,,,,,,,,,,,,,,, 0.7.0, 0.7.1, 0.7.2, 0.7.3
Change log CHANGELOG.md
Dependencies base (>=4.9 && <5), containers, mtl, template-haskell, vector [details]
License BSD-3-Clause
Author Jonas Carpay
Maintainer jonascarpay@gmail.com
Revised Revision 1 made by HerbertValerioRiedel at Sun Feb 3 20:01:45 UTC 2019
Category Game, Control, Data
Home page https://github.com/jonascarpay/apecs#readme
Source repo head: git clone git://github.com/jonascarpay/apecs.git
Uploaded by jonascarpay at Fri Nov 30 03:58:22 UTC 2018
Distributions LTSHaskell:0.7.3, NixOS:0.7.3, Stackage:0.7.3
Downloads 6321 total (982 in the last 30 days)
Rating (no votes yet) [estimated by rule of succession]
Your Rating
  • λ
  • λ
  • λ
Status Hackage Matrix CI
Docs available [build log]
Last success reported on 2018-11-30 [all 1 reports]


[Index] [Quick Jump]


Note: This package has metadata revisions in the cabal description newer than included in the tarball. To unpack the package including the revisions, use 'cabal get'.

Maintainer's Corner

For package maintainers and hackage trustees

Readme for apecs-0.7.0

[back to package description]


apecs is an Entity Component System (ECS) framework inspired by specs and Entitas. ECS presents a data-driven approach to game development, that elegantly tackles many of the unique issues of game programming. apecs aims to be

  • Fast - apecs is designed for high-performance applications. Its performance is competitive with Rust ECS libraries.
  • Simple - Game logic is expressed using a small number of combinators, and minimal boilerplate.
  • Safe - The cmap/cfold-DSL hides all the dangers of the low-level API.
  • Extensible - apecs can be used with anything that implements the low-level API. See apecs-physics or apecs-stm for examples.



ecs-bench shows that apecs is competitive with the fastest Rust ECS frameworks.



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

import Apecs
import Control.Monad
import Apecs.Util
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