apecs: Fast Entity-Component-System library for game programming

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

The Entity-Component-System architecture provides an imperative game programming paradigm that tackles many of the shortcomings of more OO-oriented approaches. apecs is a type-driven ECS library, that leverages strong typing for an expressive DSL that compiles into fast game code.


[Skip to Readme]

Downloads

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

Package maintainers

For package maintainers and hackage trustees

Candidates

  • No Candidates
Versions [RSS] 0.1.0.0, 0.1.1.0, 0.2.0.0, 0.2.0.1, 0.2.0.2, 0.2.0.3, 0.2.1.0, 0.2.1.1, 0.2.2.0, 0.2.3.0, 0.2.4.0, 0.2.4.1, 0.2.4.2, 0.2.4.3, 0.2.4.4, 0.2.4.5, 0.2.4.6, 0.2.4.7, 0.3.0.0, 0.3.0.1, 0.3.0.2, 0.4.0.0, 0.4.0.1, 0.4.1.0, 0.4.1.1, 0.5.0.0, 0.5.1.0, 0.5.1.1, 0.6.0.0, 0.7.0, 0.7.1, 0.7.2, 0.7.3, 0.8.0, 0.8.1, 0.8.2, 0.8.3, 0.9.0, 0.9.1, 0.9.2, 0.9.3, 0.9.4, 0.9.5, 0.9.6
Change log CHANGELOG.md
Dependencies base (>=4.9 && <5), containers (>=0.5 && <0.8), mtl (>=2.2 && <2.3), template-haskell (>=2.12 && <2.15), vector (>=0.11 && <0.13) [details]
License BSD-3-Clause
Author Jonas Carpay
Maintainer jonascarpay@gmail.com
Revised Revision 1 made by sjakobi at 2021-11-13T08:37:29Z
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 2019-02-28T18:08:49Z
Distributions LTSHaskell:0.9.6, NixOS:0.9.5, Stackage:0.9.6
Reverse Dependencies 5 direct, 1 indirect [details]
Downloads 26582 total (134 in the last 30 days)
Rating 2.25 (votes: 2) [estimated by Bayesian average]
Your Rating
  • λ
  • λ
  • λ
Status Docs available [build log]
Last success reported on 2019-02-28 [all 1 reports]

Readme for apecs-0.7.3

[back to package description]

apecs Build Status

apecs is an Entity Component System (ECS) library 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 - Performance is competitive with Rust ECS libraries (see benchmark results below).
  • Concise - Game logic is expressed using a small number of powerful combinators.
  • Safe - The cmap/cfold-DSL completely hides the dangers of the low-level API.
  • Extensible - At its heart apecs is just a data manipulation DSL that can be implemented with any number of backends. as a monad transformer it easily integrates into larger applications.
  • Cool

Benchmarks

By other authors

Status

Package Hackage Stack LTS Stack Nightly
apecs Hackage Stackage Stackage
apecs-physics Hackage Stackage Stackage
apecs-gloss Hackage Stackage Stackage
apecs-stm Hackage - -
examples - - -

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