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]
- 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
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.
fetch @Position `as` #p <?> fetch @Velocity `as` #v `returning` #p :. #x :& #v :. #v
FETCH position AS p AND FETCH velocity AS v RETURNING (p.x, v.v)
-
Parent-child hierarchies.
-
Aztecs scripting language.
-
SDL window management and rendering support.
-
SDL image and spritesheet rendering support.
-
SDL text rendering support.
Aztecs' approach to type-safety is inspired by Bevy, but with direct archetype-based storage similar to Flecs.