Jeck - Removed a ton of unreached or unused code from the cache, to make debugging easier. None of this actually effects execution at all. Some of these functions (though not many) are potentially useful, but as they aren't actually used there's no reason to have them cluttering up the files.

This commit is contained in:
wagic.jeck
2009-10-26 05:55:52 +00:00
parent eefd03ad84
commit 8e0bcef6e9
4 changed files with 4 additions and 137 deletions
+1 -14
View File
@@ -16,8 +16,6 @@ public:
WResource(); WResource();
virtual ~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 unsigned long size()=0; //Size of cached item in bytes.
virtual bool isGood()=0; //Return true if this has data. virtual bool isGood()=0; //Return true if this has data.
virtual bool isLocked(); //Is the resource locked? virtual bool isLocked(); //Is the resource locked?
@@ -51,8 +49,6 @@ class WTrackedQuad: public WResource {
public: public:
WTrackedQuad(string _resname); WTrackedQuad(string _resname);
~WTrackedQuad(); ~WTrackedQuad();
void Nullify();
void Trash();
bool isGood(); bool isGood();
unsigned long size(); unsigned long size();
string resname; string resname;
@@ -72,9 +68,6 @@ public:
bool isLocked(); bool isLocked();
bool Attempt(string filename, int submode, int & error); bool Attempt(string filename, int submode, int & error);
bool compare(JTexture * t) {return (t == texture);}; bool compare(JTexture * t) {return (t == texture);};
void Nullify();
void Trash();
JTexture * Actual(); //Return this texture as is. Does not make a new one. JTexture * Actual(); //Return this texture as is. Does not make a new one.
JQuad * GetQuad(string resname); JQuad * GetQuad(string resname);
@@ -87,7 +80,6 @@ public:
protected: protected:
JTexture * texture; JTexture * texture;
vector<WTrackedQuad*> trackedQuads; vector<WTrackedQuad*> trackedQuads;
static vector<WTrackedQuad*> garbageTQs;
}; };
class WCachedParticles: public WCachedResource{ class WCachedParticles: public WCachedResource{
@@ -96,11 +88,8 @@ public:
template<class cacheItem,class cacheActual> friend class WCache; template<class cacheItem,class cacheActual> friend class WCache;
WCachedParticles(); WCachedParticles();
~WCachedParticles(); ~WCachedParticles();
void Nullify();
void Trash();
void Refresh(); void Refresh();
unsigned long size(); unsigned long size();
bool isGood(); bool isGood();
bool Attempt(string filename, int submode, int & error); bool Attempt(string filename, int submode, int & error);
@@ -117,8 +106,6 @@ public:
template<class cacheItem,class cacheActual> friend class WCache; template<class cacheItem,class cacheActual> friend class WCache;
WCachedSample(); WCachedSample();
~WCachedSample(); ~WCachedSample();
void Nullify();
void Trash();
bool compare(JSample * s) {return (s == sample);}; bool compare(JSample * s) {return (s == sample);};
unsigned long size(); unsigned long size();
bool isGood(); bool isGood();
-5
View File
@@ -80,9 +80,7 @@ public:
bool RemoveMiss(int id=0); //Removes a cache miss. bool RemoveMiss(int id=0); //Removes a cache miss.
bool RemoveOldest(); //Remove oldest unlocked item. bool RemoveOldest(); //Remove oldest unlocked item.
bool Cleanup(); //Repeats RemoveOldest() until cache fits in size limits bool Cleanup(); //Repeats RemoveOldest() until cache fits in size limits
void Clear(); //Removes everything cached. Not lock safe, does not remove managed items.
void ClearUnlocked(); //Remove all unlocked items. void ClearUnlocked(); //Remove all unlocked items.
void ClearMisses(); //Clear all cache misses.
void Refresh(); //Refreshes all cache items. void Refresh(); //Refreshes all cache items.
unsigned int Flatten(); //Ensures that the times don't loop. Returns new lastTime. 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". void Resize(unsigned long size, int items); //Sets new limits, then enforces them. Lock safe, so not a "hard limit".
@@ -108,8 +106,6 @@ protected:
unsigned int cacheItems; unsigned int cacheItems;
int mError; int mError;
}; };
@@ -139,7 +135,6 @@ public:
bool RemoveOldest(); bool RemoveOldest();
bool Cleanup(); //Force a cleanup. Return false if nothing removed. bool Cleanup(); //Force a cleanup. Return false if nothing removed.
void ClearMisses(); //Remove all cache misses.
void ClearUnlocked(); //Remove unlocked items. void ClearUnlocked(); //Remove unlocked items.
void Refresh(); //Refreshes all files in cache, for when mode/profile changes. void Refresh(); //Refreshes all files in cache, for when mode/profile changes.
+1 -59
View File
@@ -60,8 +60,6 @@ void WResource::hit(){
lastTime = resources.nowTime(); lastTime = resources.nowTime();
} }
//WCachedTexture //WCachedTexture
vector<WTrackedQuad*> WCachedTexture::garbageTQs;
WCachedTexture::WCachedTexture(){ WCachedTexture::WCachedTexture(){
texture = NULL; texture = NULL;
} }
@@ -112,14 +110,8 @@ bool WCachedTexture::ReleaseQuad(JQuad* quad){
tq->unlock(); tq->unlock();
if(!tq->isLocked()){ if(!tq->isLocked()){
if(WCachedTexture::garbageTQs.size() < MAX_CACHE_GARBAGE){
tq->Trash();
garbageTQs.push_back(tq);
}
else
SAFE_DELETE(tq); SAFE_DELETE(tq);
trackedQuads.erase(it);
trackedQuads.erase(it);
} }
return true; //Returns true when found. return true; //Returns true when found.
@@ -307,39 +299,7 @@ bool WCachedTexture::Attempt(string filename, int submode, int & error){
return true; return true;
} }
void WCachedTexture::Nullify(){
if(texture)
texture = NULL;
}
void WCachedTexture::Trash(){
SAFE_DELETE(texture);
vector<WTrackedQuad*>::iterator it;
WTrackedQuad * tq = NULL;
for(it=trackedQuads.begin();it!=trackedQuads.end();it++){
tq = (*it);
if(WCachedTexture::garbageTQs.size() > MAX_CACHE_GARBAGE)
SAFE_DELETE(tq);
else{
tq->Trash();
WCachedTexture::garbageTQs.push_back(tq);
}
}
trackedQuads.clear();
}
//WCachedSample //WCachedSample
void WCachedSample::Nullify(){
if(sample){
sample = NULL;
}
}
void WCachedSample::Trash(){
SAFE_DELETE(sample);
}
WCachedSample::WCachedSample(){ WCachedSample::WCachedSample(){
sample = NULL; sample = NULL;
} }
@@ -454,25 +414,7 @@ WCachedParticles::~WCachedParticles(){
SAFE_DELETE(particles); SAFE_DELETE(particles);
} }
void WCachedParticles::Nullify(){
if(particles)
particles = NULL;
}
void WCachedParticles::Trash(){
SAFE_DELETE(particles);
}
//WTrackedQuad //WTrackedQuad
void WTrackedQuad::Nullify() {
quad = NULL;
}
void WTrackedQuad::Trash(){
resname.clear();
SAFE_DELETE(quad);
}
unsigned long WTrackedQuad::size() { unsigned long WTrackedQuad::size() {
return sizeof(JQuad); return sizeof(JQuad);
} }
+2 -59
View File
@@ -181,13 +181,6 @@ WResourceManager::~WResourceManager(){
SAFE_DELETE(wm); SAFE_DELETE(wm);
} }
managedQuads.clear(); managedQuads.clear();
//Remove all our reserved WTrackedQuads from WCachedTexture
vector<WTrackedQuad*>::iterator g;
for(g=WCachedTexture::garbageTQs.begin();g!=WCachedTexture::garbageTQs.end();g++){
WTrackedQuad * tq = *g;
SAFE_DELETE(tq);
}
LOG("==Successfully Destroyed WResourceManager=="); LOG("==Successfully Destroyed WResourceManager==");
} }
@@ -356,13 +349,6 @@ void WResourceManager::Release(JQuad * quad){
if(it != textureWCache.cache.end() && it->second) if(it != textureWCache.cache.end() && it->second)
textureWCache.RemoveItem(it->second,false); //won't remove locked. textureWCache.RemoveItem(it->second,false); //won't remove locked.
} }
void WResourceManager::ClearMisses(){
textureWCache.ClearMisses();
sampleWCache.ClearMisses();
psiWCache.ClearMisses();
}
void WResourceManager::ClearUnlocked(){ void WResourceManager::ClearUnlocked(){
textureWCache.ClearUnlocked(); textureWCache.ClearUnlocked();
sampleWCache.ClearUnlocked(); sampleWCache.ClearUnlocked();
@@ -889,27 +875,6 @@ bool WCache<cacheItem, cacheActual>::RemoveOldest(){
return false; return false;
} }
template <class cacheItem, class cacheActual>
void WCache<cacheItem, cacheActual>::Clear(){
typename map<int,cacheItem*>::iterator it, next;
for(it = cache.begin(); it != cache.end();it=next){
next = it;
next++;
if(it->second)
Delete(it->second);
cache.erase(it);
}
for(it = managed.begin(); it != managed.end();it=next){
next = it;
next++;
if(!it->second)
managed.erase(it);
}
}
template <class cacheItem, class cacheActual> template <class cacheItem, class cacheActual>
void WCache<cacheItem, cacheActual>::ClearUnlocked(){ void WCache<cacheItem, cacheActual>::ClearUnlocked(){
typename map<int,cacheItem*>::iterator it, next; typename map<int,cacheItem*>::iterator it, next;
@@ -927,31 +892,11 @@ void WCache<cacheItem, cacheActual>::ClearUnlocked(){
} }
} }
} }
template <class cacheItem, class cacheActual>
void WCache<cacheItem, cacheActual>::ClearMisses(){
typename map<int,cacheItem*>::iterator it, next;
for(it = cache.begin(); it != cache.end();it=next){
next = it;
next++;
if(!it->second)
cache.erase(it);
}
for(it = managed.begin(); it != managed.end();it=next){
next = it;
next++;
if(!it->second)
managed.erase(it);
}
}
template <class cacheItem, class cacheActual> template <class cacheItem, class cacheActual>
void WCache<cacheItem, cacheActual>::Resize(unsigned long size, int items){ void WCache<cacheItem, cacheActual>::Resize(unsigned long size, int items){
maxCacheSize = size; maxCacheSize = size;
if(items > MAX_CACHE_OBJECTS || items < 0) if(items > MAX_CACHE_OBJECTS || items < 1)
maxCached = MAX_CACHE_OBJECTS; maxCached = MAX_CACHE_OBJECTS;
else else
maxCached = items; maxCached = items;
@@ -1200,7 +1145,7 @@ bool WCache<cacheItem, cacheActual>::Cleanup(){
template <class cacheItem, class cacheActual> template <class cacheItem, class cacheActual>
unsigned int WCache<cacheItem, cacheActual>::Flatten(){ unsigned int WCache<cacheItem, cacheActual>::Flatten(){
unsigned int youngest = 65535; unsigned int youngest = (unsigned int) 65535;
unsigned int oldest = 0; unsigned int oldest = 0;
for (typename map<int,cacheItem*>::iterator it = cache.begin(); it != cache.end(); ++it){ for (typename map<int,cacheItem*>::iterator it = cache.begin(); it != cache.end(); ++it){
@@ -1283,8 +1228,6 @@ template <class cacheItem, class cacheActual>
bool WCache<cacheItem, cacheActual>::Delete(cacheItem * item){ bool WCache<cacheItem, cacheActual>::Delete(cacheItem * item){
if(!item) if(!item)
return false; return false;
if(maxCached == 0)
item->Nullify();
unsigned long isize = item->size(); unsigned long isize = item->size();
totalSize -= isize; totalSize -= isize;