Skip to content

Commit

Permalink
Bug fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
UnrealKaraulov committed Dec 23, 2024
1 parent f970429 commit 8562559
Show file tree
Hide file tree
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
Expand Up @@ -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();
}

Expand Down
1 change: 1 addition & 0 deletions src/editor/BspRenderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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++)
Expand Down
9 changes: 9 additions & 0 deletions src/editor/Command.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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)
{
Expand Down
23 changes: 11 additions & 12 deletions src/editor/Gui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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))
Expand Down Expand Up @@ -5728,6 +5731,8 @@ void Gui::drawMenuBar()
}
}
//todo....

g_app->pickInfo.selectedEnts.clear();
}
ImGui::EndMenu();
}
Expand Down Expand Up @@ -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());
}
Expand Down Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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>();
Expand All @@ -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)
Expand Down Expand Up @@ -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();
}
Expand Down
47 changes: 16 additions & 31 deletions src/editor/Renderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -4827,7 +4812,7 @@ void Renderer::deleteEnts()
{
reloadBspModels();
}

g_app->pickInfo.selectedEnts.clear();
map->getBspRender()->pushUndoState("Delete ents", FL_ENTITIES);
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
// Notes: (newbspguy):
// ...

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


#ifdef WIN32
Expand Down
1 change: 1 addition & 0 deletions src/util/as.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
Expand Down
19 changes: 19 additions & 0 deletions src/util/util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Up @@ -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.