Jeck - WResourceManager / Cache should now be leak free. Demo mode still crashes around EnstackBlocker.

This commit is contained in:
wagic.jeck
2009-09-18 01:20:46 +00:00
parent 6abd3cc160
commit 8ba34dafca
16 changed files with 794 additions and 594 deletions

View File

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

View File

@@ -20,6 +20,7 @@ class hgeDistortionMesh;
class ShopItem:public JGuiObject{
private:
bool mHasFocus;
bool mRelease;
JLBFont *mFont;
string mText;
float xy[8];

View File

@@ -18,24 +18,47 @@ 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 Attempt(string filename, int submode, int & error)=0; //Returns true if we've loaded our data and isGood().
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.
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.
protected:
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 WCachedTexture: public WResource{
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{
public:
friend class WResourceManager;
template<class cacheItem,class cacheActual> friend class WCache;
@@ -44,23 +67,28 @@ public:
void Refresh(string filename);
unsigned long size();
bool isGood();
bool isGood();
bool isLocked();
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);
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.
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 * 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;
map<JQuad*,string> trackedQuads;
vector<WTrackedQuad*> trackedQuads;
};
class WCachedParticles: public WResource{
class WCachedParticles: public WCachedResource{
public:
friend class WResourceManager;
template<class cacheItem,class cacheActual> friend class WCache;
@@ -79,13 +107,12 @@ protected:
hgeParticleSystemInfo * particles;
};
class WCachedSample: public WResource{
class WCachedSample: public WCachedResource{
public:
friend class WResourceManager;
template<class cacheItem,class cacheActual> friend class WCache;
WCachedSample();
~WCachedSample();
~WCachedSample();
void Nullify();
bool compare(JSample * s) {return (s == sample);};
unsigned long size();
@@ -98,4 +125,4 @@ protected:
JSample * sample;
};
#endif
#endif

View File

@@ -7,17 +7,28 @@
#include "MTGCard.h"
#include "WCachedResource.h"
//Hard Limits.
//Soft limits.
#define HUGE_CACHE_LIMIT 10000000
#define HUGE_CACHE_ITEMS 400
#define LARGE_CACHE_LIMIT 5000000
#define SMALL_CACHE_LIMIT 2000000
#define MAX_CACHE_OBJECTS 200
#define LARGE_CACHE_ITEMS 300
#define SMALL_CACHE_LIMIT 1000000
#define SMALL_CACHE_ITEMS 200
//Hard Limits.
#define MAX_CACHE_OBJECTS 400
#define MAX_CACHE_ATTEMPTS 10
#define MAX_CACHE_MISSES 200
#define MAX_CACHED_SAMPLES 0
enum ENUM_WRES_INFO{
WRES_UNLOCKED = 0, //Resource is unlocked.
WRES_MAX_LOCK = 250, //Maximum number of locks for a resource.
WRES_PERMANENT = 251, //Resource is permanent (ie, managed)
WRES_UNDERLOCKED = 252, //Resource was released too many times.
};
enum ENUM_RETRIEVE_STYLE{
@@ -166,8 +177,7 @@ public:
//Wrapped from JSoundSystem. TODO: Privatize.
JMusic * ssLoadMusic(const char *fileName);
void LargeCache();
void SmallCache();
void CacheForState(int state);
void DebugRender();
@@ -183,7 +193,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;