From 2afcd9e6541cc3fbfa33e2e528af3f58660d1679 Mon Sep 17 00:00:00 2001 From: Anders Jenbo Date: Thu, 20 Apr 2023 21:37:52 +0200 Subject: [PATCH] Cleanup generation of LightConeInterpolations --- Source/lighting.cpp | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/Source/lighting.cpp b/Source/lighting.cpp index 533f216a4..69137c9eb 100644 --- a/Source/lighting.cpp +++ b/Source/lighting.cpp @@ -65,7 +65,7 @@ const DisplacementOf VisionCrawlTable[23][15] = { uint8_t LightFalloffs[16][128]; bool dovision; /** interpolations of a 32x32 (16x16 mirrored) light circle moving between tiles in steps of 1/8 of a tile */ -uint8_t LightConeInterpolations[64][16][16]; +uint8_t LightConeInterpolations[8][8][16][16]; /** RadiusAdj maps from VisionCrawlTable index to lighting vision radius adjustment. */ const uint8_t RadiusAdj[23] = { 0, 0, 0, 0, 1, 1, 1, 2, 2, 2, 3, 4, 3, 2, 2, 2, 1, 1, 1, 0, 0, 0, 0 }; @@ -267,16 +267,15 @@ void DoLighting(Point position, int nRadius, int lnum) } for (int i = 0; i < 4; i++) { - int mult = xoff + 8 * yoff; int yBound = i > 0 && i < 3 ? maxY : minY; int xBound = i < 2 ? maxX : minX; for (int y = 0; y < yBound; y++) { for (int x = 1; x < xBound; x++) { - int radiusBlock = LightConeInterpolations[mult][y + blockY][x + blockX]; - if (radiusBlock >= 128) + int linearDistance = LightConeInterpolations[xoff][yoff][x + blockX][y + blockY]; + if (linearDistance >= 128) continue; Point temp = position + (Displacement { x, y }).Rotate(-i); - uint8_t v = LightFalloffs[nRadius][radiusBlock]; + uint8_t v = LightFalloffs[nRadius][linearDistance]; if (!InDungeonBounds(temp)) continue; if (v < GetLight(temp)) @@ -483,13 +482,15 @@ void MakeLightTable() } } } - for (int j = 0; j < 8; j++) { - for (int i = 0; i < 8; i++) { - for (int k = 0; k < 16; k++) { - for (int l = 0; l < 16; l++) { - int a = (8 * l - j); - int b = (8 * k - i); - LightConeInterpolations[j * 8 + i][k][l] = static_cast(sqrt(a * a + b * b)); + + // Generate the linght cone interpolations + for (int offsetY = 0; offsetY < 8; offsetY++) { + for (int offsetX = 0; offsetX < 8; offsetX++) { + for (int y = 0; y < 16; y++) { + for (int x = 0; x < 16; x++) { + int a = (8 * x - offsetY); + int b = (8 * y - offsetX); + LightConeInterpolations[offsetX][offsetY][x][y] = static_cast(sqrt(a * a + b * b)); } } }