From ae09618c04b9ecd0dbc4df5c9d801fa84f8ff468 Mon Sep 17 00:00:00 2001 From: Nixinova Date: Sun, 21 Jul 2024 23:17:37 +1200 Subject: [PATCH] Refactor texel generator code --- src/com/nixinova/graphics/BlocksRenderer.java | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/src/com/nixinova/graphics/BlocksRenderer.java b/src/com/nixinova/graphics/BlocksRenderer.java index a410fd0..a5b3f39 100644 --- a/src/com/nixinova/graphics/BlocksRenderer.java +++ b/src/com/nixinova/graphics/BlocksRenderer.java @@ -130,17 +130,14 @@ private void generateRenderedTexel(int pixel, PxCoord screenPos, BlockCoord bloc int startY = (int) screenPos.y; double zIndex = screenPos.z; - for (int x = 0; x < TEXEL_SIZE; x++) { - for (int y = 0; y < TEXEL_SIZE; y++) { - int screenX = startX + x - Texture.SIZE; - int screenY = startY + y - Texture.SIZE; - - // Ensure pixel is within screen bounds - if (isValidPosition(screenX, screenY)) { - int brightAmount = (int) (Options.gamma * 10 * (Options.renderDistance - zIndex / 10)); - int fogAppliedPixel = applyFog(pixel, brightAmount); - this.savePixel(screenX, screenY, fogAppliedPixel, zIndex); - } + // Apply fog to pixel + int brightAmount = (int) (Options.gamma * 10 * (Options.renderDistance - zIndex / 10)); + int fogAppliedPixel = applyFog(pixel, brightAmount); + + // Generate texel of given size and save o screen image + for (int x = startX; x < startX + TEXEL_SIZE && x < super.width; x++) { + for (int y = startY; y < startY + TEXEL_SIZE && y < super.height; y++) { + this.savePixel(x, y, fogAppliedPixel, zIndex); } } }