Skip to content

Commit

Permalink
now using BaseSystems onCreate and onDestroy
Browse files Browse the repository at this point in the history
  • Loading branch information
Yoieh committed Nov 28, 2021
1 parent b4df273 commit 02cf765
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions src/engine/Engine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,16 @@ import { EntityManager } from '../ecs/EntityManager';
import { Signal } from '@yoieh/signal';

export class Engine implements IUpdate {
private stopUpdate = false;

public onSystemAdded = new Signal();

public onSystemRemoved = new Signal();

private _lastDeltaTime = 0;

public get lastDeltaTime() {
return this._lastDeltaTime;
}

private static _instance: Engine;
public static get instance(): Engine {
if (!Engine._instance) {
Expand All @@ -29,16 +33,20 @@ export class Engine implements IUpdate {
system.onUpdate(deltaTime);
}
}

this._lastDeltaTime = deltaTime;
}

public registerSystem(system: BaseSystem): void {
system.onCreate(this._lastDeltaTime);
this.systems.push(system);
this.onSystemAdded.dispatch(system);
}

public unregisterSystem(system: BaseSystem): void {
this.systems = this.systems.filter((s) => s !== system);
this.onSystemRemoved.dispatch(system);
system.onDestroy(this._lastDeltaTime);
}
}

Expand Down

0 comments on commit 02cf765

Please sign in to comment.