summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authortomsmeding <tom.smeding@gmail.com>2018-02-22 21:04:04 +0100
committertomsmeding <tom.smeding@gmail.com>2018-02-22 21:04:04 +0100
commit24b57ecbe4e5d9e9d9b01ad6399c18625d8d03b6 (patch)
tree225f2a43d23f21db4a8af707fe6d1001cd866cde
parentb1b3cf82c0d0ccd6429145334c964e336858274a (diff)
Add canvas draw cacheHEADmaster
-rw-r--r--index.html12
1 files changed, 12 insertions, 0 deletions
diff --git a/index.html b/index.html
index 405e6f8..a2223dc 100644
--- a/index.html
+++ b/index.html
@@ -120,6 +120,9 @@ function boardY(idx){
return (~~(idx/currentGame.size)+0.5)*CELL_WID;
}
+var _redrawBoard_cache_board=null;
+var _redrawBoard_cache_canvas=null;
+
function redrawBoard(){
if(currentGame==null){
interfaceSwitch("connect");
@@ -127,6 +130,12 @@ function redrawBoard(){
}
var G=currentGame;
+ var GboardJSON=JSON.stringify(G.board);
+
+ if(_redrawBoard_cache_board&&GboardJSON==_redrawBoard_cache_board){
+ ctx.putImageData(_redrawBoard_cache_canvas,0,0);
+ return;
+ }
var bsz=G.size*CELL_WID;
if(cvs.width!=bsz||cvs.height!=bsz){cvs.width=bsz; cvs.height=bsz;}
@@ -164,6 +173,9 @@ function redrawBoard(){
ctx.arc(boardX(i),boardY(i),STONE_SIZE,0,2*Math.PI,true);
ctx.fill();
}
+
+ _redrawBoard_cache_board=GboardJSON;
+ _redrawBoard_cache_canvas=ctx.getImageData(0,0,cvs.width,cvs.height);
}
function interfaceGameState(state){