From 1a154f6abf246a051e75729ca552eeaac590902f Mon Sep 17 00:00:00 2001 From: Kevin Zheng Date: Sat, 28 Oct 2023 01:29:18 +1100 Subject: [PATCH] Renderer consistency --- .../renderer/parser/parseTrace.worker.ts | 1 + .../src/d2-renderer/D2RendererWorker.ts | 14 +++++++------- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/client/src/components/renderer/parser/parseTrace.worker.ts b/client/src/components/renderer/parser/parseTrace.worker.ts index 2741f95c..c7e789ef 100644 --- a/client/src/components/renderer/parser/parseTrace.worker.ts +++ b/client/src/components/renderer/parser/parseTrace.worker.ts @@ -46,6 +46,7 @@ function parse({ ...context, ...ctx, event, + events: trace?.events, }) ) ) diff --git a/internal-renderers/src/d2-renderer/D2RendererWorker.ts b/internal-renderers/src/d2-renderer/D2RendererWorker.ts index 338935f1..8ae4ffe1 100644 --- a/internal-renderers/src/d2-renderer/D2RendererWorker.ts +++ b/internal-renderers/src/d2-renderer/D2RendererWorker.ts @@ -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) => ({ @@ -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; @@ -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; } } }