Skip to content

Commit

Permalink
Add remove counter for cull face. Bugfix undo/redo
Browse files Browse the repository at this point in the history
Add remove counter for cull face. Bugfix undo/redo
  • Loading branch information
UnrealKaraulov committed Dec 29, 2023
1 parent b7f3c64 commit 313fb9d
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 32 deletions.
19 changes: 10 additions & 9 deletions src/bsp/Bsp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<BSPFACE32> all_faces;
for (int f = 0; f < faceCount; f++)
{
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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());
}

Expand All @@ -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)
Expand All @@ -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;
Expand Down Expand Up @@ -7847,7 +7848,7 @@ void Bsp::hideEnts(bool hide)

std::vector<int> Bsp::getLeafFaces(BSPLEAF32& leaf)
{
std::vector<int> retFaces;
std::vector<int> retFaces{};
for (int i = 0; i < leaf.nMarkSurfaces; i++)
{
retFaces.push_back(marksurfs[leaf.iFirstMarkSurface + i]);
Expand All @@ -7857,7 +7858,7 @@ std::vector<int> Bsp::getLeafFaces(BSPLEAF32& leaf)

std::vector<int> Bsp::getLeafFaces(int leafIdx)
{
std::vector<int> retFaces;
std::vector<int> retFaces{};
if (leafIdx < 0)
return retFaces;

Expand Down
39 changes: 17 additions & 22 deletions src/editor/Gui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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();
Expand Down Expand Up @@ -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)
Expand All @@ -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();
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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++)
Expand All @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion src/editor/Renderer.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
#include <GL/glew.h>
#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;

Expand Down

0 comments on commit 313fb9d

Please sign in to comment.