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
This commit is contained in:
@@ -39,7 +39,7 @@ RegionFile::RegionFile(ConsoleSaveFile *saveFile, File *path)
|
||||
*/
|
||||
|
||||
fileEntry = m_saveFile->createFile( fileName->getName() );
|
||||
m_saveFile->setFilePointer( fileEntry, 0, NULL, FILE_END );
|
||||
m_saveFile->setFilePointer( fileEntry, 0, nullptr, FILE_END );
|
||||
|
||||
if ( fileEntry->getFileSize() < SECTOR_BYTES)
|
||||
{
|
||||
@@ -54,7 +54,7 @@ RegionFile::RegionFile(ConsoleSaveFile *saveFile, File *path)
|
||||
m_bIsEmpty = false;
|
||||
}
|
||||
|
||||
//if ((GetFileSize(file,NULL) & 0xfff) != 0)
|
||||
//if ((GetFileSize(file,nullptr) & 0xfff) != 0)
|
||||
if ((fileEntry->getFileSize() & 0xfff) != 0)
|
||||
{
|
||||
//byte zero = 0;
|
||||
@@ -78,7 +78,7 @@ RegionFile::RegionFile(ConsoleSaveFile *saveFile, File *path)
|
||||
}
|
||||
else
|
||||
{
|
||||
nSectors = (int) fileEntry->getFileSize() / SECTOR_BYTES;
|
||||
nSectors = static_cast<int>(fileEntry->getFileSize()) / SECTOR_BYTES;
|
||||
}
|
||||
sectorFree = new vector<bool>;
|
||||
sectorFree->reserve(nSectors);
|
||||
@@ -91,7 +91,7 @@ RegionFile::RegionFile(ConsoleSaveFile *saveFile, File *path)
|
||||
sectorFree->at(0) = false; // chunk offset table
|
||||
sectorFree->at(1) = false; // for the last modified info
|
||||
|
||||
m_saveFile->setFilePointer( fileEntry, 0, NULL, FILE_BEGIN );
|
||||
m_saveFile->setFilePointer( fileEntry, 0, nullptr, FILE_BEGIN );
|
||||
for (int i = 0; i < SECTOR_INTS; ++i)
|
||||
{
|
||||
unsigned int offset = 0;
|
||||
@@ -139,11 +139,11 @@ void RegionFile::writeAllOffsets() // used for the file ConsoleSaveFile conversi
|
||||
m_saveFile->LockSaveAccess();
|
||||
|
||||
DWORD numberOfBytesWritten = 0;
|
||||
m_saveFile->setFilePointer( fileEntry, 0, NULL, FILE_BEGIN );
|
||||
m_saveFile->setFilePointer( fileEntry, 0, nullptr, FILE_BEGIN );
|
||||
m_saveFile->writeFile(fileEntry,offsets, SECTOR_BYTES ,&numberOfBytesWritten);
|
||||
|
||||
numberOfBytesWritten = 0;
|
||||
m_saveFile->setFilePointer( fileEntry, SECTOR_BYTES, NULL, FILE_BEGIN );
|
||||
m_saveFile->setFilePointer( fileEntry, SECTOR_BYTES, nullptr, FILE_BEGIN );
|
||||
m_saveFile->writeFile(fileEntry, chunkTimestamps, SECTOR_BYTES, &numberOfBytesWritten);
|
||||
|
||||
m_saveFile->ReleaseSaveAccess();
|
||||
@@ -175,7 +175,7 @@ DataInputStream *RegionFile::getChunkDataInputStream(int x, int z) // TODO - was
|
||||
if (outOfBounds(x, z))
|
||||
{
|
||||
// debugln("READ", x, z, "out of bounds");
|
||||
return NULL;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
// 4J - removed try/catch
|
||||
@@ -184,7 +184,7 @@ DataInputStream *RegionFile::getChunkDataInputStream(int x, int z) // TODO - was
|
||||
if (offset == 0)
|
||||
{
|
||||
// debugln("READ", x, z, "miss");
|
||||
return NULL;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
unsigned int sectorNumber = offset >> 8;
|
||||
@@ -193,13 +193,13 @@ DataInputStream *RegionFile::getChunkDataInputStream(int x, int z) // TODO - was
|
||||
if (sectorNumber + numSectors > sectorFree->size())
|
||||
{
|
||||
// debugln("READ", x, z, "invalid sector");
|
||||
return NULL;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
m_saveFile->LockSaveAccess();
|
||||
|
||||
//SetFilePointer(file,sectorNumber * SECTOR_BYTES,0,FILE_BEGIN);
|
||||
m_saveFile->setFilePointer( fileEntry, sectorNumber * SECTOR_BYTES, NULL, FILE_BEGIN);
|
||||
m_saveFile->setFilePointer( fileEntry, sectorNumber * SECTOR_BYTES, nullptr, FILE_BEGIN);
|
||||
|
||||
unsigned int length;
|
||||
unsigned int decompLength;
|
||||
@@ -229,7 +229,7 @@ DataInputStream *RegionFile::getChunkDataInputStream(int x, int z) // TODO - was
|
||||
// debugln("READ", x, z, "invalid length: " + length + " > 4096 * " + numSectors);
|
||||
|
||||
m_saveFile->ReleaseSaveAccess();
|
||||
return NULL;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
MemSect(50);
|
||||
@@ -326,7 +326,7 @@ void RegionFile::write(int x, int z, byte *data, int length) // TODO - was sync
|
||||
|
||||
PIXBeginNamedEvent(0,"Scanning for free space\n");
|
||||
/* scan for a free space large enough to store this chunk */
|
||||
int runStart = (int)(find(sectorFree->begin(),sectorFree->end(),true) - sectorFree->begin()); // 4J - was sectorFree.indexOf(true)
|
||||
int runStart = static_cast<int>(find(sectorFree->begin(), sectorFree->end(), true) - sectorFree->begin()); // 4J - was sectorFree.indexOf(true)
|
||||
int runLength = 0;
|
||||
if (runStart != -1)
|
||||
{
|
||||
@@ -373,16 +373,16 @@ void RegionFile::write(int x, int z, byte *data, int length) // TODO - was sync
|
||||
*/
|
||||
// debug("SAVE", x, z, length, "grow");
|
||||
//SetFilePointer(file,0,0,FILE_END);
|
||||
m_saveFile->setFilePointer( fileEntry, 0, NULL, FILE_END );
|
||||
m_saveFile->setFilePointer( fileEntry, 0, nullptr, FILE_END );
|
||||
|
||||
sectorNumber = (int)sectorFree->size();
|
||||
sectorNumber = static_cast<int>(sectorFree->size());
|
||||
#ifndef _CONTENT_PACAKGE
|
||||
//wprintf(L"Writing chunk (%d,%d) in %ls from new sector %d to %d\n", x,z, fileEntry->data.filename, sectorNumber, sectorNumber + sectorsNeeded - 1);
|
||||
#endif
|
||||
DWORD numberOfBytesWritten = 0;
|
||||
for (int i = 0; i < sectorsNeeded; ++i)
|
||||
{
|
||||
//WriteFile(file,emptySector.data,SECTOR_BYTES,&numberOfBytesWritten,NULL);
|
||||
//WriteFile(file,emptySector.data,SECTOR_BYTES,&numberOfBytesWritten,nullptr);
|
||||
m_saveFile->writeFile(fileEntry,emptySector.data,SECTOR_BYTES,&numberOfBytesWritten);
|
||||
sectorFree->push_back(false);
|
||||
}
|
||||
@@ -393,7 +393,7 @@ void RegionFile::write(int x, int z, byte *data, int length) // TODO - was sync
|
||||
PIXEndNamedEvent();
|
||||
}
|
||||
}
|
||||
setTimestamp(x, z, (int) (System::currentTimeMillis() / 1000L));
|
||||
setTimestamp(x, z, static_cast<int>(System::currentTimeMillis() / 1000L));
|
||||
}
|
||||
m_saveFile->ReleaseSaveAccess();
|
||||
|
||||
@@ -407,7 +407,7 @@ void RegionFile::write(int sectorNumber, byte *data, int length, unsigned int co
|
||||
{
|
||||
DWORD numberOfBytesWritten = 0;
|
||||
//SetFilePointer(file,sectorNumber * SECTOR_BYTES,0,FILE_BEGIN);
|
||||
m_saveFile->setFilePointer( fileEntry, sectorNumber * SECTOR_BYTES, NULL, FILE_BEGIN );
|
||||
m_saveFile->setFilePointer( fileEntry, sectorNumber * SECTOR_BYTES, nullptr, FILE_BEGIN );
|
||||
|
||||
// 4J - this differs a bit from the java file format. Java has length stored as an int, then a type as a byte, then length-1 bytes of data
|
||||
// We store length and decompression length as ints, then length bytes of xbox LZX compressed data
|
||||
@@ -426,7 +426,7 @@ void RegionFile::zero(int sectorNumber, int length)
|
||||
{
|
||||
DWORD numberOfBytesWritten = 0;
|
||||
//SetFilePointer(file,sectorNumber * SECTOR_BYTES,0,FILE_BEGIN);
|
||||
m_saveFile->setFilePointer( fileEntry, sectorNumber * SECTOR_BYTES, NULL, FILE_BEGIN );
|
||||
m_saveFile->setFilePointer( fileEntry, sectorNumber * SECTOR_BYTES, nullptr, FILE_BEGIN );
|
||||
m_saveFile->zeroFile( fileEntry, length, &numberOfBytesWritten );
|
||||
}
|
||||
|
||||
@@ -449,7 +449,7 @@ bool RegionFile::hasChunk(int x, int z)
|
||||
// 4J added - write the initial two sectors that used to be written in the ctor when the file was empty
|
||||
void RegionFile::insertInitialSectors()
|
||||
{
|
||||
m_saveFile->setFilePointer( fileEntry, 0, NULL, FILE_BEGIN );
|
||||
m_saveFile->setFilePointer( fileEntry, 0, nullptr, FILE_BEGIN );
|
||||
DWORD numberOfBytesWritten = 0;
|
||||
byte zeroBytes[ SECTOR_BYTES ];
|
||||
ZeroMemory(zeroBytes, SECTOR_BYTES);
|
||||
@@ -472,7 +472,8 @@ void RegionFile::setOffset(int x, int z, int offset)
|
||||
|
||||
DWORD numberOfBytesWritten = 0;
|
||||
offsets[x + z * 32] = offset;
|
||||
m_saveFile->setFilePointer( fileEntry, (x + z * 32) * 4, NULL, FILE_BEGIN );
|
||||
|
||||
m_saveFile->setFilePointer( fileEntry, (x + z * 32) * 4, nullptr, FILE_BEGIN );
|
||||
|
||||
m_saveFile->writeFile(fileEntry,&offset,4,&numberOfBytesWritten);
|
||||
}
|
||||
@@ -486,7 +487,7 @@ void RegionFile::setTimestamp(int x, int z, int value)
|
||||
|
||||
DWORD numberOfBytesWritten = 0;
|
||||
chunkTimestamps[x + z * 32] = value;
|
||||
m_saveFile->setFilePointer( fileEntry, SECTOR_BYTES + (x + z * 32) * 4, NULL, FILE_BEGIN );
|
||||
m_saveFile->setFilePointer( fileEntry, SECTOR_BYTES + (x + z * 32) * 4, nullptr, FILE_BEGIN );
|
||||
|
||||
m_saveFile->writeFile(fileEntry,&value,4,&numberOfBytesWritten);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user