More changes

Remove include stdafx.h from the .h files.
Replace malloc with mi_malloc and free with mi_free
Move MiniAudio and Zlib to Libs folder
This commit is contained in:
GabsPuNs
2026-04-13 04:31:42 -04:00
parent 6be56e5786
commit 3d5357eeb3
75 changed files with 19140 additions and 18446 deletions

View File

@@ -16,19 +16,19 @@ void SparseDataStorage::staticCtor()
// Initialise data storage, with very limited compression - the very first plane is stored as either compressed to be "all 0", and the rest of the planes aren't compressed at all.
// The reason behind this is to keep the total allocation as a round number of 4K (small) pages, ie 16K.
// By doing this, and doing this "special" allocation as a XPhysicalAlloc rather than a malloc, we can help ensure that this full allocation gets cleaned up properly when the first
// proper compression is done on this storage. If it were just allocated with malloc, then the memory management system would have a large number of 16512 allocations to free, and
// it seems from experimentation that these basically don't make it back to the system as free pages.
// By doing this, and doing this "special" allocation as a XPhysicalAlloc rather than a mi_malloc, we can help ensure that this full allocation gets cleaned up properly when the first
// proper compression is done on this storage. If it were just allocated with mi_malloc, then the memory management system would have a large number of 16512 allocations to mi_free, and
// it seems from experimentation that these basically don't make it back to the system as mi_free pages.
// Note - the other approach here would be to allocate *no* actual storage for the data at the ctor stage. However, as chunks are created then this creates an awful lot of intermediate
// stages as each line of data is added, so it is actually much cleaner to just allocate almost fully here & then attempt to do a single compression pass over the data later on.
SparseDataStorage::SparseDataStorage()
{
// Allocate using physical alloc. As this will (by default) return memory from the pool of 4KB pages, the address will in the range of MM_PHYSICAL_4KB_BASE upwards. We can use
// this fact to identify the allocation later, and so free it with the corresponding call to XPhysicalFree.
// this fact to identify the allocation later, and so mi_free it with the corresponding call to XPhysicalFree.
#ifdef _XBOX
unsigned char *planeIndices = (unsigned char *)XPhysicalAlloc(128 * 128, MAXULONG_PTR, 4096, PAGE_READWRITE);
#else
unsigned char *planeIndices = static_cast<unsigned char *>(malloc(128 * 128));
unsigned char *planeIndices = static_cast<unsigned char *>(mi_malloc(128 * 128));
#endif
unsigned char *data = planeIndices + 128;
planeIndices[0] = ALL_0_INDEX;
@@ -50,8 +50,8 @@ SparseDataStorage::SparseDataStorage()
SparseDataStorage::SparseDataStorage(bool isUpper)
{
// Allocate using physical alloc. As this will (by default) return memory from the pool of 4KB pages, the address will in the range of MM_PHYSICAL_4KB_BASE upwards. We can use
// this fact to identify the allocation later, and so free it with the corresponding call to XPhysicalFree.
unsigned char *planeIndices = static_cast<unsigned char *>(malloc(128));
// this fact to identify the allocation later, and so mi_free it with the corresponding call to XPhysicalFree.
unsigned char *planeIndices = static_cast<unsigned char *>(mi_malloc(128));
for( int i = 0; i < 128; i++ )
{
planeIndices[i] = ALL_0_INDEX;
@@ -69,7 +69,7 @@ SparseDataStorage::SparseDataStorage(bool isUpper)
SparseDataStorage::~SparseDataStorage()
{
unsigned char *indicesAndData = (unsigned char *)(dataAndCount & 0x0000ffffffffffff);
// Determine correct means to free this data - could have been allocated either with XPhysicalAlloc or malloc
// Determine correct means to mi_free this data - could have been allocated either with XPhysicalAlloc or mi_malloc
#ifdef _XBOX
if( (unsigned int)indicesAndData >= MM_PHYSICAL_4KB_BASE )
@@ -79,9 +79,9 @@ SparseDataStorage::~SparseDataStorage()
else
#endif
{
free(indicesAndData);
mi_free(indicesAndData);
}
// printf("Free (in dtor) 0x%x\n", indicesAndData);
// printf("mi_free (in dtor) 0x%x\n", indicesAndData);
}
SparseDataStorage::SparseDataStorage(SparseDataStorage *copyFrom)
@@ -92,7 +92,7 @@ SparseDataStorage::SparseDataStorage(SparseDataStorage *copyFrom)
int sourceCount = (sourceDataAndCount >> 48 ) & 0xffff;
// Allocate & copy indices ( 128 bytes ) and any allocated planes (128 * count)
unsigned char *destIndicesAndData = static_cast<unsigned char *>(malloc(sourceCount * 128 + 128));
unsigned char *destIndicesAndData = static_cast<unsigned char *>(mi_malloc(sourceCount * 128 + 128));
// AP - I've moved this to be before the memcpy because of a very strange bug on vita. Sometimes dataAndCount wasn't valid in time when ::get was called.
// This should never happen and this isn't a proper solution but fixes it for now.
@@ -146,7 +146,7 @@ void SparseDataStorage::setData(byteArray dataIn, unsigned int inOffset)
}
// Allocate required storage
unsigned char *planeIndices = static_cast<unsigned char *>(malloc(128 * allocatedPlaneCount + 128));
unsigned char *planeIndices = static_cast<unsigned char *>(mi_malloc(128 * allocatedPlaneCount + 128));
unsigned char *data = planeIndices + 128;
XMemCpy(planeIndices, _planeIndices, 128);
@@ -394,7 +394,7 @@ void SparseDataStorage::addNewPlane(int y)
int linesUsed = lastLinesUsed + 1;
// Allocate new memory storage, copy over anything from old storage, and initialise remainder
auto dataPointer = static_cast<unsigned char *>(malloc(linesUsed * 128 + 128));
auto dataPointer = static_cast<unsigned char *>(mi_malloc(linesUsed * 128 + 128));
XMemCpy( dataPointer, lastDataPointer, 128 * lastLinesUsed + 128);
XMemSet( dataPointer + ( 128 * lastLinesUsed ) + 128, 0, 128 );
dataPointer[y] = lastLinesUsed;
@@ -450,13 +450,13 @@ void SparseDataStorage::tick()
// before we ever delete something, from when the request to delete it came in
const int freeIndex = ( deleteQueueIndex + 1 ) % 3;
// printf("Free queue: %d, %d\n",deleteQueue[freeIndex].GetEntryCount(),deleteQueue[freeIndex].GetAllocated());
// printf("mi_free queue: %d, %d\n",deleteQueue[freeIndex].GetEntryCount(),deleteQueue[freeIndex].GetAllocated());
unsigned char *toFree = nullptr;
do
{
toFree = deleteQueue[freeIndex].Pop();
// if( toFree ) printf("Deleting 0x%x\n", toFree);
// Determine correct means to free this data - could have been allocated either with XPhysicalAlloc or malloc
// Determine correct means to mi_free this data - could have been allocated either with XPhysicalAlloc or mi_malloc
#ifdef _XBOX
if( (unsigned int)toFree >= MM_PHYSICAL_4KB_BASE )
{
@@ -465,7 +465,7 @@ void SparseDataStorage::tick()
else
#endif
{
free(toFree);
mi_free(toFree);
}
} while( toFree );
@@ -543,7 +543,7 @@ int SparseDataStorage::compress()
if( needsCompressed )
{
unsigned char *newIndicesAndData = static_cast<unsigned char *>(malloc(128 + 128 * planesToAlloc));
unsigned char *newIndicesAndData = static_cast<unsigned char *>(mi_malloc(128 + 128 * planesToAlloc));
unsigned char *pucData = newIndicesAndData + 128;
XMemCpy( newIndicesAndData, _planeIndices, 128 );
@@ -612,7 +612,7 @@ void SparseDataStorage::write(DataOutputStream *dos)
void SparseDataStorage::read(DataInputStream *dis)
{
const int count = dis->readInt();
unsigned char *dataPointer = static_cast<unsigned char *>(malloc(count * 128 + 128));
unsigned char *dataPointer = static_cast<unsigned char *>(mi_malloc(count * 128 + 128));
const byteArray wrapper(dataPointer, count * 128 + 128);
dis->readFully(wrapper);