mirror of
https://github.com/sehugg/8bitworkshop.git
synced 2024-05-28 23:41:32 +00:00
ecs: only register events when used in a system instance
This commit is contained in:
parent
30db34837c
commit
d87a05747e
|
@ -1117,6 +1117,7 @@ export class EntityScope implements SourceLocated {
|
||||||
if (!inst) throw new Error();
|
if (!inst) throw new Error();
|
||||||
inst.id = this.instances.length+1;
|
inst.id = this.instances.length+1;
|
||||||
this.instances.push(inst);
|
this.instances.push(inst);
|
||||||
|
this.em.registerSystemEvents(inst.system);
|
||||||
return inst;
|
return inst;
|
||||||
}
|
}
|
||||||
newSystemInstanceWithDefaults(system: System) {
|
newSystemInstanceWithDefaults(system: System) {
|
||||||
|
@ -1649,13 +1650,15 @@ export class EntityManager {
|
||||||
defineSystem(system: System) {
|
defineSystem(system: System) {
|
||||||
let existing = this.systems[system.name];
|
let existing = this.systems[system.name];
|
||||||
if (existing) throw new ECSError(`system ${system.name} already defined`, existing);
|
if (existing) throw new ECSError(`system ${system.name} already defined`, existing);
|
||||||
|
return this.systems[system.name] = system;
|
||||||
|
}
|
||||||
|
registerSystemEvents(system: System) {
|
||||||
for (let a of system.actions) {
|
for (let a of system.actions) {
|
||||||
let event = a.event;
|
let event = a.event;
|
||||||
let list = this.event2systems[event];
|
let list = this.event2systems[event];
|
||||||
if (list == null) list = this.event2systems[event] = [];
|
if (list == null) list = this.event2systems[event] = [];
|
||||||
if (!list.includes(system)) list.push(system);
|
if (!list.includes(system)) list.push(system);
|
||||||
}
|
}
|
||||||
return this.systems[system.name] = system;
|
|
||||||
}
|
}
|
||||||
addArchetype(atype: EntityArchetype): EntityArchetype {
|
addArchetype(atype: EntityArchetype): EntityArchetype {
|
||||||
let key = atype.components.map(c => c.name).join(',');
|
let key = atype.components.map(c => c.name).join(',');
|
||||||
|
|
Loading…
Reference in New Issue
Block a user