/ecso

Experimental Entity Component System for Haxe.

Primary LanguageOCamlMIT LicenseMIT

ecso

ecso is an open-source and experimental Entity Component System plugin for Haxe, which enables ECS oriented compiler features and focuses on simplicity.

If you have any suggestions or run into any problems, please open an issue .

MIT License Slack GitHub Workflow Status

Features

  • Framework agnostic: focus exclusively on core ECS aspects.
  • Haxe-Powered: integrates with built-in semantics and features (such as macros, type inference, closures, null safety, etc).
  • Advanced code-analyzes: structure for high-level ECS-oriented compiler optimizations.
  • Super simple API: lightweight with clarity, readability and discoverability in mind.
  • Cross-platform: enables target-specific optimizations, and run on every Haxe target.
  • Performance: while the current focus is on design and not on speed, the nature of ecso promises a good level of customization to best fit specific needs, optimizing out branching and unboxing from systems, etc.
  • Fast Compilation: plugins are incredibly fast, with zero-overhead for non-ecso projects.

Code example

import ecso.Entity;

typedef Position = {
    var x:Int;
    var y:Int;
}

typedef Velocity = {
    var vx:Int;
    var vy:Int;
}

function move (entity:Position & Velocity) {
    entity.x += entity.vx;
    entity.y += entity.vy;
}

function teleport (entity:Position, x:Int, y:Int) {
    entity.x = x;
    entity.y = y;
}

function main () {
    final entities = new EntityGroup();

    entities.createEntity({
        x: 10,
        y: 10,
        vx: 2,
        vy: 1
    });

    entities.foreachEntity( move ); // runs the system `move`.
    entities.foreachEntity( teleport.bind(_, 0, 0) ); // runs `teleport` with arguments.
    entities.foreachEntity( function (entity:{ y:Int, vy:Int }) { // runs an anonymous system.
        if (entity.y < 100)
            entity.vy -= 1;
    });
}

For more details about ecso please visit the wiki page.

How to install

Run haxelib install ecso and add --library ecso to your compilation flags.

To use ecso from source or use nightly builds, you can refer to the installation page.

Contribution

Any kind of contribution is welcome and appreciated. You can read more here. Thank you!