Skip to content

Commit

Permalink
Update light merger
Browse files Browse the repository at this point in the history
  • Loading branch information
UnrealKaraulov committed Mar 17, 2024
1 parent b57ee53 commit a899b19
Showing 1 changed file with 15 additions and 16 deletions.
31 changes: 15 additions & 16 deletions src/bsp/BspMerger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1066,40 +1066,39 @@ void BspMerger::merge_ents(Bsp& mapA, Bsp& mapB)
const int start_toggle_lightstyle = 32;

g_progress.update("Merging lightstyles", (int)(mapA.faceCount + mapB.faceCount));
std::set<int> mapA_light_styles;
std::map<int, int> remap_light_styles;

std::set<int> usage_lightstyles;
std::map<unsigned char, unsigned char> remap_light_styles;

for (int i = 0; i < mapA.faceCount; i++)
{
for (int s = 0; s < MAX_LIGHTMAPS; s++)
{
int style = mapA.faces[i].nStyles[s];
unsigned char style = mapA.faces[i].nStyles[s];

if (style != 255 &&
if (style < 255 &&
style >= start_toggle_lightstyle &&
!mapA_light_styles.count(style))
!usage_lightstyles.count(style))
{
mapA_light_styles.insert(style);
usage_lightstyles.insert(style);
}
}


g_progress.tick();
}

int remapped_lightstyles = 0;

int remapped_lightfaces = 0;

for (int i = 0; i < mapB.faceCount; i++)
{
for (int s = 0; s < MAX_LIGHTMAPS; s++)
{
int style = mapB.faces[i].nStyles[s];
unsigned char style = mapB.faces[i].nStyles[s];

if (style != 255 &&
if (style < 255 &&
style >= start_toggle_lightstyle &&
mapA_light_styles.count(style))
usage_lightstyles.count(style))
{
if (remap_light_styles.find(style) != remap_light_styles.end())
{
Expand All @@ -1109,19 +1108,18 @@ void BspMerger::merge_ents(Bsp& mapA, Bsp& mapB)
}

remapped_lightstyles++;
int newstyle = 32;
unsigned char newstyle = 32;
for (; newstyle < 254; newstyle++)
{
if (!mapA_light_styles.count(newstyle))
if (!usage_lightstyles.count(newstyle)
&& remap_light_styles.find(style) == remap_light_styles.end())
{
break;
}
}

remap_light_styles[style] = newstyle;
mapB.faces[i].nStyles[s] = newstyle;

mapA_light_styles.insert(newstyle);
}
}

Expand All @@ -1137,7 +1135,7 @@ void BspMerger::merge_ents(Bsp& mapA, Bsp& mapB)
if (mapB.ents[i]->hasKey("style"))
{
int style = str_to_int(mapB.ents[i]->keyvalues["style"]);
if (remap_light_styles.find(style) != remap_light_styles.end())
if (style < 255 && style >= start_toggle_lightstyle && remap_light_styles.find((unsigned char)style) != remap_light_styles.end())
{
remapped_lightents++;
mapB.ents[i]->setOrAddKeyvalue("style", std::to_string(remap_light_styles[style]));
Expand All @@ -1146,6 +1144,7 @@ void BspMerger::merge_ents(Bsp& mapA, Bsp& mapB)
}
}

print_log(PRINT_BLUE, "MapA used {} light styles. MapB used {} light styles!\n", usage_lightstyles.size(), remap_light_styles.size());
print_log(PRINT_BLUE, "Remapped {} light styles in {} entities and {} faces!\n", remapped_lightstyles, remapped_lightents, remapped_lightfaces);

for (size_t i = 0; i < mapB.ents.size(); i++)
Expand Down

0 comments on commit a899b19

Please sign in to comment.