apecs: Fast ECS framework for game programming

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

Apecs is an Entity Component System framework, suitable for high-performance game programming.


[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
Dependencies async, base (>=4.9 && <4.12), containers, mtl, template-haskell, vector [details]
License BSD-3-Clause
Author Jonas Carpay
Maintainer jonascarpay@gmail.com
Revised Revision 1 made by HerbertValerioRiedel at 2019-02-03T20:01:43Z
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 2018-07-09T06:01:27Z
Distributions LTSHaskell:0.9.6, NixOS:0.9.5, Stackage:0.9.6
Reverse Dependencies 5 direct, 1 indirect [details]
Downloads 26581 total (135 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 2018-07-09 [all 1 reports]

Readme for apecs-0.4.1.1

[back to package description]

apecs

Build Status Hackage Stackage

apecs is an Entity Component System (ECS) framework inspired by specs and Entitas. The front-end DSL uses a small set of combinators to concisely express game logic, which then translate to fast primitive operations on back-end stores. Both the DSL and storage framework can easily be extended to meet any performance/expressivity needs.

Performance

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

Benchmarks

Example

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

import Apecs
import Linear (V2 (..))

newtype Position = Position (V2 Double) deriving Show
-- To declare a component, we need to specify how to store it
instance Component Position where
  type Storage Position = Map Position -- The simplest store is a Map

newtype Velocity = Velocity (V2 Double) deriving Show
instance Component Velocity where
  type Storage Velocity = Cache 100 (Map Velocity) -- Caching adds fast reads/writes

data Flying = Flying
instance Component Flying where
  type Storage Flying = Map Flying

makeWorld "World" [''Position, ''Velocity, ''Flying] -- Generate World and instances

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

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

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