Fixed compilation times by refactoring: WResourceManager.h gets included either directly or indirectly into every header & cpp file; so does its includes & implementation details. Broke out WResourceManager into a pure virtual class that contains only the required calls, and added a WResourceManagerImpl header that contains all the dirty details that the rest of the app doesn't care about / need to know.
This commit is contained in:
@@ -13,7 +13,7 @@
|
|||||||
class WResource
|
class WResource
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
friend class WResourceManager;
|
friend class ResourceManagerImpl;
|
||||||
friend struct WCacheSort;
|
friend struct WCacheSort;
|
||||||
template<class cacheItem, class cacheActual> friend class WCache;
|
template<class cacheItem, class cacheActual> friend class WCache;
|
||||||
|
|
||||||
@@ -39,7 +39,7 @@ protected:
|
|||||||
class WCachedResource: public WResource
|
class WCachedResource: public WResource
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
friend class WResourceManager;
|
friend class ResourceManagerImpl;
|
||||||
template<class cacheItem,class cacheActual> friend class WCache;
|
template<class cacheItem,class cacheActual> friend class WCache;
|
||||||
|
|
||||||
virtual ~WCachedResource();
|
virtual ~WCachedResource();
|
||||||
@@ -52,7 +52,7 @@ public:
|
|||||||
class WCachedTexture: public WCachedResource
|
class WCachedTexture: public WCachedResource
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
friend class WResourceManager;
|
friend class ResourceManagerImpl;
|
||||||
template<class cacheItem,class cacheActual> friend class WCache;
|
template<class cacheItem,class cacheActual> friend class WCache;
|
||||||
|
|
||||||
WCachedTexture();
|
WCachedTexture();
|
||||||
@@ -82,7 +82,7 @@ protected:
|
|||||||
class WCachedParticles: public WCachedResource
|
class WCachedParticles: public WCachedResource
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
friend class WResourceManager;
|
friend class ResourceManagerImpl;
|
||||||
template<class cacheItem,class cacheActual> friend class WCache;
|
template<class cacheItem,class cacheActual> friend class WCache;
|
||||||
WCachedParticles();
|
WCachedParticles();
|
||||||
~WCachedParticles();
|
~WCachedParticles();
|
||||||
@@ -104,7 +104,7 @@ protected:
|
|||||||
class WCachedSample: public WCachedResource
|
class WCachedSample: public WCachedResource
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
friend class WResourceManager;
|
friend class ResourceManagerImpl;
|
||||||
template<class cacheItem,class cacheActual> friend class WCache;
|
template<class cacheItem,class cacheActual> friend class WCache;
|
||||||
|
|
||||||
WCachedSample();
|
WCachedSample();
|
||||||
|
|||||||
@@ -1,41 +1,9 @@
|
|||||||
#ifndef _WRESOURCEMANAGER_H_
|
#ifndef _WResourceManager_H_
|
||||||
#define _WRESOURCEMANAGER_H_
|
#define _WResourceManager_H_
|
||||||
|
|
||||||
|
#include "WResource_Fwd.h"
|
||||||
#include <JResourceManager.h>
|
#include <JResourceManager.h>
|
||||||
#include <JSoundSystem.h>
|
#include <JSoundSystem.h>
|
||||||
#include <JTypes.h>
|
|
||||||
#include "MTGDeck.h"
|
|
||||||
#include "MTGCard.h"
|
|
||||||
#include "utils.h"
|
|
||||||
#include "WCachedResource.h"
|
|
||||||
#include "WFont.h"
|
|
||||||
#include "JLogger.h"
|
|
||||||
#include <sstream>
|
|
||||||
|
|
||||||
#include "Threading.h"
|
|
||||||
|
|
||||||
#define HUGE_CACHE_LIMIT 20000000 // Size of the cache for Windows and Linux
|
|
||||||
#define SAMPLES_CACHE_SIZE 1500000 // Size in bytes of the cached samples
|
|
||||||
#define PSI_CACHE_SIZE 500000 // Size in bytes of the cached particles
|
|
||||||
#define TEXTURES_CACHE_MINSIZE 2000000 // Minimum size of the cache on the PSP. The program should complain if the cache ever gets smaller than this
|
|
||||||
#define OPERATIONAL_SIZE 5000000 // Size required by Wagic for operational stuff. 3MB is not enough. The cache will usually try to take (Total Ram - Operational size)
|
|
||||||
#define MIN_LINEAR_RAM 1500000
|
|
||||||
#ifdef DEBUG_CACHE
|
|
||||||
#define MAX_CACHE_TIME 2000 //The threshold above which we try to prevent nowTime() from looping.
|
|
||||||
#else
|
|
||||||
#define MAX_CACHE_TIME 2000000000
|
|
||||||
#endif
|
|
||||||
|
|
||||||
|
|
||||||
#define THUMBNAILS_OFFSET 100000000
|
|
||||||
#define OTHERS_OFFSET 2000000000
|
|
||||||
|
|
||||||
//Hard Limits.
|
|
||||||
#define MAX_CACHE_OBJECTS 300
|
|
||||||
#define MAX_CACHE_ATTEMPTS 10
|
|
||||||
#define MAX_CACHE_MISSES 200
|
|
||||||
#define MAX_CACHED_SAMPLES 50
|
|
||||||
#define MAX_CACHE_GARBAGE 10
|
|
||||||
|
|
||||||
|
|
||||||
enum ENUM_WRES_INFO
|
enum ENUM_WRES_INFO
|
||||||
{
|
{
|
||||||
@@ -83,226 +51,75 @@ enum ENUM_CACHE_ERROR
|
|||||||
CACHE_ERROR_NOT_MANAGED,
|
CACHE_ERROR_NOT_MANAGED,
|
||||||
};
|
};
|
||||||
|
|
||||||
struct WCacheSort
|
struct WManagedQuad;
|
||||||
{
|
class WFont;
|
||||||
bool operator()(const WResource * l, const WResource * r); //Predicate for use in sorting. See flatten().
|
class MTGCard;
|
||||||
};
|
struct hgeParticleSystemInfo;
|
||||||
|
|
||||||
template <class cacheItem, class cacheActual>
|
|
||||||
class WCache
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
friend class WResourceManager;
|
|
||||||
friend class ThreadedCardRetriever;
|
|
||||||
friend class UnthreadedCardRetriever;
|
|
||||||
|
|
||||||
WCache();
|
|
||||||
~WCache();
|
|
||||||
|
|
||||||
cacheItem* Retrieve(int id, const string& filename, int style = RETRIEVE_NORMAL, int submode = CACHE_NORMAL); //Primary interface function.
|
|
||||||
bool Release(cacheActual* actual); //Releases an item, and deletes it if unlocked.
|
|
||||||
bool RemoveMiss(int id=0); //Removes a cache miss.
|
|
||||||
bool RemoveOldest(); //Remove oldest unlocked item.
|
|
||||||
bool Cleanup(); //Repeats RemoveOldest() until cache fits in size limits
|
|
||||||
void ClearUnlocked(); //Remove all unlocked items.
|
|
||||||
void Refresh(); //Refreshes all cache items.
|
|
||||||
unsigned int Flatten(); //Ensures that the times don't loop. Returns new lastTime.
|
|
||||||
void Resize(unsigned long size, int items); //Sets new limits, then enforces them. Lock safe, so not a "hard limit".
|
|
||||||
|
|
||||||
protected:
|
|
||||||
|
|
||||||
cacheItem* LoadIntoCache(int id, const string& filename, int submode, int style = RETRIEVE_NORMAL);
|
|
||||||
|
|
||||||
/*
|
|
||||||
** Attempts a new cache item, progressively clearing cache if it fails.
|
|
||||||
*/
|
|
||||||
cacheItem* AttemptNew(const string& filename, int submode);
|
|
||||||
|
|
||||||
bool RemoveItem(cacheItem* item, bool force = true); //Removes an item, deleting it. if(force), ignores locks / permanent
|
|
||||||
bool UnlinkCache(cacheItem* item); //Removes an item from our cache, does not delete it. Use with care.
|
|
||||||
bool Delete(cacheItem* item); //SAFE_DELETE and garbage collect. If maxCached == 0, nullify first. (This means you have to free that cacheActual later!)
|
|
||||||
cacheItem* Get(int id, const string& filename, int style = RETRIEVE_NORMAL, int submode = CACHE_NORMAL); //Subordinate to Retrieve.
|
|
||||||
|
|
||||||
int makeID(int id, const string& filename, int submode); //Makes an ID appropriate to the submode.
|
|
||||||
|
|
||||||
inline bool RequiresMissCleanup()
|
|
||||||
{
|
|
||||||
return (cacheItems < cache.size() /*&& cache.size() - cacheItems > MAX_CACHE_MISSES*/);
|
|
||||||
}
|
|
||||||
|
|
||||||
inline bool RequiresOldItemCleanup()
|
|
||||||
{
|
|
||||||
if (cacheItems > MAX_CACHE_OBJECTS || cacheItems > maxCached || cacheSize > maxCacheSize)
|
|
||||||
{
|
|
||||||
std::ostringstream stream;
|
|
||||||
if (cacheItems > MAX_CACHE_OBJECTS)
|
|
||||||
{
|
|
||||||
stream << "CacheItems exceeded 300, cacheItems = " << cacheItems;
|
|
||||||
}
|
|
||||||
else if (cacheItems > maxCached)
|
|
||||||
{
|
|
||||||
stream << "CacheItems (" << cacheItems << ") exceeded arbitrary limit of " << maxCached;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
stream << "Cache size (" << cacheSize << ") exceeded max value of " << maxCacheSize;
|
|
||||||
}
|
|
||||||
|
|
||||||
LOG(stream.str().c_str());
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
#if PSPENV
|
|
||||||
if (ramAvailableLineareMax() < MIN_LINEAR_RAM)
|
|
||||||
{
|
|
||||||
DebugTrace("Memory below minimum threshold!!");
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
map<string,int> ids;
|
|
||||||
map<int,cacheItem*> cache;
|
|
||||||
map<int,cacheItem*> managed; //Cache can be arbitrarily large, so managed items are separate.
|
|
||||||
unsigned long totalSize;
|
|
||||||
unsigned long cacheSize;
|
|
||||||
|
|
||||||
//Applies to cacheSize only.
|
|
||||||
unsigned long maxCacheSize;
|
|
||||||
unsigned int maxCached;
|
|
||||||
|
|
||||||
unsigned int cacheItems;
|
|
||||||
int mError;
|
|
||||||
|
|
||||||
// mutex meant for the cache map
|
|
||||||
boost::mutex mCacheMutex;
|
|
||||||
// mutex meant to protect against unthread-safe calls into JFileSystem, etc.
|
|
||||||
boost::mutex mLoadFunctionMutex;
|
|
||||||
};
|
|
||||||
|
|
||||||
struct WManagedQuad
|
|
||||||
{
|
|
||||||
WCachedTexture* texture;
|
|
||||||
string resname;
|
|
||||||
};
|
|
||||||
|
|
||||||
class WResourceManager
|
class WResourceManager
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
static WResourceManager* Instance()
|
static WResourceManager* Instance();
|
||||||
|
static void Terminate();
|
||||||
|
|
||||||
|
virtual ~WResourceManager()
|
||||||
{
|
{
|
||||||
if (sInstance == NULL)
|
|
||||||
{
|
|
||||||
sInstance = NEW WResourceManager;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return sInstance;
|
virtual bool IsThreaded() = 0;
|
||||||
}
|
|
||||||
|
|
||||||
static void Terminate()
|
virtual JQuadPtr RetrieveCard(MTGCard * card, int style = RETRIEVE_NORMAL,int submode = CACHE_NORMAL) = 0;
|
||||||
{
|
virtual JSample * RetrieveSample(const string& filename, int style = RETRIEVE_NORMAL, int submode = CACHE_NORMAL) = 0;
|
||||||
if (sInstance)
|
virtual JTexture * RetrieveTexture(const string& filename, int style = RETRIEVE_NORMAL, int submode = CACHE_NORMAL) = 0;
|
||||||
SAFE_DELETE(sInstance);
|
virtual JQuadPtr RetrieveQuad(const string& filename, float offX=0.0f, float offY=0.0f, float width=0.0f, float height=0.0f, string resname="", int style = RETRIEVE_LOCK, int submode = CACHE_NORMAL, int id = 0) = 0;
|
||||||
}
|
virtual JQuadPtr RetrieveTempQuad(const string& filename, int submode = CACHE_NORMAL) = 0;
|
||||||
|
virtual hgeParticleSystemInfo * RetrievePSI(const string& filename, JQuad * texture, int style = RETRIEVE_NORMAL, int submode = CACHE_NORMAL) = 0;
|
||||||
|
virtual int RetrieveError() = 0;
|
||||||
|
|
||||||
virtual ~WResourceManager();
|
virtual void Release(JTexture * tex) = 0;
|
||||||
|
virtual void Release(JSample * sample) = 0;
|
||||||
|
|
||||||
bool IsThreaded();
|
//Refreshes all files in cache, for when mode/profile changes.
|
||||||
|
virtual void Refresh() = 0;
|
||||||
|
|
||||||
void Unmiss(string filename);
|
virtual unsigned int nowTime() = 0;
|
||||||
JQuadPtr RetrieveCard(MTGCard * card, int style = RETRIEVE_NORMAL,int submode = CACHE_NORMAL);
|
|
||||||
JSample * RetrieveSample(const string& filename, int style = RETRIEVE_NORMAL, int submode = CACHE_NORMAL);
|
|
||||||
JTexture * RetrieveTexture(const string& filename, int style = RETRIEVE_NORMAL, int submode = CACHE_NORMAL);
|
|
||||||
JQuadPtr RetrieveQuad(const string& filename, float offX=0.0f, float offY=0.0f, float width=0.0f, float height=0.0f, string resname="", int style = RETRIEVE_LOCK, int submode = CACHE_NORMAL, int id = 0);
|
|
||||||
JQuadPtr RetrieveTempQuad(const string& filename, int submode = CACHE_NORMAL);
|
|
||||||
hgeParticleSystemInfo * RetrievePSI(const string& filename, JQuad * texture, int style = RETRIEVE_NORMAL, int submode = CACHE_NORMAL);
|
|
||||||
int RetrieveError();
|
|
||||||
|
|
||||||
void Release(JTexture * tex);
|
virtual JQuadPtr GetQuad(const string &quadName) = 0;
|
||||||
void Release(JSample * sample);
|
|
||||||
bool RemoveOldest();
|
|
||||||
|
|
||||||
void ClearUnlocked(); //Remove unlocked items.
|
|
||||||
void Refresh(); //Refreshes all files in cache, for when mode/profile changes.
|
|
||||||
|
|
||||||
unsigned int nowTime();
|
|
||||||
|
|
||||||
unsigned long Size();
|
|
||||||
unsigned long SizeCached();
|
|
||||||
unsigned long SizeManaged();
|
|
||||||
|
|
||||||
unsigned int Count();
|
|
||||||
unsigned int CountCached();
|
|
||||||
unsigned int CountManaged();
|
|
||||||
|
|
||||||
int CreateQuad(const string &quadName, const string &textureName, float x, float y, float width, float height);
|
|
||||||
JQuadPtr GetQuad(const string &quadName);
|
|
||||||
JQuadPtr GetQuad(int id);
|
|
||||||
|
|
||||||
int AddQuadToManaged(const WManagedQuad& inManagedQuad);
|
|
||||||
|
|
||||||
//Our file redirect system.
|
//Our file redirect system.
|
||||||
string graphicsFile(const string& filename);
|
virtual string graphicsFile(const string& filename) = 0;
|
||||||
string avatarFile(const string& filename);
|
virtual string avatarFile(const string& filename) = 0;
|
||||||
string cardFile(const string& filename);
|
virtual string cardFile(const string& filename) = 0;
|
||||||
string musicFile(const string& filename);
|
virtual string musicFile(const string& filename) = 0;
|
||||||
string sfxFile(const string& filename);
|
virtual string sfxFile(const string& filename) = 0;
|
||||||
int fileOK(const string&, bool relative = false);
|
virtual int fileOK(const string&, bool relative = false) = 0;
|
||||||
int dirOK(const string& dirname);
|
virtual int dirOK(const string& dirname) = 0;
|
||||||
|
|
||||||
//For backwards compatibility with JResourceManager. Avoid using these, they're not optimal.
|
//For backwards compatibility with JWResourceManager. Avoid using these, they're not optimal.
|
||||||
int CreateTexture(const string &textureName);
|
virtual int CreateTexture(const string &textureName) = 0;
|
||||||
JTexture* GetTexture(const string &textureName);
|
virtual JTexture* GetTexture(const string &textureName) = 0;
|
||||||
JTexture* GetTexture(int id);
|
|
||||||
|
|
||||||
// Font management functions
|
// Font management functions
|
||||||
void InitFonts(const std::string& inLang);
|
virtual void InitFonts(const std::string& inLang) = 0;
|
||||||
int ReloadWFonts();
|
virtual int ReloadWFonts() = 0;
|
||||||
WFont* LoadWFont(const string& inFontname, int inFontHeight, int inFontID);
|
virtual WFont* LoadWFont(const string& inFontname, int inFontHeight, int inFontID) = 0;
|
||||||
WFont* GetWFont(int id);
|
virtual WFont* GetWFont(int id) = 0;
|
||||||
void RemoveWFonts();
|
|
||||||
|
|
||||||
//Wrapped from JSoundSystem. TODO: Privatize.
|
//Wrapped from JSoundSystem. TODO: Privatize.
|
||||||
JMusic * ssLoadMusic(const char *fileName);
|
virtual JMusic * ssLoadMusic(const char *fileName) = 0;
|
||||||
|
|
||||||
//Resets the cache limits on when it starts to purge data.
|
//Resets the cache limits on when it starts to purge data.
|
||||||
void ResetCacheLimits();
|
virtual void ResetCacheLimits() = 0;
|
||||||
|
|
||||||
void DebugRender();
|
virtual void DebugRender() = 0;
|
||||||
|
|
||||||
#ifdef DEBUG_CACHE
|
protected:
|
||||||
unsigned long menuCached;
|
|
||||||
string debugMessage;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
private:
|
|
||||||
/*
|
/*
|
||||||
** Singleton object only accessibly via Instance(), constructor is private
|
** Singleton object only accessibly via Instance(), constructor is private
|
||||||
*/
|
*/
|
||||||
WResourceManager();
|
WResourceManager()
|
||||||
|
{
|
||||||
bool bThemedCards; //Does the theme have a "sets" directory for overwriting cards?
|
}
|
||||||
void FlattenTimes(); //To prevent bad cache timing on int overflow
|
|
||||||
|
|
||||||
//For cached stuff
|
|
||||||
WCache<WCachedTexture,JTexture> textureWCache;
|
|
||||||
WCache<WCachedSample,JSample> sampleWCache;
|
|
||||||
WCache<WCachedParticles,hgeParticleSystemInfo> psiWCache;
|
|
||||||
|
|
||||||
typedef std::map<std::string, WManagedQuad> ManagedQuadMap;
|
|
||||||
ManagedQuadMap mManagedQuads;
|
|
||||||
|
|
||||||
typedef std::map<int, std::string> IDLookupMap;
|
|
||||||
IDLookupMap mIDLookupMap;
|
|
||||||
|
|
||||||
//Statistics of record.
|
|
||||||
unsigned int lastTime;
|
|
||||||
int lastError;
|
|
||||||
|
|
||||||
typedef std::map<int, WFont*> FontMap;
|
|
||||||
FontMap mWFontMap;
|
|
||||||
std::string mFontFileExtension;
|
|
||||||
|
|
||||||
static WResourceManager* sInstance;
|
static WResourceManager* sInstance;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -0,0 +1,241 @@
|
|||||||
|
#ifndef RESOURCEMANAGERIMPLIMPL_H
|
||||||
|
#define RESOURCEMANAGERIMPLIMPL_H
|
||||||
|
#include <JTypes.h>
|
||||||
|
#include "MTGDeck.h"
|
||||||
|
#include "MTGCard.h"
|
||||||
|
#include "utils.h"
|
||||||
|
#include "Threading.h"
|
||||||
|
#include "WResourceManager.h"
|
||||||
|
#include "WCachedResource.h"
|
||||||
|
#include "WFont.h"
|
||||||
|
#include "JLogger.h"
|
||||||
|
#include <sstream>
|
||||||
|
|
||||||
|
#define HUGE_CACHE_LIMIT 20000000 // Size of the cache for Windows and Linux
|
||||||
|
#define SAMPLES_CACHE_SIZE 1500000 // Size in bytes of the cached samples
|
||||||
|
#define PSI_CACHE_SIZE 500000 // Size in bytes of the cached particles
|
||||||
|
#define TEXTURES_CACHE_MINSIZE 2000000 // Minimum size of the cache on the PSP. The program should complain if the cache ever gets smaller than this
|
||||||
|
#define OPERATIONAL_SIZE 5000000 // Size required by Wagic for operational stuff. 3MB is not enough. The cache will usually try to take (Total Ram - Operational size)
|
||||||
|
#define MIN_LINEAR_RAM 1500000
|
||||||
|
#ifdef DEBUG_CACHE
|
||||||
|
#define MAX_CACHE_TIME 2000 //The threshold above which we try to prevent nowTime() from looping.
|
||||||
|
#else
|
||||||
|
#define MAX_CACHE_TIME 2000000000
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
#define THUMBNAILS_OFFSET 100000000
|
||||||
|
#define OTHERS_OFFSET 2000000000
|
||||||
|
|
||||||
|
//Hard Limits.
|
||||||
|
#define MAX_CACHE_OBJECTS 300
|
||||||
|
#define MAX_CACHE_ATTEMPTS 10
|
||||||
|
#define MAX_CACHE_MISSES 200
|
||||||
|
#define MAX_CACHED_SAMPLES 50
|
||||||
|
#define MAX_CACHE_GARBAGE 10
|
||||||
|
|
||||||
|
struct WCacheSort
|
||||||
|
{
|
||||||
|
bool operator()(const WResource * l, const WResource * r); //Predicate for use in sorting. See flatten().
|
||||||
|
};
|
||||||
|
|
||||||
|
template <class cacheItem, class cacheActual>
|
||||||
|
class WCache
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
friend class ResourceManagerImpl;
|
||||||
|
friend class ThreadedCardRetriever;
|
||||||
|
friend class UnthreadedCardRetriever;
|
||||||
|
|
||||||
|
WCache();
|
||||||
|
~WCache();
|
||||||
|
|
||||||
|
cacheItem* Retrieve(int id, const string& filename, int style = RETRIEVE_NORMAL, int submode = CACHE_NORMAL); //Primary interface function.
|
||||||
|
bool Release(cacheActual* actual); //Releases an item, and deletes it if unlocked.
|
||||||
|
bool RemoveMiss(int id=0); //Removes a cache miss.
|
||||||
|
bool RemoveOldest(); //Remove oldest unlocked item.
|
||||||
|
bool Cleanup(); //Repeats RemoveOldest() until cache fits in size limits
|
||||||
|
void ClearUnlocked(); //Remove all unlocked items.
|
||||||
|
void Refresh(); //Refreshes all cache items.
|
||||||
|
unsigned int Flatten(); //Ensures that the times don't loop. Returns new lastTime.
|
||||||
|
void Resize(unsigned long size, int items); //Sets new limits, then enforces them. Lock safe, so not a "hard limit".
|
||||||
|
|
||||||
|
protected:
|
||||||
|
|
||||||
|
cacheItem* LoadIntoCache(int id, const string& filename, int submode, int style = RETRIEVE_NORMAL);
|
||||||
|
|
||||||
|
/*
|
||||||
|
** Attempts a new cache item, progressively clearing cache if it fails.
|
||||||
|
*/
|
||||||
|
cacheItem* AttemptNew(const string& filename, int submode);
|
||||||
|
|
||||||
|
bool RemoveItem(cacheItem* item, bool force = true); //Removes an item, deleting it. if(force), ignores locks / permanent
|
||||||
|
bool UnlinkCache(cacheItem* item); //Removes an item from our cache, does not delete it. Use with care.
|
||||||
|
bool Delete(cacheItem* item); //SAFE_DELETE and garbage collect. If maxCached == 0, nullify first. (This means you have to free that cacheActual later!)
|
||||||
|
cacheItem* Get(int id, const string& filename, int style = RETRIEVE_NORMAL, int submode = CACHE_NORMAL); //Subordinate to Retrieve.
|
||||||
|
|
||||||
|
int makeID(int id, const string& filename, int submode); //Makes an ID appropriate to the submode.
|
||||||
|
|
||||||
|
inline bool RequiresMissCleanup()
|
||||||
|
{
|
||||||
|
return (cacheItems < cache.size() /*&& cache.size() - cacheItems > MAX_CACHE_MISSES*/);
|
||||||
|
}
|
||||||
|
|
||||||
|
inline bool RequiresOldItemCleanup()
|
||||||
|
{
|
||||||
|
if (cacheItems > MAX_CACHE_OBJECTS || cacheItems > maxCached || cacheSize > maxCacheSize)
|
||||||
|
{
|
||||||
|
std::ostringstream stream;
|
||||||
|
if (cacheItems > MAX_CACHE_OBJECTS)
|
||||||
|
{
|
||||||
|
stream << "CacheItems exceeded 300, cacheItems = " << cacheItems;
|
||||||
|
}
|
||||||
|
else if (cacheItems > maxCached)
|
||||||
|
{
|
||||||
|
stream << "CacheItems (" << cacheItems << ") exceeded arbitrary limit of " << maxCached;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
stream << "Cache size (" << cacheSize << ") exceeded max value of " << maxCacheSize;
|
||||||
|
}
|
||||||
|
|
||||||
|
LOG(stream.str().c_str());
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
#if PSPENV
|
||||||
|
if (ramAvailableLineareMax() < MIN_LINEAR_RAM)
|
||||||
|
{
|
||||||
|
DebugTrace("Memory below minimum threshold!!");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
map<string,int> ids;
|
||||||
|
map<int,cacheItem*> cache;
|
||||||
|
map<int,cacheItem*> managed; //Cache can be arbitrarily large, so managed items are separate.
|
||||||
|
unsigned long totalSize;
|
||||||
|
unsigned long cacheSize;
|
||||||
|
|
||||||
|
//Applies to cacheSize only.
|
||||||
|
unsigned long maxCacheSize;
|
||||||
|
unsigned int maxCached;
|
||||||
|
|
||||||
|
unsigned int cacheItems;
|
||||||
|
int mError;
|
||||||
|
|
||||||
|
// mutex meant for the cache map
|
||||||
|
boost::mutex mCacheMutex;
|
||||||
|
// mutex meant to protect against unthread-safe calls into JFileSystem, etc.
|
||||||
|
boost::mutex mLoadFunctionMutex;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct WManagedQuad
|
||||||
|
{
|
||||||
|
WCachedTexture* texture;
|
||||||
|
string resname;
|
||||||
|
};
|
||||||
|
|
||||||
|
class ResourceManagerImpl : public WResourceManager
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
|
||||||
|
ResourceManagerImpl();
|
||||||
|
virtual ~ResourceManagerImpl();
|
||||||
|
|
||||||
|
bool IsThreaded();
|
||||||
|
|
||||||
|
void Unmiss(string filename);
|
||||||
|
JQuadPtr RetrieveCard(MTGCard * card, int style = RETRIEVE_NORMAL,int submode = CACHE_NORMAL);
|
||||||
|
JSample * RetrieveSample(const string& filename, int style = RETRIEVE_NORMAL, int submode = CACHE_NORMAL);
|
||||||
|
JTexture * RetrieveTexture(const string& filename, int style = RETRIEVE_NORMAL, int submode = CACHE_NORMAL);
|
||||||
|
JQuadPtr RetrieveQuad(const string& filename, float offX=0.0f, float offY=0.0f, float width=0.0f, float height=0.0f, string resname="", int style = RETRIEVE_LOCK, int submode = CACHE_NORMAL, int id = 0);
|
||||||
|
JQuadPtr RetrieveTempQuad(const string& filename, int submode = CACHE_NORMAL);
|
||||||
|
hgeParticleSystemInfo * RetrievePSI(const string& filename, JQuad * texture, int style = RETRIEVE_NORMAL, int submode = CACHE_NORMAL);
|
||||||
|
int RetrieveError();
|
||||||
|
|
||||||
|
void Release(JTexture * tex);
|
||||||
|
void Release(JSample * sample);
|
||||||
|
bool RemoveOldest();
|
||||||
|
|
||||||
|
void ClearUnlocked(); //Remove unlocked items.
|
||||||
|
void Refresh(); //Refreshes all files in cache, for when mode/profile changes.
|
||||||
|
|
||||||
|
unsigned int nowTime();
|
||||||
|
|
||||||
|
unsigned long Size();
|
||||||
|
unsigned long SizeCached();
|
||||||
|
unsigned long SizeManaged();
|
||||||
|
|
||||||
|
unsigned int Count();
|
||||||
|
unsigned int CountCached();
|
||||||
|
unsigned int CountManaged();
|
||||||
|
|
||||||
|
int CreateQuad(const string &quadName, const string &textureName, float x, float y, float width, float height);
|
||||||
|
JQuadPtr GetQuad(const string &quadName);
|
||||||
|
JQuadPtr GetQuad(int id);
|
||||||
|
|
||||||
|
int AddQuadToManaged(const WManagedQuad& inManagedQuad);
|
||||||
|
|
||||||
|
//Our file redirect system.
|
||||||
|
string graphicsFile(const string& filename);
|
||||||
|
string avatarFile(const string& filename);
|
||||||
|
string cardFile(const string& filename);
|
||||||
|
string musicFile(const string& filename);
|
||||||
|
string sfxFile(const string& filename);
|
||||||
|
int fileOK(const string&, bool relative = false);
|
||||||
|
int dirOK(const string& dirname);
|
||||||
|
|
||||||
|
//For backwards compatibility with JResourceManager. Avoid using these, they're not optimal.
|
||||||
|
int CreateTexture(const string &textureName);
|
||||||
|
JTexture* GetTexture(const string &textureName);
|
||||||
|
JTexture* GetTexture(int id);
|
||||||
|
|
||||||
|
// Font management functions
|
||||||
|
void InitFonts(const std::string& inLang);
|
||||||
|
int ReloadWFonts();
|
||||||
|
WFont* LoadWFont(const string& inFontname, int inFontHeight, int inFontID);
|
||||||
|
WFont* GetWFont(int id);
|
||||||
|
void RemoveWFonts();
|
||||||
|
|
||||||
|
//Wrapped from JSoundSystem. TODO: Privatize.
|
||||||
|
JMusic * ssLoadMusic(const char *fileName);
|
||||||
|
|
||||||
|
//Resets the cache limits on when it starts to purge data.
|
||||||
|
void ResetCacheLimits();
|
||||||
|
|
||||||
|
void DebugRender();
|
||||||
|
|
||||||
|
#ifdef DEBUG_CACHE
|
||||||
|
unsigned long menuCached;
|
||||||
|
string debugMessage;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
private:
|
||||||
|
bool bThemedCards; //Does the theme have a "sets" directory for overwriting cards?
|
||||||
|
void FlattenTimes(); //To prevent bad cache timing on int overflow
|
||||||
|
|
||||||
|
//For cached stuff
|
||||||
|
WCache<WCachedTexture,JTexture> textureWCache;
|
||||||
|
WCache<WCachedSample,JSample> sampleWCache;
|
||||||
|
WCache<WCachedParticles,hgeParticleSystemInfo> psiWCache;
|
||||||
|
|
||||||
|
typedef std::map<std::string, WManagedQuad> ManagedQuadMap;
|
||||||
|
ManagedQuadMap mManagedQuads;
|
||||||
|
|
||||||
|
typedef std::map<int, std::string> IDLookupMap;
|
||||||
|
IDLookupMap mIDLookupMap;
|
||||||
|
|
||||||
|
//Statistics of record.
|
||||||
|
unsigned int lastTime;
|
||||||
|
int lastError;
|
||||||
|
|
||||||
|
typedef std::map<int, WFont*> FontMap;
|
||||||
|
FontMap mWFontMap;
|
||||||
|
std::string mFontFileExtension;
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
||||||
@@ -4,6 +4,7 @@
|
|||||||
#include <JFileSystem.h>
|
#include <JFileSystem.h>
|
||||||
#include "GameOptions.h"
|
#include "GameOptions.h"
|
||||||
#include "WResourceManager.h"
|
#include "WResourceManager.h"
|
||||||
|
#include "WCachedResource.h"
|
||||||
#include <hge/hgeparticle.h>
|
#include <hge/hgeparticle.h>
|
||||||
|
|
||||||
#ifdef WITH_FMOD
|
#ifdef WITH_FMOD
|
||||||
|
|||||||
@@ -3,6 +3,7 @@
|
|||||||
#include "WFont.h"
|
#include "WFont.h"
|
||||||
#include "WResourceManager.h"
|
#include "WResourceManager.h"
|
||||||
#include "JFileSystem.h"
|
#include "JFileSystem.h"
|
||||||
|
#include "GameApp.h"
|
||||||
|
|
||||||
#define ISGBK(c) ((c) > 0x80 || (c) < 0x30 || (c) == '-' || (c) == '/')
|
#define ISGBK(c) ((c) > 0x80 || (c) < 0x30 || (c) == '-' || (c) == '/')
|
||||||
|
|
||||||
|
|||||||
@@ -1,10 +1,11 @@
|
|||||||
#include "PrecompiledHeader.h"
|
#include "PrecompiledHeader.h"
|
||||||
|
|
||||||
#include "GameOptions.h"
|
#include "GameOptions.h"
|
||||||
#include "CacheEngine.h"
|
#include "WResourceManagerImpl.h"
|
||||||
#include "WResourceManager.h"
|
|
||||||
#include "StyleManager.h"
|
#include "StyleManager.h"
|
||||||
|
|
||||||
|
#include "CacheEngine.h"
|
||||||
|
|
||||||
#if defined (WIN32)
|
#if defined (WIN32)
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
@@ -29,12 +30,29 @@ namespace
|
|||||||
|
|
||||||
WResourceManager* WResourceManager::sInstance = NULL;
|
WResourceManager* WResourceManager::sInstance = NULL;
|
||||||
|
|
||||||
int WResourceManager::RetrieveError()
|
WResourceManager* WResourceManager::Instance()
|
||||||
|
{
|
||||||
|
if (sInstance == NULL)
|
||||||
|
{
|
||||||
|
sInstance = NEW ResourceManagerImpl;
|
||||||
|
}
|
||||||
|
|
||||||
|
return sInstance;
|
||||||
|
}
|
||||||
|
|
||||||
|
void WResourceManager::Terminate()
|
||||||
|
{
|
||||||
|
if (sInstance)
|
||||||
|
SAFE_DELETE(sInstance);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int ResourceManagerImpl::RetrieveError()
|
||||||
{
|
{
|
||||||
return lastError;
|
return lastError;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool WResourceManager::RemoveOldest()
|
bool ResourceManagerImpl::RemoveOldest()
|
||||||
{
|
{
|
||||||
if (sampleWCache.RemoveOldest()) return true;
|
if (sampleWCache.RemoveOldest()) return true;
|
||||||
if (textureWCache.RemoveOldest()) return true;
|
if (textureWCache.RemoveOldest()) return true;
|
||||||
@@ -43,11 +61,11 @@ bool WResourceManager::RemoveOldest()
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
//WResourceManager
|
//ResourceManagerImpl
|
||||||
void WResourceManager::DebugRender()
|
void ResourceManagerImpl::DebugRender()
|
||||||
{
|
{
|
||||||
JRenderer* renderer = JRenderer::GetInstance();
|
JRenderer* renderer = JRenderer::GetInstance();
|
||||||
WFont * font = WResourceManager::Instance()->GetWFont(Fonts::MAIN_FONT);
|
WFont * font = ResourceManagerImpl::Instance()->GetWFont(Fonts::MAIN_FONT);
|
||||||
if (!font || !renderer) return;
|
if (!font || !renderer) return;
|
||||||
|
|
||||||
font->SetColor(ARGB(255,255,255,255));
|
font->SetColor(ARGB(255,255,255,255));
|
||||||
@@ -87,7 +105,7 @@ void WResourceManager::DebugRender()
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned long WResourceManager::Size()
|
unsigned long ResourceManagerImpl::Size()
|
||||||
{
|
{
|
||||||
unsigned long res = 0;
|
unsigned long res = 0;
|
||||||
res += textureWCache.totalSize;
|
res += textureWCache.totalSize;
|
||||||
@@ -96,7 +114,7 @@ unsigned long WResourceManager::Size()
|
|||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned long WResourceManager::SizeCached()
|
unsigned long ResourceManagerImpl::SizeCached()
|
||||||
{
|
{
|
||||||
unsigned long res = 0;
|
unsigned long res = 0;
|
||||||
res += textureWCache.cacheSize;
|
res += textureWCache.cacheSize;
|
||||||
@@ -105,7 +123,7 @@ unsigned long WResourceManager::SizeCached()
|
|||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned long WResourceManager::SizeManaged()
|
unsigned long ResourceManagerImpl::SizeManaged()
|
||||||
{
|
{
|
||||||
unsigned long res = 0;
|
unsigned long res = 0;
|
||||||
if (textureWCache.totalSize > textureWCache.cacheSize) res += textureWCache.totalSize - textureWCache.cacheSize;
|
if (textureWCache.totalSize > textureWCache.cacheSize) res += textureWCache.totalSize - textureWCache.cacheSize;
|
||||||
@@ -117,7 +135,7 @@ unsigned long WResourceManager::SizeManaged()
|
|||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned int WResourceManager::Count()
|
unsigned int ResourceManagerImpl::Count()
|
||||||
{
|
{
|
||||||
unsigned int count = 0;
|
unsigned int count = 0;
|
||||||
count += textureWCache.cacheItems;
|
count += textureWCache.cacheItems;
|
||||||
@@ -129,7 +147,7 @@ unsigned int WResourceManager::Count()
|
|||||||
return count;
|
return count;
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned int WResourceManager::CountCached()
|
unsigned int ResourceManagerImpl::CountCached()
|
||||||
{
|
{
|
||||||
unsigned int count = 0;
|
unsigned int count = 0;
|
||||||
count += textureWCache.cacheItems;
|
count += textureWCache.cacheItems;
|
||||||
@@ -137,7 +155,7 @@ unsigned int WResourceManager::CountCached()
|
|||||||
count += psiWCache.cacheItems;
|
count += psiWCache.cacheItems;
|
||||||
return count;
|
return count;
|
||||||
}
|
}
|
||||||
unsigned int WResourceManager::CountManaged()
|
unsigned int ResourceManagerImpl::CountManaged()
|
||||||
{
|
{
|
||||||
unsigned int count = 0;
|
unsigned int count = 0;
|
||||||
count += textureWCache.managed.size();
|
count += textureWCache.managed.size();
|
||||||
@@ -146,14 +164,14 @@ unsigned int WResourceManager::CountManaged()
|
|||||||
return count;
|
return count;
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned int WResourceManager::nowTime()
|
unsigned int ResourceManagerImpl::nowTime()
|
||||||
{
|
{
|
||||||
if (lastTime > MAX_CACHE_TIME) FlattenTimes();
|
if (lastTime > MAX_CACHE_TIME) FlattenTimes();
|
||||||
|
|
||||||
return ++lastTime;
|
return ++lastTime;
|
||||||
}
|
}
|
||||||
|
|
||||||
void WResourceManager::FlattenTimes()
|
void ResourceManagerImpl::FlattenTimes()
|
||||||
{
|
{
|
||||||
unsigned int t;
|
unsigned int t;
|
||||||
lastTime = sampleWCache.Flatten();
|
lastTime = sampleWCache.Flatten();
|
||||||
@@ -165,9 +183,9 @@ void WResourceManager::FlattenTimes()
|
|||||||
if (t > lastTime) lastTime = t;
|
if (t > lastTime) lastTime = t;
|
||||||
}
|
}
|
||||||
|
|
||||||
WResourceManager::WResourceManager()
|
ResourceManagerImpl::ResourceManagerImpl()
|
||||||
{
|
{
|
||||||
DebugTrace("Init WResourceManager : " << this);
|
DebugTrace("Init ResourceManagerImpl : " << this);
|
||||||
#ifdef DEBUG_CACHE
|
#ifdef DEBUG_CACHE
|
||||||
menuCached = 0;
|
menuCached = 0;
|
||||||
#endif
|
#endif
|
||||||
@@ -189,21 +207,21 @@ WResourceManager::WResourceManager()
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
WResourceManager::~WResourceManager()
|
ResourceManagerImpl::~ResourceManagerImpl()
|
||||||
{
|
{
|
||||||
LOG("==Destroying WResourceManager==");
|
LOG("==Destroying ResourceManagerImpl==");
|
||||||
RemoveWFonts();
|
RemoveWFonts();
|
||||||
|
|
||||||
CacheEngine::Terminate();
|
CacheEngine::Terminate();
|
||||||
LOG("==Successfully Destroyed WResourceManager==");
|
LOG("==Successfully Destroyed ResourceManagerImpl==");
|
||||||
}
|
}
|
||||||
|
|
||||||
bool WResourceManager::IsThreaded()
|
bool ResourceManagerImpl::IsThreaded()
|
||||||
{
|
{
|
||||||
return CacheEngine::IsThreaded();
|
return CacheEngine::IsThreaded();
|
||||||
}
|
}
|
||||||
|
|
||||||
JQuadPtr WResourceManager::RetrieveCard(MTGCard * card, int style, int submode)
|
JQuadPtr ResourceManagerImpl::RetrieveCard(MTGCard * card, int style, int submode)
|
||||||
{
|
{
|
||||||
//Cards are never, ever resource managed, so just check cache.
|
//Cards are never, ever resource managed, so just check cache.
|
||||||
if (!card || options[Options::DISABLECARDS].number) return JQuadPtr();
|
if (!card || options[Options::DISABLECARDS].number) return JQuadPtr();
|
||||||
@@ -232,7 +250,7 @@ JQuadPtr WResourceManager::RetrieveCard(MTGCard * card, int style, int submode)
|
|||||||
return JQuadPtr();
|
return JQuadPtr();
|
||||||
}
|
}
|
||||||
|
|
||||||
int WResourceManager::AddQuadToManaged(const WManagedQuad& inQuad)
|
int ResourceManagerImpl::AddQuadToManaged(const WManagedQuad& inQuad)
|
||||||
{
|
{
|
||||||
int id = mIDLookupMap.size();
|
int id = mIDLookupMap.size();
|
||||||
mIDLookupMap.insert(make_pair(id, inQuad.resname));
|
mIDLookupMap.insert(make_pair(id, inQuad.resname));
|
||||||
@@ -241,7 +259,7 @@ int WResourceManager::AddQuadToManaged(const WManagedQuad& inQuad)
|
|||||||
return id;
|
return id;
|
||||||
}
|
}
|
||||||
|
|
||||||
int WResourceManager::CreateQuad(const string &quadName, const string &textureName, float x, float y, float width, float height)
|
int ResourceManagerImpl::CreateQuad(const string &quadName, const string &textureName, float x, float y, float width, float height)
|
||||||
{
|
{
|
||||||
if (!quadName.size() || !textureName.size()) return INVALID_ID;
|
if (!quadName.size() || !textureName.size()) return INVALID_ID;
|
||||||
|
|
||||||
@@ -276,7 +294,7 @@ int WResourceManager::CreateQuad(const string &quadName, const string &textureNa
|
|||||||
return id;
|
return id;
|
||||||
}
|
}
|
||||||
|
|
||||||
JQuadPtr WResourceManager::GetQuad(const string &quadName)
|
JQuadPtr ResourceManagerImpl::GetQuad(const string &quadName)
|
||||||
{
|
{
|
||||||
JQuadPtr result;
|
JQuadPtr result;
|
||||||
ManagedQuadMap::const_iterator found = mManagedQuads.find(quadName);
|
ManagedQuadMap::const_iterator found = mManagedQuads.find(quadName);
|
||||||
@@ -288,7 +306,7 @@ JQuadPtr WResourceManager::GetQuad(const string &quadName)
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
JQuadPtr WResourceManager::GetQuad(int id)
|
JQuadPtr ResourceManagerImpl::GetQuad(int id)
|
||||||
{
|
{
|
||||||
JQuadPtr result;
|
JQuadPtr result;
|
||||||
if (id < 0 || id >= (int) mManagedQuads.size()) return result;
|
if (id < 0 || id >= (int) mManagedQuads.size()) return result;
|
||||||
@@ -306,12 +324,12 @@ JQuadPtr WResourceManager::GetQuad(int id)
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
JQuadPtr WResourceManager::RetrieveTempQuad(const string& filename, int submode)
|
JQuadPtr ResourceManagerImpl::RetrieveTempQuad(const string& filename, int submode)
|
||||||
{
|
{
|
||||||
return RetrieveQuad(filename, 0, 0, 0, 0, "temporary", RETRIEVE_NORMAL, submode);
|
return RetrieveQuad(filename, 0, 0, 0, 0, "temporary", RETRIEVE_NORMAL, submode);
|
||||||
}
|
}
|
||||||
|
|
||||||
JQuadPtr WResourceManager::RetrieveQuad(const string& filename, float offX, float offY, float width, float height, string resname,
|
JQuadPtr ResourceManagerImpl::RetrieveQuad(const string& filename, float offX, float offY, float width, float height, string resname,
|
||||||
int style, int submode, int id)
|
int style, int submode, int id)
|
||||||
{
|
{
|
||||||
//Lookup managed resources, but only with a real resname.
|
//Lookup managed resources, but only with a real resname.
|
||||||
@@ -368,7 +386,7 @@ JQuadPtr WResourceManager::RetrieveQuad(const string& filename, float offX, floa
|
|||||||
return JQuadPtr();
|
return JQuadPtr();
|
||||||
}
|
}
|
||||||
|
|
||||||
void WResourceManager::Release(JTexture * tex)
|
void ResourceManagerImpl::Release(JTexture * tex)
|
||||||
{
|
{
|
||||||
if (!tex) return;
|
if (!tex) return;
|
||||||
|
|
||||||
@@ -393,28 +411,28 @@ void WResourceManager::Release(JTexture * tex)
|
|||||||
return; //Released!
|
return; //Released!
|
||||||
}
|
}
|
||||||
|
|
||||||
void WResourceManager::Unmiss(string filename)
|
void ResourceManagerImpl::Unmiss(string filename)
|
||||||
{
|
{
|
||||||
map<int, WCachedTexture*>::iterator it;
|
map<int, WCachedTexture*>::iterator it;
|
||||||
int id = textureWCache.makeID(0, filename, CACHE_NORMAL);
|
int id = textureWCache.makeID(0, filename, CACHE_NORMAL);
|
||||||
textureWCache.RemoveMiss(id);
|
textureWCache.RemoveMiss(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
void WResourceManager::ClearUnlocked()
|
void ResourceManagerImpl::ClearUnlocked()
|
||||||
{
|
{
|
||||||
textureWCache.ClearUnlocked();
|
textureWCache.ClearUnlocked();
|
||||||
sampleWCache.ClearUnlocked();
|
sampleWCache.ClearUnlocked();
|
||||||
psiWCache.ClearUnlocked();
|
psiWCache.ClearUnlocked();
|
||||||
}
|
}
|
||||||
|
|
||||||
void WResourceManager::Release(JSample * sample)
|
void ResourceManagerImpl::Release(JSample * sample)
|
||||||
{
|
{
|
||||||
if (!sample) return;
|
if (!sample) return;
|
||||||
|
|
||||||
sampleWCache.Release(sample);
|
sampleWCache.Release(sample);
|
||||||
}
|
}
|
||||||
|
|
||||||
JTexture * WResourceManager::RetrieveTexture(const string& filename, int style, int submode)
|
JTexture * ResourceManagerImpl::RetrieveTexture(const string& filename, int style, int submode)
|
||||||
{
|
{
|
||||||
//Aliases.
|
//Aliases.
|
||||||
if (style == RETRIEVE_THUMB)
|
if (style == RETRIEVE_THUMB)
|
||||||
@@ -464,7 +482,7 @@ JTexture * WResourceManager::RetrieveTexture(const string& filename, int style,
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
int WResourceManager::CreateTexture(const string &textureName)
|
int ResourceManagerImpl::CreateTexture(const string &textureName)
|
||||||
{
|
{
|
||||||
JTexture * jtex = RetrieveTexture(textureName, RETRIEVE_MANAGE);
|
JTexture * jtex = RetrieveTexture(textureName, RETRIEVE_MANAGE);
|
||||||
|
|
||||||
@@ -473,13 +491,13 @@ int WResourceManager::CreateTexture(const string &textureName)
|
|||||||
return INVALID_ID;
|
return INVALID_ID;
|
||||||
}
|
}
|
||||||
|
|
||||||
JTexture* WResourceManager::GetTexture(const string &textureName)
|
JTexture* ResourceManagerImpl::GetTexture(const string &textureName)
|
||||||
{
|
{
|
||||||
JTexture * jtex = RetrieveTexture(textureName, RETRIEVE_RESOURCE);
|
JTexture * jtex = RetrieveTexture(textureName, RETRIEVE_RESOURCE);
|
||||||
return jtex;
|
return jtex;
|
||||||
}
|
}
|
||||||
|
|
||||||
JTexture* WResourceManager::GetTexture(int id)
|
JTexture* ResourceManagerImpl::GetTexture(int id)
|
||||||
{
|
{
|
||||||
map<int, WCachedTexture*>::iterator it;
|
map<int, WCachedTexture*>::iterator it;
|
||||||
JTexture *jtex = NULL;
|
JTexture *jtex = NULL;
|
||||||
@@ -498,7 +516,7 @@ JTexture* WResourceManager::GetTexture(int id)
|
|||||||
return jtex;
|
return jtex;
|
||||||
}
|
}
|
||||||
|
|
||||||
hgeParticleSystemInfo * WResourceManager::RetrievePSI(const string& filename, JQuad * texture, int style, int submode)
|
hgeParticleSystemInfo * ResourceManagerImpl::RetrievePSI(const string& filename, JQuad * texture, int style, int submode)
|
||||||
{
|
{
|
||||||
if (!texture) return NULL;
|
if (!texture) return NULL;
|
||||||
|
|
||||||
@@ -515,7 +533,7 @@ hgeParticleSystemInfo * WResourceManager::RetrievePSI(const string& filename, JQ
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
JSample * WResourceManager::RetrieveSample(const string& filename, int style, int submode)
|
JSample * ResourceManagerImpl::RetrieveSample(const string& filename, int style, int submode)
|
||||||
{
|
{
|
||||||
WCachedSample * tc = NULL;
|
WCachedSample * tc = NULL;
|
||||||
tc = sampleWCache.Retrieve(0, filename, style, submode);
|
tc = sampleWCache.Retrieve(0, filename, style, submode);
|
||||||
@@ -531,7 +549,7 @@ JSample * WResourceManager::RetrieveSample(const string& filename, int style, in
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
string WResourceManager::graphicsFile(const string& filename)
|
string ResourceManagerImpl::graphicsFile(const string& filename)
|
||||||
{
|
{
|
||||||
char buf[512];
|
char buf[512];
|
||||||
|
|
||||||
@@ -582,7 +600,7 @@ string WResourceManager::graphicsFile(const string& filename)
|
|||||||
return graphdir;
|
return graphdir;
|
||||||
}
|
}
|
||||||
|
|
||||||
string WResourceManager::avatarFile(const string& filename)
|
string ResourceManagerImpl::avatarFile(const string& filename)
|
||||||
{
|
{
|
||||||
char buf[512];
|
char buf[512];
|
||||||
|
|
||||||
@@ -636,7 +654,7 @@ string WResourceManager::avatarFile(const string& filename)
|
|||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
|
|
||||||
string WResourceManager::cardFile(const string& filename)
|
string ResourceManagerImpl::cardFile(const string& filename)
|
||||||
{
|
{
|
||||||
char buf[512];
|
char buf[512];
|
||||||
string::size_type i = 0;
|
string::size_type i = 0;
|
||||||
@@ -709,7 +727,7 @@ string WResourceManager::cardFile(const string& filename)
|
|||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
|
|
||||||
string WResourceManager::musicFile(const string& filename)
|
string ResourceManagerImpl::musicFile(const string& filename)
|
||||||
{
|
{
|
||||||
char buf[512];
|
char buf[512];
|
||||||
|
|
||||||
@@ -746,7 +764,7 @@ string WResourceManager::musicFile(const string& filename)
|
|||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
|
|
||||||
string WResourceManager::sfxFile(const string& filename)
|
string ResourceManagerImpl::sfxFile(const string& filename)
|
||||||
{
|
{
|
||||||
char buf[512];
|
char buf[512];
|
||||||
|
|
||||||
@@ -778,7 +796,7 @@ string WResourceManager::sfxFile(const string& filename)
|
|||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
|
|
||||||
int WResourceManager::dirOK(const string& dirname)
|
int ResourceManagerImpl::dirOK(const string& dirname)
|
||||||
{
|
{
|
||||||
char fname[512];
|
char fname[512];
|
||||||
|
|
||||||
@@ -796,7 +814,7 @@ int WResourceManager::dirOK(const string& dirname)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int WResourceManager::fileOK(const string& filename, bool relative)
|
int ResourceManagerImpl::fileOK(const string& filename, bool relative)
|
||||||
{
|
{
|
||||||
wagic::ifstream * fp = NULL;
|
wagic::ifstream * fp = NULL;
|
||||||
if (relative)
|
if (relative)
|
||||||
@@ -817,7 +835,7 @@ int WResourceManager::fileOK(const string& filename, bool relative)
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
void WResourceManager::InitFonts(const std::string& inLang)
|
void ResourceManagerImpl::InitFonts(const std::string& inLang)
|
||||||
{
|
{
|
||||||
unsigned int idOffset = 0;
|
unsigned int idOffset = 0;
|
||||||
|
|
||||||
@@ -851,7 +869,7 @@ void WResourceManager::InitFonts(const std::string& inLang)
|
|||||||
LoadWFont("smallface", 7, Fonts::SMALLFACE_FONT + idOffset);
|
LoadWFont("smallface", 7, Fonts::SMALLFACE_FONT + idOffset);
|
||||||
}
|
}
|
||||||
|
|
||||||
int WResourceManager::ReloadWFonts()
|
int ResourceManagerImpl::ReloadWFonts()
|
||||||
{
|
{
|
||||||
RemoveWFonts();
|
RemoveWFonts();
|
||||||
|
|
||||||
@@ -863,7 +881,7 @@ int WResourceManager::ReloadWFonts()
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
WFont* WResourceManager::LoadWFont(const string& inFontname, int inFontHeight, int inFontID)
|
WFont* ResourceManagerImpl::LoadWFont(const string& inFontname, int inFontHeight, int inFontID)
|
||||||
{
|
{
|
||||||
WFont* font = GetWFont(inFontID);
|
WFont* font = GetWFont(inFontID);
|
||||||
if (font)
|
if (font)
|
||||||
@@ -885,7 +903,7 @@ WFont* WResourceManager::LoadWFont(const string& inFontname, int inFontHeight, i
|
|||||||
return font;
|
return font;
|
||||||
}
|
}
|
||||||
|
|
||||||
WFont* WResourceManager::GetWFont(int id)
|
WFont* ResourceManagerImpl::GetWFont(int id)
|
||||||
{
|
{
|
||||||
WFont* font = NULL;
|
WFont* font = NULL;
|
||||||
FontMap::iterator iter = mWFontMap.find(id);
|
FontMap::iterator iter = mWFontMap.find(id);
|
||||||
@@ -896,7 +914,7 @@ WFont* WResourceManager::GetWFont(int id)
|
|||||||
return font;
|
return font;
|
||||||
}
|
}
|
||||||
|
|
||||||
void WResourceManager::RemoveWFonts()
|
void ResourceManagerImpl::RemoveWFonts()
|
||||||
{
|
{
|
||||||
for (FontMap::iterator font = mWFontMap.begin(); font != mWFontMap.end(); ++font)
|
for (FontMap::iterator font = mWFontMap.begin(); font != mWFontMap.end(); ++font)
|
||||||
{
|
{
|
||||||
@@ -905,7 +923,7 @@ void WResourceManager::RemoveWFonts()
|
|||||||
mWFontMap.clear();
|
mWFontMap.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
void WResourceManager::ResetCacheLimits()
|
void ResourceManagerImpl::ResetCacheLimits()
|
||||||
{
|
{
|
||||||
#if defined WIN32 || defined LINUX || defined (IOS)
|
#if defined WIN32 || defined LINUX || defined (IOS)
|
||||||
#ifdef FORCE_LOW_CACHE_MEMORY
|
#ifdef FORCE_LOW_CACHE_MEMORY
|
||||||
@@ -927,14 +945,14 @@ void WResourceManager::ResetCacheLimits()
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
JMusic * WResourceManager::ssLoadMusic(const char *fileName)
|
JMusic * ResourceManagerImpl::ssLoadMusic(const char *fileName)
|
||||||
{
|
{
|
||||||
string file = musicFile(fileName);
|
string file = musicFile(fileName);
|
||||||
if (!file.size()) return NULL;
|
if (!file.size()) return NULL;
|
||||||
return JSoundSystem::GetInstance()->LoadMusic(file.c_str());
|
return JSoundSystem::GetInstance()->LoadMusic(file.c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
void WResourceManager::Refresh()
|
void ResourceManagerImpl::Refresh()
|
||||||
{
|
{
|
||||||
//Really easy cache relinking.
|
//Really easy cache relinking.
|
||||||
ReloadWFonts();
|
ReloadWFonts();
|
||||||
|
|||||||
@@ -982,6 +982,10 @@
|
|||||||
RelativePath=".\include\AllAbilities.h"
|
RelativePath=".\include\AllAbilities.h"
|
||||||
>
|
>
|
||||||
</File>
|
</File>
|
||||||
|
<File
|
||||||
|
RelativePath=".\include\CacheEngine.h"
|
||||||
|
>
|
||||||
|
</File>
|
||||||
<File
|
<File
|
||||||
RelativePath=".\include\CardDescriptor.h"
|
RelativePath=".\include\CardDescriptor.h"
|
||||||
>
|
>
|
||||||
@@ -1374,6 +1378,10 @@
|
|||||||
RelativePath=".\include\WResourceManager.h"
|
RelativePath=".\include\WResourceManager.h"
|
||||||
>
|
>
|
||||||
</File>
|
</File>
|
||||||
|
<File
|
||||||
|
RelativePath=".\include\WResourceManagerImpl.h"
|
||||||
|
>
|
||||||
|
</File>
|
||||||
</Filter>
|
</Filter>
|
||||||
<Filter
|
<Filter
|
||||||
Name="Resource Files"
|
Name="Resource Files"
|
||||||
|
|||||||
Reference in New Issue
Block a user