From 856255962894acfc9f7ff083fb7eddf6524afce9 Mon Sep 17 00:00:00 2001 From: Unreal Karaulov Date: Mon, 23 Dec 2024 17:44:23 +0300 Subject: [PATCH] Bug fixes --- src/bsp/Bsp.cpp | 2 +- src/editor/BspRenderer.cpp | 1 + src/editor/Command.cpp | 9 ++++++++ src/editor/Gui.cpp | 23 +++++++++---------- src/editor/Renderer.cpp | 47 +++++++++++++------------------------- src/main.cpp | 2 +- src/util/as.cpp | 1 + src/util/util.cpp | 19 +++++++++++++++ src/util/util.h | 3 ++- 9 files changed, 61 insertions(+), 46 deletions(-) diff --git a/src/bsp/Bsp.cpp b/src/bsp/Bsp.cpp index 76ec226b..a0e7bbac 100644 --- a/src/bsp/Bsp.cpp +++ b/src/bsp/Bsp.cpp @@ -5744,7 +5744,7 @@ void Bsp::reload_ents() { for (size_t i = 0; i < ents.size(); i++) delete ents[i]; - ents = load_ents(std::string((char*)lumps[LUMP_ENTITIES].data(), (char*)lumps[LUMP_ENTITIES].data() + bsp_header.lump[LUMP_ENTITIES].nLength), bsp_name); + ents = load_ents(std::string((char*)lumps[LUMP_ENTITIES].data(), (char*)lumps[LUMP_ENTITIES].data() + lumps[LUMP_ENTITIES].size()), bsp_name); update_ent_lump(); } diff --git a/src/editor/BspRenderer.cpp b/src/editor/BspRenderer.cpp index 1176f4c6..4c48e4d0 100644 --- a/src/editor/BspRenderer.cpp +++ b/src/editor/BspRenderer.cpp @@ -1809,6 +1809,7 @@ void BspRenderer::generateClipnodeBufferForHull(int modelIdx, int hullIdx) } COLOR4 faceColor = color * (dot); + faceColor.a = (g_render_flags & RENDER_TRANSPARENT) ? 128 : 255; // convert from TRIANGLE_FAN style verts to TRIANGLES for (size_t k = 2; k < faceVerts.size(); k++) diff --git a/src/editor/Command.cpp b/src/editor/Command.cpp index 2408f434..1e46df86 100644 --- a/src/editor/Command.cpp +++ b/src/editor/Command.cpp @@ -102,6 +102,11 @@ void EditBspCommand::execute() } } + auto entAdded = GetEntsAdded(oldLumps, newLumps, map->bsp_name); + + if (entAdded < 0) + g_app->pickInfo.selectedEnts.clear(); + /*if (mdls.size() > 5) { renderer->genRenderFaces(); @@ -176,6 +181,10 @@ void EditBspCommand::undo() mdls.push_back(map->get_model_from_face(face)); } } + auto entAdded = GetEntsAdded(newLumps, oldLumps, map->bsp_name); + + if (entAdded < 0) + g_app->pickInfo.selectedEnts.clear(); /*if (mdls.size() > 5) { diff --git a/src/editor/Gui.cpp b/src/editor/Gui.cpp index ffd2e3a6..eaa3e7ae 100644 --- a/src/editor/Gui.cpp +++ b/src/editor/Gui.cpp @@ -1648,6 +1648,8 @@ void Gui::drawBspContexMenu() ents_to_erase.pop_back(); } + g_app->pickInfo.selectedEnts.clear(); + rend->loadLightmaps(); rend->pushUndoState("MERGE {} and {} SELECTED BSP ENTITIES", EDIT_MODEL_LUMPS | FL_ENTITIES); @@ -5675,6 +5677,7 @@ void Gui::drawMenuBar() map->resize_all_lightmaps(); rend->pushUndoState(get_localized_string(LANG_0590), dupLumps); + rend->refreshModel(modelIdx); } if (ImGui::MenuItem("BSP Clip model", 0, false, !app->isLoading && map)) @@ -5728,6 +5731,8 @@ void Gui::drawMenuBar() } } //todo.... + + g_app->pickInfo.selectedEnts.clear(); } ImGui::EndMenu(); } @@ -8483,7 +8488,7 @@ void Gui::drawTransformWidget() if (ImGui::Begin(fmt::format("{}###TRANSFORM_WIDGET", get_localized_string(LANG_0688)).c_str(), &showTransformWidget, 0)) { - if (!ent || modelIdx < 0) + if (!ent) { ImGui::Text(get_localized_string(LANG_1180).c_str()); } @@ -9871,10 +9876,12 @@ void Gui::drawSettings() { g_render_flags ^= RENDER_WORLD_CLIPNODES; } + if (ImGui::Checkbox(get_localized_string(LANG_0791).c_str(), &renderEntClipnodes)) { g_render_flags ^= RENDER_ENT_CLIPNODES; } + if (ImGui::Checkbox(get_localized_string(LANG_0792).c_str(), &transparentNodes)) { g_render_flags ^= RENDER_TRANSPARENT; @@ -9883,6 +9890,7 @@ void Gui::drawSettings() mapRenderers[i]->updateClipnodeOpacity(transparentNodes ? 128 : 255); } } + if (ImGui::Checkbox("Map boundary", &renderMapBoundary)) { g_render_flags ^= RENDER_MAP_BOUNDARY; @@ -10674,7 +10682,6 @@ void Gui::drawEntityReport() } else { - ImGui::BeginGroup(); static float startFrom = 0.0f; static int MAX_FILTERS = 1; static std::vector keyFilter = std::vector(); @@ -10688,6 +10695,8 @@ void Gui::drawEntityReport() static bool selectAllItems = false; float footerHeight = ImGui::GetFrameHeightWithSpacing() * 5.f + 16.f; + + ImGui::BeginGroup(); ImGui::BeginChild(get_localized_string(LANG_0848).c_str(), ImVec2(0.f, -footerHeight)); if (filterNeeded) @@ -10856,16 +10865,6 @@ void Gui::drawEntityReport() if (isHovered) { - ImGui::BeginTooltip(); - if (!app->fgd || !app->fgd->getFgdClass(cname)) - { - ImGui::Text(fmt::format(fmt::runtime(get_localized_string(LANG_0404)), cname).c_str()); - } - else - { - ImGui::Text(fmt::format("{}", "This entity is hidden on map, press 'unhide' to show it!").c_str()); - } - ImGui::EndTooltip(); } ImGui::PopStyleColor(); } diff --git a/src/editor/Renderer.cpp b/src/editor/Renderer.cpp index 0be23f1c..74910c35 100644 --- a/src/editor/Renderer.cpp +++ b/src/editor/Renderer.cpp @@ -4621,41 +4621,26 @@ void Renderer::grabEnt() void Renderer::cutEnt() { - auto ents = pickInfo.selectedEnts; - if (ents.empty()) - return; - - std::sort(ents.begin(), ents.end()); - std::reverse(ents.begin(), ents.end()); - Bsp* map = SelectedMap; - if (!map) - return; - BspRenderer * rend = map->getBspRender(); - - std::ostringstream ss; - - for (size_t i = 0; i < ents.size(); i++) + if (map && pickInfo.selectedEnts.size() > 0) { - if (ents[i] <= 0) - continue; - ss << map->ents[ents[i]]->serialize(); - - if (map->ents[ents[i]]->getBspModelIdx() > 0) + auto ents = pickInfo.selectedEnts; + std::ostringstream ss; + for (size_t i = 0; i < ents.size(); i++) { - removeFile(g_working_dir + "copyModel" + std::to_string(map->ents[ents[i]]->getBspModelIdx()) + ".bsp"); - ExportModel(map, g_working_dir + "copyModel" + std::to_string(map->ents[ents[i]]->getBspModelIdx()) + ".bsp", map->ents[ents[i]]->getBspModelIdx(), 2, true); - } - } + if (ents[i] <= 0) + continue; + ss << map->ents[ents[i]]->serialize(); - for (int i = (int)ents.size() - 1; i >= 0; i--) - { - delete map->ents[i]; - map->ents.erase(map->ents.begin() + i); + if (map->ents[ents[i]]->getBspModelIdx() > 0) + { + removeFile(g_working_dir + "copyModel" + std::to_string(map->ents[ents[i]]->getBspModelIdx()) + ".bsp"); + ExportModel(map, g_working_dir + "copyModel" + std::to_string(map->ents[ents[i]]->getBspModelIdx()) + ".bsp", map->ents[ents[i]]->getBspModelIdx(), 2, true); + } + } + ImGui::SetClipboardText(ss.str().c_str()); } - - rend->pushUndoState("Cut Entity", FL_ENTITIES); - ImGui::SetClipboardText(ss.str().c_str()); + deleteEnts(); } void Renderer::copyEnt() @@ -4827,7 +4812,7 @@ void Renderer::deleteEnts() { reloadBspModels(); } - + g_app->pickInfo.selectedEnts.clear(); map->getBspRender()->pushUndoState("Delete ents", FL_ENTITIES); } } diff --git a/src/main.cpp b/src/main.cpp index ce9caded..0d934fe8 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -24,7 +24,7 @@ // Notes: (newbspguy): // ... -std::string g_version_string = "NewBSPGuy v4.48"; +std::string g_version_string = "NewBSPGuy v4.49"; #ifdef WIN32 diff --git a/src/util/as.cpp b/src/util/as.cpp index 136ba1f8..b20fefda 100644 --- a/src/util/as.cpp +++ b/src/util/as.cpp @@ -282,6 +282,7 @@ bool Native_RemoveEntity(int entIdx) { rend->map->ents.erase(rend->map->ents.begin() + i); rend->map->update_ent_lump(); + g_app->pickInfo.selectedEnts.clear(); return true; } } diff --git a/src/util/util.cpp b/src/util/util.cpp index 055a8495..ed40616a 100644 --- a/src/util/util.cpp +++ b/src/util/util.cpp @@ -3051,4 +3051,23 @@ std::vector load_ents(const std::string& entLump, const std::string& ma delete ent; return ents; +} + +int GetEntsAdded(LumpState& oldLump, LumpState& newLump, const std::string & bsp_name) +{ + std::vector ent1List{}; + if (oldLump.lumps[LUMP_ENTITIES].size()) + ent1List = load_ents(std::string((char*)oldLump.lumps[LUMP_ENTITIES].data(), (char*)oldLump.lumps[LUMP_ENTITIES].data() + oldLump.lumps[LUMP_ENTITIES].size()), bsp_name); + int ent1Count = (int)ent1List.size(); + for (auto& ent : ent1List) + delete ent; + + std::vector ent2List{}; + if (newLump.lumps[LUMP_ENTITIES].size()) + ent2List = load_ents(std::string((char*)newLump.lumps[LUMP_ENTITIES].data(), (char*)newLump.lumps[LUMP_ENTITIES].data() + newLump.lumps[LUMP_ENTITIES].size()), bsp_name); + int ent2Count = (int)ent2List.size(); + for (auto& ent : ent2List) + delete ent; + + return ent2Count - ent1Count; } \ No newline at end of file diff --git a/src/util/util.h b/src/util/util.h index d5c8b332..00edb3f0 100644 --- a/src/util/util.h +++ b/src/util/util.h @@ -292,4 +292,5 @@ unsigned char FixBounds(unsigned int i); unsigned char FixBounds(float i); unsigned char FixBounds(double i); -std::vector load_ents(const std::string& entLump, const std::string& mapName); \ No newline at end of file +std::vector load_ents(const std::string& entLump, const std::string& mapName); +int GetEntsAdded(LumpState& oldLump, LumpState& newLump, const std::string& bsp_name); \ No newline at end of file