This commit is contained in:
Gene 2025-04-07 04:21:35 -07:00
commit 9e32e58c8f
11 changed files with 101 additions and 75 deletions

View file

@ -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)
{

View file

@ -35,8 +35,6 @@
#pragma once
#include <unordered_map>
#include "doomdata.h"
#include "g_level.h"
#include "r_defs.h"
@ -62,8 +60,8 @@
struct FGlobalDLightLists
{
std::unordered_map<FSection*, std::unordered_map<FDynamicLight*, FLightNode*>> flat_dlist;
std::unordered_map<side_t*, std::unordered_map<FDynamicLight*, FLightNode*>> wall_dlist;
TMap<FSection*, TMap<FDynamicLight*, FLightNode*>> flat_dlist;
TMap<side_t*, TMap<FDynamicLight*, FLightNode*>> wall_dlist;
};
//============================================================================

View file

@ -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<FDynamicLight *, FLightNode *> u = { {this, node} };
Level->lightlists.flat_dlist.try_emplace(section, u);
TMap<FDynamicLight *, FLightNode *> 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<FDynamicLight *, FLightNode *> u = { {this, node} };
Level->lightlists.wall_dlist.try_emplace(sidedef, u);
TMap<FDynamicLight *, FLightNode *> 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<side_t *, side_t *>::Iterator wit(touchlists->wall_tlist);
TMap<side_t *, side_t *>::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<FSection *, FSection *>::Iterator fit(touchlists->flat_tlist);
TMap<FSection *, FSection *>::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;
}

View file

@ -197,8 +197,8 @@ struct FLightNode
struct FDynamicLightTouchLists
{
std::unordered_map<FSection*, FSection*> flat_tlist;
std::unordered_map<side_t*, side_t*> wall_tlist;
TMap<FSection*, FSection*> flat_tlist;
TMap<side_t*, side_t*> wall_tlist;
};
struct FDynamicLight

View file

@ -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<FDynamicLight *, FLightNode *>::Iterator it(*flatLightList);
TMap<FDynamicLight *, FLightNode *>::Pair *pair;
while (it.NextPair(pair))
{
auto node = nodeIterator->second;
auto node = pair->Value;
if (!node) continue;
FDynamicLight * light = node->lightsource;

View file

@ -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<FDynamicLight *, FLightNode *>::Iterator it(*flatLightList);
TMap<FDynamicLight *, FLightNode *>::Pair *pair;
while (it.NextPair(pair))
{
auto node = nodeIterator->second;
auto node = pair->Value;
if (!node) continue;
FDynamicLight * light = node->lightsource;

View file

@ -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<FDynamicLight *, FLightNode *>::Iterator it(*flatLightList);
TMap<FDynamicLight *, FLightNode *>::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<FDynamicLight *, FLightNode *>::Iterator it(*flatLightList);
TMap<FDynamicLight *, FLightNode *>::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))

View file

@ -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<FDynamicLight *, FLightNode *>::Iterator it(*flatLightList);
TMap<FDynamicLight *, FLightNode *>::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<FDynamicLight *, FLightNode *>::Iterator it(*wallLightList);
TMap<FDynamicLight *, FLightNode *>::Pair *pair;
while (it.NextPair(pair))
{
auto node = nodeIterator->second;
auto node = pair->Value;
if (!node) continue;
if (node->lightsource->IsActive() && !node->lightsource->DontLightMap())

View file

@ -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<FDynamicLight *, FLightNode *>::Iterator it(*wallLightList);
TMap<FDynamicLight *, FLightNode *>::Pair *pair;
while (it.NextPair(pair))
{
auto node = nodeIterator->second;
auto node = pair->Value;
if (!node) continue;
if (node->lightsource->IsActive())

View file

@ -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<FDynamicLight *, FLightNode *>::Iterator it(*flatLightList);
TMap<FDynamicLight *, FLightNode *>::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))

View file

@ -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<FDynamicLight *, FLightNode *>::Iterator it(*flatLightList);
TMap<FDynamicLight *, FLightNode *>::Pair *pair;
while (it.NextPair(pair))
{
auto node = nodeIterator->second;
auto node = pair->Value;
if (!node) continue;
FDynamicLight *light = node->lightsource;