diff --git a/Source/levels/gendung.cpp b/Source/levels/gendung.cpp index fa6741abf..a86e87413 100644 --- a/Source/levels/gendung.cpp +++ b/Source/levels/gendung.cpp @@ -338,7 +338,12 @@ void InitGlobals() memset(dItem, 0, sizeof(dItem)); memset(dObject, 0, sizeof(dObject)); memset(dSpecial, 0, sizeof(dSpecial)); - memset(dLight, DisableLighting || leveltype == DTYPE_TOWN ? 0 : 15, sizeof(dLight)); + uint8_t defaultLight = leveltype == DTYPE_TOWN ? 0 : 15; +#ifdef _DEBUG + if (DisableLighting) + defaultLight = 0; +#endif + memset(dLight, defaultLight, sizeof(dLight)); DRLG_InitTrans(); diff --git a/Source/lighting.cpp b/Source/lighting.cpp index cb5ef64a5..c92b9a800 100644 --- a/Source/lighting.cpp +++ b/Source/lighting.cpp @@ -25,7 +25,9 @@ std::array, NumLightingLevels> LightTables; std::array InfravisionTable; std::array StoneTable; std::array PauseTable; +#ifdef _DEBUG bool DisableLighting; +#endif bool UpdateLighting; namespace { @@ -463,7 +465,9 @@ void InitLighting() UpdateVision = false; VisionCount = 0; VisionId = 1; +#ifdef _DEBUG DisableLighting = false; +#endif for (int i = 0; i < MAXLIGHTS; i++) { ActiveLights[i] = i; @@ -476,8 +480,10 @@ void InitLighting() int AddLight(Point position, uint8_t radius) { +#ifdef _DEBUG if (DisableLighting) return NO_LIGHT; +#endif if (ActiveLightCount >= MAXLIGHTS) return NO_LIGHT; @@ -496,9 +502,12 @@ int AddLight(Point position, uint8_t radius) void AddUnLight(int i) { - if (DisableLighting || i == NO_LIGHT) { +#ifdef _DEBUG + if (DisableLighting) + return; +#endif + if (i == NO_LIGHT) return; - } Lights[i].isInvalid = true; @@ -507,9 +516,12 @@ void AddUnLight(int i) void ChangeLightRadius(int i, uint8_t radius) { - if (DisableLighting || i == NO_LIGHT) { +#ifdef _DEBUG + if (DisableLighting) + return; +#endif + if (i == NO_LIGHT) return; - } Light &light = Lights[i]; light.hasChanged = true; @@ -522,9 +534,12 @@ void ChangeLightRadius(int i, uint8_t radius) void ChangeLightXY(int i, Point position) { - if (DisableLighting || i == NO_LIGHT) { +#ifdef _DEBUG + if (DisableLighting) + return; +#endif + if (i == NO_LIGHT) return; - } Light &light = Lights[i]; light.hasChanged = true; @@ -537,9 +552,12 @@ void ChangeLightXY(int i, Point position) void ChangeLightOffset(int i, Displacement offset) { - if (DisableLighting || i == NO_LIGHT) { +#ifdef _DEBUG + if (DisableLighting) + return; +#endif + if (i == NO_LIGHT) return; - } Light &light = Lights[i]; light.hasChanged = true; @@ -552,9 +570,12 @@ void ChangeLightOffset(int i, Displacement offset) void ChangeLight(int i, Point position, uint8_t radius) { - if (DisableLighting || i == NO_LIGHT) { +#ifdef _DEBUG + if (DisableLighting) + return; +#endif + if (i == NO_LIGHT) return; - } Light &light = Lights[i]; light.hasChanged = true; @@ -568,8 +589,10 @@ void ChangeLight(int i, Point position, uint8_t radius) void ProcessLightList() { +#ifdef _DEBUG if (DisableLighting) return; +#endif if (!UpdateLighting) return; for (int i = 0; i < ActiveLightCount; i++) { diff --git a/Source/lighting.h b/Source/lighting.h index 615e96ebe..f4cb543e3 100644 --- a/Source/lighting.h +++ b/Source/lighting.h @@ -54,7 +54,9 @@ extern std::array, NumLightingLevels> LightTables; extern std::array InfravisionTable; extern std::array StoneTable; extern std::array PauseTable; +#ifdef _DEBUG extern bool DisableLighting; +#endif extern bool UpdateLighting; void DoLighting(Point position, uint8_t radius, int Lnum); diff --git a/Source/objects.cpp b/Source/objects.cpp index 96081eae4..fd775f2f5 100644 --- a/Source/objects.cpp +++ b/Source/objects.cpp @@ -1529,28 +1529,35 @@ void AddMushPatch() } } -void UpdateObjectLight(Object &light, int lightRadius) +bool IsLightVisible(Object &light, int lightRadius) { - if (light._oVar1 == -1) { - return; - } +#ifdef _DEBUG + if (!DisableLighting) + return false; +#endif - bool turnon = false; - if (!DisableLighting) { - for (const Player &player : Players) { - if (!player.plractive) - continue; + for (const Player &player : Players) { + if (!player.plractive) + continue; - if (!player.isOnActiveLevel()) - continue; + if (!player.isOnActiveLevel()) + continue; - if (player.position.tile.WalkingDistance(light.position) < lightRadius + 10) { - turnon = true; - break; - } + if (player.position.tile.WalkingDistance(light.position) < lightRadius + 10) { + return true; } } - if (turnon) { + + return false; +} + +void UpdateObjectLight(Object &light, int lightRadius) +{ + if (light._oVar1 == -1) { + return; + } + + if (IsLightVisible(light, lightRadius)) { if (light._oVar1 == 0) light._olid = AddLight(light.position, lightRadius); light._oVar1 = 1;