From b149ef12ee581f8885812389fda7cda06cb29562 Mon Sep 17 00:00:00 2001 From: Unreal Karaulov Date: Sat, 16 Mar 2024 21:48:44 +0300 Subject: [PATCH] Fix map merge. Add select map dialog. --- src/bsp/Bsp.cpp | 2 +- src/bsp/BspMerger.cpp | 21 +++++++++++++++++++-- src/cli/ProgressMeter.cpp | 2 +- src/editor/Gui.cpp | 32 +++++++++++++++++++++++++++++--- 4 files changed, 50 insertions(+), 7 deletions(-) diff --git a/src/bsp/Bsp.cpp b/src/bsp/Bsp.cpp index 8af4387a..230f2e4e 100644 --- a/src/bsp/Bsp.cpp +++ b/src/bsp/Bsp.cpp @@ -3121,8 +3121,8 @@ void Bsp::write(const std::string& path) if (replacedLump[LUMP_SURFEDGES]) { delete[] lumps[LUMP_SURFEDGES]; - replacedLump[LUMP_SURFEDGES] = true; } + replacedLump[LUMP_SURFEDGES] = true; lumps[LUMP_SURFEDGES] = (unsigned char*)newsurfs; surfedgeCount++; bsp_header.lump[LUMP_SURFEDGES].nLength = (surfedgeCount) * sizeof(int); diff --git a/src/bsp/BspMerger.cpp b/src/bsp/BspMerger.cpp index 7a3bd000..1602d853 100644 --- a/src/bsp/BspMerger.cpp +++ b/src/bsp/BspMerger.cpp @@ -1071,7 +1071,7 @@ void BspMerger::merge_ents(Bsp& mapA, Bsp& mapB) for (int i = 0; i < mapA.faceCount; i++) { - for (int s = 0; s < MAX_LIGHTSTYLES; s++) + for (int s = 0; s < MAX_LIGHTMAPS; s++) { int style = mapA.faces[i].nStyles[s]; @@ -1093,7 +1093,7 @@ void BspMerger::merge_ents(Bsp& mapA, Bsp& mapB) for (int i = 0; i < mapB.faceCount; i++) { - for (int s = 0; s < MAX_LIGHTSTYLES; s++) + for (int s = 0; s < MAX_LIGHTMAPS; s++) { int style = mapB.faces[i].nStyles[s]; @@ -1487,9 +1487,26 @@ void BspMerger::merge_faces(Bsp& mapA, Bsp& mapB) if (i < worldFaceCountA || i >= worldFaceCountA + mapB.faceCount) continue; + BSPFACE32& face = newFaces[i]; + + if (face.iPlane >= planeRemap.size()) + { + print_log(PRINT_RED, "FATAL ERROR! Invalid plane remap {}\n", face.iPlane); + continue; + } + + face.iPlane = planeRemap[face.iPlane]; face.iFirstEdge = face.iFirstEdge + thisSurfEdgeCount; + + + if (face.iTextureInfo >= texInfoRemap.size()) + { + print_log(PRINT_RED, "FATAL ERROR! Invalid texinfo remap {}\n", face.iTextureInfo); + continue; + } + face.iTextureInfo = texInfoRemap[face.iTextureInfo]; g_progress.tick(); } diff --git a/src/cli/ProgressMeter.cpp b/src/cli/ProgressMeter.cpp index 8567c50d..130c8cb3 100644 --- a/src/cli/ProgressMeter.cpp +++ b/src/cli/ProgressMeter.cpp @@ -44,7 +44,7 @@ void ProgressMeter::tick() last_progress = now; } - if (simpleMode) + if (simpleMode && g_app) { g_app->updateWindowTitle(glfwGetTime()); return; diff --git a/src/editor/Gui.cpp b/src/editor/Gui.cpp index 4f9e454e..36fa860b 100644 --- a/src/editor/Gui.cpp +++ b/src/editor/Gui.cpp @@ -8991,8 +8991,8 @@ void Gui::drawAbout() void Gui::drawMergeWindow() { - ImGui::SetNextWindowSize(ImVec2(500.f, 240.f), ImGuiCond_FirstUseEver); - ImGui::SetNextWindowSizeConstraints(ImVec2(500.f, 240.f), ImVec2(500.f, 240.f)); + ImGui::SetNextWindowSize(ImVec2(600.f, 250.f), ImGuiCond_FirstUseEver); + ImGui::SetNextWindowSizeConstraints(ImVec2(600.f, 250.f), ImVec2(600.f, 500.f)); static std::string outPath = "outbsp.bsp"; static std::vector inPaths; static bool DeleteUnusedInfo = true; @@ -9002,6 +9002,9 @@ void Gui::drawMergeWindow() static bool NoScript = true; bool addNew = false; + + static int select_path = 0; + if (inPaths.size() < 1) { inPaths.push_back(std::string("")); @@ -9009,17 +9012,40 @@ void Gui::drawMergeWindow() if (ImGui::Begin(fmt::format("{}###MERGE_WIDGET", get_localized_string(LANG_0825)).c_str(), &showMergeMapWidget)) { + if (ifd::FileDialog::Instance().IsDone("BspMergeDialog")) + { + if (ifd::FileDialog::Instance().HasResult()) + { + std::filesystem::path res = ifd::FileDialog::Instance().GetResult(); + inPaths[select_path] = res.string(); + g_settings.lastdir = stripFileName(res.string()); + } + ifd::FileDialog::Instance().Close(); + } + for (size_t i = 0; i < inPaths.size(); i++) { std::string& s = inPaths[i]; - ImGui::InputText(fmt::format(fmt::runtime(get_localized_string(LANG_0826)), i).c_str(), &s); + ImGui::SetNextItemWidth(280); + ImGui::InputText(fmt::format(fmt::runtime("##inpath{}"), i).c_str(), &s); + ImGui::SameLine(); + if (ImGui::Button((get_localized_string(LANG_0834) +"##" + std::to_string(i)).c_str())) + { + select_path = i; + ifd::FileDialog::Instance().Open("BspMergeDialog", "Opep bsp model", "BSP file (*.bsp){.bsp},.*", false, g_settings.lastdir); + } + ImGui::SameLine(); + ImGui::TextUnformatted(fmt::format(fmt::runtime(get_localized_string(LANG_0826)), i).c_str()); + if (s.length() > 1 && i + 1 == inPaths.size()) { addNew = true; } } + ImGui::SetNextItemWidth(280); ImGui::InputText(get_localized_string(LANG_0828).c_str(), &outPath); + ImGui::Checkbox(get_localized_string(LANG_0829).c_str(), &DeleteUnusedInfo); ImGui::Checkbox(get_localized_string(LANG_1121).c_str(), &Optimize); ImGui::Checkbox(get_localized_string(LANG_0830).c_str(), &DeleteHull2);