Skip to content

Commit

Permalink
Fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
UnrealKaraulov committed Dec 15, 2024
1 parent ef64a23 commit 7cbdad1
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 53 deletions.
91 changes: 53 additions & 38 deletions src/bsp/Bsp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1320,33 +1320,35 @@ bool Bsp::should_resize_lightmap(LIGHTMAP& oldLightmap, LIGHTMAP& newLightmap)
}


void Bsp::resize_all_lightmaps(bool logged)
void Bsp::resize_all_lightmaps(bool logged)
{
if (logged)
if (logged)
{
g_progress.update("Resize lightmaps", faceCount);
if (!undo_lightmaps.size())
}
if (!undo_lightmaps.size())
{
save_undo_lightmaps(true);
}

std::vector<COLOR3> newLightData;

for (int faceId = 0; faceId < faceCount; faceId++)
for (int faceId = 0; faceId < faceCount; faceId++)
{
BSPFACE32& face = faces[faceId];
int newLightMapOffset = (int)newLightData.size();
for (int lightId = 0; lightId < MAX_LIGHTMAPS; lightId++)
int newLightMapOffset = static_cast<int>(newLightData.size());
for (int lightId = 0; lightId < MAX_LIGHTMAPS; lightId++)
{
if (face.nStyles[lightId] == 255 || face.nLightmapOffset < 0)
if (face.nStyles[lightId] == 255 || face.nLightmapOffset < 0)
{
continue;
int size[2];

if (faceId < (int)undo_lightmaps.size())
}
int size[2] = { 0, 0 };
if (faceId < static_cast<int>(undo_lightmaps.size()))
{
size[0] = undo_lightmaps[faceId].width;
size[1] = undo_lightmaps[faceId].height;
}
else
{
size[0] = size[1] = 0;
}
int newsize[2];
GetFaceLightmapSize(faceId, newsize);

Expand All @@ -1356,43 +1358,42 @@ void Bsp::resize_all_lightmaps(bool logged)
COLOR3* data = (COLOR3*)(lightdata + offset);

std::vector<COLOR3> newdata;

if (newsize[0] == size[0] && size[1] == newsize[1])
if (newsize[0] == size[0] && newsize[1] == size[1])
{
if (lightdata && offset < lightDataLength && lightId < undo_lightmaps[faceId].layers)
if (lightdata && offset < lightDataLength && lightId < undo_lightmaps[faceId].layers)
{
newdata.insert(newdata.end(), data, data + size[0] * size[1]);
}
else
else
{
newdata.resize(size[0] * size[1]);
std::fill(newdata.begin(), newdata.end(), COLOR3(255, 255, 255));
newdata.resize(size[0] * size[1], COLOR3(255, 255, 255));
}
}
else
else
{
if (lightmapSz > 0 && lightdata && offset < lightDataLength && lightId < undo_lightmaps[faceId].layers)
if (lightmapSz > 0 && lightdata && offset < lightDataLength && lightId < undo_lightmaps[faceId].layers)
{
scaleImage(data, newdata, size[0], size[1], newsize[0], newsize[1]);
}
else
else
{
newdata.resize(newsize[0] * newsize[1]);
std::fill(newdata.begin(), newdata.end(), COLOR3(255, 255, 255));
newdata.resize(newsize[0] * newsize[1], COLOR3(255, 255, 255));
}
}
newLightData.insert(newLightData.end(), newdata.begin(), newdata.end());
}

if (face.nLightmapOffset >= 0)
if (face.nLightmapOffset >= 0)
{
face.nLightmapOffset = newLightMapOffset * sizeof(COLOR3);
}
if (logged)
if (logged)
{
g_progress.tick();
}
}

if (logged)
if (logged)
{
g_progress.clear();
g_progress = ProgressMeter();
Expand All @@ -1402,6 +1403,7 @@ void Bsp::resize_all_lightmaps(bool logged)
memcpy(tmpLump, newLightData.data(), newLightData.size() * sizeof(COLOR3));
replace_lump(LUMP_LIGHTING, tmpLump, newLightData.size() * sizeof(COLOR3));
save_undo_lightmaps(logged);

delete[] tmpLump;
}

Expand Down Expand Up @@ -9432,6 +9434,9 @@ bool Bsp::cull_leaf_faces(int leafIdx)
g_progress.clear();
g_progress = ProgressMeter();

save_undo_lightmaps();
resize_all_lightmaps();

STRUCTCOUNT count_2(this);
count_1.sub(count_2);
count_1.print_delete_stats(1);
Expand Down Expand Up @@ -9565,6 +9570,9 @@ void Bsp::remove_faces_by_content(int content)
removedFaces++;
}

save_undo_lightmaps();
resize_all_lightmaps();

g_progress.clear();
g_progress = ProgressMeter();

Expand All @@ -9579,6 +9587,16 @@ bool Bsp::remove_face(int faceIdx, bool fromModels)
return false;
}

// Create a vector to hold all the faces except the one to be removed
std::vector<BSPFACE32> all_faces;
for (int f = 0; f < faceCount; f++)
{
if (f != faceIdx)
{
all_faces.push_back(faces[f]);
}
}

// Shift face count in models
for (int m = 0; m < modelCount; m++)
{
Expand Down Expand Up @@ -9607,16 +9625,6 @@ bool Bsp::remove_face(int faceIdx, bool fromModels)

if (!fromModels)
{
// Create a vector to hold all the faces except the one to be removed
std::vector<BSPFACE32> all_faces;
for (int f = 0; f < faceCount; f++)
{
if (f != faceIdx)
{
all_faces.push_back(faces[f]);
}
}

// Shift face count in nodes
for (int n = 0; n < nodeCount; n++)
{
Expand Down Expand Up @@ -11395,7 +11403,10 @@ void Bsp::ExportToObjWIP(const std::string& path, int iscale, bool lightmapmode,
print_log(PRINT_RED, " Merged {} verts \n", merged);
remove_unused_model_structures(CLEAN_EDGES_FORCE | CLEAN_TEXINFOS_FORCE);


save_undo_lightmaps();
resize_all_lightmaps();

bsprend->reuploadTextures();
bsprend->loadLightmaps();

Expand Down Expand Up @@ -12037,6 +12048,10 @@ void Bsp::ExportToMapWIP(const std::string& path, bool selected, bool merge_face
remove_faces_by_content(CONTENTS_SKY);
remove_faces_by_content(CONTENTS_SOLID);


save_undo_lightmaps();
resize_all_lightmaps();

remove_unused_model_structures();
}

Expand Down
22 changes: 7 additions & 15 deletions src/editor/Gui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4970,12 +4970,8 @@ void Gui::drawMenuBar()
{
map->remove_faces_by_content(CONTENTS_SKY);

map->save_undo_lightmaps();
map->resize_all_lightmaps();
rend->loadLightmaps();
rend->preRenderFaces();

map->update_ent_lump();
map->update_lump_pointers();

rend->pushUndoState("REMOVE FACES FROM SKY", EDIT_MODEL_LUMPS);
}
Expand All @@ -4990,13 +4986,9 @@ void Gui::drawMenuBar()
{
map->remove_faces_by_content(CONTENTS_SOLID);


map->save_undo_lightmaps();
map->resize_all_lightmaps();
rend->loadLightmaps();
rend->preRenderFaces();

map->update_ent_lump();
map->update_lump_pointers();
rend->pushUndoState("REMOVE FACES FROM SOLID", EDIT_MODEL_LUMPS);
}
if (ImGui::IsItemHovered() && g.HoveredIdTimer > g_tooltip_delay)
Expand Down Expand Up @@ -5725,6 +5717,9 @@ void Gui::drawMenuBar()
}
}

map->save_undo_lightmaps();
map->resize_all_lightmaps();

rend->loadLightmaps();
rend->preRenderFaces();

Expand Down Expand Up @@ -12535,11 +12530,8 @@ void Gui::drawFaceEditorWidget()
app->pickInfo.selectedFaces.pop_back();
}

mapRenderer->loadLightmaps();
mapRenderer->preRenderFaces();

map->update_ent_lump();
map->update_lump_pointers();
map->save_undo_lightmaps();
map->resize_all_lightmaps();

mapRenderer->pushUndoState("DELETE FACES", EDIT_MODEL_LUMPS);
}
Expand Down

0 comments on commit 7cbdad1

Please sign in to comment.