refactor(Minecraft.World): Implement LCEMP changes.
This commit is contained in:
@@ -10,6 +10,7 @@ byteArray RegionFile::emptySector(SECTOR_BYTES);
|
||||
|
||||
RegionFile::RegionFile(ConsoleSaveFile *saveFile, File *path)
|
||||
{
|
||||
InitializeCriticalSectionAndSpinCount(&m_cs, 4000);
|
||||
_lastModified = 0;
|
||||
|
||||
m_saveFile = saveFile;
|
||||
@@ -38,7 +39,12 @@ RegionFile::RegionFile(ConsoleSaveFile *saveFile, File *path)
|
||||
}
|
||||
*/
|
||||
|
||||
fileEntry = m_saveFile->createFile( fileName->getName() );
|
||||
wstring saveName = fileName->getPath();
|
||||
for (size_t i = 0; i < saveName.size(); i++)
|
||||
{
|
||||
if (saveName[i] == L'\\') saveName[i] = L'/';
|
||||
}
|
||||
fileEntry = m_saveFile->createFile( ConsoleSavePath(saveName) );
|
||||
m_saveFile->setFilePointer( fileEntry, 0, NULL, FILE_END );
|
||||
|
||||
if ( fileEntry->getFileSize() < SECTOR_BYTES)
|
||||
@@ -135,6 +141,8 @@ void RegionFile::writeAllOffsets() // used for the file ConsoleSaveFile conversi
|
||||
{
|
||||
if(m_bIsEmpty == false)
|
||||
{
|
||||
EnterCriticalSection(&m_cs);
|
||||
|
||||
// save all the offsets and timestamps
|
||||
m_saveFile->LockSaveAccess();
|
||||
|
||||
@@ -147,6 +155,7 @@ void RegionFile::writeAllOffsets() // used for the file ConsoleSaveFile conversi
|
||||
m_saveFile->writeFile(fileEntry, chunkTimestamps, SECTOR_BYTES, &numberOfBytesWritten);
|
||||
|
||||
m_saveFile->ReleaseSaveAccess();
|
||||
LeaveCriticalSection(&m_cs);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -156,6 +165,7 @@ RegionFile::~RegionFile()
|
||||
delete[] chunkTimestamps;
|
||||
delete sectorFree;
|
||||
m_saveFile->closeHandle( fileEntry );
|
||||
DeleteCriticalSection(&m_cs);
|
||||
}
|
||||
|
||||
__int64 RegionFile::lastModified()
|
||||
@@ -165,8 +175,10 @@ __int64 RegionFile::lastModified()
|
||||
|
||||
int RegionFile::getSizeDelta() // TODO - was synchronized
|
||||
{
|
||||
EnterCriticalSection(&m_cs);
|
||||
int ret = sizeDelta;
|
||||
sizeDelta = 0;
|
||||
LeaveCriticalSection(&m_cs);
|
||||
return ret;
|
||||
}
|
||||
|
||||
@@ -178,12 +190,14 @@ DataInputStream *RegionFile::getChunkDataInputStream(int x, int z) // TODO - was
|
||||
return NULL;
|
||||
}
|
||||
|
||||
EnterCriticalSection(&m_cs);
|
||||
// 4J - removed try/catch
|
||||
// try {
|
||||
int offset = getOffset(x, z);
|
||||
if (offset == 0)
|
||||
{
|
||||
// debugln("READ", x, z, "miss");
|
||||
LeaveCriticalSection(&m_cs);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@@ -192,6 +206,7 @@ DataInputStream *RegionFile::getChunkDataInputStream(int x, int z) // TODO - was
|
||||
|
||||
if (sectorNumber + numSectors > sectorFree->size())
|
||||
{
|
||||
LeaveCriticalSection(&m_cs);
|
||||
// debugln("READ", x, z, "invalid sector");
|
||||
return NULL;
|
||||
}
|
||||
@@ -227,7 +242,7 @@ DataInputStream *RegionFile::getChunkDataInputStream(int x, int z) // TODO - was
|
||||
if (length > SECTOR_BYTES * numSectors)
|
||||
{
|
||||
// debugln("READ", x, z, "invalid length: " + length + " > 4096 * " + numSectors);
|
||||
|
||||
LeaveCriticalSection(&m_cs);
|
||||
m_saveFile->ReleaseSaveAccess();
|
||||
return NULL;
|
||||
}
|
||||
@@ -240,6 +255,7 @@ DataInputStream *RegionFile::getChunkDataInputStream(int x, int z) // TODO - was
|
||||
m_saveFile->readFile(fileEntry,data,length,&numberOfBytesRead);
|
||||
|
||||
m_saveFile->ReleaseSaveAccess();
|
||||
LeaveCriticalSection(&m_cs);
|
||||
|
||||
Compression::getCompression()->SetDecompressionType(m_saveFile->getSavePlatform()); // if this save is from another platform, set the correct decompression type
|
||||
|
||||
@@ -290,6 +306,7 @@ void RegionFile::write(int x, int z, byte *data, int length) // TODO - was sync
|
||||
return;
|
||||
}
|
||||
|
||||
EnterCriticalSection(&m_cs);
|
||||
m_saveFile->LockSaveAccess();
|
||||
{
|
||||
int offset = getOffset(x, z);
|
||||
@@ -396,6 +413,7 @@ void RegionFile::write(int x, int z, byte *data, int length) // TODO - was sync
|
||||
setTimestamp(x, z, (int) (System::currentTimeMillis() / 1000L));
|
||||
}
|
||||
m_saveFile->ReleaseSaveAccess();
|
||||
LeaveCriticalSection(&m_cs);
|
||||
|
||||
// } catch (IOException e) {
|
||||
// e.printStackTrace();
|
||||
|
||||
Reference in New Issue
Block a user