diff --git a/src/bsp/Bsp.cpp b/src/bsp/Bsp.cpp index 66ce6677..f405f9eb 100644 --- a/src/bsp/Bsp.cpp +++ b/src/bsp/Bsp.cpp @@ -6502,7 +6502,7 @@ bool Bsp::remove_face(int faceIdx, bool onlyleafs) } else { - print_log("Remove face with id:{}\n", faceIdx); + //print_log("Remove face with id:{}\n", faceIdx); std::vector all_faces; for (int f = 0; f < faceCount; f++) { @@ -6519,7 +6519,7 @@ bool Bsp::remove_face(int faceIdx, bool onlyleafs) continue; if (faceIdx >= models[m].iFirstFace && faceIdx < models[m].iFirstFace + models[m].nFaces) { - print_log("Remove face from {} model\n", m); + //print_log("Remove face from {} model\n", m); models[m].nFaces--; } else if (models[m].iFirstFace != 0 && models[m].iFirstFace > faceIdx) @@ -6535,7 +6535,7 @@ bool Bsp::remove_face(int faceIdx, bool onlyleafs) continue; if (faceIdx >= nodes[n].iFirstFace && faceIdx < nodes[n].iFirstFace + nodes[n].nFaces) { - print_log("Remove face from {} node\n", n); + //print_log("Remove face from {} node\n", n); nodes[n].nFaces--; } else if (nodes[n].iFirstFace != 0 && nodes[n].iFirstFace > faceIdx) @@ -6552,7 +6552,7 @@ bool Bsp::remove_face(int faceIdx, bool onlyleafs) if (faceIdx == marksurfs[s]) { - print_log("Remove face from {} surface\n", s); + //print_log("Remove face from {} surface\n", s); marksurfs[s] = leafFaceTarget; } else if (marksurfs[s] != 0 && marksurfs[s] > faceIdx) @@ -6565,7 +6565,8 @@ bool Bsp::remove_face(int faceIdx, bool onlyleafs) // Update faces array unsigned char* newLump = new unsigned char[sizeof(BSPFACE32) * all_faces.size()]; - memcpy(newLump, &all_faces[0], sizeof(BSPFACE32) * all_faces.size()); + if (sizeof(BSPFACE32) * all_faces.size() > 0) + memcpy(newLump, &all_faces[0], sizeof(BSPFACE32) * all_faces.size()); replace_lump(LUMP_FACES, newLump, sizeof(BSPFACE32) * all_faces.size()); } @@ -6584,7 +6585,7 @@ bool Bsp::remove_face(int faceIdx, bool onlyleafs) continue; if (s >= leaves[m].iFirstMarkSurface && s < leaves[m].iFirstMarkSurface + leaves[m].nMarkSurfaces) { - print_log("Remove face {} from {} leaf\n", faceIdx, m); + //print_log("Remove face {} from {} leaf\n", faceIdx, m); leaves[m].nMarkSurfaces--; } else if (leaves[m].iFirstMarkSurface != 0 && leaves[m].iFirstMarkSurface > s) @@ -6595,7 +6596,7 @@ bool Bsp::remove_face(int faceIdx, bool onlyleafs) } } - unsigned char *newLump = new unsigned char[sizeof(int) * all_mark_surfaces.size()]; + unsigned char* newLump = new unsigned char[sizeof(int) * all_mark_surfaces.size()]; memcpy(newLump, &all_mark_surfaces[0], sizeof(int) * all_mark_surfaces.size()); replace_lump(LUMP_MARKSURFACES, newLump, sizeof(int) * all_mark_surfaces.size()); return true; @@ -7847,7 +7848,7 @@ void Bsp::hideEnts(bool hide) std::vector Bsp::getLeafFaces(BSPLEAF32& leaf) { - std::vector retFaces; + std::vector retFaces{}; for (int i = 0; i < leaf.nMarkSurfaces; i++) { retFaces.push_back(marksurfs[leaf.iFirstMarkSurface + i]); @@ -7857,7 +7858,7 @@ std::vector Bsp::getLeafFaces(BSPLEAF32& leaf) std::vector Bsp::getLeafFaces(int leafIdx) { - std::vector retFaces; + std::vector retFaces{}; if (leafIdx < 0) return retFaces; diff --git a/src/editor/Gui.cpp b/src/editor/Gui.cpp index f54de66b..12b14b3e 100644 --- a/src/editor/Gui.cpp +++ b/src/editor/Gui.cpp @@ -2720,17 +2720,12 @@ void Gui::drawMenuBar() if (l == leafIdx || CHECKVISBIT(visData, l)) { auto faceList = map->getLeafFaces(l + 1); - for (const auto& idx : faceList) - { - cullfaces++; - } + cullfaces += faceList.size(); } } - + STRUCTCOUNT count_1(map); g_progress.update("Remove cull faces.[LEAF 0 CLEAN]", cullfaces); - - while (FoundAnyFace) { FoundAnyFace = false; @@ -2739,17 +2734,19 @@ void Gui::drawMenuBar() if (l == leafIdx || CHECKVISBIT(visData, l)) { auto faceList = map->getLeafFaces(l + 1); - for (const auto& idx : faceList) + if (faceList.size()) { - map->remove_face(idx); + map->remove_face(faceList[faceList.size()-1]); g_progress.tick(); FoundAnyFace = true; - break; } } } } delete[] visData; + STRUCTCOUNT count_2(map); + count_1.sub(count_2); + count_1.print_delete_stats(1); map->getBspRender()->loadLightmaps(); map->getBspRender()->calcFaceMaths(); @@ -2787,19 +2784,15 @@ void Gui::drawMenuBar() bool FoundAnyFace = true; int cullfaces = 0; - for (int l = 0; l < map->leafCount - 1; l++) { if (l == leafIdx || CHECKVISBIT(visData, l)) { auto faceList = map->getLeafFaces(l + 1); - for (const auto& idx : faceList) - { - cullfaces++; - } + cullfaces += faceList.size(); } } - + STRUCTCOUNT count_1(map); g_progress.update("Remove cull faces.[LEAF 0 CLEAN]", cullfaces); while (FoundAnyFace) @@ -2810,17 +2803,19 @@ void Gui::drawMenuBar() if (l == leafIdx || CHECKVISBIT(visData, l)) { auto faceList = map->getLeafFaces(l + 1); - for (const auto& idx : faceList) + if (faceList.size()) { - map->remove_face(idx); + map->remove_face(faceList[faceList.size() - 1]); g_progress.tick(); FoundAnyFace = true; - break; } } } } delete[] visData; + STRUCTCOUNT count_2(map); + count_1.sub(count_2); + count_1.print_delete_stats(1); map->getBspRender()->loadLightmaps(); map->getBspRender()->calcFaceMaths(); @@ -5227,8 +5222,6 @@ void Gui::drawGOTOWidget() if (ImGui::Begin(get_localized_string(LANG_0676).c_str(), &showGOTOWidget, 0)) { - if (entid == -1) - entid = g_app->pickInfo.GetSelectedEnt(); ImGuiStyle& style = ImGui::GetStyle(); float padding = style.WindowPadding.x * 2 + style.FramePadding.x * 2; float inputWidth = (ImGui::GetWindowWidth() - (padding + style.ScrollbarSize)) * 0.33f; @@ -5294,6 +5287,7 @@ void Gui::drawGOTOWidget() ImGui::PopItemWidth(); if (ImGui::Button("Go to##2")) { + app->pickMode = PICK_OBJECT; if (modelid >= 0 && modelid < map->modelCount) { for (size_t i = 0; i < map->ents.size(); i++) @@ -5306,8 +5300,9 @@ void Gui::drawGOTOWidget() } } } - else if (faceid > 0 && faceid < map->faceCount) + else if (faceid >= 0 && faceid < map->faceCount) { + app->pickMode = PICK_FACE; app->goToFace(map, faceid); int modelIdx = map->get_model_from_face(faceid); if (modelIdx >= 0) diff --git a/src/editor/Renderer.h b/src/editor/Renderer.h index b5101aec..8881dbe8 100644 --- a/src/editor/Renderer.h +++ b/src/editor/Renderer.h @@ -14,7 +14,7 @@ #include #include "mdl_studio.h" -#define EDIT_MODEL_LUMPS (FL_PLANES | FL_TEXTURES | FL_VERTICES | FL_NODES | FL_TEXINFO | FL_FACES | FL_LIGHTING | FL_CLIPNODES | FL_LEAVES | FL_EDGES | FL_SURFEDGES | FL_MODELS) +#define EDIT_MODEL_LUMPS (FL_PLANES | FL_TEXTURES | FL_VERTICES | FL_NODES | FL_TEXINFO | FL_FACES | FL_LIGHTING | FL_CLIPNODES | FL_LEAVES | FL_EDGES | FL_SURFEDGES | FL_MODELS | FL_MARKSURFACES) class Gui;