Jeck - I somehow managed to break the test suite. Rolled back my changes to r843, won't commit until they're properly debugged.

This commit is contained in:
wagic.jeck
2009-09-15 01:53:02 +00:00
parent 1b468bde14
commit 505ee8d1eb
8 changed files with 81 additions and 243 deletions

View File

@@ -13,7 +13,7 @@ class GuiCombat : public GuiLayer
GameObserver* go;
DamagerDamaged* active;
AttackerDamaged* activeAtk;
static JTexture* ok_tex;
static JQuad* ok_quad;
Pos ok, enemy_avatar;
vector<AttackerDamaged*> attackers;
DamagerDamaged* current;

View File

@@ -2,12 +2,6 @@
#define _WCACHEDRESOURCE_H_
#include <hge/hgeparticle.h>
#if defined WIN32 || defined LINUX
#define INVALID_MTEX ((GLuint) -1)
#else
#define INVALID_MTEX -1
#endif
class WResource{
public:
friend class WResourceManager;
@@ -18,47 +12,24 @@ public:
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 void Refresh(string filename)=0; //Basically calls Attempt(filename) and remaps in situ.
virtual bool isGood()=0; //Return true if this has data.
virtual bool isLocked(); //Is the resource locked?
virtual void lock(); //Lock it.
virtual void unlock(bool force = false); //Unlock it. Forcing a lock will also remove "permanent" status.
bool isPermanent(); //Is the resource permanent?
void deadbolt(); //Make it permanent.
void hit(); //Update resource's last used time.
virtual bool Attempt(string filename, int submode, int & error)=0; //Returns true if we've loaded our data and isGood().
protected:
bool isLocked(); //Is the resource locked?
bool isPermanent(); //Is the resource permanent?
void lock(); //Lock it.
void deadbolt(); //Make it permanent.
void unlock(bool force = false); //Unlock it. Forcing a lock will also remove "permanent" status.
void hit(); //Update resource's last used time.
int loadedMode; //What submode settings were we loaded with? (For refresh)
unsigned int lastTime; //When was the last time we were hit?
unsigned char locks; //Remember to unlock when we're done using locked stuff, or else this'll be useless.
};
class WCachedResource: public WResource {
public:
friend class WResourceManager;
template<class cacheItem,class cacheActual> friend class WCache;
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().
};
class WTrackedQuad: public WResource {
public:
WTrackedQuad(string _resname);
~WTrackedQuad();
void Nullify();
unsigned long size();
bool isGood();
string resname;
JQuad * quad;
#ifdef DEBUG_CACHE
static int totalTracked;
#endif
};
class WCachedTexture: public WCachedResource{
class WCachedTexture: public WResource{
public:
friend class WResourceManager;
template<class cacheItem,class cacheActual> friend class WCache;
@@ -67,28 +38,23 @@ public:
void Refresh(string filename);
unsigned long size();
bool isGood();
bool isLocked();
bool isGood();
bool Attempt(string filename, int submode, int & error);
bool compare(JTexture * t) {return (t == texture);};
void Nullify();
JTexture * Actual(); //Return this texture as is. Does not make a new one.
JQuad * GetQuad(string resname);
WTrackedQuad* GetTrackedQuad(float offX=0.0f, float offY=0.0f, float width=0.0f, float height=0.0f,string resname=""); //Get us a new/existing quad.
JQuad * GetQuad(float offX=0.0f, float offY=0.0f, float width=0.0f, float height=0.0f,string resname=""); //Alias to GetTrackedQuad.
JQuad * GetQuad(float offX=0.0f, float offY=0.0f, float width=0.0f, float height=0.0f,string resname=""); //Get us a new/existing quad.
JQuad * GetCard(float offX=0.0f, float offY=0.0f, float width=0.0f, float height=0.0f,string resname=""); //Same as above, but centered when new.
bool ReleaseQuad(JQuad* quad); //We're done with this quad, so delete and stop tracking. True if existed.
protected:
JTexture * texture;
bool bVRAM;
vector<WTrackedQuad*> trackedQuads;
map<JQuad*,string> trackedQuads;
};
class WCachedParticles: public WCachedResource{
class WCachedParticles: public WResource{
public:
friend class WResourceManager;
template<class cacheItem,class cacheActual> friend class WCache;
@@ -107,7 +73,7 @@ protected:
hgeParticleSystemInfo * particles;
};
class WCachedSample: public WCachedResource{
class WCachedSample: public WResource{
public:
friend class WResourceManager;
template<class cacheItem,class cacheActual> friend class WCache;

View File

@@ -23,13 +23,13 @@ enum ENUM_WRES_INFO{
enum ENUM_RETRIEVE_STYLE{
RETRIEVE_EXISTING, //Only returns a resource if it already exists. Does not lock or unlock.
RETRIEVE_NORMAL, //Returns or creates a resource. Does not change lock status.
RETRIEVE_LOCK, //As above, locks cached resource.
RETRIEVE_UNLOCK, //As above, unlocks cached resource.
RETRIEVE_LOCK, //As above, locks cached resource. Not for quads.
RETRIEVE_UNLOCK, //As above, unlocks cached resource. Not for quads.
RETRIEVE_RESOURCE, //Only retrieves a managed resource. Does not make a new one.
RETRIEVE_VRAM, //Retrieve it, and use vram if have to we create it. Must still remove it.
RETRIEVE_MANAGE, //Makes resource permanent.
RETRIEVE_THUMB, //Retrieve it as a thumbnail.
CACHE_THUMB = RETRIEVE_THUMB, //Backwards compatibility.
CACHE_THUMB = RETRIEVE_THUMB, //Backwords compatibility.
};
enum ENUM_CACHE_SUBTYPE{
@@ -104,9 +104,7 @@ protected:
#endif
};
class WManagedQuad {
public:
WManagedQuad() {texture = NULL;};
struct WManagedQuad {
WCachedTexture * texture;
string resname;
};
@@ -185,7 +183,7 @@ private:
WCache<WCachedTexture,JTexture> textureWCache;
WCache<WCachedSample,JSample> sampleWCache;
WCache<WCachedParticles,hgeParticleSystemInfo> psiWCache;
vector<WManagedQuad*> managedQuads;
vector<WManagedQuad> managedQuads;
//Statistics of record.
unsigned int lastTime;

View File

@@ -73,7 +73,6 @@ void GameStateDuel::Start()
testSuite = NEW TestSuite(RESPATH"/test/_tests.txt",mParent->collection);
#endif
resources.RetrieveTexture("OK.png",RETRIEVE_LOCK);
mGamePhase = DUEL_STATE_CHOOSE_DECK1;
credits = NEW Credits();
@@ -219,7 +218,6 @@ void GameStateDuel::End()
#if defined (WIN32) || defined (LINUX)
OutputDebugString("Ending GamestateDuel\n");
#endif
resources.Release(resources.RetrieveTexture("OK.png"));
resources.SmallCache();
SAFE_DELETE(deckmenu);
JRenderer::GetInstance()->EnableVSync(false);

View File

@@ -12,21 +12,25 @@ struct Left : public Exp { static inline bool test(DamagerDamaged* ref, DamagerD
struct Right : public Exp { static inline bool test(DamagerDamaged* ref, DamagerDamaged* test)
{ return ref->y == test->y && ref->x < test->x && test->show; } };
JTexture* GuiCombat::ok_tex = NULL;
JQuad* GuiCombat::ok_quad = NULL;
GuiCombat::GuiCombat(GameObserver* go) : GuiLayer(), go(go), active(false), activeAtk(NULL),
ok(SCREEN_WIDTH - MARGIN, 210, 1, 0, 255),
enemy_avatar(SCREEN_WIDTH - MARGIN, TOP_LINE, 2, 0, 255),
cursor_pos(NONE), step(DAMAGE)
{
if(NULL == ok_tex)
if(NULL == ok_quad)
{
ok_tex = resources.RetrieveTexture("OK.png");
ok_quad = resources.RetrieveQuad("OK.png");
if (ok_quad) ok_quad->SetHotSpot(28, 22);
}
}
GuiCombat::~GuiCombat()
{
if(ok_quad)
resources.Release(ok_quad);
for (inner_iterator it = attackers.begin(); it != attackers.end(); ++it)
{
for (vector<DefenserDamaged*>::iterator q = (*it)->blockers.begin(); q != (*it)->blockers.end(); ++q)
@@ -273,11 +277,7 @@ void GuiCombat::Render()
}
}
}
if (ok_tex) {
JQuad *ok_quad = resources.RetrieveTempQuad("ok.png");
ok_quad->SetHotSpot(28, 22);
ok.Render(ok_quad);
}
if (ok_quad) ok.Render(ok_quad);
renderer->DrawLine(0, SCREEN_HEIGHT / 2 + 10, SCREEN_WIDTH, SCREEN_HEIGHT / 2 + 10, ARGB(255, 255, 64, 0));
if (FIRST_STRIKE == step)
{

View File

@@ -526,6 +526,7 @@ void OptionsList::save(){
for (int i = 0; i < nbitems; i++){
listItems[i]->setData();
}
::options.save();
}
void OptionsList::Update(float dt){
@@ -651,8 +652,6 @@ void OptionsMenu::save(){
for(int x=0;x<MAX_OPTION_TABS;x++)
if(tabs[x] != NULL)
tabs[x]->save();
::options.save();
}
bool OptionsMenu::isTab(string name){

View File

@@ -66,16 +66,12 @@ WCachedTexture::~WCachedTexture(){
if(!trackedQuads.size())
return;
vector<WTrackedQuad*>::iterator it;
WTrackedQuad * tq = NULL;
map<JQuad*,string>::iterator it, nit;
for(it=trackedQuads.begin();it!=trackedQuads.end();it++){
tq = (*it);
if(!tq)
continue;
SAFE_DELETE(tq->quad);
SAFE_DELETE(tq);
for(it=trackedQuads.begin();it!=trackedQuads.end();it=nit){
nit = it;
nit++;
trackedQuads.erase(it);
}
trackedQuads.clear();
}
@@ -83,52 +79,29 @@ WCachedTexture::~WCachedTexture(){
JTexture * WCachedTexture::Actual(){
return texture;
}
bool WCachedTexture::isLocked(){
if(locks != WRES_UNLOCKED)
return true;
for(vector<WTrackedQuad*>::iterator it=trackedQuads.begin();it!=trackedQuads.end();it++){
if((*it)->isLocked())
return true;
}
return false;
}
bool WCachedTexture::ReleaseQuad(JQuad* quad){
#ifdef DEBUG_CACHE
OutputDebugString("Quad released.\n");
#endif
if(quad == NULL)
return false;
WTrackedQuad * tq = NULL;
for(vector<WTrackedQuad*>::iterator it = trackedQuads.begin();it!=trackedQuads.end();it++){
if((*it) && (*it)->quad == quad ){
tq = (*it);
tq->unlock();
if(!tq->isLocked()){
SAFE_DELETE(tq->quad);
SAFE_DELETE(tq);
trackedQuads.erase(it);
}
return true; //Returns true when found, not released.
for(map<JQuad*,string>::iterator i = trackedQuads.begin();i!=trackedQuads.end();i++){
if(i->first == quad ){
unlock();
trackedQuads.erase(i);
return true;
}
}
return false;
}
WTrackedQuad * WCachedTexture::GetTrackedQuad(float offX, float offY, float width, float height,string resname){
JQuad * WCachedTexture::GetQuad(float offX, float offY, float width, float height,string resname){
if(texture == NULL)
return NULL;
bool allocated = false;
WTrackedQuad * tq = NULL;
JQuad * quad = NULL;
JQuad * jq = NULL;
vector<WTrackedQuad*>::iterator it;
map<JQuad*,string>::iterator it;
std::transform(resname.begin(),resname.end(),resname.begin(),::tolower);
if(width == 0.0f || width > texture->mWidth)
@@ -136,73 +109,40 @@ WTrackedQuad * WCachedTexture::GetTrackedQuad(float offX, float offY, float widt
if(height == 0.0f || height > texture->mHeight)
height = texture->mHeight;
for(it = trackedQuads.begin();it!=trackedQuads.end();it++){
if((*it) && (*it)->resname == resname){
tq = (*it);
break;
if(it->second == resname){
jq = it->first;
}
}
if(tq == NULL){
allocated = true;
tq = NEW WTrackedQuad(resname);
if(!tq) {
if(jq == NULL){
jq = NEW JQuad(texture,offX,offY,width,height);
if(!jq) {
//Probably out of memory. Try again.
resources.Cleanup();
tq = NEW WTrackedQuad(resname);
}
}
if(tq == NULL)
return NULL;
quad = tq->quad;
if(quad == NULL){
quad = NEW JQuad(texture,offX,offY,width,height);
if(!quad) {
//Probably out of memory. Try again.
resources.Cleanup();
quad = NEW JQuad(texture,offX,offY,width,height);
jq = NEW JQuad(texture,offX,offY,width,height);
}
if(!quad){
if(allocated)
SAFE_DELETE(tq);
if(!jq)
return NULL; //Probably a crash.
}
tq->quad = quad;
trackedQuads.push_back(tq);
return tq;
}
else{
trackedQuads[jq] = resname;
return jq;
}else{
//Update JQ's values to what we called this with.
quad->SetTextureRect(offX,offY,width,height);
return tq;
jq->SetTextureRect(offX,offY,width,height);
return jq;
}
return NULL;
}
JQuad * WCachedTexture::GetQuad(float offX, float offY, float width, float height,string resname){
WTrackedQuad * tq = GetTrackedQuad(offX,offY,width,height,resname);
if(tq)
return tq->quad;
return NULL;
}
JQuad * WCachedTexture::GetQuad(string resname){
vector<WTrackedQuad*>::iterator it;
map<JQuad*,string>::iterator it;
std::transform(resname.begin(),resname.end(),resname.begin(),::tolower);
for(it = trackedQuads.begin();it!=trackedQuads.end();it++){
if((*it) && (*it)->resname == resname){
return (*it)->quad;
if(it->second == resname){
return it->first;
}
}
@@ -241,9 +181,9 @@ void WCachedTexture::Refresh(string filename){
else
SAFE_DELETE(old);
for(vector<WTrackedQuad*>::iterator it=trackedQuads.begin();it!=trackedQuads.end();it++){
if((*it) && (*it)->quad)
(*it)->quad->mTex = texture;
for(map<JQuad*,string>::iterator it=trackedQuads.begin();it!=trackedQuads.end();it++){
if(it->first)
it->first->mTex = texture;
}
}
@@ -294,7 +234,7 @@ bool WCachedTexture::Attempt(string filename, int submode, int & error){
}
//Failure of a different sort.
if(texture->mTexId == INVALID_MTEX){
if(texture->mTexId == -1){
SAFE_DELETE(texture);
error = CACHE_ERROR_BAD;
return false;
@@ -445,35 +385,3 @@ void WCachedParticles::Nullify(){
if(particles)
particles = NULL;
}
//WTrackedQuad
void WTrackedQuad::Nullify() {
quad = NULL;
}
#if defined DEBUG_CACHE
int WTrackedQuad::totalTracked = 0;
#endif
unsigned long WTrackedQuad::size() {
return sizeof(JQuad);
}
bool WTrackedQuad::isGood(){
return (quad != NULL);
}
WTrackedQuad::WTrackedQuad(string _resname) {
#if defined DEBUG_CACHE
OutputDebugString("Tracked quad created.\n");
totalTracked++;
#endif
quad = NULL; resname = _resname;
}
WTrackedQuad::~WTrackedQuad() {
#if defined DEBUG_CACHE
char buf[512];
totalTracked--;
sprintf(buf,"~WTrackedQuad(). %d left.\n",totalTracked);
OutputDebugString(buf);
#endif
if(quad) SAFE_DELETE(quad);
}

View File

@@ -54,7 +54,6 @@ void WResourceManager::DebugRender(){
#ifdef DEBUG_CACHE
if(debugMessage.size())
font->DrawString(debugMessage.c_str(), SCREEN_WIDTH-10,SCREEN_HEIGHT-25,JGETEXT_RIGHT);
#endif
}
@@ -162,11 +161,6 @@ WResourceManager::WResourceManager(){
WResourceManager::~WResourceManager(){
LOG("==Destroying WResourceManager==");
RemoveAll();
for(vector<WManagedQuad*>::iterator it=managedQuads.begin();it!=managedQuads.end();it++){
WManagedQuad* wm = *it;
SAFE_DELETE(wm);
}
managedQuads.clear();
LOG("==Successfully Destroyed WResourceManager==");
}
@@ -205,10 +199,10 @@ int WResourceManager::CreateQuad(const string &quadName, const string &textureNa
string resname = quadName;
std::transform(resname.begin(),resname.end(),resname.begin(),::tolower);
vector<WManagedQuad*>::iterator it;
vector<WManagedQuad>::iterator it;
int pos = 0;
for(it = managedQuads.begin();it!=managedQuads.end();it++,pos++){
if((*it)->resname == resname)
if(it->resname == resname)
return pos;
}
@@ -222,10 +216,9 @@ int WResourceManager::CreateQuad(const string &quadName, const string &textureNa
JQuad * jq = jtex->GetQuad(x,y,width,height,quadName);
if(jq){
WManagedQuad * mq;
mq = NEW WManagedQuad();
mq->resname = resname;
mq->texture = jtex;
WManagedQuad mq;
mq.resname = resname;
mq.texture = jtex;
managedQuads.push_back(mq);
}
@@ -239,9 +232,9 @@ JQuad * WResourceManager::GetQuad(const string &quadName){
string lookup = quadName;
std::transform(lookup.begin(),lookup.end(),lookup.begin(),::tolower);
for(vector<WManagedQuad*>::iterator it=managedQuads.begin();it!=managedQuads.end();it++){
if((*it)->resname == lookup)
return (*it)->texture->GetQuad(lookup);
for(vector<WManagedQuad>::iterator it=managedQuads.begin();it!=managedQuads.end();it++){
if(it->resname == lookup)
return it->texture->GetQuad(lookup);
}
return NULL;
@@ -251,11 +244,11 @@ JQuad * WResourceManager::GetQuad(int id){
if(id < 0 || id >= (int) managedQuads.size())
return NULL;
WCachedTexture * jtex = managedQuads[id]->texture;
WCachedTexture * jtex = managedQuads[id].texture;
if(!jtex)
return NULL;
return jtex->GetQuad(managedQuads[id]->resname);
return jtex->GetQuad(managedQuads[id].resname);
}
JQuad * WResourceManager::RetrieveTempQuad(string filename){
@@ -272,26 +265,12 @@ JQuad * WResourceManager::RetrieveQuad(string filename, float offX, float offY,
return jq;
}
//Aliases.
if(style == RETRIEVE_VRAM){
submode = submode | TEXTURE_SUB_VRAM;
style = RETRIEVE_LOCK;
}
else if(style == RETRIEVE_THUMB){
submode = submode | TEXTURE_SUB_THUMB;
style = RETRIEVE_NORMAL;
}
//Resname defaults to filename.
if(!resname.size())
resname = filename;
//No quad, but we have a managed texture for this!
WCachedTexture * jtex = NULL;
if(style == RETRIEVE_MANAGE)
jtex = textureWCache.Retrieve(filename,RETRIEVE_MANAGE,submode);
else
jtex = textureWCache.Retrieve(filename,RETRIEVE_NORMAL,submode);
WCachedTexture * jtex = textureWCache.Retrieve(filename,style,submode);
//Somehow, jtex wasn't promoted.
if(style == RETRIEVE_MANAGE && jtex && !jtex->isPermanent())
@@ -299,26 +278,16 @@ JQuad * WResourceManager::RetrieveQuad(string filename, float offX, float offY,
//Make this quad, overwriting any similarly resname'd quads.
if(jtex){
WTrackedQuad * tq = jtex->GetTrackedQuad(offX,offY,width,height,resname);
if(tq == NULL)
return NULL;
jq = jtex->GetQuad(offX,offY,width,height,resname);
if(style == RETRIEVE_MANAGE && resname != ""){
WManagedQuad * mq = NEW WManagedQuad();
mq->resname = resname;
mq->texture = jtex;
WManagedQuad mq;
mq.resname = resname;
mq.texture = jtex;
managedQuads.push_back(mq);
}
if(style == RETRIEVE_LOCK)
tq->lock();
else if(style == RETRIEVE_UNLOCK)
tq->unlock();
else if(style == RETRIEVE_MANAGE)
tq->deadbolt();
return tq->quad;
return jq;
}
//Texture doesn't exist, so no quad.
@@ -448,7 +417,7 @@ JTexture* WResourceManager::GetTexture(int id){
for(it = textureWCache.managed.begin();it!= textureWCache.managed.end(); it++){
if(it->second){
jtex = it->second->Actual();
if(id == (int) jtex->mTexId)
if(jtex->mTexId == id)
return jtex;
}
}