mirror of
https://git.huckle.dev/Huckles-Minecraft-Archive/GabsPuNs-MinecraftConsoles.git
synced 2026-05-30 02:48:07 +00:00
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:
@@ -16,19 +16,19 @@ void SparseLightStorage::staticCtor()
|
||||
|
||||
// Initialise lighting storage, with very limited compression - the very first plane is stored as either compressed to be "all 15" or "all 0" depending on whether this
|
||||
// will store sky or not, 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 lights at the ctor stage. However, as chunks are created then this creates an awful lot of intermediate
|
||||
// stages as each line of lighting 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.
|
||||
SparseLightStorage::SparseLightStorage(bool sky)
|
||||
{
|
||||
// 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[127] = sky ? ALL_15_INDEX : ALL_0_INDEX;
|
||||
@@ -50,8 +50,8 @@ SparseLightStorage::SparseLightStorage(bool sky)
|
||||
SparseLightStorage::SparseLightStorage(bool sky, 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] = sky ? ALL_15_INDEX : ALL_0_INDEX;
|
||||
@@ -69,7 +69,7 @@ SparseLightStorage::SparseLightStorage(bool sky, bool isUpper)
|
||||
SparseLightStorage::~SparseLightStorage()
|
||||
{
|
||||
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,7 +79,7 @@ SparseLightStorage::~SparseLightStorage()
|
||||
else
|
||||
#endif
|
||||
{
|
||||
free(indicesAndData);
|
||||
mi_free(indicesAndData);
|
||||
}
|
||||
// printf("Free (in dtor) 0x%x\n", indicesAndData);
|
||||
}
|
||||
@@ -92,7 +92,7 @@ SparseLightStorage::SparseLightStorage(SparseLightStorage *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.
|
||||
@@ -150,7 +150,7 @@ void SparseLightStorage::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);
|
||||
|
||||
@@ -305,7 +305,7 @@ void SparseLightStorage::set(int x, int y, int z, int val)
|
||||
|
||||
void SparseLightStorage::setAllBright()
|
||||
{
|
||||
unsigned char *planeIndices = static_cast<unsigned char *>(malloc(128));
|
||||
unsigned char *planeIndices = static_cast<unsigned char *>(mi_malloc(128));
|
||||
for( int i = 0; i < 128; i++ )
|
||||
{
|
||||
planeIndices[i] = ALL_15_INDEX;
|
||||
@@ -400,7 +400,7 @@ void SparseLightStorage::addNewPlane(int y)
|
||||
int linesUsed = lastLinesUsed + 1;
|
||||
|
||||
// Allocate new memory storage, copy over anything from old storage, and initialise remainder
|
||||
unsigned char *dataPointer = static_cast<unsigned char *>(malloc(linesUsed * 128 + 128));
|
||||
unsigned char *dataPointer = static_cast<unsigned char *>(mi_malloc(linesUsed * 128 + 128));
|
||||
XMemCpy( dataPointer, lastDataPointer, 128 * lastLinesUsed + 128);
|
||||
XMemSet( dataPointer + ( 128 * lastLinesUsed ) + 128, prefill, 128 );
|
||||
dataPointer[y] = lastLinesUsed;
|
||||
@@ -462,7 +462,7 @@ void SparseLightStorage::tick()
|
||||
{
|
||||
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 )
|
||||
{
|
||||
@@ -471,7 +471,7 @@ void SparseLightStorage::tick()
|
||||
else
|
||||
#endif
|
||||
{
|
||||
free(toFree);
|
||||
mi_free(toFree);
|
||||
}
|
||||
} while( toFree );
|
||||
|
||||
@@ -560,7 +560,7 @@ int SparseLightStorage::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 );
|
||||
|
||||
@@ -629,7 +629,7 @@ void SparseLightStorage::write(DataOutputStream *dos)
|
||||
void SparseLightStorage::read(DataInputStream *dis)
|
||||
{
|
||||
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));
|
||||
byteArray wrapper(dataPointer, count * 128 + 128);
|
||||
dis->readFully(wrapper);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user