Switched the managed JQuad container implementation from a vector to a map. This speeds up the cache lookup time from O(n) to O(log n). Hard to see a noticeable difference on win, but it definitely feels snappier on my psp, for instance, when browsing your library for a card, or your graveyard, etc.
I'm also noticing that the GetQuad(int) variant never seems to get hit, so I suspect that the ID lookup map is redundant. I left it alone as the JResourceManager base class forces the need for the function; I need to spend more time looking at just how much of JResourceManager we actually use at this point.
This commit is contained in:
@@ -24,6 +24,7 @@ using namespace std;
|
|||||||
|
|
||||||
|
|
||||||
#define INVALID_ID -1
|
#define INVALID_ID -1
|
||||||
|
#define ALREADY_EXISTS -2
|
||||||
|
|
||||||
class JRenderer;
|
class JRenderer;
|
||||||
class JSample;
|
class JSample;
|
||||||
|
|||||||
@@ -162,6 +162,8 @@ public:
|
|||||||
JQuad* GetQuad(const string &quadName);
|
JQuad* GetQuad(const string &quadName);
|
||||||
JQuad* GetQuad(int id);
|
JQuad* GetQuad(int id);
|
||||||
|
|
||||||
|
int AddQuadToManaged(const WManagedQuad& inManagedQuad);
|
||||||
|
|
||||||
//Our file redirect system.
|
//Our file redirect system.
|
||||||
string graphicsFile(const string filename);
|
string graphicsFile(const string filename);
|
||||||
string avatarFile(const string filename);
|
string avatarFile(const string filename);
|
||||||
@@ -207,7 +209,12 @@ private:
|
|||||||
WCache<WCachedTexture,JTexture> textureWCache;
|
WCache<WCachedTexture,JTexture> textureWCache;
|
||||||
WCache<WCachedSample,JSample> sampleWCache;
|
WCache<WCachedSample,JSample> sampleWCache;
|
||||||
WCache<WCachedParticles,hgeParticleSystemInfo> psiWCache;
|
WCache<WCachedParticles,hgeParticleSystemInfo> psiWCache;
|
||||||
vector<WManagedQuad*> managedQuads;
|
|
||||||
|
typedef std::map<std::string, WManagedQuad> ManagedQuadMap;
|
||||||
|
ManagedQuadMap mManagedQuads;
|
||||||
|
|
||||||
|
typedef std::map<int, std::string> IDLookupMap;
|
||||||
|
IDLookupMap mIDLookupMap;
|
||||||
|
|
||||||
//Statistics of record.
|
//Statistics of record.
|
||||||
unsigned int lastTime;
|
unsigned int lastTime;
|
||||||
|
|||||||
@@ -195,11 +195,6 @@ WResourceManager::~WResourceManager(){
|
|||||||
RemoveWFonts();
|
RemoveWFonts();
|
||||||
RemoveWLBFonts();
|
RemoveWLBFonts();
|
||||||
|
|
||||||
for(vector<WManagedQuad*>::iterator it=managedQuads.begin();it!=managedQuads.end();it++){
|
|
||||||
WManagedQuad* wm = *it;
|
|
||||||
SAFE_DELETE(wm);
|
|
||||||
}
|
|
||||||
managedQuads.clear();
|
|
||||||
LOG("==Successfully Destroyed WResourceManager==");
|
LOG("==Successfully Destroyed WResourceManager==");
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -260,65 +255,78 @@ JQuad * WResourceManager::RetrieveCard(MTGCard * card, int style, int submode){
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int WResourceManager::AddQuadToManaged(const WManagedQuad& inQuad)
|
||||||
|
{
|
||||||
|
int id = mIDLookupMap.size();
|
||||||
|
mIDLookupMap.insert(make_pair(id, inQuad.resname));
|
||||||
|
mManagedQuads.insert(make_pair(inQuad.resname, inQuad));
|
||||||
|
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
|
||||||
int WResourceManager::CreateQuad(const string &quadName, const string &textureName, float x, float y, float width, float height){
|
int WResourceManager::CreateQuad(const string &quadName, const string &textureName, float x, float y, float width, float height){
|
||||||
if(!quadName.size() || !textureName.size())
|
if(!quadName.size() || !textureName.size())
|
||||||
return INVALID_ID;
|
return INVALID_ID;
|
||||||
|
|
||||||
string resname = quadName;
|
|
||||||
|
|
||||||
vector<WManagedQuad*>::iterator it;
|
if (GetQuad(quadName) != NULL)
|
||||||
int pos = 0;
|
{
|
||||||
for(it = managedQuads.begin();it!=managedQuads.end();it++,pos++){
|
assert(false);
|
||||||
if((*it)->resname == resname)
|
return ALREADY_EXISTS;
|
||||||
return pos;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
WCachedTexture * jtex = textureWCache.Retrieve(0,textureName,RETRIEVE_MANAGE);
|
WCachedTexture * jtex = textureWCache.Retrieve(0,textureName,RETRIEVE_MANAGE);
|
||||||
lastError = textureWCache.mError;
|
lastError = textureWCache.mError;
|
||||||
|
int id = INVALID_ID;
|
||||||
//Somehow, jtex wasn't promoted.
|
//Somehow, jtex wasn't promoted.
|
||||||
if(RETRIEVE_MANAGE && jtex && !jtex->isPermanent())
|
if(RETRIEVE_MANAGE && jtex && !jtex->isPermanent())
|
||||||
return INVALID_ID;
|
return id;
|
||||||
|
|
||||||
if(jtex){
|
if(jtex){
|
||||||
WTrackedQuad * tq = jtex->GetTrackedQuad(x,y,width,height,quadName);
|
WTrackedQuad * tq = jtex->GetTrackedQuad(x,y,width,height,quadName);
|
||||||
|
|
||||||
if(tq){
|
if(tq){
|
||||||
tq->deadbolt();
|
tq->deadbolt();
|
||||||
WManagedQuad * mq;
|
|
||||||
mq = NEW WManagedQuad();
|
|
||||||
mq->resname = resname;
|
|
||||||
mq->texture = jtex;
|
|
||||||
managedQuads.push_back(mq);
|
|
||||||
}
|
|
||||||
|
|
||||||
return (int) (managedQuads.size() - 1);
|
WManagedQuad mq;
|
||||||
|
mq.resname = quadName;
|
||||||
|
mq.texture = jtex;
|
||||||
|
id = AddQuadToManaged(mq);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return INVALID_ID;
|
assert(id != INVALID_ID);
|
||||||
|
return id;
|
||||||
}
|
}
|
||||||
|
|
||||||
JQuad * WResourceManager::GetQuad(const string &quadName){
|
JQuad* WResourceManager::GetQuad(const string &quadName){
|
||||||
string lookup = quadName;
|
|
||||||
|
JQuad* result = NULL;
|
||||||
for(vector<WManagedQuad*>::iterator it=managedQuads.begin();it!=managedQuads.end();it++){
|
ManagedQuadMap::const_iterator found = mManagedQuads.find(quadName);
|
||||||
if((*it)->resname == lookup)
|
if (found != mManagedQuads.end())
|
||||||
return (*it)->texture->GetQuad(lookup);
|
{
|
||||||
|
result = found->second.texture->GetQuad(quadName);
|
||||||
}
|
}
|
||||||
|
|
||||||
return NULL;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
JQuad * WResourceManager::GetQuad(int id){
|
JQuad * WResourceManager::GetQuad(int id){
|
||||||
if(id < 0 || id >= (int) managedQuads.size())
|
|
||||||
return NULL;
|
|
||||||
|
|
||||||
WCachedTexture * jtex = managedQuads[id]->texture;
|
JQuad* result = NULL;
|
||||||
if(!jtex)
|
if(id < 0 || id >= (int) mManagedQuads.size())
|
||||||
return NULL;
|
return result;
|
||||||
|
|
||||||
return jtex->GetQuad(managedQuads[id]->resname);
|
IDLookupMap::const_iterator key = mIDLookupMap.find(id);
|
||||||
|
if (key != mIDLookupMap.end())
|
||||||
|
{
|
||||||
|
WCachedTexture * jtex = mManagedQuads[key->second].texture;
|
||||||
|
if(jtex)
|
||||||
|
{
|
||||||
|
result = jtex->GetQuad(key->second);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
JQuad * WResourceManager::RetrieveTempQuad(string filename,int submode){
|
JQuad * WResourceManager::RetrieveTempQuad(string filename,int submode){
|
||||||
@@ -365,10 +373,10 @@ JQuad * WResourceManager::RetrieveQuad(string filename, float offX, float offY,
|
|||||||
if(!tq) return NULL;
|
if(!tq) return NULL;
|
||||||
|
|
||||||
if(style == RETRIEVE_MANAGE && resname != ""){
|
if(style == RETRIEVE_MANAGE && resname != ""){
|
||||||
WManagedQuad * mq = NEW WManagedQuad();
|
WManagedQuad mq;
|
||||||
mq->resname = resname;
|
mq.resname = resname;
|
||||||
mq->texture = jtex;
|
mq.texture = jtex;
|
||||||
managedQuads.push_back(mq);
|
AddQuadToManaged(mq);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(style == RETRIEVE_LOCK)
|
if(style == RETRIEVE_LOCK)
|
||||||
|
|||||||
Reference in New Issue
Block a user