Skip to content

Commit

Permalink
Added type and base to system trait
Browse files Browse the repository at this point in the history
allowing adding and removing systems
  • Loading branch information
Gamerfiend committed Apr 13, 2019
1 parent 575f6a9 commit 9a4c591
Showing 1 changed file with 30 additions and 13 deletions.
43 changes: 30 additions & 13 deletions src/ecs.kit
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,11 @@ trait Component {
}

trait System {
public function update(): Void;
public function update(delta: Float): Void;
function typeIdentifier(): CString;
public function base(): Ptr[Void]{
return &this;
}
}

struct Entity {
Expand Down Expand Up @@ -85,13 +89,13 @@ struct Entity {

struct Engine {
private var entities: Map[Int, Ptr[Entity]];
private var systems: Vector[Box[System]];
private var systems: Map[CString, Box[System]];
private var entitesToComponent: Map[CString, Set[Int]];
private var allocator: Box[Allocator];

public static function new(allocator: Box[Allocator]): Engine using implicit allocator {
var entities: Map[Int, Ptr[Entity]] = Map.new(10);
var systems: Vector[Box[System]] = Vector.new(10);
var systems: Map[CString, Box[System]] = Map.new(10);
var entitesToComponent: Map[CString, Set[Int]] = Map.new(10);

return struct Self {
Expand Down Expand Up @@ -157,19 +161,32 @@ struct Engine {
}
}

public function addSystem(system: Box[System]) {

}

public function removeSystem(system: Box[System]) {

public function addSystem(type: CString, system: Box[System]) {
if(!this.systems.exists(type)){
this.systems.put(type, system);
}
}

public function entitiesForComponent(type: CString): Array[Ptr[Entity]] {

public function removeSystem(type: CString, system: Box[System]) {
if(!this.systems.exists(type)){
this.systems.remove(type);
}
}

public function update() {

// set struct needs for loop
// public function entitiesForComponent(type: CString): Array[Ptr[Entity]] {
// if this.entitesToComponent.exists(type) {
// var entitySet = this.entitesToComponent.get(type).unwrap();
// var entityArray: Array[Ptr[Entity]] = Array.new(entitySet.length);
// for i in 1 ... entitySet.length {
// entityArray[i] = this.entites.get()
// }
// }
// }

public function update(delta: Float) {
for key in this.systems {
this.systems.get(key).unwrap().update(delta);
}
}
}

0 comments on commit 9a4c591

Please sign in to comment.