From af7adda16154eba9e9d48a1f2d778f441461b673 Mon Sep 17 00:00:00 2001 From: ephphatha Date: Mon, 7 Jun 2021 00:41:11 +1000 Subject: [PATCH] Refactor GetLight/SetLight to take Points instead of x/y params Doing both functions at once as they are called from the same places with the same arguments. They also operate on char values internally but get treated as if they are ints, might be more appropriate to use int8_t/uint8_t? --- Source/lighting.cpp | 54 +++++++++++++++++++++------------------------ 1 file changed, 25 insertions(+), 29 deletions(-) diff --git a/Source/lighting.cpp b/Source/lighting.cpp index cae2324d5..0b0236835 100644 --- a/Source/lighting.cpp +++ b/Source/lighting.cpp @@ -475,20 +475,20 @@ void RotateRadius(int *x, int *y, int *dx, int *dy, int *lx, int *ly, int *bx, i } } -void SetLight(int x, int y, char v) +void SetLight(Point position, char v) { if (LoadingMapObjects) - dPreLight[x][y] = v; + dPreLight[position.x][position.y] = v; else - dLight[x][y] = v; + dLight[position.x][position.y] = v; } -char GetLight(int x, int y) +char GetLight(Point position) { if (LoadingMapObjects) - return dPreLight[x][y]; + return dPreLight[position.x][position.y]; - return dLight[x][y]; + return dLight[position.x][position.y]; } void DoLighting(Point position, int nRadius, int lnum) @@ -535,9 +535,9 @@ void DoLighting(Point position, int nRadius, int lnum) if (position.x >= 0 && position.x < MAXDUNX && position.y >= 0 && position.y < MAXDUNY) { if (currlevel < 17) { - SetLight(position.x, position.y, 0); - } else if (GetLight(position.x, position.y) > lightradius[nRadius][0]) { - SetLight(position.x, position.y, lightradius[nRadius][0]); + SetLight(position, 0); + } else if (GetLight(position) > lightradius[nRadius][0]) { + SetLight(position, lightradius[nRadius][0]); } } @@ -546,12 +546,11 @@ void DoLighting(Point position, int nRadius, int lnum) for (int x = 1; x < maxX; x++) { int radiusBlock = lightblock[mult][y][x]; if (radiusBlock < 128) { - int tempX = position.x + x; - int tempY = position.y + y; + Point temp = position + Displacement { x, y }; int8_t v = lightradius[nRadius][radiusBlock]; - if (tempX >= 0 && tempX < MAXDUNX && tempY >= 0 && tempY < MAXDUNY) - if (v < GetLight(tempX, tempY)) - SetLight(tempX, tempY, v); + if (temp.x >= 0 && temp.x < MAXDUNX && temp.y >= 0 && temp.y < MAXDUNY) + if (v < GetLight(temp)) + SetLight(temp, v); } } } @@ -561,12 +560,11 @@ void DoLighting(Point position, int nRadius, int lnum) for (int x = 1; x < maxX; x++) { int radiusBlock = lightblock[mult][y + blockY][x + blockX]; if (radiusBlock < 128) { - int tempX = position.x + y; - int tempY = position.y - x; + Point temp = position + Displacement { y, -x }; int8_t v = lightradius[nRadius][radiusBlock]; - if (tempX >= 0 && tempX < MAXDUNX && tempY >= 0 && tempY < MAXDUNY) - if (v < GetLight(tempX, tempY)) - SetLight(tempX, tempY, v); + if (temp.x >= 0 && temp.x < MAXDUNX && temp.y >= 0 && temp.y < MAXDUNY) + if (v < GetLight(temp)) + SetLight(temp, v); } } } @@ -576,12 +574,11 @@ void DoLighting(Point position, int nRadius, int lnum) for (int x = 1; x < minX; x++) { int radiusBlock = lightblock[mult][y + blockY][x + blockX]; if (radiusBlock < 128) { - int tempX = position.x - x; - int tempY = position.y - y; + Point temp = position - Displacement { x, y }; int8_t v = lightradius[nRadius][radiusBlock]; - if (tempX >= 0 && tempX < MAXDUNX && tempY >= 0 && tempY < MAXDUNY) - if (v < GetLight(tempX, tempY)) - SetLight(tempX, tempY, v); + if (temp.x >= 0 && temp.x < MAXDUNX && temp.y >= 0 && temp.y < MAXDUNY) + if (v < GetLight(temp)) + SetLight(temp, v); } } } @@ -591,12 +588,11 @@ void DoLighting(Point position, int nRadius, int lnum) for (int x = 1; x < minX; x++) { int radiusBlock = lightblock[mult][y + blockY][x + blockX]; if (radiusBlock < 128) { - int tempX = position.x - y; - int tempY = position.y + x; + Point temp = position + Displacement { -y, x }; int8_t v = lightradius[nRadius][radiusBlock]; - if (tempX >= 0 && tempX < MAXDUNX && tempY >= 0 && tempY < MAXDUNY) - if (v < GetLight(tempX, tempY)) - SetLight(tempX, tempY, v); + if (temp.x >= 0 && temp.x < MAXDUNX && temp.y >= 0 && temp.y < MAXDUNY) + if (v < GetLight(temp)) + SetLight(temp, v); } } }