This commit is contained in:
GabsPuNs
2026-06-05 16:05:55 -04:00
parent 77ad7e0e90
commit 22a1aa3a74
29 changed files with 160 additions and 1668 deletions

View File

@@ -54,8 +54,8 @@ CompressedTileStorage::CompressedTileStorage(CompressedTileStorage *copyFrom)
allocatedSize = copyFrom->allocatedSize;
if(allocatedSize > 0)
{
indicesAndData = static_cast<unsigned char *>(XPhysicalAlloc(allocatedSize, MAXULONG_PTR, 4096, PAGE_READWRITE));//(unsigned char *)malloc(allocatedSize);
XMemCpy(indicesAndData, copyFrom->indicesAndData, allocatedSize);
indicesAndData = static_cast<unsigned char *>(malloc(allocatedSize));
memcpy(indicesAndData, copyFrom->indicesAndData, allocatedSize);
}
else
{
@@ -74,7 +74,7 @@ CompressedTileStorage::CompressedTileStorage(byteArray initFrom, unsigned int in
allocatedSize = 0;
// We need 32768 bytes for a fully uncompressed chunk, plus 1024 for the index. Rounding up to nearest 4096 bytes for allocation
indicesAndData = static_cast<unsigned char *>(XPhysicalAlloc(32768 + 4096, MAXULONG_PTR, 4096, PAGE_READWRITE));
indicesAndData = static_cast<unsigned char *>(malloc(32768 + 4096));
unsigned short *indices = (unsigned short *)indicesAndData;
unsigned char *data = indicesAndData + 1024;
@@ -124,7 +124,7 @@ CompressedTileStorage::CompressedTileStorage(bool isEmpty)
// XPhysicalAlloc just maps to malloc on PS3, so allocate the smallest amount
indicesAndData = (unsigned char *)XPhysicalAlloc(1024, MAXULONG_PTR, 4096, PAGE_READWRITE);
#else
indicesAndData = static_cast<unsigned char *>(XPhysicalAlloc(4096, MAXULONG_PTR, 4096, PAGE_READWRITE));
indicesAndData = static_cast<unsigned char *>(malloc(4096));
#endif //__PS3__
unsigned short *indices = (unsigned short *)indicesAndData;
//unsigned char *data = indicesAndData + 1024;
@@ -217,7 +217,7 @@ bool CompressedTileStorage::isSameAs(CompressedTileStorage *other)
CompressedTileStorage::~CompressedTileStorage()
{
#if 1
if(indicesAndData) XPhysicalFree(indicesAndData);
if(indicesAndData) free(indicesAndData);
#else
if( (unsigned int)indicesAndData >= MM_PHYSICAL_4KB_BASE )
{
@@ -387,7 +387,7 @@ void CompressedTileStorage::setData(byteArray dataIn, unsigned int inOffset)
// printf("%d: %d (0) %d (1) %d (2) %d (4) %d (8)\n", chunkTotal, type0 / chunkTotal, type1 / chunkTotal, type2 / chunkTotal, type4 / chunkTotal, type8 / chunkTotal);
memToAlloc += 1024; // For the indices
unsigned char *newIndicesAndData = static_cast<unsigned char *>(XPhysicalAlloc(memToAlloc, MAXULONG_PTR, 4096, PAGE_READWRITE));//(unsigned char *)malloc( memToAlloc );
unsigned char *newIndicesAndData = static_cast<unsigned char *>(malloc(memToAlloc));//(unsigned char *)malloc( memToAlloc );
unsigned char *pucData = newIndicesAndData + 1024;
unsigned short usDataOffset = 0;
unsigned short *newIndices = (unsigned short *) newIndicesAndData;
@@ -436,8 +436,8 @@ void CompressedTileStorage::setData(byteArray dataIn, unsigned int inOffset)
unsigned char *tile_types = pucData + usDataOffset;
repacked = tile_types + tiletypecount;
XMemSet(tile_types, 255, tiletypecount);
XMemSet(repacked, 0,tiledatasize);
memset(tile_types, 255, tiletypecount);
memset(repacked, 0,tiledatasize);
newIndices[i] |= ( usDataOffset & INDEX_OFFSET_MASK) << INDEX_OFFSET_SHIFT;
usDataOffset += tiletypecount + tiledatasize;
int count = 0;
@@ -820,7 +820,7 @@ void CompressedTileStorage::tick()
toFree = deleteQueue[freeIndex].Pop();
// if( toFree ) printf("Deleting 0x%x\n", toFree);
#if 1
if( toFree ) XPhysicalFree(toFree);
if( toFree ) free(toFree);
#else
// Determine correct means to free this data - could have been allocated either with XPhysicalAlloc or malloc
if( (unsigned int)toFree >= MM_PHYSICAL_4KB_BASE )
@@ -855,7 +855,7 @@ void CompressedTileStorage::compress_SPU(int upgradeBlock/*=-1*/)
if(dataIn.neededCompressed)
{
unsigned char *newIndicesAndData = (unsigned char *)XPhysicalAlloc(dataIn.newAllocatedSize, MAXULONG_PTR, 4096, PAGE_READWRITE);//(unsigned char *)malloc( memToAlloc );
unsigned char *newIndicesAndData = (unsigned char *)malloc(dataIn.newAllocatedSize);
memcpy(newIndicesAndData, compBuffer, dataIn.newAllocatedSize);
queueForDelete( indicesAndData );
indicesAndData = newIndicesAndData;
@@ -1057,7 +1057,7 @@ void CompressedTileStorage::compress(int upgradeBlock/*=-1*/)
if( needsCompressed )
{
memToAlloc += 1024; // For the indices
unsigned char *newIndicesAndData = static_cast<unsigned char *>(XPhysicalAlloc(memToAlloc, MAXULONG_PTR, 4096, PAGE_READWRITE));//(unsigned char *)malloc( memToAlloc );
unsigned char *newIndicesAndData = static_cast<unsigned char *>(malloc(memToAlloc));
if( newIndicesAndData == nullptr )
{
DWORD lastError = GetLastError();
@@ -1095,7 +1095,7 @@ void CompressedTileStorage::compress(int upgradeBlock/*=-1*/)
{
packed_data = data + ( ( blockIndices[i] >> INDEX_OFFSET_SHIFT ) & INDEX_OFFSET_MASK);
usDataOffset = (usDataOffset + 3 ) & 0xfffc;
XMemCpy( pucData + usDataOffset, packed_data, 64 );
memcpy( pucData + usDataOffset, packed_data, 64 );
newIndices[i] |= ( usDataOffset & INDEX_OFFSET_MASK) << INDEX_OFFSET_SHIFT;
usDataOffset += 64;
}
@@ -1109,7 +1109,7 @@ void CompressedTileStorage::compress(int upgradeBlock/*=-1*/)
int dataSize = 8 << indexTypeOld; // 8, 16 or 32 bytes of per-tile storage
dataSize += 1 << ( 1 << indexTypeOld ); // 2, 4 or 16 bytes to store each tile type
newIndices[i] |= ( usDataOffset & INDEX_OFFSET_MASK) << INDEX_OFFSET_SHIFT;
XMemCpy( pucData + usDataOffset, packed_data, dataSize );
memcpy( pucData + usDataOffset, packed_data, dataSize );
usDataOffset += dataSize;
done = true;
}
@@ -1128,7 +1128,7 @@ void CompressedTileStorage::compress(int upgradeBlock/*=-1*/)
{
unpacked_data = tempdata;
int value = ( blockIndices[i] >> INDEX_TILE_SHIFT ) & INDEX_TILE_MASK;
XMemSet( tempdata, value, 64 );
memset( tempdata, value, 64 );
}
else
{
@@ -1178,7 +1178,7 @@ void CompressedTileStorage::compress(int upgradeBlock/*=-1*/)
else
{
usDataOffset = (usDataOffset + 3 ) & 0xfffc; // Make sure offset is 4 BYTE aligned
XMemCpy( pucData + usDataOffset, unpacked_data, 64 );
memcpy( pucData + usDataOffset, unpacked_data, 64 );
newIndices[i] |= ( usDataOffset & INDEX_OFFSET_MASK) << INDEX_OFFSET_SHIFT;
usDataOffset += 64;
}
@@ -1195,8 +1195,8 @@ void CompressedTileStorage::compress(int upgradeBlock/*=-1*/)
tile_types = pucData + usDataOffset;
repacked = tile_types + tiletypecount;
XMemSet(tile_types, 255, tiletypecount);
XMemSet(repacked, 0,tiledatasize);
memset(tile_types, 255, tiletypecount);
memset(repacked, 0,tiledatasize);
newIndices[i] |= ( usDataOffset & INDEX_OFFSET_MASK) << INDEX_OFFSET_SHIFT;
usDataOffset += tiletypecount + tiledatasize;
int count = 0;
@@ -1357,9 +1357,9 @@ void CompressedTileStorage::read(DataInputStream *dis)
// This delete should be safe to do in a non-thread safe way as the chunk is fully read before any external reference is available to it from another thread
if( indicesAndData )
{
XPhysicalFree(indicesAndData);
free(indicesAndData);
}
indicesAndData = static_cast<unsigned char *>(XPhysicalAlloc(allocatedSize, MAXULONG_PTR, 4096, PAGE_READWRITE));
indicesAndData = static_cast<unsigned char *>(malloc(allocatedSize));
byteArray wrapper(indicesAndData, allocatedSize);
dis->readFully(wrapper);