Skip to content

Commit

Permalink
feat: Optimize testing canvas performance for frequent image data reads
Browse files Browse the repository at this point in the history
Added the `willReadFrequently` option to the canvas context to enhance performance for frequent `getImageData` operations. This change helps reduce memory overhead and improve the speed of pixel data access, particularly useful in scenarios involving intensive image processing or frequent canvas updates.
  • Loading branch information
TKanX committed Aug 21, 2024
1 parent 2a0e0f0 commit 84d0ee9
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion public/js/game.js
Original file line number Diff line number Diff line change
Expand Up @@ -705,6 +705,7 @@ class GameRenderer {
/**
* Handle click event. (Private)
* @param {Event} event - The click event.
* @returns {number} The clicked piece index.
*/
_handleClick(event) {
const rect = this.canvas.getBoundingClientRect();
Expand All @@ -714,7 +715,9 @@ class GameRenderer {
const testingCanvas = document.createElement("canvas");
testingCanvas.width = this.canvas.width;
testingCanvas.height = this.canvas.height;
const testingCtx = testingCanvas.getContext("2d");
const testingCtx = testingCanvas.getContext("2d", {
willReadFrequently: true,
});

this.map.tiles.forEach((tile, index) => {
const tileImage = tile.flipped
Expand Down

0 comments on commit 84d0ee9

Please sign in to comment.