Skip to content

Commit

Permalink
Bug fixes
Browse files Browse the repository at this point in the history
UnrealKaraulov committed Dec 23, 2024

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
1 parent f970429 commit 8562559
Showing 9 changed files with 61 additions and 46 deletions.
2 changes: 1 addition & 1 deletion src/bsp/Bsp.cpp
Original file line number Diff line number Diff line change
@@ -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();
}

1 change: 1 addition & 0 deletions src/editor/BspRenderer.cpp
Original file line number Diff line number Diff line change
@@ -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++)
9 changes: 9 additions & 0 deletions src/editor/Command.cpp
Original file line number Diff line number Diff line change
@@ -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)
{
23 changes: 11 additions & 12 deletions src/editor/Gui.cpp
Original file line number Diff line number Diff line change
@@ -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<std::string> keyFilter = std::vector<std::string>();
@@ -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();
}
47 changes: 16 additions & 31 deletions src/editor/Renderer.cpp
Original file line number Diff line number Diff line change
@@ -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);
}
}
2 changes: 1 addition & 1 deletion src/main.cpp
Original file line number Diff line number Diff line change
@@ -24,7 +24,7 @@
// Notes: (newbspguy):
// ...

std::string g_version_string = "NewBSPGuy v4.48";
std::string g_version_string = "NewBSPGuy v4.49";


#ifdef WIN32
1 change: 1 addition & 0 deletions src/util/as.cpp
Original file line number Diff line number Diff line change
@@ -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;
}
}
19 changes: 19 additions & 0 deletions src/util/util.cpp
Original file line number Diff line number Diff line change
@@ -3051,4 +3051,23 @@ std::vector<Entity*> 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<Entity*> 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<Entity*> 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;
}
3 changes: 2 additions & 1 deletion src/util/util.h
Original file line number Diff line number Diff line change
@@ -292,4 +292,5 @@ unsigned char FixBounds(unsigned int i);
unsigned char FixBounds(float i);
unsigned char FixBounds(double i);

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

0 comments on commit 8562559

Please sign in to comment.