2021-03-02 02:13:17 +00:00
|
|
|
// Project64 - A Nintendo 64 emulator
|
|
|
|
// http://www.pj64-emu.com/
|
|
|
|
// Copyright(C) 2001-2021 Project64
|
|
|
|
// Copyright(C) 2007 Hiroshi Morii
|
|
|
|
// Copyright(C) 2003 Rice1964
|
|
|
|
// GNU/GPLv2 licensed: https://gnu.org/licenses/gpl-2.0.html
|
|
|
|
|
2013-04-17 10:30:38 +00:00
|
|
|
#ifdef WIN32
|
|
|
|
#pragma warning(disable: 4786)
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* dump cache to disk (0:disable, 1:enable) */
|
|
|
|
#define DUMP_CACHE 1
|
|
|
|
|
|
|
|
#include "TxTexCache.h"
|
|
|
|
#include "TxDbg.h"
|
|
|
|
#include <zlib/zlib.h>
|
|
|
|
#include <string>
|
|
|
|
#include <Common/path.h>
|
2016-01-20 06:09:05 +00:00
|
|
|
#include <Common/StdString.h>
|
2013-04-17 10:30:38 +00:00
|
|
|
|
|
|
|
TxTexCache::~TxTexCache()
|
|
|
|
{
|
|
|
|
#if DUMP_CACHE
|
2016-02-10 07:02:20 +00:00
|
|
|
if (_options & DUMP_TEXCACHE)
|
|
|
|
{
|
|
|
|
/* dump cache to disk */
|
|
|
|
std::string filename = _ident + "_MEMORYCACHE.dat";
|
|
|
|
CPath cachepath(_path.c_str(), "");
|
2016-08-21 21:43:49 +00:00
|
|
|
cachepath.AppendDirectory("Cache");
|
2013-04-17 10:30:38 +00:00
|
|
|
|
2016-02-10 07:02:20 +00:00
|
|
|
int config = _options & (FILTER_MASK | ENHANCEMENT_MASK | COMPRESS_TEX | COMPRESSION_MASK | FORCE16BPP_TEX | GZ_TEXCACHE);
|
2013-04-17 10:30:38 +00:00
|
|
|
|
2016-02-10 07:02:20 +00:00
|
|
|
TxCache::save(cachepath, filename.c_str(), config);
|
|
|
|
}
|
2013-04-17 10:30:38 +00:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2016-02-10 07:02:20 +00:00
|
|
|
TxTexCache::TxTexCache(int options, int cachesize, const char *path, const char *ident, dispInfoFuncExt callback) :
|
2017-04-26 10:23:36 +00:00
|
|
|
TxCache((options & ~GZ_HIRESTEXCACHE), cachesize, path, ident, callback)
|
2013-04-17 10:30:38 +00:00
|
|
|
{
|
2016-02-10 07:02:20 +00:00
|
|
|
/* assert local options */
|
|
|
|
if (_path.empty() || _ident.empty() || !_cacheSize)
|
|
|
|
{
|
|
|
|
_options &= ~DUMP_TEXCACHE;
|
|
|
|
}
|
2013-04-17 10:30:38 +00:00
|
|
|
|
|
|
|
#if DUMP_CACHE
|
2016-02-10 07:02:20 +00:00
|
|
|
if (_options & DUMP_TEXCACHE)
|
|
|
|
{
|
|
|
|
/* find it on disk */
|
|
|
|
std::string filename = _ident + "_MEMORYCACHE.dat";
|
|
|
|
CPath cachepath(_path.c_str(), "");
|
2016-08-21 21:43:49 +00:00
|
|
|
cachepath.AppendDirectory("Cache");
|
2016-02-10 07:02:20 +00:00
|
|
|
int config = _options & (FILTER_MASK | ENHANCEMENT_MASK | COMPRESS_TEX | COMPRESSION_MASK | FORCE16BPP_TEX | GZ_TEXCACHE);
|
2013-04-17 10:30:38 +00:00
|
|
|
|
2016-02-10 07:02:20 +00:00
|
|
|
TxCache::load(cachepath, filename.c_str(), config);
|
|
|
|
}
|
2013-04-17 10:30:38 +00:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2017-04-26 10:23:36 +00:00
|
|
|
bool TxTexCache::add(uint64_t checksum, GHQTexInfo *info)
|
2013-04-17 10:30:38 +00:00
|
|
|
{
|
2016-02-10 07:02:20 +00:00
|
|
|
if (_cacheSize <= 0) return 0;
|
2013-04-17 10:30:38 +00:00
|
|
|
|
2016-02-10 07:02:20 +00:00
|
|
|
return TxCache::add(checksum, info);
|
2017-04-26 10:23:36 +00:00
|
|
|
}
|