[Glide64] Clean up GlideHQ/TxCache.cpp
This commit is contained in:
parent
612bbb71e5
commit
0ebcf6d608
|
@ -58,14 +58,14 @@ TxCache::TxCache(int options, int cachesize, const wchar_t *path, const wchar_t
|
|||
_ident.assign(ident);
|
||||
|
||||
/* zlib memory buffers to (de)compress hires textures */
|
||||
if (_options & (GZ_TEXCACHE|GZ_HIRESTEXCACHE)) {
|
||||
if (_options & (GZ_TEXCACHE | GZ_HIRESTEXCACHE)) {
|
||||
_gzdest0 = TxMemBuf::getInstance()->get(0);
|
||||
_gzdest1 = TxMemBuf::getInstance()->get(1);
|
||||
_gzdestLen = (TxMemBuf::getInstance()->size_of(0) < TxMemBuf::getInstance()->size_of(1)) ?
|
||||
TxMemBuf::getInstance()->size_of(0) : TxMemBuf::getInstance()->size_of(1);
|
||||
|
||||
if (!_gzdest0 || !_gzdest1 || !_gzdestLen) {
|
||||
_options &= ~(GZ_TEXCACHE|GZ_HIRESTEXCACHE);
|
||||
_options &= ~(GZ_TEXCACHE | GZ_HIRESTEXCACHE);
|
||||
_gzdest0 = NULL;
|
||||
_gzdest1 = NULL;
|
||||
_gzdestLen = 0;
|
||||
|
@ -88,15 +88,16 @@ TxCache::add(uint64 checksum, GHQTexInfo *info, int dataSize)
|
|||
|
||||
if (!dataSize) return 0;
|
||||
|
||||
if (_options & (GZ_TEXCACHE|GZ_HIRESTEXCACHE)) {
|
||||
if (_options & (GZ_TEXCACHE | GZ_HIRESTEXCACHE)) {
|
||||
/* zlib compress it. compression level:1 (best speed) */
|
||||
uLongf destLen = _gzdestLen;
|
||||
dest = (dest == _gzdest0) ? _gzdest1 : _gzdest0;
|
||||
if (compress2(dest, &destLen, info->data, dataSize, 1) != Z_OK) {
|
||||
dest = info->data;
|
||||
DBG_INFO(80, L"Error: zlib compression failed!\n");
|
||||
} else {
|
||||
DBG_INFO(80, L"zlib compressed: %.02fkb->%.02fkb\n", (float)dataSize/1000, (float)destLen/1000);
|
||||
}
|
||||
else {
|
||||
DBG_INFO(80, L"zlib compressed: %.02fkb->%.02fkb\n", (float)dataSize / 1000, (float)destLen / 1000);
|
||||
dataSize = destLen;
|
||||
format |= GR_TEXFMT_GZ;
|
||||
}
|
||||
|
@ -184,7 +185,7 @@ TxCache::add(uint64 checksum, GHQTexInfo *info, int dataSize)
|
|||
return 1;
|
||||
}
|
||||
free(tmpdata);
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -217,7 +218,7 @@ TxCache::get(uint64 checksum, GHQTexInfo *info)
|
|||
}
|
||||
info->data = dest;
|
||||
info->format &= ~GR_TEXFMT_GZ;
|
||||
DBG_INFO(80, L"zlib decompressed: %.02fkb->%.02fkb\n", (float)(((*itMap).second)->size)/1000, (float)destLen/1000);
|
||||
DBG_INFO(80, L"zlib decompressed: %.02fkb->%.02fkb\n", (float)(((*itMap).second)->size) / 1000, (float)destLen / 1000);
|
||||
}
|
||||
|
||||
return 1;
|
||||
|
@ -233,7 +234,7 @@ TxCache::save(const wchar_t *path, const wchar_t *filename, int config)
|
|||
/* dump cache to disk */
|
||||
char cbuf[MAX_PATH];
|
||||
|
||||
CPath cachepath(stdstr().FromUTF16(path),"");
|
||||
CPath cachepath(stdstr().FromUTF16(path), "");
|
||||
cachepath.DirectoryCreate();
|
||||
|
||||
/* Ugly hack to enable fopen/gzopen in Win9x */
|
||||
|
@ -320,7 +321,7 @@ boolean
|
|||
TxCache::load(const wchar_t *path, const wchar_t *filename, int config)
|
||||
{
|
||||
/* find it on disk */
|
||||
CPath cbuf(stdstr().FromUTF16(path).c_str(),stdstr().FromUTF16(filename).c_str());
|
||||
CPath cbuf(stdstr().FromUTF16(path).c_str(), stdstr().FromUTF16(filename).c_str());
|
||||
|
||||
gzFile gzfp = gzopen(cbuf, "rb");
|
||||
DBG_INFO(80, L"gzfp:%x file:%ls\n", gzfp, filename);
|
||||
|
@ -363,14 +364,14 @@ TxCache::load(const wchar_t *path, const wchar_t *filename, int config)
|
|||
add(checksum, &tmpInfo, (tmpInfo.format & GR_TEXFMT_GZ) ? dataSize : 0);
|
||||
|
||||
free(tmpInfo.data);
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
gzseek(gzfp, dataSize, SEEK_CUR);
|
||||
}
|
||||
|
||||
/* skip in between to prevent the loop from being tied down to vsync */
|
||||
if (_callback && (!(_cache.size() % 100) || gzeof(gzfp)))
|
||||
(*_callback)(L"[%d] total mem:%.02fmb - %ls\n", _cache.size(), (float)_totalSize/1000000, filename);
|
||||
|
||||
(*_callback)(L"[%d] total mem:%.02fmb - %ls\n", _cache.size(), (float)_totalSize / 1000000, filename);
|
||||
} while (!gzeof(gzfp));
|
||||
gzclose(gzfp);
|
||||
}
|
||||
|
@ -386,7 +387,6 @@ TxCache::del(uint64 checksum)
|
|||
|
||||
std::map<uint64, TXCACHE*>::iterator itMap = _cache.find(checksum);
|
||||
if (itMap != _cache.end()) {
|
||||
|
||||
/* for texture cache (not hi-res cache) */
|
||||
if (!_cachelist.empty()) _cachelist.erase(((*itMap).second)->it);
|
||||
|
||||
|
|
Loading…
Reference in New Issue