Skip to content

Commit

Permalink
Fix model load. Test C++20 compatibility with linux build
Browse files Browse the repository at this point in the history
Fix model load. Test C++20 compatibility with linux build
  • Loading branch information
Karaulov committed Dec 23, 2022
1 parent 1201c8c commit 7f3dd81
Show file tree
Hide file tree
Showing 28 changed files with 692 additions and 539 deletions.
205 changes: 110 additions & 95 deletions src/bsp/Bsp.cpp

Large diffs are not rendered by default.

42 changes: 21 additions & 21 deletions src/bsp/BspMerger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ Bsp* BspMerger::merge(std::vector<Bsp*> maps, const vec3& gap, const std::string

if (abs(block.offset.x) >= EPSILON || abs(block.offset.y) >= EPSILON || abs(block.offset.z) >= EPSILON)
{
logf(" Apply offset (%6.0f, %6.0f, %6.0f) to %s\n",
logf(" Apply offset (%6.0f, %6.0f, %6.0f) to {}\n",
block.offset.x, block.offset.y, block.offset.z, block.map->bsp_name.c_str());
block.map->move(block.offset);
}
Expand All @@ -50,7 +50,7 @@ Bsp* BspMerger::merge(std::vector<Bsp*> maps, const vec3& gap, const std::string
// TODO: Don't merge linearly. Merge gradually bigger chunks to minimize BSP tree depth.
// Not worth it until more than 27 maps are merged together (merge cube bigger than 3x3x3)

logf("\nMerging %d maps:\n", maps.size());
logf("\nMerging {} maps:\n", maps.size());


// merge maps along X axis to form rows of maps
Expand All @@ -67,7 +67,7 @@ Bsp* BspMerger::merge(std::vector<Bsp*> maps, const vec3& gap, const std::string

if (x != 0)
{
//logf("Merge %d,%d,%d -> %d,%d,%d\n", x, y, z, 0, y, z);
//logf("Merge {},{},{} -> {},{},{}\n", x, y, z, 0, y, z);
std::string merge_name = ++mergeCount < maps.size() ? "row_" + std::to_string(rowId) : "result";
merge(rowStart, block, merge_name);
}
Expand All @@ -87,7 +87,7 @@ Bsp* BspMerger::merge(std::vector<Bsp*> maps, const vec3& gap, const std::string

if (y != 0)
{
//logf("Merge %d,%d,%d -> %d,%d,%d\n", 0, y, z, 0, 0, z);
//logf("Merge {},{},{} -> {},{},{}\n", 0, y, z, 0, 0, z);
std::string merge_name = ++mergeCount < maps.size() ? "layer_" + std::to_string(colId) : "result";
merge(colStart, block, merge_name);
}
Expand All @@ -103,7 +103,7 @@ Bsp* BspMerger::merge(std::vector<Bsp*> maps, const vec3& gap, const std::string

if (z != 0)
{
//logf("Merge %d,%d,%d -> %d,%d,%d\n", 0, 0, z, 0, 0, 0);
//logf("Merge {},{},{} -> {},{},{}\n", 0, 0, z, 0, 0, 0);
merge(layerStart, block, "result");
}
}
Expand All @@ -130,7 +130,7 @@ void BspMerger::merge(MAPBLOCK& dst, MAPBLOCK& src, std::string resultType)
std::string thisName = dst.merge_name.size() ? dst.merge_name : dst.map->bsp_name;
std::string otherName = src.merge_name.size() ? src.merge_name : src.map->bsp_name;
dst.merge_name = std::move(resultType);
logf(" %-8s = %s + %s\n", dst.merge_name.c_str(), thisName.c_str(), otherName.c_str());
logf(" %-8s = {} + {}\n", dst.merge_name, thisName, otherName);

merge(*dst.map, *src.map);
}
Expand Down Expand Up @@ -238,8 +238,8 @@ std::vector<std::vector<std::vector<MAPBLOCK>>> BspMerger::separate(std::vector<
MAPBLOCK& block = blocks[blockIdx];

block.offset = targetMins - block.mins;
//logf("block %d: %.0f %.0f %.0f\n", blockIdx, targetMins.x, targetMins.y, targetMins.z);
//logf("%s offset: %.0f %.0f %.0f\n", block.map->name.c_str(), block.offset.x, block.offset.y, block.offset.z);
//logf("block {}: %.0f %.0f %.0f\n", blockIdx, targetMins.x, targetMins.y, targetMins.z);
//logf("{} offset: %.0f %.0f %.0f\n", block.map->name, block.offset.x, block.offset.y, block.offset.z);

row.push_back(block);

Expand Down Expand Up @@ -829,10 +829,10 @@ void BspMerger::update_map_series_entity_logic(Bsp* mergedMap, std::vector<MAPBL

g_progress.clear();

logf(" Replaced %d level transitions\n", replaced_changelevels);
logf(" Updated %d spawn points\n", updated_spawns);
logf(" Replaced %d monster_* ents with squadmakers\n", updated_monsters);
logf(" Renamed %d entities to prevent conflicts between map sections\n", renameCount);
logf(" Replaced {} level transitions\n", replaced_changelevels);
logf(" Updated {} spawn points\n", updated_spawns);
logf(" Replaced {} monster_* ents with squadmakers\n", updated_monsters);
logf(" Renamed {} entities to prevent conflicts between map sections\n", renameCount);

mergedMap->update_ent_lump();

Expand Down Expand Up @@ -939,7 +939,7 @@ bool BspMerger::merge(Bsp& mapA, Bsp& mapB, bool modelMerge)
{
if (!modelMerge)
{
logf("Replacing %s lump\n", g_lump_names[i]);
logf("Replacing {} lump\n", g_lump_names[i]);
mapA.bsp_header.lump[i].nLength = mapB.bsp_header.lump[i].nLength;
mapA.lumps[i] = new unsigned char[mapB.bsp_header.lump[i].nLength];
memcpy(mapA.lumps[i], mapB.lumps[i], mapB.bsp_header.lump[i].nLength);
Expand All @@ -954,7 +954,7 @@ bool BspMerger::merge(Bsp& mapA, Bsp& mapB, bool modelMerge)
}
else if (!mapB.lumps[i])
{
logf("Keeping %s lump\n", g_lump_names[i]);
logf("Keeping {} lump\n", g_lump_names[i]);
}
else
{
Expand Down Expand Up @@ -1067,10 +1067,10 @@ BSPPLANE BspMerger::separate(Bsp& mapA, Bsp& mapB)

logf("Bounding boxes for each map:\n");
logf("(%6.0f, %6.0f, %6.0f)", amin.x, amin.y, amin.z);
logf(" - (%6.0f, %6.0f, %6.0f) %s\n", amax.x, amax.y, amax.z, mapA.bsp_name.c_str());
logf(" - (%6.0f, %6.0f, %6.0f) {}\n", amax.x, amax.y, amax.z, mapA.bsp_name);

logf("(%6.0f, %6.0f, %6.0f)", bmin.x, bmin.y, bmin.z);
logf(" - (%6.0f, %6.0f, %6.0f) %s\n", bmax.x, bmax.y, bmax.z, mapB.bsp_name.c_str());
logf(" - (%6.0f, %6.0f, %6.0f) {}\n", bmax.x, bmax.y, bmax.z, mapB.bsp_name);
}

return separationPlane;
Expand Down Expand Up @@ -1215,7 +1215,7 @@ void BspMerger::merge_planes(Bsp& mapA, Bsp& mapB)
size_t newLen = mergedPlanes.size() * sizeof(BSPPLANE);
size_t duplicates = (mapA.planeCount + mapB.planeCount) - mergedPlanes.size();

logf("\rRemoved %u duplicate planes \n", duplicates);
logf("\rRemoved {} duplicate planes \n", duplicates);

unsigned char* newPlanes = new unsigned char[newLen];
memcpy(newPlanes, &mergedPlanes[0], newLen);
Expand Down Expand Up @@ -1326,7 +1326,7 @@ void BspMerger::merge_textures(Bsp& mapA, Bsp& mapB)
delete[] mipTexOffsets;


logf("\rRemoved %u duplicate textures \n", duplicates);
logf("\rRemoved {} duplicate textures \n", duplicates);

mapA.replace_lump(LUMP_TEXTURES, newTextureData, newLen);
}
Expand Down Expand Up @@ -1396,7 +1396,7 @@ void BspMerger::merge_texinfo(Bsp& mapA, Bsp& mapB)
unsigned char* newTexinfoData = new unsigned char[newLen];
memcpy(newTexinfoData, &mergedInfo[0], newLen);

logf("\rRemoved %u duplicate tex infos \n", duplicates);
logf("\rRemoved {} duplicate tex infos \n", duplicates);

mapA.replace_lump(LUMP_TEXINFO, newTexinfoData, newLen);
}
Expand Down Expand Up @@ -1835,7 +1835,7 @@ void BspMerger::merge_vis(Bsp& mapA, Bsp& mapB)

mapA.replace_lump(LUMP_VISIBILITY, compressedVisResize, newVisLen);

logf("\rVis data length %u > %u \n", oldLen, newVisLen);
logf("\rVis data length {} > {} \n", oldLen, newVisLen);

delete[] decompressedVis;
delete[] compressedVis;
Expand Down Expand Up @@ -1977,7 +1977,7 @@ void BspMerger::create_merge_headnodes(Bsp& mapA, Bsp& mapB, BSPPLANE separation
BSPCLIPNODE newHeadNodes[NEW_NODE_COUNT];
for (int i = 0; i < NEW_NODE_COUNT; i++)
{
//logf("HULL %d starts at %d\n", i+1, thisWorld.iHeadnodes[i+1]);
//logf("HULL {} starts at {}\n", i+1, thisWorld.iHeadnodes[i+1]);
newHeadNodes[i] = {
separationPlaneIdx, // plane idx
{ // child nodes
Expand Down
26 changes: 13 additions & 13 deletions src/bsp/Wad.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,23 +56,23 @@ bool Wad::readInfo()

if (!fileExists(file))
{
logf("%s does not exist!\n", filename.c_str());
logf("{} does not exist!\n", filename);
return false;
}

filedata = (unsigned char*)loadFile(file, fileLen);

if (!filedata)
{
logf("%s does not exist!\n", filename.c_str());
logf("{} does not exist!\n", filename);
return false;
}

if (fileLen < sizeof(WADHEADER))
{
delete[] filedata;
filedata = NULL;
logf("%s is not wad file[small]!\n", filename.c_str());
logf("{} is not wad file[small]!\n", filename);
return false;
}

Expand All @@ -84,15 +84,15 @@ bool Wad::readInfo()
{
delete[] filedata;
filedata = NULL;
logf("%s is not wad file[invalid header]!\n", filename.c_str());
logf("{} is not wad file[invalid header]!\n", filename);
return false;
}

if (header.nDirOffset >= (int)fileLen)
{
delete[] filedata;
filedata = NULL;
logf("%s is not wad file[buffer overrun]!\n", filename.c_str());
logf("{} is not wad file[buffer overrun]!\n", filename);
return false;
}

Expand All @@ -105,7 +105,7 @@ bool Wad::readInfo()

usableTextures = false;

//logf("D %d %d\n", header.nDirOffset, header.nDir);
//logf("D {} {}\n", header.nDirOffset, header.nDir);

for (int i = 0; i < header.nDir; i++)
{
Expand All @@ -130,7 +130,7 @@ bool Wad::readInfo()

if (!usableTextures)
{
logf("Info: %s contains no regular textures\n", basename(filename).c_str());
logf("Info: {} contains no regular textures\n", basename(filename));
if (!dirEntries.size())
return false;
}
Expand Down Expand Up @@ -202,7 +202,7 @@ WADTEX* Wad::readTexture(const std::string& texname, int* texturetype)
memcpy((char*)&mtex, &filedata[offset], sizeof(BSPMIPTEX));
offset += sizeof(BSPMIPTEX);
if (g_settings.verboseLogs)
logf("Load wad BSPMIPTEX name %s size %d/%d\n", mtex.szName, mtex.nWidth, mtex.nHeight);
logf("Load wad BSPMIPTEX name {} size {}/{}\n", mtex.szName, mtex.nWidth, mtex.nHeight);
int w = mtex.nWidth;
int h = mtex.nHeight;
int sz = w * h; // miptex 0
Expand All @@ -224,7 +224,7 @@ WADTEX* Wad::readTexture(const std::string& texname, int* texturetype)
tex->data = data;
tex->needclean = true;
if (g_settings.verboseLogs)
logf("Return WADTEX name %s size %d/%d\n", tex->szName, tex->nWidth, tex->nHeight);
logf("Return WADTEX name {} size {}/{}\n", tex->szName, tex->nWidth, tex->nHeight);
return tex;
}

Expand Down Expand Up @@ -435,7 +435,7 @@ WADTEX* create_wadtex(const char* name, COLOR3* rgbdata, int width, int height)
COLOR3* ConvertWadTexToRGB(WADTEX* wadTex)
{
if (g_settings.verboseLogs)
logf("Convert WADTEX to RGB name %s size %d/%d\n", wadTex->szName, wadTex->nWidth, wadTex->nHeight);
logf("Convert WADTEX to RGB name {} size {}/{}\n", wadTex->szName, wadTex->nWidth, wadTex->nHeight);
int lastMipSize = (wadTex->nWidth / 8) * (wadTex->nHeight / 8);

COLOR3* palette = (COLOR3*)(wadTex->data + wadTex->nOffsets[3] + lastMipSize + 2 - 40);
Expand All @@ -451,13 +451,13 @@ COLOR3* ConvertWadTexToRGB(WADTEX* wadTex)
}

if (g_settings.verboseLogs)
logf("Converted WADTEX to RGB name %s size %d/%d\n", wadTex->szName, wadTex->nWidth, wadTex->nHeight);
logf("Converted WADTEX to RGB name {} size {}/{}\n", wadTex->szName, wadTex->nWidth, wadTex->nHeight);
return imageData;
}
COLOR3* ConvertMipTexToRGB(BSPMIPTEX* tex)
{
if (g_settings.verboseLogs)
logf("Convert BSPMIPTEX to RGB name %s size %d/%d\n", tex->szName, tex->nWidth, tex->nHeight);
logf("Convert BSPMIPTEX to RGB name {} size {}/{}\n", tex->szName, tex->nWidth, tex->nHeight);
int lastMipSize = (tex->nWidth / 8) * (tex->nHeight / 8);

COLOR3* palette = (COLOR3*)(((unsigned char*)tex) + tex->nOffsets[3] + lastMipSize + 2);
Expand All @@ -473,6 +473,6 @@ COLOR3* ConvertMipTexToRGB(BSPMIPTEX* tex)
}

if (g_settings.verboseLogs)
logf("Converted BSPMIPTEX to RGB name %s size %d/%d\n", tex->szName, tex->nWidth, tex->nHeight);
logf("Converted BSPMIPTEX to RGB name {} size {}/{}\n", tex->szName, tex->nWidth, tex->nHeight);
return imageData;
}
4 changes: 2 additions & 2 deletions src/bsp/remap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ void print_stat(int indent, int stat, const char* data)
}
int statabs = abs(stat);

logf("%s %d %s%s\n", stat > 0 ? "Deleted" : "Added", statabs, data, statabs > 1 ? plural : "");
logf("{} {} {}{}\n", stat > 0 ? "Deleted" : "Added", statabs, data, statabs > 1 ? plural : "");
}

void print_stat_mem(int indent, int bytes, const char* data)
Expand All @@ -104,7 +104,7 @@ void print_stat_mem(int indent, int bytes, const char* data)
{
return;
}
logf("%s %.2f KB of %s\n", bytes > 0 ? "Deleted" : "Added", abs(bytes) / 1024.0f, data);
logf("{} %.2f KB of {}\n", bytes > 0 ? "Deleted" : "Added", abs(bytes) / 1024.0f, data);
}

void STRUCTCOUNT::print_delete_stats(int indent)
Expand Down
4 changes: 2 additions & 2 deletions src/cli/CommandLine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ bool CommandLine::hasOptionVector(const std::string& optionName)

if (parts.size() != 3)
{
logf("ERROR: invalid number of coordinates for option %s\n", optionName.c_str());
logf("ERROR: invalid number of coordinates for option {}\n", optionName);
return false;
}

Expand All @@ -106,7 +106,7 @@ vec3 CommandLine::getOptionVector(const std::string& optionName)

if (parts.size() != 3)
{
logf("ERROR: invalid number of coordinates for option %s\n", optionName.c_str());
logf("ERROR: invalid number of coordinates for option {}\n", optionName);
return ret;
}

Expand Down
2 changes: 1 addition & 1 deletion src/cli/ProgressMeter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ void ProgressMeter::update(const char* newTitle, int totalProgressTicks)
progress_total = totalProgressTicks;
if (simpleMode && !hide)
{
logf((std::string(newTitle) + "\n").c_str());
logf(std::string(newTitle) + "\n");
}
}

Expand Down
Loading

0 comments on commit 7f3dd81

Please sign in to comment.