All Projects → deepcake → echo

deepcake / echo

Licence: MIT license
Super lightweight Entity Component System framework for Haxe

Programming Languages

haxe
709 projects

Projects that are alternatives of or similar to echo

gdk-for-unity-blank-project
SpatialOS GDK for Unity Blank Project
Stars: ✭ 33 (-19.51%)
Mutual labels:  ecs, entity-component-system
artemis-odb-entity-tracker
🎲 Visual Entity Tracker for ECS library: artemis-odb
Stars: ✭ 27 (-34.15%)
Mutual labels:  ecs, entity-component-system
Octopuskit
2D ECS game engine in 100% Swift + SwiftUI for iOS, macOS, tvOS
Stars: ✭ 246 (+500%)
Mutual labels:  ecs, entity-component-system
Awesome Entity Component System
😎 A curated list of Entity-Component-System (ECS) libraries and resources
Stars: ✭ 180 (+339.02%)
Mutual labels:  ecs, entity-component-system
imgui entt entity editor
A drop-in entity editor for EnTT with Dear ImGui
Stars: ✭ 146 (+256.1%)
Mutual labels:  ecs, entity-component-system
Egocs
EgoCS: An Entity (GameObject) Component System framework for Unity3D
Stars: ✭ 211 (+414.63%)
Mutual labels:  ecs, entity-component-system
ECS
Entity-Component-System
Stars: ✭ 122 (+197.56%)
Mutual labels:  ecs, entity-component-system
Pyro
A linear Entity Component System
Stars: ✭ 125 (+204.88%)
Mutual labels:  ecs, entity-component-system
rockgo
A developing game server framework,based on Entity Component System(ECS).
Stars: ✭ 617 (+1404.88%)
Mutual labels:  ecs, entity-component-system
TinyECS
Tiny ECS is an easy to use Entity-Component-System framework that's designed specially for Unity3D.
Stars: ✭ 20 (-51.22%)
Mutual labels:  ecs, entity-component-system
Uecs
Ubpa Entity-Component-System (U ECS) in Unity3D-style
Stars: ✭ 174 (+324.39%)
Mutual labels:  ecs, entity-component-system
Learning-Unity-ECS
A bunch of small Unity projects where I explore and learn Unity's new ECS and Job System.
Stars: ✭ 60 (+46.34%)
Mutual labels:  ecs, entity-component-system
Ape Ecs
Entity-Component-System library for JavaScript.
Stars: ✭ 137 (+234.15%)
Mutual labels:  ecs, entity-component-system
Entitas Cpp
Entitas++ is a fast Entity Component System (ECS) C++11 port of Entitas C#
Stars: ✭ 229 (+458.54%)
Mutual labels:  ecs, entity-component-system
Flecs
A fast entity component system (ECS) for C & C++
Stars: ✭ 2,201 (+5268.29%)
Mutual labels:  ecs, entity-component-system
SpaceWar-ECS
A space war game made with ECS and JobSystem in Unity.
Stars: ✭ 26 (-36.59%)
Mutual labels:  ecs, entity-component-system
Edyn
Edyn is a real-time physics engine organized as an ECS.
Stars: ✭ 113 (+175.61%)
Mutual labels:  ecs, entity-component-system
Gdk For Unity Fps Starter Project
SpatialOS GDK for Unity FPS Starter Project
Stars: ✭ 119 (+190.24%)
Mutual labels:  ecs, entity-component-system
ent-comp
A light, fast Entity Component System in JS
Stars: ✭ 25 (-39.02%)
Mutual labels:  ecs, entity-component-system
ecs
🐰 Entity Component System
Stars: ✭ 62 (+51.22%)
Mutual labels:  ecs, entity-component-system

Echo

TravisCI Build Status

Super lightweight Entity Component System framework for Haxe. Initially created to learn the power of macros. Focused to be simple and fast. Inspired by other haxe ECS frameworks, especially EDGE, ECX, ESKIMO and Ash-Haxe

Wip

Overview

  • Component is an instance of T:Any class. For each class T will be generated a global component container, where instance of T is a value and Entity is a key.
  • Entity in that case is just an abstract over the Int, but with the ability to work with it as with a set of components like in other regular ECS frameworks.
  • View<T1, T2, TN> is a collection of entities containing all components of the required types T1, T2, TN. Views are placed in Systems.
  • System is a place for processing a certain set of data represented by views.
  • To organize systems in phases can be used the SystemList.

Example

import echoes.SystemList;
import echoes.Workflow;
import echoes.Entity;

class Example {
  static function main() {
    var physics = new SystemList()
      .add(new Movement())
      .add(new CollisionResolver());

    Workflow.addSystem(physics);
    Workflow.addSystem(new Render()); // or just add systems directly

    var john = createRabbit(0, 0, 1, 1, 'John');
    var jack = createRabbit(5, 5, 1, 1, 'Jack');

    trace(jack.exists(Position)); // true
    trace(jack.get(Position).x); // 5
    jack.remove(Position); // oh no!
    jack.add(new Position(1, 1)); // okay

    // also somewhere should be Workflow.update call on every tick
    Workflow.update(1.0);
  }
  static function createTree(x:Float, y:Float) {
    return new Entity()
      .add(new Position(x, y))
      .add(new Sprite('assets/tree.png'));
  }
  static function createRabbit(x:Float, y:Float, vx:Float, vy:Float, name:Name) {
    var pos = new Position(x, y);
    var vel = new Velocity(vx, vy);
    var spr = new Sprite('assets/rabbit.png');
    return new Entity().add(pos, vel, spr, name);
  }
}

@:forward
abstract Name(String) from String to String {
  public function new(name:String) this = name;
}

class Movement extends echoes.System {
  // @update-functions will be called for every entity that contains all the defined components;
  // All args are interpreted as components, except Float (reserved for delta time) and Int/Entity;
  @update function updateBody(pos:Position, vel:Velocity, dt:Float, entity:Entity) {
    pos.x += vel.x * dt;
    pos.y += vel.y * dt;
  }
  // If @update-functions are defined without components, 
  // they are called only once per system's update;
  @update function traceHello(dt:Float) {
    trace('Hello!');
  }
  // The execution order of @update-functions is the same as the definition order, 
  // so you can perform some preparations before or after iterating over entities;
  @update function traceWorld() {
    trace('World!');
  }
}

class NamePrinter extends echoes.System {
  // All of necessary for meta-functions views will be defined and initialized under the hood, 
  // but it is also possible to define the View manually (initialization is still not required) 
  // for additional features such as counting and sorting entities;
  var named:View<Name>;

  @update function sortAndPrint() {
    named.entities.sort((e1, e2) -> e1.get(Name) < e2.get(Name) ? -1 : 1);
    // using Lambda
    named.entities.iter(e -> trace(e.get(Name)));
  }
}

class Render extends echoes.System {
  var scene:DisplayObjectContainer;
  // There are @a, @u and @r shortcuts for @added, @update and @removed metas;
  // @added/@removed-functions are callbacks that are called when an entity is added/removed from the view;
  @a function onEntityWithSpriteAndPositionAdded(spr:Sprite, pos:Position) {
    scene.addChild(spr);
  }
  // Even if callback was triggered by destroying the entity, 
  // @removed-function will be called before this happens, 
  // so access to the component will be still exists;
  @r function onEntityWithSpriteAndPositionRemoved(spr:Sprite, pos:Position, e:Entity) {
    scene.removeChild(spr); // spr is still not a null
    trace('Oh My God! They removed ${ e.exists(Name) ? e.get(Name) : "Unknown Sprite" }!');
  }
  @u inline function updateSpritePosition(spr:Sprite, pos:Position) {
    spr.x = pos.x;
    spr.y = pos.y;
  }
  @u inline function afterSpritePositionsUpdated() {
    // rendering, etc
  }
}

Live

Tiger on the Meadow! (source) - small example of using Echo framework

Also

There is also exists a few additional compiler flags:

  • -D echoes_profiling - collecting some more info in Workflow.info() method for debug purposes
  • -D echoes_report - traces a short report of built components and views
  • -D echoes_array_container - using Array instead IntMap for global component containers

Install

haxelib git echoes https://github.com/deepcake/echo.git

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].