https://github.com/simre1/haskell-worlds
Another Haskell ECS
https://github.com/simre1/haskell-worlds
ecs entity-component-architecture entity-component-system haskell
Last synced: 10 days ago
JSON representation
Another Haskell ECS
- Host: GitHub
- URL: https://github.com/simre1/haskell-worlds
- Owner: Simre1
- License: bsd-3-clause
- Created: 2020-11-29T22:52:29.000Z (about 5 years ago)
- Default Branch: master
- Last Pushed: 2021-02-08T18:02:22.000Z (almost 5 years ago)
- Last Synced: 2024-12-29T05:22:29.652Z (12 months ago)
- Topics: ecs, entity-component-architecture, entity-component-system, haskell
- Language: Haskell
- Homepage:
- Size: 11.7 KB
- Stars: 3
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# Haskell Worlds
Haskell Worlds is an *Entity Component System* (ECS) implemented in Haskell. Design choices have been heavily influenced by *apecs*, but I have tried to create an even more ergonomic interface. The most interesting feature is that you can immediately add new components without any boilerplate. It is also possible to dynamically add more components to a world as the application runs.
Here's an example:
```haskell
{-# LANGUAGE TypeApplications #-}
module Main where
import HWorlds
import Control.Monad (replicateM_)
import Control.Monad.IO.Class (MonadIO(liftIO))
data Position = Position Double Double
data Velocity = Velocity Double Double
main :: IO ()
main = do
positionWorld <- mapWorld @Position
velocityWorld <- mapWorld @Velocity
entityWorld <- entityWorld
let myWorld = mergeWorld positionWorld $ mergeWorld velocityWorld entityWorld
runWorldT myWorld $ do
initEntity (Position 0 0)
initEntity (Position 10 10, Velocity 0 5)
replicateM_ 10 $ do
cmap $ \(Velocity dx dy) -> Velocity dx (pred dy)
cmap $ \(Position x y, Velocity dx dy) -> Position (dx + x) (dy + y)
cmapM_ $ \(Position x y) -> liftIO $ print (x,y)
```
## Getting started
*HWorlds* does not require any special build instructions, but you need to use *ghc-8.10*. The following should then work without any issues:
```bash
git clone https://github.com/Simre1/haskell-worlds
cd haskell-worlds
cabal build
```
You can now run the example app or a minimal benchmark which compares *apecs* and *haskell-worlds*:
```haskell
cabal run app
cabal run bench
```