Skip to content

Commit

Permalink
Open dialog bugfix, umd export issues fixed
Browse files Browse the repository at this point in the history
  • Loading branch information
UnrealKaraulov committed Dec 16, 2024
1 parent 9af382f commit 1cae411
Show file tree
Hide file tree
Showing 4 changed files with 71 additions and 71 deletions.
107 changes: 65 additions & 42 deletions src/editor/Gui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,13 +59,13 @@ struct cell
cell_type type;
};


int cell_idx(const vec3& pos, const vec3& mins, float cell_size, int cell_x, int cell_y, int cell_layers, int layer) {
int y = static_cast<int>(floatRound((pos.x - mins.x) / cell_size));
int x = static_cast<int>(floatRound((pos.y - mins.y) / cell_size));
int lvl = static_cast<int>(floatRound((pos.z - mins.z) / cell_size));
int x = static_cast<int>(std::round((pos.x - mins.x) / cell_size));
int y = static_cast<int>(std::round((pos.y - mins.y) / cell_size));
int lvl = static_cast<int>(std::round((pos.z - mins.z) / cell_size));
y = cell_y - 1 - y;
int index = (lvl * cell_layers + layer) * cell_y * cell_x + y * cell_x + x;
return index < 0 ? 0 : index;
return index;
}

void IMGUI_TOOLTIP(ImGuiContext& g, const std::string& IMGUI_TOOLTIP)
Expand Down Expand Up @@ -1756,9 +1756,6 @@ void Gui::drawBspContexMenu()
void Gui::OpenFile(const std::string& file)
{
Bsp* map = app->getSelectedMap();
BspRenderer* rend = map ? map->getBspRender() : NULL;
if (!rend)
return;

std::string pathlowercase = toLowerCase(file);
if (ends_with(pathlowercase, ".wad"))
Expand All @@ -1772,6 +1769,9 @@ void Gui::OpenFile(const std::string& file)

if (map)
{
BspRenderer* rend = map ? map->getBspRender() : NULL;
if (!rend)
return;
bool foundInMap = false;
for (auto& wad : rend->wads)
{
Expand Down Expand Up @@ -1825,8 +1825,12 @@ void Gui::OpenFile(const std::string& file)
app->addMap(tmpMap);
app->selectMap(tmpMap);
}
else
else
{
if (!ends_with(pathlowercase, ".bsp"))
{
print_log(get_localized_string(LANG_0898), file);
}
Bsp* tmpMap = new Bsp(file);
app->addMap(tmpMap);
app->selectMap(tmpMap);
Expand Down Expand Up @@ -3165,10 +3169,12 @@ void Gui::drawMenuBar()
}

FlushConsoleLog();

mins += rend->mapOffset;
maxs += rend->mapOffset;
mins -= cell_size * 1.0f;
maxs += cell_size * 1.0f;

mins -= cell_size * 0.5f;
maxs += cell_size * 0.5f;

print_log("Found real world mins/maxs! Map offsets {},{},{}\n", rend->mapOffset.x, rend->mapOffset.y, rend->mapOffset.z);

Expand All @@ -3177,29 +3183,32 @@ void Gui::drawMenuBar()
int hull = hull_for_export;

int cell_x = 0;
for (float x = mins.x; x < maxs.x; x += cell_size)
for (float x = mins.x; x <= maxs.x; x += cell_size)
{
cell_x += 1;
}
int cell_y = 0;
for (float y = mins.y; y < maxs.y; y += cell_size)
for (float y = mins.y; y <= maxs.y; y += cell_size)
{
cell_y += 1;
}

int cell_levels = 0;
for (float z = mins.z; z < maxs.z; z += cell_size)
for (float z = mins.z; z <= maxs.z; z += cell_size)
{
cell_levels += 1;
}
int cell_layers = 2;

int cell_layers = 1;

std::vector<std::string> umdTextures{};


std::vector<cell> cell_list(cell_x * cell_y * cell_levels * cell_layers);

memset(&cell_list[0], 0, cell_list.size() * sizeof(cell));

print_log("Pre vars calculated. Map mins/maxs {},{},{} / {},{},{}!\n", mins.x, mins.y, mins.z, maxs.x, maxs.y, maxs.z);
print_log("Pre vars calculated. CellX/Y {}/{} /\n Map mins/maxs {},{},{} / {},{},{}!\n", cell_x, cell_y, mins.x, mins.y, mins.z, maxs.x, maxs.y, maxs.z);
FlushConsoleLog();

for (size_t entIdx = 0; entIdx < map->ents.size(); entIdx++)
Expand All @@ -3211,7 +3220,14 @@ void Gui::drawMenuBar()
auto entity = map->ents[entIdx];
if (modelIdx < 0)
{
int idx = cell_idx(entity->origin, mins, cell_size * 1.0f, cell_x, cell_y, cell_layers, 1);
int idx = cell_idx(entity->origin, mins, cell_size * 1.0f, cell_x, cell_y, cell_layers, cell_layers - 1);

if ((size_t)idx >= cell_list.size())
{
print_log("Fatal crash[#3], index {} out of bounds {}\n", idx, cell_list.size());
return;
}

if (idx < (int)cell_list.size())
{
if (entity->classname.find("light") != std::string::npos)
Expand Down Expand Up @@ -3289,14 +3305,18 @@ void Gui::drawMenuBar()
std::vector<vec3> offsets =
{
{0, 0, 0},
{cell_size / 3.f, 0, 0},
{-cell_size / 3.f, 0, 0},
{0, cell_size / 3.f, 0},
{0, -cell_size / 3.f, 0},
{0, 0, cell_size / 3.f},
{0, 0, -cell_size / 3.f},
{0, 0, cell_size / 2.2f},
{0, 0, -cell_size / 2.2f}
{cell_size / 4.f, 0, 0},
{-cell_size / 4.f, 0, 0},
{0, cell_size / 4.f, 0},
{0, -cell_size / 4.f, 0},
{0, 0, cell_size / 4.f},
{0, 0, -cell_size / 4.f},
{cell_size / 2.f, 0, 0},
{-cell_size / 2.f, 0, 0},
{0, cell_size / 2.f, 0},
{0, -cell_size / 2.f, 0},
{0, 0, cell_size / 2.f},
{0, 0, -cell_size / 2.f},
};

std::vector<float> parallel_X{};
Expand All @@ -3319,7 +3339,7 @@ void Gui::drawMenuBar()

for (int layer = 0; layer < cell_layers; layer++)
{
if (layer != 0)
if (layer != cell_layers - 1)
{
continue;
}
Expand All @@ -3345,7 +3365,10 @@ void Gui::drawMenuBar()
int index = cell_idx(pos, mins, (float)cell_size, cell_x, cell_y, cell_layers, layer);

if ((size_t)index >= cell_list.size())
{
print_log("Fatal crash[#2], index {} out of bounds {}\n", index, cell_list.size());
return;
}
cell& cur_cell = cell_list[index];
expandBoundingBox(pos, pos_debug_mins, pos_debug_maxs);

Expand Down Expand Up @@ -8298,7 +8321,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 || modelIdx < 0)
{
ImGui::Text(get_localized_string(LANG_1180).c_str());
}
Expand Down Expand Up @@ -8405,7 +8428,7 @@ void Gui::drawTransformWidget()
ImGui::Text(get_localized_string(LANG_0690).c_str());
ImGui::PushItemWidth(inputWidth);

if (!app->isTransformableSolid || app->modelUsesSharedStructures || app->transformMode != TRANSFORM_MODE_SCALE)
if (modelIdx==0 ||!app->isTransformableSolid || app->modelUsesSharedStructures || app->transformMode != TRANSFORM_MODE_SCALE)
{
ImGui::BeginDisabled();
}
Expand All @@ -8429,7 +8452,7 @@ void Gui::drawTransformWidget()
if (ImGui::IsItemHovered() || ImGui::IsItemActive())
guiHoverAxis = 2;

if (!app->isTransformableSolid || app->modelUsesSharedStructures || app->transformMode != TRANSFORM_MODE_SCALE)
if (modelIdx == 0 || !app->isTransformableSolid || app->modelUsesSharedStructures || app->transformMode != TRANSFORM_MODE_SCALE)
{
ImGui::EndDisabled();
}
Expand All @@ -8451,7 +8474,7 @@ void Gui::drawTransformWidget()
ImGui::AlignTextToFramePadding();
ImGui::Text(get_localized_string(LANG_0694).c_str()); ImGui::NextColumn();

if (app->transformMode == TRANSFORM_MODE_NONE)
if (modelIdx == 0 || app->transformMode == TRANSFORM_MODE_NONE)
{
ImGui::BeginDisabled();
}
Expand All @@ -8463,7 +8486,7 @@ void Gui::drawTransformWidget()
}

ImGui::NextColumn();
if (modelIdx < 0)
if (modelIdx <= 0)
{
ImGui::BeginDisabled();
if (app->transformTarget == TRANSFORM_ORIGIN
Expand All @@ -8472,7 +8495,7 @@ void Gui::drawTransformWidget()
app->transformTarget = TRANSFORM_OBJECT;
}
}
if (!app->isTransformableSolid || app->modelUsesSharedStructures)
if (modelIdx == 0 || !app->isTransformableSolid || app->modelUsesSharedStructures)
{
if (app->transformTarget == TRANSFORM_VERTEX)
{
Expand All @@ -8485,12 +8508,12 @@ void Gui::drawTransformWidget()
pickCount++;
vertPickCount++;
}
if (!app->isTransformableSolid || app->modelUsesSharedStructures)
if (modelIdx == 0 || !app->isTransformableSolid || app->modelUsesSharedStructures)
{
ImGui::EndDisabled();
}

if (app->transformMode == TRANSFORM_MODE_SCALE)
if (modelIdx == 0 || app->transformMode == TRANSFORM_MODE_SCALE)
{
ImGui::BeginDisabled();
if (app->transformTarget == TRANSFORM_ORIGIN)
Expand All @@ -8506,16 +8529,16 @@ void Gui::drawTransformWidget()
pickCount++;
vertPickCount++;
}
if (modelIdx < 0)
if (modelIdx <= 0)
{
ImGui::EndDisabled();
}
ImGui::NextColumn();
if (app->transformMode == TRANSFORM_MODE_SCALE)
if (modelIdx == 0 || app->transformMode == TRANSFORM_MODE_SCALE)
{
ImGui::EndDisabled();
}
if (app->transformMode == TRANSFORM_MODE_NONE)
if (modelIdx == 0 || app->transformMode == TRANSFORM_MODE_NONE)
{
ImGui::EndDisabled();
}
Expand All @@ -8524,15 +8547,15 @@ void Gui::drawTransformWidget()
ImGui::NextColumn();
ImGui::RadioButton(get_localized_string(LANG_1111).c_str(), &app->transformMode, TRANSFORM_MODE_MOVE);
ImGui::NextColumn();
if (modelIdx < 0 || !app->isTransformableSolid || app->modelUsesSharedStructures)
if (modelIdx <= 0 || !app->isTransformableSolid || app->modelUsesSharedStructures)
{
if (app->transformMode == TRANSFORM_MODE_SCALE)
app->transformMode = TRANSFORM_MODE_MOVE;
ImGui::BeginDisabled();
}
ImGui::RadioButton(get_localized_string(LANG_1112).c_str(), &app->transformMode, TRANSFORM_MODE_SCALE);
ImGui::NextColumn();
if (modelIdx < 0 || !app->isTransformableSolid || app->modelUsesSharedStructures)
if (modelIdx <= 0 || !app->isTransformableSolid || app->modelUsesSharedStructures)
{
ImGui::EndDisabled();
}
Expand Down Expand Up @@ -8573,10 +8596,10 @@ void Gui::drawTransformWidget()
}

ImGui::SameLine();
if (app->transformMode != TRANSFORM_MODE_MOVE || app->transformTarget != TRANSFORM_OBJECT || app->modelUsesSharedStructures)
if (modelIdx == 0 || app->transformMode != TRANSFORM_MODE_MOVE || app->transformTarget != TRANSFORM_OBJECT || app->modelUsesSharedStructures)
ImGui::BeginDisabled();
ImGui::Checkbox(get_localized_string(LANG_0703).c_str(), &app->moveOrigin);
if (app->transformMode != TRANSFORM_MODE_MOVE || app->transformTarget != TRANSFORM_OBJECT || app->modelUsesSharedStructures)
if (modelIdx == 0 || app->transformMode != TRANSFORM_MODE_MOVE || app->transformTarget != TRANSFORM_OBJECT || app->modelUsesSharedStructures)
ImGui::EndDisabled();

if (ImGui::IsItemHovered(ImGuiHoveredFlags_::ImGuiHoveredFlags_AllowWhenDisabled))
Expand All @@ -8603,7 +8626,7 @@ void Gui::drawTransformWidget()
ImGui::Text(fmt::format("Model origin: {:.2f} {:.2f} {:.2f}", map->models[modelIdx].vOrigin.x, map->models[modelIdx].vOrigin.y, map->models[modelIdx].vOrigin.z).c_str());
vec3 modelCenter = getCenter(map->models[modelIdx].nMins, map->models[modelIdx].nMaxs);
ImGui::Text(fmt::format("Model center: {:.2f} {:.2f} {:.2f}", modelCenter.x, modelCenter.y, modelCenter.z).c_str());
ImGui::Text(fmt::format("Model bounds: \n{:.2f} {:.2f} {:.2f} / {:.2f} {:.2f} {:.2f}", map->models[modelIdx].nMins.x, map->models[modelIdx].nMins.y, map->models[modelIdx].nMins.z, map->models[modelIdx].nMaxs.x, map->models[modelIdx].nMaxs.y, map->models[modelIdx].nMaxs.z).c_str());
ImGui::Text(fmt::format("Model size/bounds: {:.2f} {:.2f} {:.2f} \n{:.2f} {:.2f} {:.2f} / {:.2f} {:.2f} {:.2f}", map->models[modelIdx].nMaxs.x - map->models[modelIdx].nMins.x, map->models[modelIdx].nMaxs.y - map->models[modelIdx].nMins.y, map->models[modelIdx].nMaxs.z - map->models[modelIdx].nMins.z, map->models[modelIdx].nMins.x, map->models[modelIdx].nMins.y, map->models[modelIdx].nMins.z, map->models[modelIdx].nMaxs.x, map->models[modelIdx].nMaxs.y, map->models[modelIdx].nMaxs.z).c_str());
}

if (currentTransformMode != app->transformMode || currentTransformTarget != app->transformTarget)
Expand Down
3 changes: 1 addition & 2 deletions src/editor/Gui.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ class Gui
void copyLightmap();
void pasteLightmap();
void refresh();

void OpenFile(const std::string& file);


bool polycount = false;
Expand Down Expand Up @@ -152,7 +152,6 @@ class Gui
void drawEntityReport();
StatInfo calcStat(std::string name, unsigned int val, unsigned int max, bool isMem);
ModelInfo calcModelStat(Bsp* map, STRUCTUSAGE* modelInfo, unsigned int val, unsigned int max, bool isMem);
void OpenFile(const std::string& file);
void checkValidHulls();
void reloadLimits();
void ExportOneBigLightmap(Bsp* map);
Expand Down
30 changes: 4 additions & 26 deletions src/editor/Renderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -101,30 +101,7 @@ void drop_callback(GLFWwindow* window, int count, const char** paths)
if (fileExists(tmpPath.string()))
{
g_settings.AddRecentFile(tmpPath.string());
if (ends_with(lowerPath, ".bsp"))
{
print_log(get_localized_string(LANG_0896), tmpPath.string());
g_app->addMap(new Bsp(tmpPath.string()));
}
else if (ends_with(lowerPath, ".mdl"))
{
print_log(get_localized_string(LANG_0897), tmpPath.string());
g_app->addMap(new Bsp(tmpPath.string()));
}
else if (ends_with(lowerPath, ".spr"))
{
print_log(get_localized_string(LANG_0897), tmpPath.string());
g_app->addMap(new Bsp(tmpPath.string()));
}
else if (ends_with(lowerPath, ".csm"))
{
print_log(get_localized_string(LANG_0897), tmpPath.string());
g_app->addMap(new Bsp(tmpPath.string()));
}
else
{
print_log(get_localized_string(LANG_0898), tmpPath.string());
}
g_app->gui->OpenFile(tmpPath.string());
}
else
{
Expand Down Expand Up @@ -1379,9 +1356,10 @@ void Renderer::renderLoop()
make_screenshot_target++;


if (make_screenshot <= 0 && !ortho_save_tga)
if (make_screenshot <= 0)
{
is_closing = true;
if (!ortho_save_tga)
is_closing = true;
}
}
else
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.45";
std::string g_version_string = "NewBSPGuy v4.46";


#ifdef WIN32
Expand Down

0 comments on commit 1cae411

Please sign in to comment.