From d87105baade79905929e2b5d06c10d4bf22e5e93 Mon Sep 17 00:00:00 2001 From: "Kacper Kostka (aider)" Date: Sat, 5 Apr 2025 15:45:13 +0200 Subject: [PATCH] feat: Ensure stone layer chunks always render and remain visible --- js/main.js | 9 +++++++++ js/render.js | 5 +++-- js/world.js | 9 +++++++-- 3 files changed, 19 insertions(+), 4 deletions(-) diff --git a/js/main.js b/js/main.js index dad3999..43865b0 100644 --- a/js/main.js +++ b/js/main.js @@ -78,6 +78,15 @@ function simulationLoop(timestamp) { // Update physics with timestamp for rate limiting updatePhysics(timestamp); + // Force stone layer chunks to be rendered every frame + const visibleChunks = getVisibleChunks(); + for (const { chunkX, chunkY, isVisible } of visibleChunks) { + if (isVisible && chunkY === 1) { + // Mark stone layer chunks as dirty to ensure they're always rendered + dirtyChunks.add(getChunkKey(chunkX, chunkY)); + } + } + // Render render(); diff --git a/js/render.js b/js/render.js index 1b5fcc3..935301b 100644 --- a/js/render.js +++ b/js/render.js @@ -13,8 +13,9 @@ function render() { const key = getChunkKey(chunkX, chunkY); - // Skip rendering if the chunk hasn't changed and isn't marked as dirty - if (!dirtyChunks.has(key) && !worldMoved) { + // Always render stone layer (chunkY = 1) chunks, even if they're not dirty + // For other chunks, only render if they're dirty or the world moved + if (chunkY !== 1 && !dirtyChunks.has(key) && !worldMoved) { continue; } diff --git a/js/world.js b/js/world.js index 92a1b76..9a30b8d 100644 --- a/js/world.js +++ b/js/world.js @@ -527,9 +527,14 @@ function generateChunksAroundPlayer() { const chunkY = 1; // The chunk at y = 1 (moved from y = -1) const key = getChunkKey(chunkX, chunkY); - // Always generate and mark as dirty to ensure rendering + // Always generate stone layer chunks getOrCreateChunk(chunkX, chunkY); - dirtyChunks.add(key); + + // Mark as dirty only if it's a new chunk or if it's visible + if (!chunks.has(key) || visibleChunks.some(chunk => + chunk.chunkX === chunkX && chunk.chunkY === chunkY && chunk.isVisible)) { + dirtyChunks.add(key); + } } // Generate visible chunks first