ECSx

Hex VersionLicenseDocumentation

ECSx is an Entity-Component-System (ECS) framework for Elixir. ECS is an architecture for building real-time games and simulations, wherein data about Entities is stored in small fragments called Components, which are then read and updated by Systems.

Setup

def deps do
  [
    {:ecsx, "~> 0.3"}
  ]
end
def start(_type, _args) do
  children = [
    MyApp.Manager
  ]

  opts = [strategy: :one_for_one, name: MyApp.Supervisor]
  Supervisor.start_link(children, opts)
end

Tutorial Project

Building a ship combat engine with ECSx in a Phoenix app
Note: This tutorial project is a work-in-progress

Usage

Entities and Components

Everything in your application is an Entity, but in ECS you won't work with these Entities directly - instead you will work with the individual attributes that an Entity might have. These attributes are given to an Entity by creating a Component, which holds, at minimum, the Entity's unique ID, but also can store a value. For example:

Systems

Once your Entities are modeled using Components, you'll create Systems to operate on them. For example:

Generators

ECSx comes with generators to quickly create new Components or Systems:

Manager

Every ECSx application requires a Manager module, where valid Component types and Systems are declared, as well as the setup to spawn world objects before any players join. This module is created for you during mix ecsx.setup and will be automatically updated by the other generators.

It is especially important to consider the order of your Systems list. The manager will run each System one at a time, in order.

License

Copyright (C) 2022 Andrew P Berrien

This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.