Skip to content

Commit

Permalink
Remove optimization for checking children changed
Browse files Browse the repository at this point in the history
  • Loading branch information
hubol committed Jan 6, 2024
1 parent 2595d78 commit ca62d4e
Showing 1 changed file with 7 additions and 25 deletions.
32 changes: 7 additions & 25 deletions src/lib/game-engine/debug/debug-panel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,12 +127,12 @@ class DisplayObjectComponent {
return el;
}

private readonly _objectsDisplayed = new Set<DisplayObject>();

static i = 0;

update() {DisplayObjectComponent.i += 1;
console.time('update' + DisplayObjectComponent.i);
update() {
DisplayObjectComponent.i += 1;
const key = 'update' + DisplayObjectComponent.i;
console.time(key);

const color = getTintCssColor(this.obj);
this._colorEl.classList[color ? 'remove' : 'add']('hidden');
Expand All @@ -143,42 +143,24 @@ class DisplayObjectComponent {

this._childrenEl.classList[this.expanded ? 'remove' : 'add']('hidden');

if (this.expanded && childrenHaveChanged(this.obj, this._objectsDisplayed)) {
console.timeLog('update' + DisplayObjectComponent.i, 'childrenHaveChanged');
this._objectsDisplayed.clear();
if (this.expanded) {
console.timeLog(key, 'childrenHaveChanged');

while (this._childrenEl.firstChild) {
this._childrenEl.removeChild(this._childrenEl.firstChild);
}

for (let i = 0; i < this.obj.children!.length; i++) {
const child = this.obj.children![i] as DisplayObject;
this._objectsDisplayed.add(child);
const component = displayObjects.get(child) ?? new DisplayObjectComponent(child, this.index + 1);
this._childrenEl.appendChild(component.el);
}
}

console.timeEnd('update' + DisplayObjectComponent.i);
console.timeEnd(key);
}
}

function childrenHaveChanged(obj: DisplayObject, objectsDisplayed: Set<DisplayObject>) {
if (!obj.children)
return false;

if (objectsDisplayed.size !== obj.children.length)
return true;

for (let i = 0; i < obj.children.length; i++) {
const child = obj.children[i] as DisplayObject;
if (!objectsDisplayed.has(child))
return true;
}

return false;
}

function getType(obj: DisplayObject) {
return constructorName.get(obj.constructor) ?? obj.constructor.name;
}
Expand Down

0 comments on commit ca62d4e

Please sign in to comment.