apecs: A fast ECS for game engine programming

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

A fast ECS for game engine programming


[Skip to Readme]
Versions 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
Dependencies async, base (>=4.7 && <5), containers, mtl, template-haskell, vector [details]
License BSD-3-Clause
Author Jonas Carpay
Maintainer jonascarpay@gmail.com
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 Tue Mar 20 01:52:14 UTC 2018
Distributions LTSHaskell:0.2.4.7, NixOS:0.3.0.2, openSUSE:0.2.4.7
Downloads 3110 total (76 in the last 30 days)
Rating (no votes yet) [estimated by rule of succession]
Your Rating
  • λ
  • λ
  • λ
Status Docs available [build log]
Last success reported on 2018-03-20 [all 1 reports]
Hackage Matrix CI

Modules

[Index]

Downloads

Maintainer's Corner

For package maintainers and hackage trustees


Readme for apecs-0.3.0.2

[back to package description]

apecs

Build Status Hackage apecs on Stackage LTS 10

apecs is an Entity Component System inspired by specs and Entitas. It provides a collection of mutable component stores, and an expressive DSL for operating on those stores, both easily extended.

Links

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 Apecs.Stores
import Apecs.Core
import Linear

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