ECSpanse - an Entity Component System framework for Elixir

ECSpanse

logo_small

Ecspanse is an Entity Component System (ECS) framework for Elixir.

Ecspanse is not a game engine, but a flexible foundation for managing state and building logic, with features like:

  • flexible queries with multiple filters
  • dynamic bidirectional relationships
  • versatile tagging capabilities
  • component templates
  • system event subscriptions
  • asynchronous system execution

Docs: Ecspanse — ECSpanse v0.8.1
GitHub: GitHub - iacobson/ecspanse: Entity Component System (ECS) library for Elixir, offering a suite of features including: flexible queries with multiple filters, dynamic bidirectional relationships, versatile tagging capabilities, system event subscriptions, or asynchronous system execution.
Article: https://iacobson.medium.com/elixir-for-fun-ecspanse-2852a7993ecd
Podcast: ECS / Game Development with Elixir vs. Python, JavaScript, React with Dorian Iacobescu & Daniel Luu | SmartLogic

22 Likes

New release v0.2.0

Introduces Component and Event Templates for simplifying the creation of related components and events.

Adds a new query Ecspanse.Query.fetch_tagged_component/2 that returns an entity’s component by a list of tags. Attention, it is the logic implementation duty to ensure that no more than one component is returned, or it will raise an error.

Introduces also some small breaking changes: the Timer Component and Event are now Templates.
use Ecspanse.Component.Timer and use Ecspanse.Event.Timer should be replaced with use Ecspanse.Template.Component.Timer and use Ecspanse.Template.Event.Timer.

1 Like

I don’t understand from reading the documentation and the article, what do you mean it’s not a game engine?

What kind of problems it actually solves, like realtime synchronization?

You might find information about ECS here…

While it’s new in OOP video game, it’s kind of natural in FP

Ecspanse is a state management library. It also runs the “game loop” and offers some built-in functionality like timers.

what I mean by “it’s not a game engine” is that has no functionality for rendering, controls/input, physics, assets, GUI, etc. So you will need to combine it with some other technology if you want to build anything user-facing.

3 Likes

Thank You for your lib, I am going to try it for some games that I have in mind :slight_smile:

1 Like

When you will have a working prototype, please paste it here. I’m extremely curious about what kind of games people think to build with Elixir.

1 Like

Will do… currently I am thinking of using React and Three, or Three fiber for the front end and controls, Phoenix for socket and clients communication, and ECS for managing game state.

But it might take some time

1 Like

Is it though? are we talking about the concepts used behind unity engine?

Yes, exactly, that’s how they could achieve a demo called something like 1000 cities… I don’t remember the name, but the demo I do

Isn’t that just a basically just a change from inheritance to composition? I mean that’s nice, however I don’t think erlang VM can fit in this theme by design,

Not only, it’s data-oriented… but to me, it looks like multiple systems doing Enum.map on a filtered set of entities.

2 Likes

New release v0.3.0

Introduces two new commands, making components creation even faster:

Introduces two new queries:

1 Like

This looks really cool - definitely better and more full-featured than what I wrote years ago with a gen_stage infrastructure ( GitHub - ecstatic-framework/ecstatic: An ECS (Entity-Component-System) framework in Elixir ).

Out of curiosity, did you find this one when you were poking around, or not? (not like it’s maintained at the moment, obviously)

1 Like

I haven’t had time to check it out, but looks interesting. I want to ask though, how does it differ from ECSx created by Dockyard? One of the use case for ECSx seems to be game dev as explained here.

1 Like

Thank you! And yes, I did find your library and also read your Medium article.
Also, out of curiosity, have you built or tried to build a game or any kind of project with it?
I’m generally very interested in any kind of game project build with Elixir.

Thanks. I think Ecspanse and ECSx try to solve the same “problem” but in different ways. I even mentioned ECSx as an alternative to Ecspanse in my Medium article.

Still, to try to answer your question, I think ECSx is more straightforward to get started with. You have generators and every component holds a single value. You can then query the individual components by their entity ID or as a list. But I think their guides section explains it better than I could.

On the other hand, Ecspanse has a bit more complicated approach, but I would say also offers more flexibility as the game becomes more complex. I would mention just a few of them:

You can find some more details and examples in the Medium article.

3 Likes

Oh, great to hear that it didn’t just die in the dark corners of the internet :slight_smile:

I originally extracted/reworked ECS as part of my work on my most off-the-rails project ever, which was an attempt to cross dwarf fortress and old-school MUDs: GitHub - Trevoke/dwarlixir: A dwarf-fortress clone / MUD / side project in Elixir - but I never finished the refactor once I had extracted it.
In the Slack community I mention in the article - the MUD coders guild - the experience is fairly common, as most folks try to build a MUD from scratch, because it’s not so much about finishing a game as about learning from building the MUD; but we did notice that extracting or making ECS libraries/frameworks is where most MUD projects go to die.

A video game studio (WindFish Studio · GitHub ) found ecstatic a few years ago and tried to build a fairly ambitious project - some kind of world-scale simulation, IIRC - but I think they eventually ran out of funding to make the game.

@oestrich wrote GitHub - oestrich/ex_venture: Text based MMORPG engine written in Elixir , has built at least one game on top of that, and a few other useful tools; he’s largely been more successful than me at building reasonable games and getting them to work :smiley:

3 Likes

Very interesting. What was the plan for the UI (frontend) for dwarlixir?
I feel like this is a big minus for developing games in Elixir. Not many options for rendering and building native apps.

I’m thinking about some terminal UI like bracket-lib, or even something more advanced, such as macroquad.

I’m building my multiplayer game with Phoenix & LiveView. But I really think Elixir would be a great choice for making games like Caves of Qud or Cogmind.

Well, I am terrible at user interfaces, so I was going to make it a very simple command-line interface. And if you think that was probably going to be unplayably messy, you’re probably right :smiley:

Yeah, I don’t really know what we do for GUIs with Erlang/Elixir, though we do have Erlang -- wx the erlang binding of wxWidgets of course.