Skip to content

matthunz/aztecs

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Aztecs

Package License CI status

A type-safe and friendly ECS for Haskell.

Features

  • High-performance: Components are stored by their unique sets in vector-based archetypes
  • Dynamic components: Scripts and remote interfaces can create unique components with runtime-specified components
  • Type-safe DSL: Components and systems are accessed by marker types that determine their storage
  • Modular design: Aztecs can be extended for a variety of use cases
import Control.Monad.IO.Class
import Data.Aztecs.Edit (Edit)
import qualified Data.Aztecs.Edit as C
import Data.Aztecs.Entity
import qualified Data.Aztecs.Query as Q
import qualified Data.Aztecs.World as W
import Text.Pretty.Simple

newtype Position = Position Int deriving (Show)

instance Component Position

newtype Velocity = Velocity Int deriving (Show)

instance Component Velocity

app :: Edit IO ()
app = do
  C.spawn_ $ entity (Position 0) <&> Velocity 1
  C.spawn_ $ entity (Position 2) <&> Velocity 2

  positions <- Q.map $
    \(Position p :& Velocity v) -> Position (p + v)

  liftIO $ pPrint positions

main :: IO ()
main = do
  _ <- C.runEdit app W.empty
  return ()

Inspiration

Aztecs' approach to type-safety is inspired by Bevy

About

A type-safe and friendly ECS for Haskell

Resources

License

Stars

Watchers

Forks

Packages

No packages published