Skip to content

Commit

Permalink
Revert back VIS validation
Browse files Browse the repository at this point in the history
  • Loading branch information
UnrealKaraulov committed Dec 17, 2023
1 parent badac0f commit 2edc1e1
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 27 deletions.
4 changes: 2 additions & 2 deletions src/bsp/Bsp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1806,7 +1806,7 @@ unsigned int Bsp::remove_unused_visdata(bool* usedLeaves, BSPLEAF32* oldLeaves,
int decompressedVisSize = oldLeafCount * oldVisRowSize;
unsigned char* decompressedVis = new unsigned char[decompressedVisSize];
memset(decompressedVis, 0xFF, decompressedVisSize);
decompress_vis_lump(oldLeaves, lumps[LUMP_VISIBILITY], decompressedVis,
decompress_vis_lump(this,oldLeaves, lumps[LUMP_VISIBILITY], decompressedVis,
oldWorldLeaves, oldVisLeafCount - 1, oldVisLeafCount - 1, oldLeavesMemSize, bsp_header.lump[LUMP_VISIBILITY].nLength);

if (oldVisRowSize != newVisRowSize)
Expand Down Expand Up @@ -4302,7 +4302,7 @@ bool Bsp::validate()
int decompressedVisSize = leafCount * newVisRowSize;
unsigned char* decompressedVis = new unsigned char[decompressedVisSize];
memset(decompressedVis, 0xFF, decompressedVisSize);
decompress_vis_lump(leaves, visdata, decompressedVis,
decompress_vis_lump(this,leaves, visdata, decompressedVis,
models[0].nVisLeafs, leafCount, leafCount, decompressedVisSize, bsp_header.lump[LUMP_VISIBILITY].nLength);
delete decompressedVis;

Expand Down
4 changes: 2 additions & 2 deletions src/bsp/BspMerger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1808,12 +1808,12 @@ void BspMerger::merge_vis(Bsp& mapA, Bsp& mapB)

// decompress this map's world leaves
// model leaves don't need to be decompressed because the game ignores VIS for them.
decompress_vis_lump(allLeaves, mapA.visdata, decompressedVis,
decompress_vis_lump(&mapA, allLeaves, mapA.visdata, decompressedVis,
thisWorldLeafCount, thisVisLeaves, totalVisLeaves, mapA.bsp_header.lump[LUMP_VISIBILITY].nLength, mapA.visDataLength);

// decompress other map's world-leaf vis data (skip empty first leaf, which now only the first map should have)
unsigned char* decompressedOtherVis = decompressedVis + thisWorldLeafCount * newVisRowSize;
decompress_vis_lump(allLeaves + thisWorldLeafCount, mapB.visdata, decompressedOtherVis,
decompress_vis_lump(&mapB,allLeaves + thisWorldLeafCount, mapB.visdata, decompressedOtherVis,
otherWorldLeafCount, otherLeafCount, totalVisLeaves, mapB.bsp_header.lump[LUMP_VISIBILITY].nLength, mapB.visDataLength);

// shift mapB's world leaves after mapA's world leaves
Expand Down
44 changes: 22 additions & 22 deletions src/qtools/vis.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ bool shiftVis(unsigned char* vis, int len, int offsetLeaf, int shift)

if (shift < 0)
{
// TODO: memcpy for negative shifts
// TODO: memcpy for negative shifts
bitShifts += byteShifts * 8;
byteShifts = 0;
}
Expand Down Expand Up @@ -142,12 +142,12 @@ bool shiftVis(unsigned char* vis, int len, int offsetLeaf, int shift)
}
}
if (overflow)
print_log(PRINT_RED | PRINT_INTENSITY, get_localized_string(LANG_0993),overflow);
print_log(PRINT_RED | PRINT_INTENSITY, get_localized_string(LANG_0993), overflow);


if (byteShifts > 0)
{
// TODO: detect overflows here too
// TODO: detect overflows here too
if (shift > 0)
{
unsigned char* temp = new unsigned char[MAX_MAP_LEAVES / 8];
Expand All @@ -163,7 +163,7 @@ bool shiftVis(unsigned char* vis, int len, int offsetLeaf, int shift)
}
else
{
// TODO LOL
// TODO LOL
}

}
Expand All @@ -175,7 +175,7 @@ bool shiftVis(unsigned char* vis, int len, int offsetLeaf, int shift)
// iterationLeaves = number of leaves to decompress vis for
// visDataLeafCount = total leaves in this map (exluding the shared solid leaf 0)
// newNumLeaves = total leaves that will be in the map after merging is finished (again, excluding solid leaf 0)
void decompress_vis_lump(BSPLEAF32* leafLump, unsigned char* visLump, unsigned char* output,
void decompress_vis_lump(Bsp* map, BSPLEAF32* leafLump, unsigned char* visLump, unsigned char* output,
int iterationLeaves, int visDataLeafCount, int newNumLeaves, int leafMemSize, int visLumpMemSize)
{
unsigned char* dest;
Expand All @@ -196,9 +196,9 @@ void decompress_vis_lump(BSPLEAF32* leafLump, unsigned char* visLump, unsigned c
dest = output + i * newVisRowSize;
if (lastUsedIdx >= 0)
{
if ((i + 1) * sizeof(BSPLEAF32) > leafMemSize)
if ((i + 1) * sizeof(BSPLEAF32) >= leafMemSize)
{
print_log(PRINT_RED | PRINT_INTENSITY, get_localized_string(LANG_0994),i + 1,leafMemSize / sizeof(BSPLEAF32));
print_log(PRINT_RED | PRINT_INTENSITY, get_localized_string(LANG_0994), i + 1, leafMemSize / sizeof(BSPLEAF32));
return;
}

Expand All @@ -209,9 +209,9 @@ void decompress_vis_lump(BSPLEAF32* leafLump, unsigned char* visLump, unsigned c
continue;
}

if (leafLump[i + 1].nVisOffset > visLumpMemSize)
if (leafLump[i + 1].nVisOffset >= visLumpMemSize)
{
print_log(PRINT_RED | PRINT_INTENSITY, get_localized_string(LANG_0995),leafLump[i + 1].nVisOffset,visLumpMemSize);
print_log(PRINT_RED | PRINT_INTENSITY, get_localized_string(LANG_0995), leafLump[i + 1].nVisOffset, visLumpMemSize);
return;
}
// Tracing ...
Expand Down Expand Up @@ -261,12 +261,12 @@ void DecompressVis(unsigned char* src, unsigned char* dest, unsigned int dest_le
{
if (out > startdst + dest_length)
{
print_log(PRINT_RED | PRINT_INTENSITY, get_localized_string(LANG_0998),(int)(out - startdst),dest_length);
print_log(PRINT_RED | PRINT_INTENSITY, get_localized_string(LANG_0998), (int)(out - startdst), dest_length);
return;
}
if (src > startsrc + src_length)
{
print_log(PRINT_RED | PRINT_INTENSITY, get_localized_string(LANG_0999),(int)(src - startsrc),src_length);
print_log(PRINT_RED | PRINT_INTENSITY, get_localized_string(LANG_0999), (int)(src - startsrc), src_length);
return;
}
*out = *src;
Expand All @@ -281,7 +281,7 @@ void DecompressVis(unsigned char* src, unsigned char* dest, unsigned int dest_le
{
if (out > startdst + dest_length)
{
print_log(PRINT_RED | PRINT_INTENSITY, get_localized_string(LANG_1142),(int)(out - startdst),dest_length);
print_log(PRINT_RED | PRINT_INTENSITY, get_localized_string(LANG_1142), (int)(out - startdst), dest_length);
return;
}
*out = 0;
Expand All @@ -308,7 +308,7 @@ int CompressVis(unsigned char* src, unsigned int src_length, unsigned char* dest

if (current_length > dest_length)
{
print_log(PRINT_RED | PRINT_INTENSITY, get_localized_string(LANG_1000),current_length,dest_length);
print_log(PRINT_RED | PRINT_INTENSITY, get_localized_string(LANG_1000), current_length, dest_length);
return (int)(dest_p - dest);
}

Expand Down Expand Up @@ -337,7 +337,7 @@ int CompressVis(unsigned char* src, unsigned int src_length, unsigned char* dest
current_length++;
if (current_length > dest_length)
{
print_log(PRINT_RED | PRINT_INTENSITY, get_localized_string(LANG_1143),current_length,dest_length);
print_log(PRINT_RED | PRINT_INTENSITY, get_localized_string(LANG_1143), current_length, dest_length);
return (int)(dest_p - dest);
}
*dest_p = rep;
Expand Down Expand Up @@ -386,7 +386,7 @@ int CompressAll(BSPLEAF32* leafs, unsigned char* uncompressed, unsigned char* ou
{
if (i + 1 >= maxLeafs)
{
print_log(PRINT_RED | PRINT_INTENSITY, get_localized_string(LANG_1001),i + 1,maxLeafs);
print_log(PRINT_RED | PRINT_INTENSITY, get_localized_string(LANG_1001), i + 1, maxLeafs);
delete[] sharedRows;
delete[] compressed;
return (int)(vismap_p - output);
Expand All @@ -396,7 +396,7 @@ int CompressAll(BSPLEAF32* leafs, unsigned char* uncompressed, unsigned char* ou
{
if (sharedRows[i] + 1 >= maxLeafs)
{
print_log(PRINT_RED | PRINT_INTENSITY, get_localized_string(LANG_1002),(int)(sharedRows[i] + 1),maxLeafs);
print_log(PRINT_RED | PRINT_INTENSITY, get_localized_string(LANG_1002), (int)(sharedRows[i] + 1), maxLeafs);
delete[] sharedRows;
delete[] compressed;
return (int)(vismap_p - output);
Expand All @@ -417,7 +417,7 @@ int CompressAll(BSPLEAF32* leafs, unsigned char* uncompressed, unsigned char* ou

if (vismap_p >= output + bufferSize)
{
print_log(PRINT_RED | PRINT_INTENSITY, get_localized_string(LANG_1003),(void*)vismap_p,(void*)(output + bufferSize));
print_log(PRINT_RED | PRINT_INTENSITY, get_localized_string(LANG_1003), (void*)vismap_p, (void*)(output + bufferSize));

delete[] sharedRows;
return (int)(vismap_p - output);
Expand Down Expand Up @@ -461,7 +461,7 @@ void DecompressLeafVis(unsigned char* src, unsigned int src_len, unsigned char*
{
if (out > dest + dest_length)
{
print_log(PRINT_RED | PRINT_INTENSITY, get_localized_string(LANG_1004),(int)(out - dest),dest_length);
print_log(PRINT_RED | PRINT_INTENSITY, get_localized_string(LANG_1004), (int)(out - dest), dest_length);
return;
}

Expand All @@ -478,13 +478,13 @@ void DecompressLeafVis(unsigned char* src, unsigned int src_len, unsigned char*
{
if (out > dest + dest_length)
{
print_log(PRINT_RED | PRINT_INTENSITY, get_localized_string(LANG_1005),(int)(out - dest),dest_length);
print_log(PRINT_RED | PRINT_INTENSITY, get_localized_string(LANG_1005), (int)(out - dest), dest_length);
return;
}

if (src > src_start + src_len)
{
print_log(PRINT_RED | PRINT_INTENSITY, get_localized_string(LANG_1006),(int)(out - dest),dest_length);
print_log(PRINT_RED | PRINT_INTENSITY, get_localized_string(LANG_1006), (int)(out - dest), dest_length);
return;
}

Expand All @@ -498,15 +498,15 @@ void DecompressLeafVis(unsigned char* src, unsigned int src_len, unsigned char*

if (src > src_start + src_len)
{
print_log(PRINT_RED | PRINT_INTENSITY, get_localized_string(LANG_1144),(int)(out - dest),dest_length);
print_log(PRINT_RED | PRINT_INTENSITY, get_localized_string(LANG_1144), (int)(out - dest), dest_length);
return;
}

while (c)
{
if (out > dest + dest_length)
{
print_log(PRINT_RED | PRINT_INTENSITY, get_localized_string(LANG_1007),(int)(out - dest),dest_length);
print_log(PRINT_RED | PRINT_INTENSITY, get_localized_string(LANG_1007), (int)(out - dest), dest_length);
return;
}

Expand Down
2 changes: 1 addition & 1 deletion src/qtools/vis.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ bool shiftVis(unsigned char* vis, int len, int offsetLeaf, int shift);
// iterationLeaves = number of leaves to decompress vis for
// visDataLeafCount = total leaves in the map (exluding the shared solid leaf 0)
// newNumLeaves = total leaves that will be in the map after merging is finished (again, excluding solid leaf 0)
void decompress_vis_lump(BSPLEAF32* leafLump, unsigned char* visLump, unsigned char* output,
void decompress_vis_lump(Bsp * map,BSPLEAF32* leafLump, unsigned char* visLump, unsigned char* output,
int iterationLeaves, int visDataLeafCount, int newNumLeaves, int leafMemSize, int visLumpMemSize);

void DecompressVis(unsigned char* src, unsigned char* dest, unsigned int dest_length, unsigned int numLeaves, unsigned int src_length);
Expand Down

0 comments on commit 2edc1e1

Please sign in to comment.