Jeck - Card ID collisions, cache fixes, cache deleted pooling.
* mtgid now defaults to 0. * TextScroller will not update when empty. * Cache now moves WCachedResources we're finished with to a garbage pool for later use (to reduce memory fragmentation). * Demo still crashes... but I'm thinking that has to do with fragmentation, not a leak?
This commit is contained in:
@@ -20,6 +20,7 @@ class GameStateMenu: public GameState, public JGuiListener
|
||||
JTexture * bgTexture;
|
||||
JTexture * movingWTexture;
|
||||
JQuad * mBg;
|
||||
JQuad * mSplash;
|
||||
JQuad * mMovingW;
|
||||
float mCreditsYPos;
|
||||
int currentState;
|
||||
|
||||
@@ -15,7 +15,8 @@ public:
|
||||
|
||||
WResource();
|
||||
virtual ~WResource();
|
||||
|
||||
|
||||
virtual void Trash()=0; //Delete the cacheActual.
|
||||
virtual void Nullify()=0; //For when our size is 0, so we don't free anything by mistake.
|
||||
virtual unsigned long size()=0; //Size of cached item in bytes.
|
||||
virtual bool isGood()=0; //Return true if this has data.
|
||||
@@ -38,6 +39,8 @@ public:
|
||||
friend class WResourceManager;
|
||||
template<class cacheItem,class cacheActual> friend class WCache;
|
||||
|
||||
virtual ~WCachedResource() {};
|
||||
|
||||
virtual void Refresh(string filename)=0; //Basically calls Attempt(filename) and remaps in situ.
|
||||
virtual bool Attempt(string filename, int submode, int & error)=0; //Returns true if we've loaded our data and isGood().
|
||||
};
|
||||
@@ -48,6 +51,7 @@ public:
|
||||
WTrackedQuad(string _resname);
|
||||
~WTrackedQuad();
|
||||
void Nullify();
|
||||
void Trash();
|
||||
unsigned long size();
|
||||
bool isGood();
|
||||
|
||||
@@ -73,6 +77,7 @@ public:
|
||||
bool compare(JTexture * t) {return (t == texture);};
|
||||
|
||||
void Nullify();
|
||||
void Trash();
|
||||
JTexture * Actual(); //Return this texture as is. Does not make a new one.
|
||||
JQuad * GetQuad(string resname);
|
||||
|
||||
@@ -86,6 +91,7 @@ protected:
|
||||
JTexture * texture;
|
||||
bool bVRAM;
|
||||
vector<WTrackedQuad*> trackedQuads;
|
||||
static vector<WTrackedQuad*> garbageTQs;
|
||||
};
|
||||
|
||||
class WCachedParticles: public WCachedResource{
|
||||
@@ -96,6 +102,7 @@ public:
|
||||
~WCachedParticles();
|
||||
|
||||
void Nullify();
|
||||
void Trash();
|
||||
void Refresh(string filename);
|
||||
unsigned long size();
|
||||
bool isGood();
|
||||
@@ -114,6 +121,7 @@ public:
|
||||
WCachedSample();
|
||||
~WCachedSample();
|
||||
void Nullify();
|
||||
void Trash();
|
||||
bool compare(JSample * s) {return (s == sample);};
|
||||
unsigned long size();
|
||||
bool isGood();
|
||||
|
||||
@@ -19,10 +19,11 @@
|
||||
|
||||
|
||||
//Hard Limits.
|
||||
#define MAX_CACHE_OBJECTS 400
|
||||
#define MAX_CACHE_OBJECTS HUGE_CACHE_ITEMS
|
||||
#define MAX_CACHE_ATTEMPTS 10
|
||||
#define MAX_CACHE_MISSES 200
|
||||
#define MAX_CACHED_SAMPLES 0
|
||||
#define MAX_CACHE_GARBAGE 10
|
||||
|
||||
enum ENUM_WRES_INFO{
|
||||
WRES_UNLOCKED = 0, //Resource is unlocked.
|
||||
@@ -61,7 +62,8 @@ enum ENUM_CACHE_ERROR{
|
||||
CACHE_ERROR_NONE = 0,
|
||||
CACHE_ERROR_NOT_CACHED = CACHE_ERROR_NONE,
|
||||
CACHE_ERROR_404,
|
||||
CACHE_ERROR_BAD,
|
||||
CACHE_ERROR_BAD, //Something went wrong with item->attempt()
|
||||
CACHE_ERROR_BAD_ALLOC, //Couldn't allocate item
|
||||
CACHE_ERROR_LOST,
|
||||
CACHE_ERROR_NOT_MANAGED,
|
||||
};
|
||||
@@ -89,15 +91,17 @@ public:
|
||||
protected:
|
||||
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); //Call SAFE_DELETE on cacheItem. If maxCached == 0, nullify first. (This means you have to free that cacheActual later!)
|
||||
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(string id, int style = RETRIEVE_NORMAL, int submode = CACHE_NORMAL); //Subordinate to Retrieve.
|
||||
cacheItem* AttemptNew(string filename, int submode); //Attempts a new cache item, progressively clearing cache if it fails.
|
||||
cacheItem* Recycle(); //Returns a cache item from the trash.
|
||||
|
||||
string makeID(string filename, int submode); //Makes an ID appropriate to the submode.
|
||||
string makeFilename(string id, int submode); //Makes a filename from an ID.
|
||||
|
||||
map<string,cacheItem*> cache;
|
||||
map<string,cacheItem*> managed; //Cache can be arbitrarily large, so managed items are seperate.
|
||||
vector<cacheItem*> garbage; //Garbage collection.
|
||||
unsigned long totalSize;
|
||||
unsigned long cacheSize;
|
||||
|
||||
@@ -138,6 +142,7 @@ public:
|
||||
void Release(JQuad * quad);
|
||||
void Release(JSample * sample);
|
||||
|
||||
bool RemoveOldest();
|
||||
|
||||
bool Cleanup(); //Force a cleanup. Return false if nothing removed.
|
||||
void ClearMisses(); //Remove all cache misses.
|
||||
|
||||
Reference in New Issue
Block a user