Skip to content

Commit

Permalink
Renderer consistency
Browse files Browse the repository at this point in the history
  • Loading branch information
spaaaacccee committed Oct 27, 2023
1 parent 1b53c4a commit 1a154f6
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
1 change: 1 addition & 0 deletions client/src/components/renderer/parser/parseTrace.worker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ function parse({
...context,
...ctx,
event,
events: trace?.events,
})
)
)
Expand Down
14 changes: 7 additions & 7 deletions internal-renderers/src/d2-renderer/D2RendererWorker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ export class D2RendererWorker extends EventEmitter<
return this.#count++;
}

#cache: { [K in string]: { key: string; tile: ImageBitmap } } = {};
#cache: { [K in string]: { hash: string; tile: ImageBitmap } } = {};

add(component: CompiledD2IntrinsicComponent[], id: string) {
const bodies = map(component, (c) => ({
Expand Down Expand Up @@ -215,10 +215,10 @@ export class D2RendererWorker extends EventEmitter<
}),
"index"
);
const newKey = hash(map(bodies, "index"));
const prevKey = hash([top, right, bottom, left]);
const oldTile = this.#cache[prevKey];
if (!oldTile || newKey !== oldTile.key) {
const nextHash = hash(map(bodies, "index"));
const tileKey = hash([top, right, bottom, left]);
const prevTile = this.#cache[tileKey];
if (!prevTile || nextHash !== prevTile.hash) {
const g = new OffscreenCanvas(tile.width, tile.height);
const ctx = g.getContext("2d")!;
ctx.imageSmoothingEnabled = false;
Expand Down Expand Up @@ -249,11 +249,11 @@ export class D2RendererWorker extends EventEmitter<
});
}
const bitmap = g.transferToImageBitmap();
this.#cache[tileKey] = { hash: nextHash, tile: bitmap };

this.#cache[prevKey] = { key: newKey, tile: bitmap };
return bitmap;
} else {
return oldTile.tile;
return prevTile.tile;
}
}
}

0 comments on commit 1a154f6

Please sign in to comment.