Skip to content

aztecs-hs/aztecs

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Aztecs

License CI status Package

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 provides side-effect free components and systems, as well as backends for rendering and input (such as aztecs-sdl), allowing you to structure your game as simple function of Input -> World -> World. For more information, please see the documentation on Hackage.

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 and systems use Arrow syntax for compile-time gurantees
  • Modular design: Aztecs can be extended for a variety of use cases
import Aztecs
import qualified Aztecs.ECS.Access as A
import qualified Aztecs.ECS.Query as Q
import qualified Aztecs.ECS.System as S
import Control.DeepSeq
import Control.Monad
import Control.Monad.IO.Class
import GHC.Generics

newtype Position = Position Int deriving (Show, Generic, NFData)

instance Component Position

newtype Velocity = Velocity Int deriving (Show, Generic, NFData)

instance Component Velocity

move :: (ArrowQuery m q) => q () Position
move = proc () -> do
  v <- Q.fetch -< ()
  Q.adjust (\(Velocity v) (Position p) -> Position $ p + v) -< v

run :: (ArrowQuery m q, MonadSystem q s, MonadIO s) => s ()
run = do
  positions <- S.map () move
  liftIO $ print positions

app :: AccessT IO ()
app = do
  A.spawn_ $ bundle (Position 0) <> bundle (Velocity 1)
  forever run

main :: IO ()
main = runAccessT_ app

Packages

Inspiration

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