Skip to content

Commit 8562559

Browse files
Bug fixes
1 parent f970429 commit 8562559

File tree

9 files changed

+61
-46
lines changed

9 files changed

+61
-46
lines changed

src/bsp/Bsp.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -5744,7 +5744,7 @@ void Bsp::reload_ents()
57445744
{
57455745
for (size_t i = 0; i < ents.size(); i++)
57465746
delete ents[i];
5747-
ents = load_ents(std::string((char*)lumps[LUMP_ENTITIES].data(), (char*)lumps[LUMP_ENTITIES].data() + bsp_header.lump[LUMP_ENTITIES].nLength), bsp_name);
5747+
ents = load_ents(std::string((char*)lumps[LUMP_ENTITIES].data(), (char*)lumps[LUMP_ENTITIES].data() + lumps[LUMP_ENTITIES].size()), bsp_name);
57485748
update_ent_lump();
57495749
}
57505750

src/editor/BspRenderer.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -1809,6 +1809,7 @@ void BspRenderer::generateClipnodeBufferForHull(int modelIdx, int hullIdx)
18091809
}
18101810

18111811
COLOR4 faceColor = color * (dot);
1812+
faceColor.a = (g_render_flags & RENDER_TRANSPARENT) ? 128 : 255;
18121813

18131814
// convert from TRIANGLE_FAN style verts to TRIANGLES
18141815
for (size_t k = 2; k < faceVerts.size(); k++)

src/editor/Command.cpp

+9
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,11 @@ void EditBspCommand::execute()
102102
}
103103
}
104104

105+
auto entAdded = GetEntsAdded(oldLumps, newLumps, map->bsp_name);
106+
107+
if (entAdded < 0)
108+
g_app->pickInfo.selectedEnts.clear();
109+
105110
/*if (mdls.size() > 5)
106111
{
107112
renderer->genRenderFaces();
@@ -176,6 +181,10 @@ void EditBspCommand::undo()
176181
mdls.push_back(map->get_model_from_face(face));
177182
}
178183
}
184+
auto entAdded = GetEntsAdded(newLumps, oldLumps, map->bsp_name);
185+
186+
if (entAdded < 0)
187+
g_app->pickInfo.selectedEnts.clear();
179188

180189
/*if (mdls.size() > 5)
181190
{

src/editor/Gui.cpp

+11-12
Original file line numberDiff line numberDiff line change
@@ -1648,6 +1648,8 @@ void Gui::drawBspContexMenu()
16481648
ents_to_erase.pop_back();
16491649
}
16501650

1651+
g_app->pickInfo.selectedEnts.clear();
1652+
16511653
rend->loadLightmaps();
16521654

16531655
rend->pushUndoState("MERGE {} and {} SELECTED BSP ENTITIES", EDIT_MODEL_LUMPS | FL_ENTITIES);
@@ -5675,6 +5677,7 @@ void Gui::drawMenuBar()
56755677

56765678
map->resize_all_lightmaps();
56775679
rend->pushUndoState(get_localized_string(LANG_0590), dupLumps);
5680+
rend->refreshModel(modelIdx);
56785681
}
56795682

56805683
if (ImGui::MenuItem("BSP Clip model", 0, false, !app->isLoading && map))
@@ -5728,6 +5731,8 @@ void Gui::drawMenuBar()
57285731
}
57295732
}
57305733
//todo....
5734+
5735+
g_app->pickInfo.selectedEnts.clear();
57315736
}
57325737
ImGui::EndMenu();
57335738
}
@@ -8483,7 +8488,7 @@ void Gui::drawTransformWidget()
84838488

84848489
if (ImGui::Begin(fmt::format("{}###TRANSFORM_WIDGET", get_localized_string(LANG_0688)).c_str(), &showTransformWidget, 0))
84858490
{
8486-
if (!ent || modelIdx < 0)
8491+
if (!ent)
84878492
{
84888493
ImGui::Text(get_localized_string(LANG_1180).c_str());
84898494
}
@@ -9871,10 +9876,12 @@ void Gui::drawSettings()
98719876
{
98729877
g_render_flags ^= RENDER_WORLD_CLIPNODES;
98739878
}
9879+
98749880
if (ImGui::Checkbox(get_localized_string(LANG_0791).c_str(), &renderEntClipnodes))
98759881
{
98769882
g_render_flags ^= RENDER_ENT_CLIPNODES;
98779883
}
9884+
98789885
if (ImGui::Checkbox(get_localized_string(LANG_0792).c_str(), &transparentNodes))
98799886
{
98809887
g_render_flags ^= RENDER_TRANSPARENT;
@@ -9883,6 +9890,7 @@ void Gui::drawSettings()
98839890
mapRenderers[i]->updateClipnodeOpacity(transparentNodes ? 128 : 255);
98849891
}
98859892
}
9893+
98869894
if (ImGui::Checkbox("Map boundary", &renderMapBoundary))
98879895
{
98889896
g_render_flags ^= RENDER_MAP_BOUNDARY;
@@ -10674,7 +10682,6 @@ void Gui::drawEntityReport()
1067410682
}
1067510683
else
1067610684
{
10677-
ImGui::BeginGroup();
1067810685
static float startFrom = 0.0f;
1067910686
static int MAX_FILTERS = 1;
1068010687
static std::vector<std::string> keyFilter = std::vector<std::string>();
@@ -10688,6 +10695,8 @@ void Gui::drawEntityReport()
1068810695
static bool selectAllItems = false;
1068910696

1069010697
float footerHeight = ImGui::GetFrameHeightWithSpacing() * 5.f + 16.f;
10698+
10699+
ImGui::BeginGroup();
1069110700
ImGui::BeginChild(get_localized_string(LANG_0848).c_str(), ImVec2(0.f, -footerHeight));
1069210701

1069310702
if (filterNeeded)
@@ -10856,16 +10865,6 @@ void Gui::drawEntityReport()
1085610865

1085710866
if (isHovered)
1085810867
{
10859-
ImGui::BeginTooltip();
10860-
if (!app->fgd || !app->fgd->getFgdClass(cname))
10861-
{
10862-
ImGui::Text(fmt::format(fmt::runtime(get_localized_string(LANG_0404)), cname).c_str());
10863-
}
10864-
else
10865-
{
10866-
ImGui::Text(fmt::format("{}", "This entity is hidden on map, press 'unhide' to show it!").c_str());
10867-
}
10868-
ImGui::EndTooltip();
1086910868
}
1087010869
ImGui::PopStyleColor();
1087110870
}

src/editor/Renderer.cpp

+16-31
Original file line numberDiff line numberDiff line change
@@ -4621,41 +4621,26 @@ void Renderer::grabEnt()
46214621

46224622
void Renderer::cutEnt()
46234623
{
4624-
auto ents = pickInfo.selectedEnts;
4625-
if (ents.empty())
4626-
return;
4627-
4628-
std::sort(ents.begin(), ents.end());
4629-
std::reverse(ents.begin(), ents.end());
4630-
46314624
Bsp* map = SelectedMap;
4632-
if (!map)
4633-
return;
4634-
BspRenderer * rend = map->getBspRender();
4635-
4636-
std::ostringstream ss;
4637-
4638-
for (size_t i = 0; i < ents.size(); i++)
4625+
if (map && pickInfo.selectedEnts.size() > 0)
46394626
{
4640-
if (ents[i] <= 0)
4641-
continue;
4642-
ss << map->ents[ents[i]]->serialize();
4643-
4644-
if (map->ents[ents[i]]->getBspModelIdx() > 0)
4627+
auto ents = pickInfo.selectedEnts;
4628+
std::ostringstream ss;
4629+
for (size_t i = 0; i < ents.size(); i++)
46454630
{
4646-
removeFile(g_working_dir + "copyModel" + std::to_string(map->ents[ents[i]]->getBspModelIdx()) + ".bsp");
4647-
ExportModel(map, g_working_dir + "copyModel" + std::to_string(map->ents[ents[i]]->getBspModelIdx()) + ".bsp", map->ents[ents[i]]->getBspModelIdx(), 2, true);
4648-
}
4649-
}
4631+
if (ents[i] <= 0)
4632+
continue;
4633+
ss << map->ents[ents[i]]->serialize();
46504634

4651-
for (int i = (int)ents.size() - 1; i >= 0; i--)
4652-
{
4653-
delete map->ents[i];
4654-
map->ents.erase(map->ents.begin() + i);
4635+
if (map->ents[ents[i]]->getBspModelIdx() > 0)
4636+
{
4637+
removeFile(g_working_dir + "copyModel" + std::to_string(map->ents[ents[i]]->getBspModelIdx()) + ".bsp");
4638+
ExportModel(map, g_working_dir + "copyModel" + std::to_string(map->ents[ents[i]]->getBspModelIdx()) + ".bsp", map->ents[ents[i]]->getBspModelIdx(), 2, true);
4639+
}
4640+
}
4641+
ImGui::SetClipboardText(ss.str().c_str());
46554642
}
4656-
4657-
rend->pushUndoState("Cut Entity", FL_ENTITIES);
4658-
ImGui::SetClipboardText(ss.str().c_str());
4643+
deleteEnts();
46594644
}
46604645

46614646
void Renderer::copyEnt()
@@ -4827,7 +4812,7 @@ void Renderer::deleteEnts()
48274812
{
48284813
reloadBspModels();
48294814
}
4830-
4815+
g_app->pickInfo.selectedEnts.clear();
48314816
map->getBspRender()->pushUndoState("Delete ents", FL_ENTITIES);
48324817
}
48334818
}

src/main.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
// Notes: (newbspguy):
2525
// ...
2626

27-
std::string g_version_string = "NewBSPGuy v4.48";
27+
std::string g_version_string = "NewBSPGuy v4.49";
2828

2929

3030
#ifdef WIN32

src/util/as.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -282,6 +282,7 @@ bool Native_RemoveEntity(int entIdx)
282282
{
283283
rend->map->ents.erase(rend->map->ents.begin() + i);
284284
rend->map->update_ent_lump();
285+
g_app->pickInfo.selectedEnts.clear();
285286
return true;
286287
}
287288
}

src/util/util.cpp

+19
Original file line numberDiff line numberDiff line change
@@ -3051,4 +3051,23 @@ std::vector<Entity*> load_ents(const std::string& entLump, const std::string& ma
30513051
delete ent;
30523052

30533053
return ents;
3054+
}
3055+
3056+
int GetEntsAdded(LumpState& oldLump, LumpState& newLump, const std::string & bsp_name)
3057+
{
3058+
std::vector<Entity*> ent1List{};
3059+
if (oldLump.lumps[LUMP_ENTITIES].size())
3060+
ent1List = load_ents(std::string((char*)oldLump.lumps[LUMP_ENTITIES].data(), (char*)oldLump.lumps[LUMP_ENTITIES].data() + oldLump.lumps[LUMP_ENTITIES].size()), bsp_name);
3061+
int ent1Count = (int)ent1List.size();
3062+
for (auto& ent : ent1List)
3063+
delete ent;
3064+
3065+
std::vector<Entity*> ent2List{};
3066+
if (newLump.lumps[LUMP_ENTITIES].size())
3067+
ent2List = load_ents(std::string((char*)newLump.lumps[LUMP_ENTITIES].data(), (char*)newLump.lumps[LUMP_ENTITIES].data() + newLump.lumps[LUMP_ENTITIES].size()), bsp_name);
3068+
int ent2Count = (int)ent2List.size();
3069+
for (auto& ent : ent2List)
3070+
delete ent;
3071+
3072+
return ent2Count - ent1Count;
30543073
}

src/util/util.h

+2-1
Original file line numberDiff line numberDiff line change
@@ -292,4 +292,5 @@ unsigned char FixBounds(unsigned int i);
292292
unsigned char FixBounds(float i);
293293
unsigned char FixBounds(double i);
294294

295-
std::vector<Entity*> load_ents(const std::string& entLump, const std::string& mapName);
295+
std::vector<Entity*> load_ents(const std::string& entLump, const std::string& mapName);
296+
int GetEntsAdded(LumpState& oldLump, LumpState& newLump, const std::string& bsp_name);

0 commit comments

Comments
 (0)