project64/Source/GlideHQ/TxTexCache.cpp

84 lines
2.5 KiB
C++
Raw Normal View History

2013-04-17 10:30:38 +00:00
/*
* Texture Filtering
* Version: 1.0
*
* Copyright (C) 2007 Hiroshi Morii All Rights Reserved.
* Email koolsmoky(at)users.sourceforge.net
* Web http://www.3dfxzone.it/koolsmoky
*
* this is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2, or (at your option)
* any later version.
*
* this is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with GNU Make; see the file COPYING. If not, write to
* the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#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>
#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(), "");
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) :
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(), "");
cachepath.AppendDirectory("cache");
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
}
2016-02-10 07:02:20 +00:00
boolean TxTexCache::add(uint64 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);
2013-04-17 10:30:38 +00:00
}