Skip to content

Latest commit

 

History

History
112 lines (71 loc) · 3.84 KB

README.md

File metadata and controls

112 lines (71 loc) · 3.84 KB

Aztecs

Discord License Package CI status

A modular game engine and ECS for Haskell. An ECS is a modern approach to organizing your application state as a database, providing patterns for data-oriented design and parallel processing.

Aztecs: An Empirical Entity Component System (ECS) for Haskell [Draft]

Examples

Features

  • High-performance: Components are stored by their unique sets in archetypes
  • Dynamic components: Scripts and remote interfaces can create runtime-specified components
  • Type-safe DSL: Queries use Applicative syntax for compile-time gurantees
  • Modular design: Aztecs can be extended for a variety of use cases
import Aztecs.ECS
import Control.Monad
import Control.Monad.IO.Class
import Data.Function

newtype Position = Position Int deriving (Show)

instance Component Position

newtype Velocity = Velocity Int

instance Component Velocity

move :: Query Position
move = fetch & zipFetchMap (\(Velocity v) (Position p) -> Position $ p + v)

run :: SystemT IO ()
run = do
  positions <- query move
  liftIO $ print positions

app :: AccessT IO ()
app = do
  _ <- spawn $ bundle (Position 0) <> bundle (Velocity 1)
  forever $ system run

main :: IO ()
main = runAccessT_ app

Scripting

aztecs-script aims to be a turing-complete query language that can be used for both scripting gameplay and controlling the ECS over a network. This package provides both fully-typed Haskell DSL for scripting as well as a low-level interpreter for the text-based scripting language.

Haskell:

fetch @Position `as` #p <?> fetch @Velocity `as` #v `returning` #p :. #x :& #v :. #v

aztecs-script:

FETCH position AS p AND FETCH velocity AS v RETURNING (p.x, v.v)

Packages

Benchmarks

Benchmark results:  (Aztecs 160us) (Apecs 772us)
(Bevy	8us)

Inspiration

Aztecs' approach to type-safety is inspired by Bevy, but with direct archetype-based storage similar to Flecs.