refactor: immutable optimizations

This commit is contained in:
cha0s 2019-04-12 13:18:34 -05:00
parent bf18ae019a
commit 400b2ebb7d
4 changed files with 30 additions and 12 deletions

View File

@ -97,10 +97,12 @@ export class EntityList extends decorate(Synchronized) {
const entity = this._entities[uuid];
entity.tick(elapsed);
}
for (const uuid in this._entities) {
const entity = this._entities[uuid];
this.state = this.state.set(uuid, entity.state);
}
this.state = this.state.withMutations((state) => {
for (const uuid in this._entities) {
const entity = this._entities[uuid];
state.set(uuid, entity.state);
}
});
}
visibleEntities(query) {

View File

@ -56,16 +56,22 @@ export class Synchronized extends decorate(class {}) {
}
tick(elapsed) {
for (const key of this.synchronizedChildren()) {
const children = this.synchronizedChildren();
for (const key of children) {
if (this[key] instanceof Synchronized) {
this[key].tick(elapsed);
this.state = this.state.set(key, this[key].state);
}
else {
this.state = this.state.set(key, this[key]);
}
}
this.state = this.state.withMutations((state) => {
for (const key of children) {
if (this[key] instanceof Synchronized) {
state.set(key, this[key].state);
}
else {
state.set(key, this[key]);
}
}
});
}
}

View File

@ -36,8 +36,13 @@ export class Synchronizer {
for (const key in this._statefuls) {
const stateful = this._statefuls[key];
stateful.tick(elapsed);
this._state = this._state.set(key, stateful.state);
}
this._state = this._state.withMutations((state) => {
for (const key in this._statefuls) {
const stateful = this._statefuls[key];
state.set(key, stateful.state);
}
});
}
}

View File

@ -115,8 +115,13 @@ export class Layers extends decorate(Synchronized) {
for (const index in this.layers) {
const layer = this.layers[index];
layer.tick(elapsed);
this.state = this.state.set(index, layer.state);
}
this.state = this.state.withMutations((state) => {
for (const index in this.layers) {
const layer = this.layers[index];
state.set(index, layer.state);
}
});
}
}