* try to resolve merge conflict
* feat: TU19 (Dec 2014) Features & Content (#32)
* December 2014 files
* Working release build
* Fix compilation issues
* Add sound to Windows64Media
* Add DLC content and force Tutorial DLC
* Revert "Add DLC content and force Tutorial DLC"
This reverts commit 97a4399472.
* Disable broken light packing
* Disable breakpoint during DLC texture map load
Allows DLC loading but the DLC textures are still broken
* Fix post build not working
* ...
* fix vs2022 build
* fix cmake build
---------
Co-authored-by: Loki <lokirautio@gmail.com>
129 lines
3.1 KiB
C++
129 lines
3.1 KiB
C++
#include "stdafx.h"
|
|
#include "File.h"
|
|
#include "RegionFileCache.h"
|
|
#include "ConsoleSaveFileIO.h"
|
|
|
|
RegionFileCache RegionFileCache::s_defaultCache;
|
|
|
|
bool RegionFileCache::useSplitSaves(ESavePlatform platform)
|
|
{
|
|
switch(platform)
|
|
{
|
|
case SAVE_FILE_PLATFORM_XBONE:
|
|
case SAVE_FILE_PLATFORM_PS4:
|
|
return true;
|
|
default:
|
|
return false;
|
|
};
|
|
}
|
|
|
|
RegionFile *RegionFileCache::_getRegionFile(ConsoleSaveFile *saveFile, const wstring &prefix, int chunkX, int chunkZ) // 4J - TODO was synchronized
|
|
{
|
|
// 4J Jev - changed back to use of the File class.
|
|
//char file[MAX_PATH_SIZE];
|
|
//sprintf(file,"%s\\region\\r.%d.%d.mcr",basePath,chunkX >> 5,chunkZ >> 5);
|
|
|
|
//File regionDir(basePath, L"region");
|
|
|
|
//File file(regionDir, wstring(L"r.") + _toString(chunkX>>5) + L"." + _toString(chunkZ>>5) + L".mcr" );
|
|
MemSect(31);
|
|
File file;
|
|
if(useSplitSaves(saveFile->getSavePlatform()))
|
|
{
|
|
file = File( prefix + wstring(L"r.") + _toString(chunkX>>4) + L"." + _toString(chunkZ>>4) + L".mcr" );
|
|
}
|
|
else
|
|
{
|
|
file = File( prefix + wstring(L"r.") + _toString(chunkX>>5) + L"." + _toString(chunkZ>>5) + L".mcr" );
|
|
}
|
|
MemSect(0);
|
|
|
|
RegionFile *ref = NULL;
|
|
AUTO_VAR(it, cache.find(file));
|
|
if( it != cache.end() )
|
|
ref = it->second;
|
|
|
|
// 4J Jev, put back in.
|
|
if (ref != NULL)
|
|
{
|
|
return ref;
|
|
}
|
|
|
|
// 4J Stu - Remove for new save files
|
|
/*
|
|
if (!regionDir.exists())
|
|
{
|
|
regionDir.mkdirs();
|
|
}
|
|
*/
|
|
if (cache.size() >= MAX_CACHE_SIZE)
|
|
{
|
|
_clear();
|
|
}
|
|
|
|
RegionFile *reg = new RegionFile(saveFile, &file);
|
|
cache[file] = reg; // 4J - this was originally a softReferenc
|
|
return reg;
|
|
|
|
}
|
|
|
|
void RegionFileCache::_clear() // 4J - TODO was synchronized
|
|
{
|
|
AUTO_VAR(itEnd, cache.end());
|
|
for( AUTO_VAR(it, cache.begin()); it != itEnd; it++ )
|
|
{
|
|
// 4J - removed try/catch
|
|
// try {
|
|
RegionFile *regionFile = it->second;
|
|
if (regionFile != NULL)
|
|
{
|
|
regionFile->close();
|
|
}
|
|
delete regionFile;
|
|
// } catch (IOException e) {
|
|
// e.printStackTrace();
|
|
// }
|
|
}
|
|
cache.clear();
|
|
}
|
|
|
|
int RegionFileCache::_getSizeDelta(ConsoleSaveFile *saveFile, const wstring &prefix, int chunkX, int chunkZ)
|
|
{
|
|
RegionFile *r = _getRegionFile(saveFile, prefix, chunkX, chunkZ);
|
|
return r->getSizeDelta();
|
|
}
|
|
|
|
DataInputStream *RegionFileCache::_getChunkDataInputStream(ConsoleSaveFile *saveFile, const wstring &prefix, int chunkX, int chunkZ)
|
|
{
|
|
RegionFile* r = _getRegionFile(saveFile, prefix, chunkX, chunkZ);
|
|
if(useSplitSaves(saveFile->getSavePlatform()))
|
|
{
|
|
return r->getChunkDataInputStream(chunkX & 15, chunkZ & 15);
|
|
}
|
|
else
|
|
{
|
|
|
|
return r->getChunkDataInputStream(chunkX & 31, chunkZ & 31);
|
|
}
|
|
}
|
|
|
|
DataOutputStream *RegionFileCache::_getChunkDataOutputStream(ConsoleSaveFile *saveFile, const wstring &prefix, int chunkX, int chunkZ)
|
|
{
|
|
RegionFile* r = _getRegionFile(saveFile, prefix, chunkX, chunkZ);
|
|
if(useSplitSaves(saveFile->getSavePlatform()))
|
|
{
|
|
return r->getChunkDataOutputStream(chunkX & 15, chunkZ & 15);
|
|
}
|
|
else
|
|
{
|
|
|
|
return r->getChunkDataOutputStream(chunkX & 31, chunkZ & 31);
|
|
}
|
|
}
|
|
|
|
|
|
RegionFileCache::~RegionFileCache()
|
|
{
|
|
_clear();
|
|
}
|