diff --git a/src/g_level.cpp b/src/g_level.cpp index f7c448407..b42d5885f 100644 --- a/src/g_level.cpp +++ b/src/g_level.cpp @@ -623,8 +623,8 @@ void G_InitNew (const char *mapname, bool bTitleLevel) primaryLevel->totaltime = 0; primaryLevel->spawnindex = 0; - primaryLevel->lightlists.wall_dlist.clear(); - primaryLevel->lightlists.flat_dlist.clear(); + primaryLevel->lightlists.wall_dlist.Clear(); + primaryLevel->lightlists.flat_dlist.Clear(); if (!multiplayer || !deathmatch) { diff --git a/src/g_levellocals.h b/src/g_levellocals.h index bbc313f49..16b97e5e2 100644 --- a/src/g_levellocals.h +++ b/src/g_levellocals.h @@ -35,8 +35,6 @@ #pragma once -#include - #include "doomdata.h" #include "g_level.h" #include "r_defs.h" @@ -62,8 +60,8 @@ struct FGlobalDLightLists { - std::unordered_map> flat_dlist; - std::unordered_map> wall_dlist; + TMap> flat_dlist; + TMap> wall_dlist; }; //============================================================================ diff --git a/src/playsim/a_dynlight.cpp b/src/playsim/a_dynlight.cpp index 4cd278b92..7be316cb8 100644 --- a/src/playsim/a_dynlight.cpp +++ b/src/playsim/a_dynlight.cpp @@ -420,7 +420,7 @@ void FDynamicLight::UpdateLocation() //============================================================================= // -// Attempts to emplace the light node in the unordered_map +// Attempts to emplace the light node in the TMap // //============================================================================= @@ -428,11 +428,11 @@ void FDynamicLight::AddLightNode(FSection *section, side_t *sidedef) { auto updateFlatTList = [&](FSection *sec) { - touchlists->flat_tlist.try_emplace(sec, sec); + touchlists->flat_tlist.Insert(sec, sec); }; auto updateWallTList = [&](side_t *sidedef) { - touchlists->wall_tlist.try_emplace(sidedef, sidedef); + touchlists->wall_tlist.Insert(sidedef, sidedef); }; FLightNode * node = new FLightNode; @@ -442,12 +442,12 @@ void FDynamicLight::AddLightNode(FSection *section, side_t *sidedef) { node->targ = section; - auto flatLightList = Level->lightlists.flat_dlist.find(section); - if (flatLightList != Level->lightlists.flat_dlist.end()) + auto flatLightList = Level->lightlists.flat_dlist.CheckKey(section); + if (flatLightList) { - auto ret = flatLightList->second.try_emplace(this, node); - if (ret.second) + if (!flatLightList->CheckKey(this)) { + flatLightList->Insert(this, node); updateFlatTList(section); } else @@ -457,8 +457,9 @@ void FDynamicLight::AddLightNode(FSection *section, side_t *sidedef) } else { - std::unordered_map u = { {this, node} }; - Level->lightlists.flat_dlist.try_emplace(section, u); + TMap u; + u.Insert(this, node); + Level->lightlists.flat_dlist.Insert(section, u); updateFlatTList(section); } } @@ -466,12 +467,12 @@ void FDynamicLight::AddLightNode(FSection *section, side_t *sidedef) { node->targ = sidedef; - auto wallLightList = Level->lightlists.wall_dlist.find(sidedef); - if (wallLightList != Level->lightlists.wall_dlist.end()) + auto wallLightList = Level->lightlists.wall_dlist.CheckKey(sidedef); + if (wallLightList) { - auto ret = wallLightList->second.try_emplace(this, node); - if (ret.second) + if (!wallLightList->CheckKey(this)) { + wallLightList->Insert(this, node); updateWallTList(sidedef); } else @@ -481,8 +482,9 @@ void FDynamicLight::AddLightNode(FSection *section, side_t *sidedef) } else { - std::unordered_map u = { {this, node} }; - Level->lightlists.wall_dlist.try_emplace(sidedef, u); + TMap u; + u.Insert(this, node); + Level->lightlists.wall_dlist.Insert(sidedef, u); updateWallTList(sidedef); } } @@ -680,40 +682,48 @@ void FDynamicLight::LinkLight() //========================================================================== void FDynamicLight::UnlinkLight () { - for (auto iter = touchlists->wall_tlist.begin(); iter != touchlists->wall_tlist.end(); iter++) + + TMap::Iterator wit(touchlists->wall_tlist); + TMap::Pair *wpair; + while (wit.NextPair(wpair)) { - auto sidedef = iter->second; + auto sidedef = wpair->Value; if (!sidedef) continue; - auto wallLightList = Level->lightlists.wall_dlist.find(sidedef); - if (wallLightList != Level->lightlists.wall_dlist.end()) + auto wallLightList = Level->lightlists.wall_dlist.CheckKey(sidedef); + if (wallLightList) { - auto light = wallLightList->second.find(this); - if (light != wallLightList->second.end()) + auto light = *wallLightList->CheckKey(this); + if (light) { - delete light->second; - wallLightList->second.erase(light); + delete light; + wallLightList->Remove(this); } } } - for (auto iter = touchlists->flat_tlist.begin(); iter != touchlists->flat_tlist.end(); iter++) + + TMap::Iterator fit(touchlists->flat_tlist); + TMap::Pair *fpair; + while (fit.NextPair(fpair)) { - auto sec = iter->second; + auto sec = fpair->Value; if (!sec) continue; - auto flatLightList = Level->lightlists.flat_dlist.find(sec); - if (flatLightList != Level->lightlists.flat_dlist.end()) + auto flatLightList = Level->lightlists.flat_dlist.CheckKey(sec); + if (flatLightList) { - auto light = flatLightList->second.find(this); - if (light != flatLightList->second.end()) + auto light = *flatLightList->CheckKey(this); + if (light) { - delete light->second; - flatLightList->second.erase(light); + delete light; + flatLightList->Remove(this); } } } + delete touchlists; touchlists = nullptr; + shadowmapped = false; } diff --git a/src/playsim/a_dynlight.h b/src/playsim/a_dynlight.h index a305278c2..00a6a82b2 100644 --- a/src/playsim/a_dynlight.h +++ b/src/playsim/a_dynlight.h @@ -197,8 +197,8 @@ struct FLightNode struct FDynamicLightTouchLists { - std::unordered_map flat_tlist; - std::unordered_map wall_tlist; + TMap flat_tlist; + TMap wall_tlist; }; struct FDynamicLight diff --git a/src/rendering/hwrenderer/scene/hw_flats.cpp b/src/rendering/hwrenderer/scene/hw_flats.cpp index 3839accad..2e5cf86ae 100644 --- a/src/rendering/hwrenderer/scene/hw_flats.cpp +++ b/src/rendering/hwrenderer/scene/hw_flats.cpp @@ -159,13 +159,15 @@ void HWFlat::SetupLights(HWDrawInfo *di, FDynLightData &lightdata, int portalgro return; // no lights on additively blended surfaces. } - auto flatLightList = di->Level->lightlists.flat_dlist.find(section); + auto flatLightList = di->Level->lightlists.flat_dlist.CheckKey(section); - if (flatLightList != di->Level->lightlists.flat_dlist.end()) + if (flatLightList) { - for (auto nodeIterator = flatLightList->second.begin(); nodeIterator != flatLightList->second.end(); nodeIterator++) + TMap::Iterator it(*flatLightList); + TMap::Pair *pair; + while (it.NextPair(pair)) { - auto node = nodeIterator->second; + auto node = pair->Value; if (!node) continue; FDynamicLight * light = node->lightsource; diff --git a/src/rendering/hwrenderer/scene/hw_renderhacks.cpp b/src/rendering/hwrenderer/scene/hw_renderhacks.cpp index c4c65fd18..540923721 100644 --- a/src/rendering/hwrenderer/scene/hw_renderhacks.cpp +++ b/src/rendering/hwrenderer/scene/hw_renderhacks.cpp @@ -117,13 +117,15 @@ int HWDrawInfo::SetupLightsForOtherPlane(subsector_t * sub, FDynLightData &light lightdata.Clear(); - auto flatLightList = Level->lightlists.flat_dlist.find(sub->section); + auto flatLightList = Level->lightlists.flat_dlist.CheckKey(sub->section); - if (flatLightList != Level->lightlists.flat_dlist.end()) + if (flatLightList) { - for (auto nodeIterator = flatLightList->second.begin(); nodeIterator != flatLightList->second.end(); nodeIterator++) + TMap::Iterator it(*flatLightList); + TMap::Pair *pair; + while (it.NextPair(pair)) { - auto node = nodeIterator->second; + auto node = pair->Value; if (!node) continue; FDynamicLight * light = node->lightsource; diff --git a/src/rendering/hwrenderer/scene/hw_spritelight.cpp b/src/rendering/hwrenderer/scene/hw_spritelight.cpp index a7a92f033..63bbf6268 100644 --- a/src/rendering/hwrenderer/scene/hw_spritelight.cpp +++ b/src/rendering/hwrenderer/scene/hw_spritelight.cpp @@ -124,13 +124,15 @@ void HWDrawInfo::GetDynSpriteLight(AActor *self, float x, float y, float z, FSec } // Go through both light lists - auto flatLightList = Level->lightlists.flat_dlist.find(sec); + auto flatLightList = Level->lightlists.flat_dlist.CheckKey(sec); - if (flatLightList != Level->lightlists.flat_dlist.end()) + if (flatLightList) { - for (auto nodeIterator = flatLightList->second.begin(); nodeIterator != flatLightList->second.end(); nodeIterator++) + TMap::Iterator it(*flatLightList); + TMap::Pair *pair; + while (it.NextPair(pair)) { - auto node = nodeIterator->second; + auto node = pair->Value; if (!node) continue; light=node->lightsource; @@ -248,12 +250,14 @@ void hw_GetDynModelLight(AActor *self, FDynLightData &modellightdata) { auto section = subsector->section; if (section->validcount == dl_validcount) return; // already done from a previous subsector. - auto flatLightList = self->Level->lightlists.flat_dlist.find(subsector->section); - if (flatLightList != self->Level->lightlists.flat_dlist.end()) + auto flatLightList = self->Level->lightlists.flat_dlist.CheckKey(subsector->section); + if (flatLightList) { - for (auto nodeIterator = flatLightList->second.begin(); nodeIterator != flatLightList->second.end(); nodeIterator++) + TMap::Iterator it(*flatLightList); + TMap::Pair *pair; + while (it.NextPair(pair)) { // check all lights touching a subsector - auto node = nodeIterator->second; + auto node = pair->Value; if (!node) continue; FDynamicLight *light = node->lightsource; if (light->ShouldLightActor(self)) diff --git a/src/rendering/hwrenderer/scene/hw_walls.cpp b/src/rendering/hwrenderer/scene/hw_walls.cpp index ea81f1fc7..3c0d3e861 100644 --- a/src/rendering/hwrenderer/scene/hw_walls.cpp +++ b/src/rendering/hwrenderer/scene/hw_walls.cpp @@ -427,13 +427,15 @@ void HWWall::SetupLights(HWDrawInfo*di, FDynLightData &lightdata) if ((seg->sidedef->Flags & WALLF_POLYOBJ) && sub) { // Polobject segs cannot be checked per sidedef so use the subsector instead. - auto flatLightList = di->Level->lightlists.flat_dlist.find(sub->section); + auto flatLightList = di->Level->lightlists.flat_dlist.CheckKey(sub->section); - if (flatLightList != di->Level->lightlists.flat_dlist.end()) + if (flatLightList) { - for (auto nodeIterator = flatLightList->second.begin(); nodeIterator != flatLightList->second.end(); nodeIterator++) + TMap::Iterator it(*flatLightList); + TMap::Pair *pair; + while (it.NextPair(pair)) { - auto node = nodeIterator->second; + auto node = pair->Value; if (!node) continue; if (node->lightsource->IsActive() && !node->lightsource->DontLightMap()) @@ -490,13 +492,15 @@ void HWWall::SetupLights(HWDrawInfo*di, FDynLightData &lightdata) } else { - auto wallLightList = di->Level->lightlists.wall_dlist.find(seg->sidedef); + auto wallLightList = di->Level->lightlists.wall_dlist.CheckKey(seg->sidedef); - if (wallLightList != di->Level->lightlists.wall_dlist.end()) + if (wallLightList) { - for (auto nodeIterator = wallLightList->second.begin(); nodeIterator != wallLightList->second.end(); nodeIterator++) + TMap::Iterator it(*wallLightList); + TMap::Pair *pair; + while (it.NextPair(pair)) { - auto node = nodeIterator->second; + auto node = pair->Value; if (!node) continue; if (node->lightsource->IsActive() && !node->lightsource->DontLightMap()) diff --git a/src/rendering/swrenderer/line/r_walldraw.cpp b/src/rendering/swrenderer/line/r_walldraw.cpp index d96b6b21e..f49bc8e7b 100644 --- a/src/rendering/swrenderer/line/r_walldraw.cpp +++ b/src/rendering/swrenderer/line/r_walldraw.cpp @@ -224,12 +224,14 @@ namespace swrenderer else if (curline && curline->sidedef) { auto Level = curline->Subsector->sector->Level; - auto wallLightList = Level->lightlists.wall_dlist.find(curline->sidedef); - if (wallLightList != Level->lightlists.wall_dlist.end()) + auto wallLightList = Level->lightlists.wall_dlist.CheckKey(curline->sidedef); + if (wallLightList) { - for (auto nodeIterator = wallLightList->second.begin(); nodeIterator != wallLightList->second.end(); nodeIterator++) + TMap::Iterator it(*wallLightList); + TMap::Pair *pair; + while (it.NextPair(pair)) { - auto node = nodeIterator->second; + auto node = pair->Value; if (!node) continue; if (node->lightsource->IsActive()) diff --git a/src/rendering/swrenderer/plane/r_visibleplane.cpp b/src/rendering/swrenderer/plane/r_visibleplane.cpp index 8a0624992..282fc25ee 100644 --- a/src/rendering/swrenderer/plane/r_visibleplane.cpp +++ b/src/rendering/swrenderer/plane/r_visibleplane.cpp @@ -76,12 +76,14 @@ namespace swrenderer return; // [SP] no dynlights if invul or lightamp auto Level = sec->sector->Level; - auto flatLightList = Level->lightlists.flat_dlist.find(sec); - if (flatLightList != Level->lightlists.flat_dlist.end()) + auto flatLightList = Level->lightlists.flat_dlist.CheckKey(sec); + if (flatLightList) { - for (auto nodeIterator = flatLightList->second.begin(); nodeIterator != flatLightList->second.end(); nodeIterator++) + TMap::Iterator it(*flatLightList); + TMap::Pair *pair; + while (it.NextPair(pair)) { - auto node = nodeIterator->second; + auto node = pair->Value; if (!node) continue; if (node->lightsource->IsActive() && (height.PointOnSide(node->lightsource->Pos) > 0)) diff --git a/src/rendering/swrenderer/things/r_sprite.cpp b/src/rendering/swrenderer/things/r_sprite.cpp index 513faa6b5..ff1d81bea 100644 --- a/src/rendering/swrenderer/things/r_sprite.cpp +++ b/src/rendering/swrenderer/things/r_sprite.cpp @@ -209,12 +209,14 @@ namespace swrenderer float lit_green = 0; float lit_blue = 0; auto Level = vis->sector->Level; - auto flatLightList = Level->lightlists.flat_dlist.find(vis->section); - if (flatLightList != Level->lightlists.flat_dlist.end()) + auto flatLightList = Level->lightlists.flat_dlist.CheckKey(vis->section); + if (flatLightList) { - for (auto nodeIterator = flatLightList->second.begin(); nodeIterator != flatLightList->second.end(); nodeIterator++) + TMap::Iterator it(*flatLightList); + TMap::Pair *pair; + while (it.NextPair(pair)) { - auto node = nodeIterator->second; + auto node = pair->Value; if (!node) continue; FDynamicLight *light = node->lightsource;