From 4256a254fa48abc18fced5ef37dc2211e1986670 Mon Sep 17 00:00:00 2001 From: HF Date: Sat, 24 Jul 2021 10:22:33 +0200 Subject: [PATCH] make offscreen canvas smaller --- src/ui/Renderer2D.js | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/src/ui/Renderer2D.js b/src/ui/Renderer2D.js index 0b69118..bcfe375 100644 --- a/src/ui/Renderer2D.js +++ b/src/ui/Renderer2D.js @@ -6,7 +6,7 @@ import type { Cell } from '../core/Cell'; import type { State } from '../reducers'; -import { TILE_SIZE } from '../core/constants'; +import { TILE_ZOOM_LEVEL, TILE_SIZE } from '../core/constants'; import { getTileOfPixel, @@ -26,8 +26,8 @@ import ChunkLoader from './ChunkLoader2D'; import pixelNotify from './PixelNotify'; // dimensions of offscreen canvas NOT whole canvas -const CANVAS_WIDTH = window.screen.width * 2; -const CANVAS_HEIGHT = window.screen.height * 2; +const CANVAS_WIDTH = window.screen.width + TILE_ZOOM_LEVEL * TILE_SIZE; +const CANVAS_HEIGHT = window.screen.height + TILE_ZOOM_LEVEL * TILE_SIZE; const SCALE_THREASHOLD = Math.min( CANVAS_WIDTH / TILE_SIZE / 3, CANVAS_HEIGHT / TILE_SIZE / 3, @@ -185,12 +185,13 @@ class Renderer { pixelNotify.updateScale(viewscale); let tiledScale = (viewscale > 0.5) ? 0 - : Math.round(Math.log2(viewscale) / 2); - tiledScale = 4 ** tiledScale; + : Math.round(Math.log2(viewscale) * 2 / TILE_ZOOM_LEVEL); + tiledScale = TILE_ZOOM_LEVEL ** tiledScale; const canvasMaxTiledZoom = (isHistoricalView) ? this.historicalCanvasMaxTiledZoom : this.canvasMaxTiledZoom; - const tiledZoom = canvasMaxTiledZoom + Math.log2(tiledScale) / 2; + const tiledZoom = canvasMaxTiledZoom + Math.log2(tiledScale) + * 2 / TILE_ZOOM_LEVEL; const relScale = viewscale / tiledScale; this.tiledScale = tiledScale;