https://github.com/aztecs-hs/aztecs
A modular game engine and ECS for Haskell
https://github.com/aztecs-hs/aztecs
ecs game-engine haskell
Last synced: about 1 month ago
JSON representation
A modular game engine and ECS for Haskell
- Host: GitHub
- URL: https://github.com/aztecs-hs/aztecs
- Owner: aztecs-hs
- License: bsd-3-clause
- Created: 2024-12-20T21:05:09.000Z (about 1 year ago)
- Default Branch: main
- Last Pushed: 2025-03-18T08:07:50.000Z (10 months ago)
- Last Synced: 2025-03-29T02:01:47.332Z (10 months ago)
- Topics: ecs, game-engine, haskell
- Language: Haskell
- Homepage:
- Size: 897 KB
- Stars: 112
- Watchers: 3
- Forks: 5
- Open Issues: 10
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- Funding: .github/FUNDING.yml
- License: LICENSE
Awesome Lists containing this project
README
# Aztecs
[](https://discord.gg/Hb7B3Qq4Xd)
[](https://github.com/aztecs-hs/aztecs/blob/main/LICENSE)
[](https://hackage.haskell.org/package/aztecs)
[](https://github.com/aztecs-hs/aztecs/actions)
A modular game engine and [ECS](https://en.wikipedia.org/wiki/Entity_component_system) 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.
[Examples](https://github.com/aztecs-hs/aztecs/tree/main/examples)
## Features
- Type-safe: Queries and systems use fully type-checked access with compile-time gurantees
- High-performance: Components are stored by their unique sets in archetypes
- Modular design: Aztecs can be extended for a variety of use cases
```hs
import Aztecs
import qualified Aztecs.World as W
import Control.Monad.IO.Class
newtype Position = Position Int
deriving (Show, Eq)
instance (Monad m) => Component m Position where
type ComponentStorage m Position = SparseStorage m
newtype Velocity = Velocity Int
deriving (Show, Eq)
instance (Monad m) => Component m Velocity where
type ComponentStorage m Velocity = SparseStorage m
data MoveSystem = MoveSystem
instance (PrimMonad m, MonadIO m) => System m MoveSystem where
type SystemIn m MoveSystem = Query (W m Position, R Velocity)
runSystem _ = mapM_ go
where
go (posRef, R (Velocity v)) = do
modifyW posRef $ \(Position p) -> Position (p + v)
p <- readW posRef
liftIO $ putStrLn $ "Moved to: " ++ show p
main :: IO ()
main = do
world <- W.empty @_ @'[Position, Velocity]
runAztecsT_ go world
where
go = do
_ <- spawn (bundle (Position 0) <> bundle (Velocity 1))
system MoveSystem
```
## Inspiration
Aztecs' approach to ECS is inspired by [Bevy](https://github.com/bevyengine/bevy/) and [Flecs](https://github.com/SanderMertens/flecs).