clay

Entity-Component-System
https://github.com/RudenkoArts/clay

To install, run:

haxelib install clay 0.0.4 

See using Haxelib in Haxelib documentation for more information.

README.md

Clay

Entity-Component-System in haxe.

Usage

import clay.Entity;
import clay.Components;
import clay.Family;
import clay.Processor;
import clay.core.EntityManager;
import clay.core.FamilyManager;
import clay.core.ProcessorManager;
import clay.core.ComponentManager;


class ComponentA {

	public var string : String;

	public function new( _string:String ) : Void {
		string = _string;
	}

}

class ComponentB {

	public var int : Int;

	public function new( _int:Int ) : Void {
		int = _int;
	}

}

class ProcessorA extends Processor {


	var ab_family:Family;
	var a_comps:Components<ComponentA>;
	var b_comps:Components<ComponentB>;


	public function new() {

		super();

	}

	override function onadded() {

		a_comps = components.get_table(ComponentA);
		b_comps = components.get_table(ComponentB);

		ab_family = families.get('ab_family');

		ab_family.onadded.add(_entity_added);
		ab_family.onremoved.add(_entity_removed);

	}

	override function onremoved() {

		ab_family.onadded.remove(_entity_added);
		ab_family.onremoved.remove(_entity_removed);
		
	}

	override function update(dt:Float) {

		for (e in ab_family) {
			var a = a_comps.get(e);
			var b = b_comps.get(e);
			trace(a.string);
			trace(b.int);
		}

	}

	function _entity_added(e:Entity) {
		
		trace('entity: $e added');

	}
	
	function _entity_removed(e:Entity) {

		trace('entity: $e removed');

	}

}

class Main {

	static function main():Void {

		var entities = new EntityManager(16384);
		var components = new ComponentManager(entities);
		var families = new FamilyManager(components);
		var processors = new ProcessorManager(entities, components, families);

		families.create('ab_family', [ComponentA, ComponentB]);
		processors.add(new ProcessorA());

		var e1 = entities.create();
		var e2 = entities.create();
		components.set_many(e1, [new ComponentA('some_string'), new ComponentB(112358)]);
		components.set_many(e2, [new ComponentA('other_string'), new ComponentB(1618)]);

		processors.update(1/60);

	}

}

Contributors
RudenkoArts
Version
0.0.4
Published
7 years ago
License
MIT

All libraries are free

Every month, more than a thousand developers use Haxelib to find, share, and reuse code — and assemble it in powerful new ways. Enjoy Haxe; It is great!

Explore Haxe

Haxe Manual

Haxe Code Cookbook

Haxe API documentation

You can try Haxe in the browser! try.haxe.org

Join us on GitHub!

Haxe is being developed on GitHub. Feel free to contribute or report issues to our projects.

Haxe on GitHub