diff --git a/src/bsp/BspMerger.cpp b/src/bsp/BspMerger.cpp index a9b4e9cb..d4e1ac42 100644 --- a/src/bsp/BspMerger.cpp +++ b/src/bsp/BspMerger.cpp @@ -6,13 +6,124 @@ #include "vis.h" -Bsp* BspMerger::merge(std::vector maps, const vec3& gap, const std::string& output_name, bool noripent, bool noscript) +Bsp* BspMerger::merge(std::vector maps, const vec3& gap, const std::string& output_name, bool noripent, bool noscript, bool nomergestyles) { - if (maps.size() < 1) + if (maps.size() < 2) { print_log(PRINT_RED | PRINT_INTENSITY, get_localized_string(LANG_0219)); return NULL; } + + skipLightStyles = nomergestyles; + + + if (!skipLightStyles) + { + const int start_toggle_lightstyle = 32; + std::set usage_lightstyles; + std::map remap_light_styles; + + for (int i = 0; i < maps[0]->faceCount; i++) + { + for (int s = 0; s < MAX_LIGHTMAPS; s++) + { + unsigned char style = maps[0]->faces[i].nStyles[s]; + + if (style < 255 && + style >= start_toggle_lightstyle && + !usage_lightstyles.count(style)) + { + usage_lightstyles.insert(style); + } + } + + g_progress.tick(); + } + + for (size_t b = 1; b < maps.size(); b++) + { + Bsp* mapB = maps[b]; + + + mapB->save_undo_lightmaps(); + + g_progress.update("Merging lightstyles", (int)(maps[0]->faceCount + maps[b]->faceCount)); + + + int remapped_lightstyles = 0; + int remapped_lightfaces = 0; + + for (int i = 0; i < mapB->faceCount; i++) + { + for (int s = 0; s < MAX_LIGHTMAPS; s++) + { + unsigned char style = mapB->faces[i].nStyles[s]; + + if (style < 255 && + style >= start_toggle_lightstyle && + usage_lightstyles.count(style)) + { + if (remap_light_styles.find(style) != remap_light_styles.end()) + {/* + print_log(PRINT_GREEN,"REMAP {} TO {}\n", mapB.faces[i].nStyles[s], remap_light_styles[style]);*/ + mapB->faces[i].nStyles[s] = remap_light_styles[style]; + remapped_lightfaces++; + continue; + } + + remapped_lightstyles++; + unsigned char newstyle = 32; + for (; newstyle < 254; newstyle++) + { + if (!usage_lightstyles.count(newstyle) + && remap_light_styles.find(style) == remap_light_styles.end()) + { + break; + } + } + + remap_light_styles[style] = newstyle; + + + //print_log(PRINT_GREEN, "REMAP2 {} TO {}\n", mapB.faces[i].nStyles[s], remap_light_styles[style]); + mapB->faces[i].nStyles[s] = newstyle; + + + usage_lightstyles.insert(newstyle); + } + } + + g_progress.tick(); + } + + int remapped_lightents = 0; + + for (size_t i = 0; i < mapB->ents.size(); i++) + { + if (mapB->ents[i]->keyvalues["classname"].find("light") != std::string::npos) + { + if (mapB->ents[i]->hasKey("style")) + { + int style = str_to_int(mapB->ents[i]->keyvalues["style"]); + 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])); + } + } + } + } + + 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); + + mapB->resize_all_lightmaps(); + + remap_light_styles.clear(); + } + } + + std::vector>> blocks = separate(maps, gap); @@ -1065,99 +1176,6 @@ void BspMerger::merge_ents(Bsp& mapA, Bsp& mapB) g_progress.tick(); } - - const int start_toggle_lightstyle = 32; - - g_progress.update("Merging lightstyles", (int)(mapA.faceCount + mapB.faceCount)); - - mapB.save_undo_lightmaps(); - - std::set usage_lightstyles; - std::map remap_light_styles; - - for (int i = 0; i < mapA.faceCount; i++) - { - for (int s = 0; s < MAX_LIGHTMAPS; s++) - { - unsigned char style = mapA.faces[i].nStyles[s]; - - if (style < 255 && - style >= start_toggle_lightstyle && - !usage_lightstyles.count(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++) - { - unsigned char style = mapB.faces[i].nStyles[s]; - - if (style < 255 && - style >= start_toggle_lightstyle && - usage_lightstyles.count(style)) - { - if (remap_light_styles.find(style) != remap_light_styles.end()) - {/* - print_log(PRINT_GREEN,"REMAP {} TO {}\n", mapB.faces[i].nStyles[s], remap_light_styles[style]);*/ - mapB.faces[i].nStyles[s] = remap_light_styles[style]; - remapped_lightfaces++; - continue; - } - - remapped_lightstyles++; - unsigned char newstyle = 32; - for (; newstyle < 254; newstyle++) - { - if (!usage_lightstyles.count(newstyle) - && remap_light_styles.find(style) == remap_light_styles.end()) - { - break; - } - } - - remap_light_styles[style] = newstyle; - - - //print_log(PRINT_GREEN, "REMAP2 {} TO {}\n", mapB.faces[i].nStyles[s], remap_light_styles[style]); - mapB.faces[i].nStyles[s] = newstyle; - } - } - - g_progress.tick(); - } - - int remapped_lightents = 0; - - for (size_t i = 0; i < mapB.ents.size(); i++) - { - if (mapB.ents[i]->keyvalues["classname"].find("light") != std::string::npos) - { - if (mapB.ents[i]->hasKey("style")) - { - int style = str_to_int(mapB.ents[i]->keyvalues["style"]); - 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])); - } - } - } - } - - 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); - - mapB.resize_all_lightmaps(); - for (size_t i = 0; i < mapB.ents.size(); i++) { if (mapB.ents[i]->keyvalues["classname"] == "worldspawn") diff --git a/src/bsp/BspMerger.h b/src/bsp/BspMerger.h index 1097c1ef..9c691c10 100644 --- a/src/bsp/BspMerger.h +++ b/src/bsp/BspMerger.h @@ -24,7 +24,7 @@ class BspMerger // merges all maps into one // noripent - don't change any entity logic // noscript - don't add support for the bspguy map script (worse performance + buggy, but simpler) - Bsp* merge(std::vector maps, const vec3& gap, const std::string& output_name, bool noripent, bool noscript); + Bsp* merge(std::vector maps, const vec3& gap, const std::string& output_name, bool noripent, bool noscript, bool nomergestyles); // wrapper around BSP data merging for nicer console output @@ -89,4 +89,6 @@ class BspMerger int thisMarkSurfCount = 0; int thisEdgeCount = 0; int thisVertCount = 0; + + bool skipLightStyles = false; }; \ No newline at end of file diff --git a/src/editor/Gui.cpp b/src/editor/Gui.cpp index 090a3960..0ff22e17 100644 --- a/src/editor/Gui.cpp +++ b/src/editor/Gui.cpp @@ -9003,6 +9003,7 @@ void Gui::drawMergeWindow() static bool Optimize = false; static bool DeleteHull2 = false; static bool NoRipent = false; + static bool NoStyles = false; static bool NoScript = true; bool addNew = false; @@ -9055,6 +9056,7 @@ void Gui::drawMergeWindow() ImGui::Checkbox(get_localized_string(LANG_0830).c_str(), &DeleteHull2); ImGui::Checkbox(get_localized_string(LANG_0831).c_str(), &NoRipent); ImGui::Checkbox(get_localized_string(LANG_0832).c_str(), &NoScript); + ImGui::Checkbox("Skip lightstyles merging", &NoStyles); if (ImGui::Button(get_localized_string(LANG_1122).c_str(), ImVec2(120, 0))) { @@ -9117,7 +9119,7 @@ void Gui::drawMergeWindow() print_log("\n"); } BspMerger merger; - Bsp* result = merger.merge(maps, vec3(), outPath, NoRipent, NoScript); + Bsp* result = merger.merge(maps, vec3(), outPath, NoRipent, NoScript, NoStyles); print_log("\n"); if (result->isValid()) result->write(outPath); diff --git a/src/main.cpp b/src/main.cpp index 447c4423..f88db414 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -165,7 +165,7 @@ int test() removed.print_delete_stats(1); BspMerger merger; - Bsp* result = merger.merge(maps, vec3(1, 1, 1), "yabma_move", false, false); + Bsp* result = merger.merge(maps, vec3(1, 1, 1), "yabma_move", false, false,false); print_log("\n"); if (result) { @@ -237,7 +237,7 @@ int merge_maps(CommandLine& cli) std::string output_name = cli.hasOption("-o") ? cli.getOption("-o") : cli.bspfile; BspMerger merger; - Bsp* result = merger.merge(maps, gap, output_name, cli.hasOption("-noripent"), cli.hasOption("-noscript")); + Bsp* result = merger.merge(maps, gap, output_name, cli.hasOption("-noripent"), cli.hasOption("-noscript"), cli.hasOption("-nostyles")); print_log("\n"); if (result->validate() && result->isValid()) result->write(output_name); diff --git a/src/qtools/rad.cpp b/src/qtools/rad.cpp index 46b92b84..c9f817ac 100644 --- a/src/qtools/rad.cpp +++ b/src/qtools/rad.cpp @@ -177,9 +177,6 @@ float CalculatePointVecsProduct(const volatile float* point, const volatile floa return (float)val; } - - - // //bool GetFaceExtentsX(Bsp* bsp, int facenum, int mins_out[2], int maxs_out[2]) //{