Skip to content

Commit

Permalink
Fix map merge. Add select map dialog.
Browse files Browse the repository at this point in the history
  • Loading branch information
UnrealKaraulov committed Mar 16, 2024
1 parent e9ef1b5 commit b149ef1
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/bsp/Bsp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3121,8 +3121,8 @@ void Bsp::write(const std::string& path)
if (replacedLump[LUMP_SURFEDGES])
{
delete[] lumps[LUMP_SURFEDGES];
replacedLump[LUMP_SURFEDGES] = true;
}
replacedLump[LUMP_SURFEDGES] = true;
lumps[LUMP_SURFEDGES] = (unsigned char*)newsurfs;
surfedgeCount++;
bsp_header.lump[LUMP_SURFEDGES].nLength = (surfedgeCount) * sizeof(int);
Expand Down
21 changes: 19 additions & 2 deletions src/bsp/BspMerger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1071,7 +1071,7 @@ void BspMerger::merge_ents(Bsp& mapA, Bsp& mapB)

for (int i = 0; i < mapA.faceCount; i++)
{
for (int s = 0; s < MAX_LIGHTSTYLES; s++)
for (int s = 0; s < MAX_LIGHTMAPS; s++)
{
int style = mapA.faces[i].nStyles[s];

Expand All @@ -1093,7 +1093,7 @@ void BspMerger::merge_ents(Bsp& mapA, Bsp& mapB)

for (int i = 0; i < mapB.faceCount; i++)
{
for (int s = 0; s < MAX_LIGHTSTYLES; s++)
for (int s = 0; s < MAX_LIGHTMAPS; s++)
{
int style = mapB.faces[i].nStyles[s];

Expand Down Expand Up @@ -1487,9 +1487,26 @@ void BspMerger::merge_faces(Bsp& mapA, Bsp& mapB)
if (i < worldFaceCountA || i >= worldFaceCountA + mapB.faceCount)
continue;


BSPFACE32& face = newFaces[i];

if (face.iPlane >= planeRemap.size())
{
print_log(PRINT_RED, "FATAL ERROR! Invalid plane remap {}\n", face.iPlane);
continue;
}


face.iPlane = planeRemap[face.iPlane];
face.iFirstEdge = face.iFirstEdge + thisSurfEdgeCount;


if (face.iTextureInfo >= texInfoRemap.size())
{
print_log(PRINT_RED, "FATAL ERROR! Invalid texinfo remap {}\n", face.iTextureInfo);
continue;
}

face.iTextureInfo = texInfoRemap[face.iTextureInfo];
g_progress.tick();
}
Expand Down
2 changes: 1 addition & 1 deletion src/cli/ProgressMeter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ void ProgressMeter::tick()
last_progress = now;
}

if (simpleMode)
if (simpleMode && g_app)
{
g_app->updateWindowTitle(glfwGetTime());
return;
Expand Down
32 changes: 29 additions & 3 deletions src/editor/Gui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8991,8 +8991,8 @@ void Gui::drawAbout()

void Gui::drawMergeWindow()
{
ImGui::SetNextWindowSize(ImVec2(500.f, 240.f), ImGuiCond_FirstUseEver);
ImGui::SetNextWindowSizeConstraints(ImVec2(500.f, 240.f), ImVec2(500.f, 240.f));
ImGui::SetNextWindowSize(ImVec2(600.f, 250.f), ImGuiCond_FirstUseEver);
ImGui::SetNextWindowSizeConstraints(ImVec2(600.f, 250.f), ImVec2(600.f, 500.f));
static std::string outPath = "outbsp.bsp";
static std::vector<std::string> inPaths;
static bool DeleteUnusedInfo = true;
Expand All @@ -9002,24 +9002,50 @@ void Gui::drawMergeWindow()
static bool NoScript = true;

bool addNew = false;

static int select_path = 0;

if (inPaths.size() < 1)
{
inPaths.push_back(std::string(""));
}

if (ImGui::Begin(fmt::format("{}###MERGE_WIDGET", get_localized_string(LANG_0825)).c_str(), &showMergeMapWidget))
{
if (ifd::FileDialog::Instance().IsDone("BspMergeDialog"))
{
if (ifd::FileDialog::Instance().HasResult())
{
std::filesystem::path res = ifd::FileDialog::Instance().GetResult();
inPaths[select_path] = res.string();
g_settings.lastdir = stripFileName(res.string());
}
ifd::FileDialog::Instance().Close();
}

for (size_t i = 0; i < inPaths.size(); i++)
{
std::string& s = inPaths[i];
ImGui::InputText(fmt::format(fmt::runtime(get_localized_string(LANG_0826)), i).c_str(), &s);
ImGui::SetNextItemWidth(280);
ImGui::InputText(fmt::format(fmt::runtime("##inpath{}"), i).c_str(), &s);
ImGui::SameLine();
if (ImGui::Button((get_localized_string(LANG_0834) +"##" + std::to_string(i)).c_str()))
{
select_path = i;
ifd::FileDialog::Instance().Open("BspMergeDialog", "Opep bsp model", "BSP file (*.bsp){.bsp},.*", false, g_settings.lastdir);
}
ImGui::SameLine();
ImGui::TextUnformatted(fmt::format(fmt::runtime(get_localized_string(LANG_0826)), i).c_str());

if (s.length() > 1 && i + 1 == inPaths.size())
{
addNew = true;
}
}

ImGui::SetNextItemWidth(280);
ImGui::InputText(get_localized_string(LANG_0828).c_str(), &outPath);

ImGui::Checkbox(get_localized_string(LANG_0829).c_str(), &DeleteUnusedInfo);
ImGui::Checkbox(get_localized_string(LANG_1121).c_str(), &Optimize);
ImGui::Checkbox(get_localized_string(LANG_0830).c_str(), &DeleteHull2);
Expand Down

0 comments on commit b149ef1

Please sign in to comment.