From 2f908277a8743327f82ea06e488557980db26939 Mon Sep 17 00:00:00 2001 From: Anders Jenbo Date: Sun, 23 Apr 2023 04:30:27 +0200 Subject: [PATCH] Apply pre calculated lighting for quest levels --- Source/levels/themes.cpp | 2 -- Source/objects.cpp | 18 ++++-------------- Source/objects.h | 2 +- Source/quests.cpp | 4 ++++ 4 files changed, 9 insertions(+), 17 deletions(-) diff --git a/Source/levels/themes.cpp b/Source/levels/themes.cpp index 75b8bffb4..22ad177af 100644 --- a/Source/levels/themes.cpp +++ b/Source/levels/themes.cpp @@ -913,7 +913,6 @@ void CreateThemeRooms() return; } - ApplyObjectLighting = true; for (int i = 0; i < numthemes; i++) { themex = 0; themey = 0; @@ -973,7 +972,6 @@ void CreateThemeRooms() app_fatal(StrCat("Unknown theme type: ", static_cast(themes[i].ttype))); } } - ApplyObjectLighting = false; if (leveltype == DTYPE_HELL && themeCount > 0) { UpdateL4Trans(); } diff --git a/Source/objects.cpp b/Source/objects.cpp index 4b553f11c..f97cd4f7d 100644 --- a/Source/objects.cpp +++ b/Source/objects.cpp @@ -49,7 +49,6 @@ Object Objects[MAXOBJECTS]; int AvailableObjects[MAXOBJECTS]; int ActiveObjects[MAXOBJECTS]; int ActiveObjectCount; -bool ApplyObjectLighting; bool LoadingMapObjects; namespace { @@ -651,7 +650,6 @@ void AddChestTraps() void LoadMapObjects(const char *path, Point start, WorldTileRectangle mapRange = {}, int leveridx = 0) { LoadingMapObjects = true; - ApplyObjectLighting = true; auto dunData = LoadFileInMem(path); @@ -678,7 +676,6 @@ void LoadMapObjects(const char *path, Point start, WorldTileRectangle mapRange = } } - ApplyObjectLighting = false; LoadingMapObjects = false; } @@ -1347,12 +1344,8 @@ void AddTrap(Object &trap) void AddObjectLight(Object &object, int r) { - if (ApplyObjectLighting) { - DoLighting(object.position, r, {}); - object._oVar1 = -1; - } else { - object._oVar1 = 0; - } + DoLighting(object.position, r, {}); + object._oVar1 = -1; } void AddBarrel(Object &barrel) @@ -1595,7 +1588,9 @@ void UpdateCircle(Object &circle) if (circle.position == Point { 35, 36 } && circle._oVar5 == 3) { circle._oVar6 = 4; if (Quests[Q_BETRAYER]._qvar1 <= 4) { + LoadingMapObjects = true; ObjChangeMap(circle._oVar1, circle._oVar2, circle._oVar3, circle._oVar4); + LoadingMapObjects = false; Quests[Q_BETRAYER]._qvar1 = 4; NetSendCmdQuest(true, Quests[Q_BETRAYER]); } @@ -3824,7 +3819,6 @@ void InitObjects() if (currlevel == 16) { AddDiabObjs(); } else { - ApplyObjectLighting = true; AdvanceRndSeed(); if (currlevel == 9 && !UseMultiplayerQuests()) AddSlainHero(); @@ -3968,7 +3962,6 @@ void InitObjects() AddObjTraps(); if (IsAnyOf(leveltype, DTYPE_CATACOMBS, DTYPE_CAVES, DTYPE_HELL, DTYPE_NEST)) AddChestTraps(); - ApplyObjectLighting = false; } } @@ -3977,7 +3970,6 @@ void SetMapObjects(const uint16_t *dunData, int startx, int starty) uint16_t filesWidths[65] = {}; ClrAllObjects(); - ApplyObjectLighting = true; int width = SDL_SwapLE16(dunData[0]); int height = SDL_SwapLE16(dunData[1]); @@ -4010,8 +4002,6 @@ void SetMapObjects(const uint16_t *dunData, int startx, int starty) } } } - - ApplyObjectLighting = false; } Object *AddObject(_object_id objType, Point objPos) diff --git a/Source/objects.h b/Source/objects.h index ee5be1aeb..241559ce3 100644 --- a/Source/objects.h +++ b/Source/objects.h @@ -258,7 +258,7 @@ extern DVL_API_FOR_TEST Object Objects[MAXOBJECTS]; extern int AvailableObjects[MAXOBJECTS]; extern int ActiveObjects[MAXOBJECTS]; extern int ActiveObjectCount; -extern bool ApplyObjectLighting; +/** @brief Indicates that objects are being loaded during gameplay and pre calculated data should be updated. */ extern bool LoadingMapObjects; /** diff --git a/Source/quests.cpp b/Source/quests.cpp index f09397c26..4a984818e 100644 --- a/Source/quests.cpp +++ b/Source/quests.cpp @@ -604,6 +604,8 @@ void ResyncQuests() if (gbIsSpawn) return; + LoadingMapObjects = true; + if (Quests[Q_LTBANNER].IsAvailable()) { Monster *snotSpill = FindUniqueMonster(UniqueMonsterType::SnotSpill); if (Quests[Q_LTBANNER]._qvar1 == 1) { @@ -787,6 +789,8 @@ void ResyncQuests() } } } + + LoadingMapObjects = false; } void DrawQuestLog(const Surface &out)