diff options
| author | ModMaker101 <119018978+ModMaker101@users.noreply.github.com> | 2026-03-07 21:56:03 -0500 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2026-03-08 09:56:03 +0700 |
| commit | a9be52c41a02d207233199e98898fe7483d7e817 (patch) | |
| tree | 71dfaec3a86b05e9ca409b97d8eb9d7f993bfdd0 /Minecraft.World/SparseLightStorage.cpp | |
| parent | 1be5faaea781402e7de06b263eeca4c688b7712c (diff) | |
Project modernization (#630)
* Fixed boats falling and a TP glitch #266
* Replaced every C-style cast with C++ ones
* Replaced every C-style cast with C++ ones
* Fixed boats falling and a TP glitch #266
* Updated NULL to nullptr and fixing some type issues
* Modernized and fixed a few bugs
- Replaced most instances of `NULL` with `nullptr`.
- Replaced most `shared_ptr(new ...)` with `make_shared`.
- Removed the `nullptr` macro as it was interfering with the actual nullptr keyword in some instances.
* Fixing more conflicts
* Replace int loops with size_t and start work on overrides
Diffstat (limited to 'Minecraft.World/SparseLightStorage.cpp')
| -rw-r--r-- | Minecraft.World/SparseLightStorage.cpp | 36 |
1 files changed, 18 insertions, 18 deletions
diff --git a/Minecraft.World/SparseLightStorage.cpp b/Minecraft.World/SparseLightStorage.cpp index a0ba41b1..a80f9c97 100644 --- a/Minecraft.World/SparseLightStorage.cpp +++ b/Minecraft.World/SparseLightStorage.cpp @@ -28,7 +28,7 @@ SparseLightStorage::SparseLightStorage(bool sky) #ifdef _XBOX unsigned char *planeIndices = (unsigned char *)XPhysicalAlloc(128 * 128, MAXULONG_PTR, 4096, PAGE_READWRITE); #else - unsigned char *planeIndices = (unsigned char *)malloc(128 * 128); + unsigned char *planeIndices = static_cast<unsigned char *>(malloc(128 * 128)); #endif unsigned char *data = planeIndices + 128; planeIndices[127] = sky ? ALL_15_INDEX : ALL_0_INDEX; @@ -51,7 +51,7 @@ 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 = (unsigned char *)malloc(128); + unsigned char *planeIndices = static_cast<unsigned char *>(malloc(128)); for( int i = 0; i < 128; i++ ) { planeIndices[i] = sky ? ALL_15_INDEX : ALL_0_INDEX; @@ -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 = (unsigned char *)malloc( sourceCount * 128 + 128 ); + unsigned char *destIndicesAndData = static_cast<unsigned char *>(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 = (unsigned char *)malloc(128 * allocatedPlaneCount + 128); + unsigned char *planeIndices = static_cast<unsigned char *>(malloc(128 * allocatedPlaneCount + 128)); unsigned char *data = planeIndices + 128; XMemCpy(planeIndices, _planeIndices, 128); @@ -180,9 +180,9 @@ void SparseLightStorage::setData(byteArray dataIn, unsigned int inOffset) // Get new data and count packed info #pragma warning ( disable : 4826 ) - int64_t newDataAndCount = ((int64_t) planeIndices) & 0x0000ffffffffffffL; + int64_t newDataAndCount = reinterpret_cast<int64_t>(planeIndices) & 0x0000ffffffffffffL; #pragma warning ( default : 4826 ) - newDataAndCount |= ((int64_t)allocatedPlaneCount) << 48; + newDataAndCount |= static_cast<int64_t>(allocatedPlaneCount) << 48; updateDataAndCount( newDataAndCount ); } @@ -305,7 +305,7 @@ void SparseLightStorage::set(int x, int y, int z, int val) void SparseLightStorage::setAllBright() { - unsigned char *planeIndices = (unsigned char *)malloc(128); + unsigned char *planeIndices = static_cast<unsigned char *>(malloc(128)); for( int i = 0; i < 128; i++ ) { planeIndices[i] = ALL_15_INDEX; @@ -346,7 +346,7 @@ int SparseLightStorage::setDataRegion(byteArray dataIn, int x0, int y0, int z0, } ptrdiff_t count = pucIn - &dataIn.data[offset]; - return (int)count; + return static_cast<int>(count); } // Updates the data at offset position dataInOut with a region of lighting information - external ordering compatible with java DataLayer @@ -376,7 +376,7 @@ int SparseLightStorage::getDataRegion(byteArray dataInOut, int x0, int y0, int z } ptrdiff_t count = pucOut - &dataInOut.data[offset]; - return (int)count; + return static_cast<int>(count); } void SparseLightStorage::addNewPlane(int y) @@ -388,7 +388,7 @@ void SparseLightStorage::addNewPlane(int y) int64_t lastDataAndCount = dataAndCount; // Unpack count & data pointer - int lastLinesUsed = (int)(( lastDataAndCount >> 48 ) & 0xffff); + int lastLinesUsed = static_cast<int>((lastDataAndCount >> 48) & 0xffff); unsigned char *lastDataPointer = (unsigned char *)(lastDataAndCount & 0x0000ffffffffffff); // Find out what to prefill the newly allocated line with @@ -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 = (unsigned char *)malloc(linesUsed * 128 + 128); + unsigned char *dataPointer = static_cast<unsigned char *>(malloc(linesUsed * 128 + 128)); XMemCpy( dataPointer, lastDataPointer, 128 * lastLinesUsed + 128); XMemSet( dataPointer + ( 128 * lastLinesUsed ) + 128, prefill, 128 ); dataPointer[y] = lastLinesUsed; @@ -409,7 +409,7 @@ void SparseLightStorage::addNewPlane(int y) #pragma warning ( disable : 4826 ) int64_t newDataAndCount = ((int64_t) dataPointer) & 0x0000ffffffffffffL; #pragma warning ( default : 4826 ) - newDataAndCount |= ((int64_t)linesUsed) << 48; + newDataAndCount |= static_cast<int64_t>(linesUsed) << 48; // Attempt to update the data & count atomically. This command will Only succeed if the data stored at // dataAndCount is equal to lastDataAndCount, and will return the value present just before the write took place @@ -457,7 +457,7 @@ void SparseLightStorage::tick() int freeIndex = ( deleteQueueIndex + 1 ) % 3; // printf("Free queue: %d, %d\n",deleteQueue[freeIndex].GetEntryCount(),deleteQueue[freeIndex].GetAllocated()); - unsigned char *toFree = NULL; + unsigned char *toFree = nullptr; do { toFree = deleteQueue[freeIndex].Pop(); @@ -560,7 +560,7 @@ int SparseLightStorage::compress() if( needsCompressed ) { - unsigned char *newIndicesAndData = (unsigned char *)malloc( 128 + 128 * planesToAlloc ); + unsigned char *newIndicesAndData = static_cast<unsigned char *>(malloc(128 + 128 * planesToAlloc)); unsigned char *pucData = newIndicesAndData + 128; XMemCpy( newIndicesAndData, _planeIndices, 128 ); @@ -577,7 +577,7 @@ int SparseLightStorage::compress() #pragma warning ( disable : 4826 ) int64_t newDataAndCount = ((int64_t) newIndicesAndData) & 0x0000ffffffffffffL; #pragma warning ( default : 4826 ) - newDataAndCount |= ((int64_t)planesToAlloc) << 48; + newDataAndCount |= static_cast<int64_t>(planesToAlloc) << 48; // Attempt to update the data & count atomically. This command will Only succeed if the data stored at // dataAndCount is equal to lastDataAndCount, and will return the value present just before the write took place @@ -603,7 +603,7 @@ int SparseLightStorage::compress() } else { - return (int)((lastDataAndCount >> 48 ) & 0xffff); + return static_cast<int>((lastDataAndCount >> 48) & 0xffff); } } @@ -629,14 +629,14 @@ void SparseLightStorage::write(DataOutputStream *dos) void SparseLightStorage::read(DataInputStream *dis) { int count = dis->readInt(); - unsigned char *dataPointer = (unsigned char *)malloc(count * 128 + 128); + unsigned char *dataPointer = static_cast<unsigned char *>(malloc(count * 128 + 128)); byteArray wrapper(dataPointer, count * 128 + 128); dis->readFully(wrapper); #pragma warning ( disable : 4826 ) int64_t newDataAndCount = ((int64_t) dataPointer) & 0x0000ffffffffffffL; #pragma warning ( default : 4826 ) - newDataAndCount |= ((int64_t)count) << 48; + newDataAndCount |= static_cast<int64_t>(count) << 48; updateDataAndCount( newDataAndCount ); } |
