From dce78dde622a58fafdb2d8c2cb6770fa942ba8d5 Mon Sep 17 00:00:00 2001 From: Anders Jenbo Date: Wed, 7 Jul 2021 01:58:17 +0200 Subject: [PATCH] Rename lighting globals --- Source/control.cpp | 2 +- Source/diablo.cpp | 2 +- Source/drlg_l1.cpp | 2 +- Source/engine/render/cel_render.cpp | 12 +- Source/engine/render/cl2_render.cpp | 4 +- Source/engine/render/common_impl.h | 2 +- Source/engine/render/dun_render.cpp | 14 +- Source/engine/render/text_render.cpp | 2 +- Source/gmenu.cpp | 2 +- Source/inv.cpp | 2 +- Source/lighting.cpp | 232 +++++++++++++-------------- Source/lighting.h | 24 +-- Source/loadsave.cpp | 36 ++--- Source/missiles.cpp | 6 +- Source/monster.cpp | 4 +- Source/objects.cpp | 2 +- Source/player.cpp | 2 +- Source/scrollrt.cpp | 24 +-- Source/scrollrt.h | 2 +- test/drlg_l1_test.cpp | 4 +- 20 files changed, 190 insertions(+), 190 deletions(-) diff --git a/Source/control.cpp b/Source/control.cpp index c2f0cbe0b..b8996a7bf 100644 --- a/Source/control.cpp +++ b/Source/control.cpp @@ -1533,7 +1533,7 @@ void DrawDurIcon(const Surface &out) void RedBack(const Surface &out) { uint8_t *dst = out.begin(); - uint8_t *tbl = &pLightTbl[4608]; + uint8_t *tbl = &LightTables[4608]; for (int h = gnViewportHeight; h != 0; h--, dst += out.pitch() - gnScreenWidth) { for (int w = gnScreenWidth; w != 0; w--) { if (leveltype != DTYPE_HELL || *dst >= 32) diff --git a/Source/diablo.cpp b/Source/diablo.cpp index 91b3653ae..eddccc3c4 100644 --- a/Source/diablo.cpp +++ b/Source/diablo.cpp @@ -1458,7 +1458,7 @@ static void UpdateMonsterLights() continue; } - LightListStruct *lid = &LightList[mon->mlid]; + LightStruct *lid = &Lights[mon->mlid]; if (mon->position.tile != lid->position.tile) { ChangeLightXY(mon->mlid, mon->position.tile); } diff --git a/Source/drlg_l1.cpp b/Source/drlg_l1.cpp index cbc3adb26..7ef6880bf 100644 --- a/Source/drlg_l1.cpp +++ b/Source/drlg_l1.cpp @@ -964,7 +964,7 @@ void DRLG_Init_Globals() memset(dItem, 0, sizeof(dItem)); memset(dMissile, 0, sizeof(dMissile)); memset(dSpecial, 0, sizeof(dSpecial)); - int8_t c = lightflag ? 0 : 15; + int8_t c = DisableLighting ? 0 : 15; memset(dLight, c, sizeof(dLight)); } diff --git a/Source/engine/render/cel_render.cpp b/Source/engine/render/cel_render.cpp index 1b35b0911..f39344d34 100644 --- a/Source/engine/render/cel_render.cpp +++ b/Source/engine/render/cel_render.cpp @@ -547,7 +547,7 @@ void CelBlitSafeTo(const Surface &out, Point position, const byte *pRLEBytes, in void CelBlitLightTransSafeTo(const Surface &out, Point position, const byte *pRLEBytes, int nDataSize, int nWidth) { assert(pRLEBytes != nullptr); - const std::uint8_t *tbl = &pLightTbl[light_table_index * 256]; + const std::uint8_t *tbl = &LightTables[LightTableIndex * 256]; bool shift = (reinterpret_cast(&out[position]) % 2 == 1); const bool pitchIsEven = (out.pitch() % 2 == 0); RenderCel( @@ -575,7 +575,7 @@ void CelBlitLightBlendedSafeTo(const Surface &out, Point position, const byte *p { assert(pRLEBytes != nullptr); if (tbl == nullptr) - tbl = &pLightTbl[light_table_index * 256]; + tbl = &LightTables[LightTableIndex * 256]; RenderCel( out, position, pRLEBytes, nDataSize, nWidth, [tbl](std::uint8_t *dst, const uint8_t *src, std::size_t w) { @@ -599,7 +599,7 @@ void CelBlitLightSafeTo(const Surface &out, Point position, const byte *pRLEByte { assert(pRLEBytes != nullptr); if (tbl == nullptr) - tbl = &pLightTbl[light_table_index * 256]; + tbl = &LightTables[LightTableIndex * 256]; RenderCelWithLightTable(out, position, pRLEBytes, nDataSize, nWidth, tbl); } @@ -625,7 +625,7 @@ void CelDrawLightTo(const Surface &out, Point position, const CelSprite &cel, in int nDataSize; const auto *pRLEBytes = CelGetFrame(cel.Data(), frame, &nDataSize); - if (light_table_index != 0 || tbl != nullptr) + if (LightTableIndex != 0 || tbl != nullptr) CelBlitLightSafeTo(out, position, pRLEBytes, nDataSize, cel.Width(frame), tbl); else CelBlitSafeTo(out, position, pRLEBytes, nDataSize, cel.Width(frame)); @@ -636,7 +636,7 @@ void CelClippedDrawLightTo(const Surface &out, Point position, const CelSprite & int nDataSize; const auto *pRLEBytes = CelGetFrameClipped(cel.Data(), frame, &nDataSize); - if (light_table_index != 0) + if (LightTableIndex != 0) CelBlitLightSafeTo(out, position, pRLEBytes, nDataSize, cel.Width(frame), nullptr); else CelBlitSafeTo(out, position, pRLEBytes, nDataSize, cel.Width(frame)); @@ -676,7 +676,7 @@ void CelClippedBlitLightTransTo(const Surface &out, Point position, const CelSpr CelBlitLightBlendedSafeTo(out, position, pRLEBytes, nDataSize, cel.Width(frame), nullptr); else CelBlitLightTransSafeTo(out, position, pRLEBytes, nDataSize, cel.Width(frame)); - } else if (light_table_index != 0) + } else if (LightTableIndex != 0) CelBlitLightSafeTo(out, position, pRLEBytes, nDataSize, cel.Width(frame), nullptr); else CelBlitSafeTo(out, position, pRLEBytes, nDataSize, cel.Width(frame)); diff --git a/Source/engine/render/cl2_render.cpp b/Source/engine/render/cl2_render.cpp index 229b497f9..17a78e971 100644 --- a/Source/engine/render/cl2_render.cpp +++ b/Source/engine/render/cl2_render.cpp @@ -799,8 +799,8 @@ void Cl2DrawLight(const Surface &out, int sx, int sy, const CelSprite &cel, int int nDataSize; const byte *pRLEBytes = CelGetFrameClipped(cel.Data(), frame, &nDataSize); - if (light_table_index != 0) - Cl2BlitLightSafe(out, sx, sy, pRLEBytes, nDataSize, cel.Width(frame), &pLightTbl[light_table_index * 256]); + if (LightTableIndex != 0) + Cl2BlitLightSafe(out, sx, sy, pRLEBytes, nDataSize, cel.Width(frame), &LightTables[LightTableIndex * 256]); else Cl2BlitSafe(out, sx, sy, pRLEBytes, nDataSize, cel.Width(frame)); } diff --git a/Source/engine/render/common_impl.h b/Source/engine/render/common_impl.h index a782ff29b..8b5763efe 100644 --- a/Source/engine/render/common_impl.h +++ b/Source/engine/render/common_impl.h @@ -20,7 +20,7 @@ inline std::uint8_t *GetLightTable(char light) idx += 256; // gray colors if (light >= 4) idx += (light - 1) << 8; - return &pLightTbl[idx]; + return &LightTables[idx]; } struct ClipX { diff --git a/Source/engine/render/dun_render.cpp b/Source/engine/render/dun_render.cpp index bec17b632..8a0954b05 100644 --- a/Source/engine/render/dun_render.cpp +++ b/Source/engine/render/dun_render.cpp @@ -1396,16 +1396,16 @@ void RenderTile(const Surface &out, int x, int y) if (clip.width <= 0 || clip.height <= 0) return; - const std::uint8_t *tbl = &pLightTbl[256 * light_table_index]; + const std::uint8_t *tbl = &LightTables[256 * LightTableIndex]; const auto *pFrameTable = reinterpret_cast(pDungeonCels.get()); const auto *src = reinterpret_cast(&pDungeonCels[SDL_SwapLE32(pFrameTable[level_cel_block & 0xFFF])]); std::uint8_t *dst = out.at(static_cast(x + clip.left), static_cast(y - clip.bottom)); const auto dstPitch = out.pitch(); if (mask == &SolidMask[TILE_HEIGHT - 1]) { - if (light_table_index == lightmax) { + if (LightTableIndex == LightsMax) { RenderTileType(tile, dst, dstPitch, src, mask, tbl, clip); - } else if (light_table_index == 0) { + } else if (LightTableIndex == 0) { RenderTileType(tile, dst, dstPitch, src, mask, tbl, clip); } else { RenderTileType(tile, dst, dstPitch, src, mask, tbl, clip); @@ -1413,17 +1413,17 @@ void RenderTile(const Surface &out, int x, int y) } else { mask -= clip.bottom; if (sgOptions.Graphics.bBlendedTransparancy) { - if (light_table_index == lightmax) { + if (LightTableIndex == LightsMax) { RenderTileType(tile, dst, dstPitch, src, mask, tbl, clip); - } else if (light_table_index == 0) { + } else if (LightTableIndex == 0) { RenderTileType(tile, dst, dstPitch, src, mask, tbl, clip); } else { RenderTileType(tile, dst, dstPitch, src, mask, tbl, clip); } } else { - if (light_table_index == lightmax) { + if (LightTableIndex == LightsMax) { RenderTileType(tile, dst, dstPitch, src, mask, tbl, clip); - } else if (light_table_index == 0) { + } else if (LightTableIndex == 0) { RenderTileType(tile, dst, dstPitch, src, mask, tbl, clip); } else { RenderTileType(tile, dst, dstPitch, src, mask, tbl, clip); diff --git a/Source/engine/render/text_render.cpp b/Source/engine/render/text_render.cpp index aebbfe916..c5a15bc94 100644 --- a/Source/engine/render/text_render.cpp +++ b/Source/engine/render/text_render.cpp @@ -153,7 +153,7 @@ void DrawChar(const Surface &out, Point position, GameFontTables size, int nCel, CelDrawLightTo(out, position, *fonts[size], nCel, fontColorTableGold); break; case ColorBlack: - light_table_index = 15; + LightTableIndex = 15; CelDrawLightTo(out, position, *fonts[size], nCel, nullptr); return; } diff --git a/Source/gmenu.cpp b/Source/gmenu.cpp index 6eaa6777f..1030c2255 100644 --- a/Source/gmenu.cpp +++ b/Source/gmenu.cpp @@ -39,7 +39,7 @@ void gmenu_draw_pause(const Surface &out) if (currlevel != 0) RedBack(out); if (sgpCurrentMenu == nullptr) { - light_table_index = 0; + LightTableIndex = 0; DrawString(out, _("Pause"), Point { 0, PANEL_TOP / 2 }, UIS_HUGE | UIS_CENTER, 2); } } diff --git a/Source/inv.cpp b/Source/inv.cpp index f5b13b5cd..33725f49e 100644 --- a/Source/inv.cpp +++ b/Source/inv.cpp @@ -247,7 +247,7 @@ void DrawInv(const Surface &out) || (myPlayer.InvBody[slot]._itype != ITYPE_SWORD && myPlayer.InvBody[slot]._itype != ITYPE_MACE)) { InvDrawSlotBack(out, { RIGHT_PANEL_X + slotPos[INVLOC_HAND_RIGHT].x, slotPos[INVLOC_HAND_RIGHT].y }, { slotSize[INVLOC_HAND_RIGHT].width * InventorySlotSizeInPixels.width, slotSize[INVLOC_HAND_RIGHT].height * InventorySlotSizeInPixels.height }); - light_table_index = 0; + LightTableIndex = 0; cel_transparency_active = true; const int dstX = RIGHT_PANEL_X + slotPos[INVLOC_HAND_RIGHT].x + (frameSize.width == InventorySlotSizeInPixels.width ? INV_SLOT_HALF_SIZE_PX : 0) - 1; diff --git a/Source/lighting.cpp b/Source/lighting.cpp index 40b0aa473..eb02e3d93 100644 --- a/Source/lighting.cpp +++ b/Source/lighting.cpp @@ -12,19 +12,19 @@ namespace devilution { -LightListStruct VisionList[MAXVISION]; -uint8_t lightactive[MAXLIGHTS]; -LightListStruct LightList[MAXLIGHTS]; -int numlights; +LightStruct VisionList[MAXVISION]; +uint8_t ActiveLights[MAXLIGHTS]; +LightStruct Lights[MAXLIGHTS]; +int ActiveLightCount; uint8_t lightradius[16][128]; bool dovision; -int numvision; -char lightmax; -bool dolighting; +int VisionCount; +char LightsMax; +bool UpdateLighting; uint8_t lightblock[64][16][16]; -int visionid; -std::array pLightTbl; -bool lightflag; +int VisionId; +std::array LightTables; +bool DisableLighting; /** * CrawlTable specifies X- and Y-coordinate deltas from a missile target coordinate. @@ -416,10 +416,10 @@ const char CrawlTable[2749] = { }; /* - * vCrawlTable specifies the X- Y-coordinate offsets of lighting visions. + * VisionCrawlTable specifies the X- Y-coordinate offsets of lighting visions. * The last entry-pair is only for alignment. */ -const BYTE vCrawlTable[23][30] = { +const BYTE VisionCrawlTable[23][30] = { // clang-format off { 1, 0, 2, 0, 3, 0, 4, 0, 5, 0, 6, 0, 7, 0, 8, 0, 9, 0, 10, 0, 11, 0, 12, 0, 13, 0, 14, 0, 15, 0 }, { 1, 0, 2, 0, 3, 0, 4, 0, 5, 0, 6, 0, 7, 0, 8, 1, 9, 1, 10, 1, 11, 1, 12, 1, 13, 1, 14, 1, 15, 1 }, @@ -447,7 +447,7 @@ const BYTE vCrawlTable[23][30] = { // clang-format on }; -/** RadiusAdj maps from vCrawlTable index to lighting vision radius adjustment. */ +/** RadiusAdj maps from VisionCrawlTable index to lighting vision radius adjustment. */ const BYTE 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 }; void RotateRadius(int *x, int *y, int *dx, int *dy, int *lx, int *ly, int *bx, int *by) @@ -501,8 +501,8 @@ void DoLighting(Point position, int nRadius, int lnum) int blockY = 0; if (lnum >= 0) { - xoff = LightList[lnum].position.offset.x; - yoff = LightList[lnum].position.offset.y; + xoff = Lights[lnum].position.offset.x; + yoff = Lights[lnum].position.offset.y; if (xoff < 0) { xoff += 8; position -= { 1, 0 }; @@ -682,33 +682,33 @@ void DoVision(Point position, int nRadius, bool doautomap, bool visible) int nCrawlY = 0; switch (v) { case 0: - nCrawlX = position.x + vCrawlTable[j][k]; - nCrawlY = position.y + vCrawlTable[j][k + 1]; - if (vCrawlTable[j][k] > 0 && vCrawlTable[j][k + 1] > 0) { + nCrawlX = position.x + VisionCrawlTable[j][k]; + nCrawlY = position.y + VisionCrawlTable[j][k + 1]; + if (VisionCrawlTable[j][k] > 0 && VisionCrawlTable[j][k + 1] > 0) { x1adj = -1; y2adj = -1; } break; case 1: - nCrawlX = position.x - vCrawlTable[j][k]; - nCrawlY = position.y - vCrawlTable[j][k + 1]; - if (vCrawlTable[j][k] > 0 && vCrawlTable[j][k + 1] > 0) { + nCrawlX = position.x - VisionCrawlTable[j][k]; + nCrawlY = position.y - VisionCrawlTable[j][k + 1]; + if (VisionCrawlTable[j][k] > 0 && VisionCrawlTable[j][k + 1] > 0) { y1adj = 1; x2adj = 1; } break; case 2: - nCrawlX = position.x + vCrawlTable[j][k]; - nCrawlY = position.y - vCrawlTable[j][k + 1]; - if (vCrawlTable[j][k] > 0 && vCrawlTable[j][k + 1] > 0) { + nCrawlX = position.x + VisionCrawlTable[j][k]; + nCrawlY = position.y - VisionCrawlTable[j][k + 1]; + if (VisionCrawlTable[j][k] > 0 && VisionCrawlTable[j][k + 1] > 0) { x1adj = -1; y2adj = 1; } break; case 3: - nCrawlX = position.x - vCrawlTable[j][k]; - nCrawlY = position.y + vCrawlTable[j][k + 1]; - if (vCrawlTable[j][k] > 0 && vCrawlTable[j][k + 1] > 0) { + nCrawlX = position.x - VisionCrawlTable[j][k]; + nCrawlY = position.y + VisionCrawlTable[j][k + 1]; + if (VisionCrawlTable[j][k] > 0 && VisionCrawlTable[j][k + 1] > 0) { y1adj = -1; x2adj = 1; } @@ -745,7 +745,7 @@ void DoVision(Point position, int nRadius, bool doautomap, bool visible) void MakeLightTable() { - uint8_t *tbl = pLightTbl.data(); + uint8_t *tbl = LightTables.data(); int shade = 0; int lights = 15; @@ -805,7 +805,7 @@ void MakeLightTable() if (leveltype == DTYPE_HELL) { BYTE blood[16]; - tbl = pLightTbl.data(); + tbl = LightTables.data(); for (int i = 0; i < lights; i++) { int l1 = lights - i; int l2 = l1; @@ -845,7 +845,7 @@ void MakeLightTable() tbl += 224; } if (currlevel >= 17) { - tbl = pLightTbl.data(); + tbl = LightTables.data(); for (int i = 0; i < lights; i++) { *tbl++ = 0; for (int j = 1; j < 16; j++) @@ -932,9 +932,9 @@ void MakeLightTable() #ifdef _DEBUG void ToggleLighting() { - lightflag = !lightflag; + DisableLighting = !DisableLighting; - if (lightflag) { + if (DisableLighting) { memset(dLight, 0, sizeof(dLight)); return; } @@ -950,17 +950,17 @@ void ToggleLighting() void InitLightMax() { - lightmax = 15; + LightsMax = 15; } void InitLighting() { - numlights = 0; - dolighting = false; - lightflag = false; + ActiveLightCount = 0; + UpdateLighting = false; + DisableLighting = false; for (int i = 0; i < MAXLIGHTS; i++) { - lightactive[i] = i; + ActiveLights[i] = i; } } @@ -968,20 +968,20 @@ int AddLight(Point position, int r) { int lid; - if (lightflag) { + if (DisableLighting) { return NO_LIGHT; } lid = NO_LIGHT; - if (numlights < MAXLIGHTS) { - lid = lightactive[numlights++]; - LightList[lid].position.tile = position; - LightList[lid]._lradius = r; - LightList[lid].position.offset = { 0, 0 }; - LightList[lid]._ldel = false; - LightList[lid]._lunflag = false; - dolighting = true; + if (ActiveLightCount < MAXLIGHTS) { + lid = ActiveLights[ActiveLightCount++]; + Lights[lid].position.tile = position; + Lights[lid]._lradius = r; + Lights[lid].position.offset = { 0, 0 }; + Lights[lid]._ldel = false; + Lights[lid]._lunflag = false; + UpdateLighting = true; } return lid; @@ -989,104 +989,104 @@ int AddLight(Point position, int r) void AddUnLight(int i) { - if (lightflag || i == NO_LIGHT) { + if (DisableLighting || i == NO_LIGHT) { return; } - LightList[i]._ldel = true; - dolighting = true; + Lights[i]._ldel = true; + UpdateLighting = true; } void ChangeLightRadius(int i, int r) { - if (lightflag || i == NO_LIGHT) { + if (DisableLighting || i == NO_LIGHT) { return; } - LightList[i]._lunflag = true; - LightList[i].position.old = LightList[i].position.tile; - LightList[i].oldRadius = LightList[i]._lradius; - LightList[i]._lradius = r; - dolighting = true; + Lights[i]._lunflag = true; + Lights[i].position.old = Lights[i].position.tile; + Lights[i].oldRadius = Lights[i]._lradius; + Lights[i]._lradius = r; + UpdateLighting = true; } void ChangeLightXY(int i, Point position) { - if (lightflag || i == NO_LIGHT) { + if (DisableLighting || i == NO_LIGHT) { return; } - LightList[i]._lunflag = true; - LightList[i].position.old = LightList[i].position.tile; - LightList[i].oldRadius = LightList[i]._lradius; - LightList[i].position.tile = position; - dolighting = true; + Lights[i]._lunflag = true; + Lights[i].position.old = Lights[i].position.tile; + Lights[i].oldRadius = Lights[i]._lradius; + Lights[i].position.tile = position; + UpdateLighting = true; } void ChangeLightOff(int i, Point position) { - if (lightflag || i == NO_LIGHT) { + if (DisableLighting || i == NO_LIGHT) { return; } - LightList[i]._lunflag = true; - LightList[i].position.old = LightList[i].position.tile; - LightList[i].oldRadius = LightList[i]._lradius; - LightList[i].position.offset = position; - dolighting = true; + Lights[i]._lunflag = true; + Lights[i].position.old = Lights[i].position.tile; + Lights[i].oldRadius = Lights[i]._lradius; + Lights[i].position.offset = position; + UpdateLighting = true; } void ChangeLight(int i, Point position, int r) { - if (lightflag || i == NO_LIGHT) { + if (DisableLighting || i == NO_LIGHT) { return; } - LightList[i]._lunflag = true; - LightList[i].position.old = LightList[i].position.tile; - LightList[i].oldRadius = LightList[i]._lradius; - LightList[i].position.tile = position; - LightList[i]._lradius = r; - dolighting = true; + Lights[i]._lunflag = true; + Lights[i].position.old = Lights[i].position.tile; + Lights[i].oldRadius = Lights[i]._lradius; + Lights[i].position.tile = position; + Lights[i]._lradius = r; + UpdateLighting = true; } void ProcessLightList() { - if (lightflag) { + if (DisableLighting) { return; } - if (dolighting) { - for (int i = 0; i < numlights; i++) { - int j = lightactive[i]; - if (LightList[j]._ldel) { - DoUnLight(LightList[j].position.tile.x, LightList[j].position.tile.y, LightList[j]._lradius); + if (UpdateLighting) { + for (int i = 0; i < ActiveLightCount; i++) { + int j = ActiveLights[i]; + if (Lights[j]._ldel) { + DoUnLight(Lights[j].position.tile.x, Lights[j].position.tile.y, Lights[j]._lradius); } - if (LightList[j]._lunflag) { - DoUnLight(LightList[j].position.old.x, LightList[j].position.old.y, LightList[j].oldRadius); - LightList[j]._lunflag = false; + if (Lights[j]._lunflag) { + DoUnLight(Lights[j].position.old.x, Lights[j].position.old.y, Lights[j].oldRadius); + Lights[j]._lunflag = false; } } - for (int i = 0; i < numlights; i++) { - int j = lightactive[i]; - if (!LightList[j]._ldel) { - DoLighting(LightList[j].position.tile, LightList[j]._lradius, j); + for (int i = 0; i < ActiveLightCount; i++) { + int j = ActiveLights[i]; + if (!Lights[j]._ldel) { + DoLighting(Lights[j].position.tile, Lights[j]._lradius, j); } } int i = 0; - while (i < numlights) { - if (LightList[lightactive[i]]._ldel) { - numlights--; - BYTE temp = lightactive[numlights]; - lightactive[numlights] = lightactive[i]; - lightactive[i] = temp; + while (i < ActiveLightCount) { + if (Lights[ActiveLights[i]]._ldel) { + ActiveLightCount--; + BYTE temp = ActiveLights[ActiveLightCount]; + ActiveLights[ActiveLightCount] = ActiveLights[i]; + ActiveLights[i] = temp; } else { i++; } } } - dolighting = false; + UpdateLighting = false; } void SavePreLighting() @@ -1096,9 +1096,9 @@ void SavePreLighting() void InitVision() { - numvision = 0; + VisionCount = 0; dovision = false; - visionid = 1; + VisionId = 1; for (int i = 0; i < TransVal; i++) { TransList[i] = false; @@ -1107,17 +1107,17 @@ void InitVision() int AddVision(Point position, int r, bool mine) { - int vid = -1; // BUGFIX: if numvision >= MAXVISION behavior is undefined (fixed) - - if (numvision < MAXVISION) { - VisionList[numvision].position.tile = position; - VisionList[numvision]._lradius = r; - vid = visionid++; - VisionList[numvision]._lid = vid; - VisionList[numvision]._ldel = false; - VisionList[numvision]._lunflag = false; - VisionList[numvision]._lflags = mine; - numvision++; + int vid = -1; // BUGFIX: if VisionCount >= MAXVISION behavior is undefined (fixed) + + if (VisionCount < MAXVISION) { + VisionList[VisionCount].position.tile = position; + VisionList[VisionCount]._lradius = r; + vid = VisionId++; + VisionList[VisionCount]._lid = vid; + VisionList[VisionCount]._ldel = false; + VisionList[VisionCount]._lunflag = false; + VisionList[VisionCount]._lflags = mine; + VisionCount++; dovision = true; } @@ -1126,7 +1126,7 @@ int AddVision(Point position, int r, bool mine) void ChangeVisionRadius(int id, int r) { - for (int i = 0; i < numvision; i++) { + for (int i = 0; i < VisionCount; i++) { if (VisionList[i]._lid == id) { VisionList[i]._lunflag = true; VisionList[i].position.old = VisionList[i].position.tile; @@ -1139,7 +1139,7 @@ void ChangeVisionRadius(int id, int r) void ChangeVisionXY(int id, Point position) { - for (int i = 0; i < numvision; i++) { + for (int i = 0; i < VisionCount; i++) { if (VisionList[i]._lid == id) { VisionList[i]._lunflag = true; VisionList[i].position.old = VisionList[i].position.tile; @@ -1153,7 +1153,7 @@ void ChangeVisionXY(int id, Point position) void ProcessVisionList() { if (dovision) { - for (int i = 0; i < numvision; i++) { + for (int i = 0; i < VisionCount; i++) { if (VisionList[i]._ldel) { DoUnVision(VisionList[i].position.tile, VisionList[i]._lradius); } @@ -1165,7 +1165,7 @@ void ProcessVisionList() for (int i = 0; i < TransVal; i++) { TransList[i] = false; } - for (int i = 0; i < numvision; i++) { + for (int i = 0; i < VisionCount; i++) { if (!VisionList[i]._ldel) { DoVision( VisionList[i].position.tile, @@ -1177,11 +1177,11 @@ void ProcessVisionList() bool delflag; do { delflag = false; - for (int i = 0; i < numvision; i++) { + for (int i = 0; i < VisionCount; i++) { if (VisionList[i]._ldel) { - numvision--; - if (numvision > 0 && i != numvision) { - VisionList[i] = VisionList[numvision]; + VisionCount--; + if (VisionCount > 0 && i != VisionCount) { + VisionList[i] = VisionList[VisionCount]; } delflag = true; } @@ -1198,7 +1198,7 @@ void lighting_color_cycling() return; } - uint8_t *tbl = pLightTbl.data(); + uint8_t *tbl = LightTables.data(); for (int j = 0; j < 16; j++) { tbl++; diff --git a/Source/lighting.h b/Source/lighting.h index 2d863e91a..437d19472 100644 --- a/Source/lighting.h +++ b/Source/lighting.h @@ -26,7 +26,7 @@ struct LightPosition { Point old; }; -struct LightListStruct { +struct LightStruct { LightPosition position; int _lradius; int _lid; @@ -36,16 +36,16 @@ struct LightListStruct { bool _lflags; }; -extern LightListStruct VisionList[MAXVISION]; -extern uint8_t lightactive[MAXLIGHTS]; -extern LightListStruct LightList[MAXLIGHTS]; -extern int numlights; -extern int numvision; -extern char lightmax; -extern bool dolighting; -extern int visionid; -extern std::array pLightTbl; -extern bool lightflag; +extern LightStruct VisionList[MAXVISION]; +extern int VisionCount; +extern int VisionId; +extern LightStruct Lights[MAXLIGHTS]; +extern uint8_t ActiveLights[MAXLIGHTS]; +extern int ActiveLightCount; +extern char LightsMax; +extern std::array LightTables; +extern bool DisableLighting; +extern bool UpdateLighting; void DoLighting(Point position, int nRadius, int Lnum); void DoUnVision(Point position, int nRadius); @@ -74,6 +74,6 @@ void lighting_color_cycling(); /* rdata */ extern const char CrawlTable[2749]; -extern const BYTE vCrawlTable[23][30]; +extern const BYTE VisionCrawlTable[23][30]; } // namespace devilution diff --git a/Source/loadsave.cpp b/Source/loadsave.cpp index ad5a9763a..7915c2b65 100644 --- a/Source/loadsave.cpp +++ b/Source/loadsave.cpp @@ -788,7 +788,7 @@ static void LoadQuest(LoadHelper *file, int i) file->Skip(sizeof(int32_t)); // Skip DoomQuestState } -static void LoadLighting(LoadHelper *file, LightListStruct *pLight) +static void LoadLighting(LoadHelper *file, LightStruct *pLight) { pLight->position.tile.x = file->NextLE(); pLight->position.tile.y = file->NextLE(); @@ -1181,17 +1181,17 @@ void LoadGame(bool firstflag) for (int i = 0; i < nobjects; i++) SyncObjectAnim(objectactive[i]); - numlights = file.NextBE(); + ActiveLightCount = file.NextBE(); - for (uint8_t &lightId : lightactive) + for (uint8_t &lightId : ActiveLights) lightId = file.NextLE(); - for (int i = 0; i < numlights; i++) - LoadLighting(&file, &LightList[lightactive[i]]); + for (int i = 0; i < ActiveLightCount; i++) + LoadLighting(&file, &Lights[ActiveLights[i]]); - visionid = file.NextBE(); - numvision = file.NextBE(); + VisionId = file.NextBE(); + VisionCount = file.NextBE(); - for (int i = 0; i < numvision; i++) + for (int i = 0; i < VisionCount; i++) LoadLighting(&file, &VisionList[i]); } @@ -1824,7 +1824,7 @@ static void SaveQuest(SaveHelper *file, int i) file->Skip(sizeof(int32_t)); // Skip DoomQuestState } -static void SaveLighting(SaveHelper *file, LightListStruct *pLight) +static void SaveLighting(SaveHelper *file, LightStruct *pLight) { file->WriteLE(pLight->position.tile.x); file->WriteLE(pLight->position.tile.y); @@ -1943,17 +1943,17 @@ void SaveGameData() for (int i = 0; i < nobjects; i++) SaveObject(&file, objectactive[i]); - file.WriteBE(numlights); + file.WriteBE(ActiveLightCount); - for (uint8_t lightId : lightactive) + for (uint8_t lightId : ActiveLights) file.WriteLE(lightId); - for (int i = 0; i < numlights; i++) - SaveLighting(&file, &LightList[lightactive[i]]); + for (int i = 0; i < ActiveLightCount; i++) + SaveLighting(&file, &Lights[ActiveLights[i]]); - file.WriteBE(visionid); - file.WriteBE(numvision); + file.WriteBE(VisionId); + file.WriteBE(VisionCount); - for (int i = 0; i < numvision; i++) + for (int i = 0; i < VisionCount; i++) SaveLighting(&file, &VisionList[i]); } @@ -2205,12 +2205,12 @@ void LoadLevel() AutomapZoomReset(); ResyncQuests(); SyncPortals(); - dolighting = true; + UpdateLighting = true; } for (auto &player : plr) { if (player.plractive && currlevel == player.plrlevel) - LightList[player._plid]._lunflag = true; + Lights[player._plid]._lunflag = true; } } diff --git a/Source/missiles.cpp b/Source/missiles.cpp index 744b08583..53c9c8de3 100644 --- a/Source/missiles.cpp +++ b/Source/missiles.cpp @@ -3710,7 +3710,7 @@ void MI_FireNova(int i) dir = plr[id]._pdir; en = TARGET_MONSTERS; } - for (const auto &k : vCrawlTable) { + for (const auto &k : VisionCrawlTable) { if (sx1 != k[6] || sy1 != k[7]) { Displacement offsets[] = { { k[6], k[7] }, { -k[6], -k[7] }, { -k[6], +k[7] }, { +k[6], -k[7] } }; for (Displacement offset : offsets) @@ -4042,7 +4042,7 @@ void MI_Guardian(int i) int ex = 0; for (int j = 0; j < 23 && ex != -1; j++) { for (int k = 10; k >= 0 && ex != -1; k -= 2) { - const Displacement offset { vCrawlTable[j][k], vCrawlTable[j][k + 1] }; + const Displacement offset { VisionCrawlTable[j][k], VisionCrawlTable[j][k + 1] }; if (offset == Displacement { 0, 0 }) { break; } @@ -4465,7 +4465,7 @@ void MI_Nova(int i) dir = plr[id]._pdir; en = TARGET_MONSTERS; } - for (const auto &k : vCrawlTable) { + for (const auto &k : VisionCrawlTable) { if (sx1 != k[6] || sy1 != k[7]) { AddMissile(src, src + Displacement { k[6], k[7] }, dir, MIS_LIGHTBALL, en, id, dam, missile[i]._mispllvl); AddMissile(src, src + Displacement { -k[6], -k[7] }, dir, MIS_LIGHTBALL, en, id, dam, missile[i]._mispllvl); diff --git a/Source/monster.cpp b/Source/monster.cpp index b2c524080..34914a6fb 100644 --- a/Source/monster.cpp +++ b/Source/monster.cpp @@ -875,7 +875,7 @@ void PlaceUniqueMonst(int uniqindex, int miniontype, int bosspacksize) char filestr[64]; sprintf(filestr, "Monsters\\Monsters\\%s.TRN", uniq->mTrnName); - LoadFileInMem(filestr, &pLightTbl[256 * (uniquetrans + 19)], 256); + LoadFileInMem(filestr, &LightTables[256 * (uniquetrans + 19)], 256); monst->_uniqtrans = uniquetrans++; @@ -3112,7 +3112,7 @@ void MAI_Sneak(int i) } int mx = monst->position.tile.x; int my = monst->position.tile.y; - if (dLight[mx][my] == lightmax) { + if (dLight[mx][my] == LightsMax) { return; } mx -= monst->enemyPosition.x; diff --git a/Source/objects.cpp b/Source/objects.cpp index 1882dc1e9..bb7531964 100644 --- a/Source/objects.cpp +++ b/Source/objects.cpp @@ -1853,7 +1853,7 @@ void Obj_Light(int i, int lr) int ox = object[i].position.x; int oy = object[i].position.y; int tr = lr + 10; - if (!lightflag) { + if (!DisableLighting) { for (int p = 0; p < MAX_PLRS && !turnon; p++) { if (plr[p].plractive) { if (currlevel == plr[p].plrlevel) { diff --git a/Source/player.cpp b/Source/player.cpp index c36ccb9a9..d3e5a87cb 100644 --- a/Source/player.cpp +++ b/Source/player.cpp @@ -46,7 +46,7 @@ void PmChangeLightOff(PlayerStruct &player) if (player._plid == NO_LIGHT) return; - const LightListStruct *l = &LightList[player._plid]; + const LightStruct *l = &Lights[player._plid]; int x = 2 * player.position.offset.deltaY + player.position.offset.deltaX; int y = 2 * player.position.offset.deltaY - player.position.offset.deltaX; diff --git a/Source/scrollrt.cpp b/Source/scrollrt.cpp index 880135097..c71b442b1 100644 --- a/Source/scrollrt.cpp +++ b/Source/scrollrt.cpp @@ -165,7 +165,7 @@ void UpdateMissilesRendererData() /** * Specifies the current light entry. */ -int light_table_index; +int LightTableIndex; uint32_t sgdwCursWdtOld; int sgdwCursX; int sgdwCursY; @@ -458,7 +458,7 @@ static void DrawMonster(const Surface &out, int x, int y, int mx, int my, int m) trans = Monsters[m]._uniqtrans + 4; if (Monsters[m]._mmode == MM_STONE) trans = 2; - if (plr[myplr]._pInfraFlag && light_table_index > 8) + if (plr[myplr]._pInfraFlag && LightTableIndex > 8) trans = 1; if (trans != 0) Cl2DrawLightTbl(out, mx, my, cel, nCel, trans); @@ -560,22 +560,22 @@ static void DrawPlayer(const Surface &out, int pnum, int x, int y, int px, int p return; } - if ((dFlags[x][y] & BFLAG_LIT) == 0 || (plr[myplr]._pInfraFlag && light_table_index > 8)) { + if ((dFlags[x][y] & BFLAG_LIT) == 0 || (plr[myplr]._pInfraFlag && LightTableIndex > 8)) { Cl2DrawLightTbl(out, px, py, *pCelSprite, nCel, 1); DrawPlayerIcons(out, pnum, px, py, true); return; } - int l = light_table_index; - if (light_table_index < 5) - light_table_index = 0; + int l = LightTableIndex; + if (LightTableIndex < 5) + LightTableIndex = 0; else - light_table_index -= 5; + LightTableIndex -= 5; Cl2DrawLight(out, px, py, *pCelSprite, nCel); DrawPlayerIcons(out, pnum, px, py, false); - light_table_index = l; + LightTableIndex = l; } /** @@ -612,7 +612,7 @@ void DrawDeadPlayer(const Surface &out, int x, int y, int sx, int sy) */ static void DrawObject(const Surface &out, int x, int y, int ox, int oy, bool pre) { - if (dObject[x][y] == 0 || light_table_index >= lightmax) + if (dObject[x][y] == 0 || LightTableIndex >= LightsMax) return; Point objectPosition {}; @@ -702,7 +702,7 @@ static void DrawCell(const Surface &out, int x, int y, int sx, int sy) static void DrawFloor(const Surface &out, int x, int y, int sx, int sy) { cel_transparency_active = false; - light_table_index = dLight[x][y]; + LightTableIndex = dLight[x][y]; arch_draw_type = 1; // Left level_cel_block = dpiece_defs_map_2[x][y].mt[0]; @@ -863,7 +863,7 @@ static void DrawDungeon(const Surface &out, int sx, int sy, int dx, int dy) return; dRendered[sx][sy] = true; - light_table_index = dLight[sx][sy]; + LightTableIndex = dLight[sx][sy]; DrawCell(out, sx, sy, dx, dy); @@ -885,7 +885,7 @@ static void DrawDungeon(const Surface &out, int sx, int sy, int dx, int dy) DrawMissile(out, sx, sy, dx, dy, true); } - if (light_table_index < lightmax && bDead != 0) { + if (LightTableIndex < LightsMax && bDead != 0) { do { DeadStruct *pDeadGuy = &Dead[(bDead & 0x1F) - 1]; auto dd = static_cast((bDead >> 5) & 7); diff --git a/Source/scrollrt.h b/Source/scrollrt.h index cec5a3225..9143828ff 100644 --- a/Source/scrollrt.h +++ b/Source/scrollrt.h @@ -29,7 +29,7 @@ enum _scroll_direction : uint8_t { extern bool sgbControllerActive; extern bool IsMovingMouseCursorWithController(); -extern int light_table_index; +extern int LightTableIndex; extern uint32_t level_cel_block; extern char arch_draw_type; extern bool cel_transparency_active; diff --git a/test/drlg_l1_test.cpp b/test/drlg_l1_test.cpp index 366967a3c..2a094b96b 100644 --- a/test/drlg_l1_test.cpp +++ b/test/drlg_l1_test.cpp @@ -8,14 +8,14 @@ using namespace devilution; TEST(Drlg_l1, DRLG_Init_Globals_noflag) { - lightflag = false; + DisableLighting = false; DRLG_Init_Globals(); EXPECT_EQ(dLight[0][0], 15); } TEST(Drlg_l1, DRLG_Init_Globals) { - lightflag = true; + DisableLighting = true; DRLG_Init_Globals(); EXPECT_EQ(dLight[0][0], 0); }