Limit sky transition buffer memory

This commit is contained in:
vini 2026-07-19 14:18:33 -03:00
parent 8c1389557b
commit c9aca2ed50

View file

@ -1590,13 +1590,14 @@ let lastProjMs = -Infinity;
function projectSky() {
const W = canvas.width, H = canvas.height;
if (!W || !H) return;
if (renderCanvas.width !== W || renderCanvas.height !== H) {
const horizonPx = H * HORIZON_F;
const bufferH = Math.ceil(Math.min(H, horizonPx * 1.05));
if (renderCanvas.width !== W || renderCanvas.height !== bufferH) {
renderCanvas.width = W;
renderCanvas.height = H;
renderCanvas.height = bufferH;
}
const bctx = renderCanvas.getContext('2d');
bctx.clearRect(0, 0, W, H);
const horizonPx = H * HORIZON_F;
bctx.clearRect(0, 0, W, bufferH);
const lst = localSiderealDeg(Date.now() + window.__skyTimeOffset);
const glareOn = !document.body.classList.contains('balada') &&
!document.body.classList.contains('chuva');
@ -1687,8 +1688,8 @@ function drawStars(ts) {
ctx.clearRect(0, 0, canvas.width, canvas.height);
const transition = Math.max(0, Math.min(1,
(ts - skyTransitionStart) / SKY_TRANSITION_MS));
if (transition < 1 && previousBaseCanvas.width === canvas.width &&
previousBaseCanvas.height === canvas.height) {
if (transition < 1 && previousBaseCanvas.width === baseCanvas.width &&
previousBaseCanvas.height === baseCanvas.height) {
const blend = transition * transition * (3 - 2 * transition);
ctx.globalAlpha = 1 - blend;
ctx.drawImage(previousBaseCanvas, 0, 0);