1
0
mirror of https://github.com/blawar/GLideN64.git synced 2024-07-07 03:13:49 +00:00

Code refactor: make methods of TxUtil static.

This commit is contained in:
Sergey Lipskiy 2016-12-15 17:48:35 +07:00
parent e8522e7034
commit 8c42c31865
8 changed files with 16 additions and 30 deletions

View File

@ -36,15 +36,11 @@ TxCache::~TxCache()
{ {
/* free memory, clean up, etc */ /* free memory, clean up, etc */
clear(); clear();
delete _txUtil;
} }
TxCache::TxCache(int options, int cachesize, const wchar_t *path, const wchar_t *ident, TxCache::TxCache(int options, int cachesize, const wchar_t *path, const wchar_t *ident,
dispInfoFuncExt callback) dispInfoFuncExt callback)
{ {
_txUtil = new TxUtil();
_options = options; _options = options;
_cacheSize = cachesize; _cacheSize = cachesize;
_callback = callback; _callback = callback;
@ -85,7 +81,7 @@ TxCache::add(uint64 checksum, GHQTexInfo *info, int dataSize)
uint32 format = info->format; uint32 format = info->format;
if (!dataSize) { if (!dataSize) {
dataSize = _txUtil->sizeofTx(info->width, info->height, info->format); dataSize = TxUtil::sizeofTx(info->width, info->height, info->format);
if (!dataSize) return 0; if (!dataSize) return 0;

View File

@ -41,7 +41,6 @@ protected:
tx_wstring _ident; tx_wstring _ident;
tx_wstring _path; tx_wstring _path;
dispInfoFuncExt _callback; dispInfoFuncExt _callback;
TxUtil *_txUtil;
struct TXCACHE { struct TXCACHE {
int size; int size;
GHQTexInfo info; GHQTexInfo info;

View File

@ -49,7 +49,6 @@ void TxFilter::clear()
/* clear other stuff */ /* clear other stuff */
delete _txImage; delete _txImage;
delete _txQuantize; delete _txQuantize;
delete _txUtil;
} }
TxFilter::~TxFilter() TxFilter::~TxFilter()
@ -60,7 +59,7 @@ TxFilter::~TxFilter()
TxFilter::TxFilter(int maxwidth, int maxheight, int maxbpp, int options, TxFilter::TxFilter(int maxwidth, int maxheight, int maxbpp, int options,
int cachesize, const wchar_t * path, const wchar_t * texPackPath, const wchar_t * ident, int cachesize, const wchar_t * path, const wchar_t * texPackPath, const wchar_t * ident,
dispInfoFuncExt callback) : dispInfoFuncExt callback) :
_tex1(nullptr), _tex2(nullptr), _txQuantize(nullptr), _txTexCache(nullptr), _txHiResCache(nullptr), _txUtil(nullptr), _txImage(nullptr) _tex1(nullptr), _tex2(nullptr), _txQuantize(nullptr), _txTexCache(nullptr), _txHiResCache(nullptr), _txImage(nullptr)
{ {
/* HACKALERT: the emulator misbehaves and sometimes forgets to shutdown */ /* HACKALERT: the emulator misbehaves and sometimes forgets to shutdown */
if ((ident && wcscmp(ident, wst("DEFAULT")) != 0 && _ident.compare(ident) == 0) && if ((ident && wcscmp(ident, wst("DEFAULT")) != 0 && _ident.compare(ident) == 0) &&
@ -90,10 +89,9 @@ TxFilter::TxFilter(int maxwidth, int maxheight, int maxbpp, int options,
_txImage = new TxImage(); _txImage = new TxImage();
_txQuantize = new TxQuantize(); _txQuantize = new TxQuantize();
_txUtil = new TxUtil();
/* get number of CPU cores. */ /* get number of CPU cores. */
_numcore = _txUtil->getNumberofProcessors(); _numcore = TxUtil::getNumberofProcessors();
_initialized = 0; _initialized = 0;
@ -161,7 +159,7 @@ TxFilter::filter(uint8 *src, int srcwidth, int srcheight, uint16 srcformat, uint
/* calculate checksum of source texture */ /* calculate checksum of source texture */
if (!g64crc) if (!g64crc)
g64crc = (uint64)(_txUtil->checksumTx(texture, srcwidth, srcheight, srcformat)); g64crc = (uint64)(TxUtil::checksumTx(texture, srcwidth, srcheight, srcformat));
DBG_INFO(80, wst("filter: crc:%08X %08X %d x %d gfmt:%x\n"), DBG_INFO(80, wst("filter: crc:%08X %08X %d x %d gfmt:%x\n"),
(uint32)(g64crc >> 32), (uint32)(g64crc & 0xffffffff), srcwidth, srcheight, srcformat); (uint32)(g64crc >> 32), (uint32)(g64crc & 0xffffffff), srcwidth, srcheight, srcformat);
@ -561,7 +559,7 @@ uint64
TxFilter::checksum64(uint8 *src, int width, int height, int size, int rowStride, uint8 *palette) TxFilter::checksum64(uint8 *src, int width, int height, int size, int rowStride, uint8 *palette)
{ {
if (_options & (HIRESTEXTURES_MASK|DUMP_TEX)) if (_options & (HIRESTEXTURES_MASK|DUMP_TEX))
return _txUtil->checksum64(src, width, height, size, rowStride, palette); return TxUtil::checksum64(src, width, height, size, rowStride, palette);
return 0; return 0;
} }

View File

@ -48,7 +48,6 @@ private:
TxQuantize *_txQuantize; TxQuantize *_txQuantize;
TxTexCache *_txTexCache; TxTexCache *_txTexCache;
TxHiResCache *_txHiResCache; TxHiResCache *_txHiResCache;
TxUtil *_txUtil;
TxImage *_txImage; TxImage *_txImage;
boolean _initialized; boolean _initialized;
void clear(); void clear();

View File

@ -672,7 +672,7 @@ TxHiResCache::loadHiResTextures(const wchar_t * dir_path, boolean replace)
/* quantize */ /* quantize */
{ {
tmptex = (uint8 *)malloc(_txUtil->sizeofTx(width, height, destformat)); tmptex = (uint8 *)malloc(TxUtil::sizeofTx(width, height, destformat));
if (tmptex) { if (tmptex) {
switch (destformat) { switch (destformat) {
case GL_RGBA8: case GL_RGBA8:

View File

@ -35,16 +35,13 @@
TxQuantize::TxQuantize() TxQuantize::TxQuantize()
{ {
_txUtil = new TxUtil();
/* get number of CPU cores. */ /* get number of CPU cores. */
_numcore = _txUtil->getNumberofProcessors(); _numcore = TxUtil::getNumberofProcessors();
} }
TxQuantize::~TxQuantize() TxQuantize::~TxQuantize()
{ {
delete _txUtil;
} }
void void

View File

@ -30,7 +30,6 @@
class TxQuantize class TxQuantize
{ {
private: private:
TxUtil *_txUtil;
int _numcore; int _numcore;
/* fast optimized... well, sort of. */ /* fast optimized... well, sort of. */

View File

@ -35,22 +35,20 @@
class TxUtil class TxUtil
{ {
private: private:
uint32 RiceCRC32(const uint8* src, int width, int height, int size, int rowStride); static uint32 RiceCRC32(const uint8* src, int width, int height, int size, int rowStride);
boolean RiceCRC32_CI4(const uint8* src, int width, int height, int rowStride, static boolean RiceCRC32_CI4(const uint8* src, int width, int height, int rowStride,
uint32* crc32, uint32* cimax); uint32* crc32, uint32* cimax);
boolean RiceCRC32_CI8(const uint8* src, int width, int height, int rowStride, static boolean RiceCRC32_CI8(const uint8* src, int width, int height, int rowStride,
uint32* crc32, uint32* cimax); uint32* crc32, uint32* cimax);
public: public:
TxUtil() { } static int sizeofTx(int width, int height, uint16 format);
~TxUtil() { } static uint32 checksumTx(uint8 *data, int width, int height, uint16 format);
int sizeofTx(int width, int height, uint16 format);
uint32 checksumTx(uint8 *data, int width, int height, uint16 format);
#if 0 /* unused */ #if 0 /* unused */
uint32 chkAlpha(uint32* src, int width, int height); static uint32 chkAlpha(uint32* src, int width, int height);
#endif #endif
uint32 checksum(uint8 *src, int width, int height, int size, int rowStride); static uint32 checksum(uint8 *src, int width, int height, int size, int rowStride);
uint64 checksum64(uint8 *src, int width, int height, int size, int rowStride, uint8 *palette); static uint64 checksum64(uint8 *src, int width, int height, int size, int rowStride, uint8 *palette);
int getNumberofProcessors(); static int getNumberofProcessors();
}; };
class TxMemBuf class TxMemBuf