Jeck - [Requires JGE rebuild] Extensive cache improvements.
* Numerous cache fixes, reduced filesystem access.
* Cache fails very gracefully.
* Cache is now a templated class, with individual caches per data-type.
* Much easier to extend.
* Extensively debugged. Try compiling with -DDEBUG_CACHE.
* Caches limits can be set on a per-item basis.
* hgeParticleSystemInfo are now cached, mana particles now fall back to defaults.
* Samples are not cached, but track filesystem misses using the cache backbone.
* Avatars are cached. Default baka avatar is now baka.jpg, to prevent collision with player.
A note on the retrieval types:
RETRIEVE_MANAGE puts a resource into a seperate, managed resource list.
Managed resources are guarenteed valid for the lifetime of the program.
Retrieving a managed quad promotes the associated texture to managed. Don't do that by mistake.
Calls to Resources.Refresh() will attempt to reload managed resources in place.
RETRIVE_LOCK (and by extension, RETRIEVE_VRAM), returns a resource after locking it.
A resource may have many locks, and remains in cache until they are all released.
If the resource is managed, it returns it unmodified.
A note on quads:
Unlike all other RetrieveWhatever() functions, the default behavior for RetrieveQuad is RETRIEVE_LOCK. Worse, Release(JQuad*) is slow, and will /always/ release one lock from the associated texture.
There's a long and complicated explanation for this, involving support for live relinking of textures to existing quads, but basically what it means is that we only use RetrieveQuad for quads we intend to store and later Release(). If a temporary quad is needed, the preferred method is to use NEW JQuad* and SAFE_DELETE with RetrieveTexture(). RetrieveTempQuad is also provided, but is only guaranteed until the next call to the cache.
Note that RetrieveCard has none of these problems.
This commit is contained in:
@@ -1,102 +1,88 @@
|
||||
//-------------------------------------------------------------------------------------
|
||||
//
|
||||
// JGE++ is a hardware accelerated 2D game SDK for PSP/Windows.
|
||||
//
|
||||
// Licensed under the BSD license, see LICENSE in JGE root for details.
|
||||
//
|
||||
// Copyright (c) 2007 James Hui (a.k.a. Dr.Watson) <jhkhui@gmail.com>
|
||||
//
|
||||
//-------------------------------------------------------------------------------------
|
||||
|
||||
#ifndef _RESOURCE_MANAGER_H_
|
||||
#define _RESOURCE_MANAGER_H_
|
||||
|
||||
#ifdef WIN32
|
||||
#pragma warning(disable : 4786)
|
||||
#endif
|
||||
|
||||
#include <stdio.h>
|
||||
#include <vector>
|
||||
#include <map>
|
||||
#include <string>
|
||||
|
||||
using namespace std;
|
||||
|
||||
|
||||
#define INVALID_ID -1
|
||||
|
||||
class JRenderer;
|
||||
class JSample;
|
||||
class JMusic;
|
||||
class JTexture;
|
||||
class JQuad;
|
||||
class JLBFont;
|
||||
|
||||
class JResourceManager
|
||||
{
|
||||
public:
|
||||
JResourceManager();
|
||||
virtual ~JResourceManager();
|
||||
|
||||
//void SetResourceRoot(const string& resourceRoot);
|
||||
bool LoadResource(const string& resourceName);
|
||||
|
||||
void RemoveAll();
|
||||
|
||||
virtual int CreateTexture(const string &textureName);
|
||||
JTexture* GetTexture(const string &textureName);
|
||||
JTexture* GetTexture(int id);
|
||||
|
||||
virtual int CreateQuad(const string &quadName, const string &textureName, float x, float y, float width, float height);
|
||||
JQuad* GetQuad(const string &quadName);
|
||||
JQuad* GetQuad(int id);
|
||||
|
||||
virtual int LoadJLBFont(const string &fontName, int height);
|
||||
JLBFont* GetJLBFont(const string &fontName);
|
||||
JLBFont* GetJLBFont(int id);
|
||||
|
||||
virtual int LoadMusic(const string &musicName);
|
||||
JMusic* GetMusic(const string &musicName);
|
||||
JMusic* GetMusic(int id);
|
||||
|
||||
virtual int LoadSample(const string &sampleName);
|
||||
JSample* GetSample(const string &sampleName);
|
||||
JSample* GetSample(int id);
|
||||
|
||||
// int RegisterParticleEffect(const string &effectName);
|
||||
// JParticleEffect* GetParticleEffect(const string &effectName);
|
||||
// JParticleEffect* GetParticleEffect(int id);
|
||||
//
|
||||
// int RegisterMotionEmitter(const string &emitterName);
|
||||
// JMotionEmitter* GetMotionEmitter(const string &emitterName);
|
||||
// JMotionEmitter* GetMotionEmitter(int id);
|
||||
|
||||
protected:
|
||||
|
||||
//JRenderer *mRenderer;
|
||||
|
||||
//string mResourceRoot;
|
||||
|
||||
vector<JTexture *> mTextureList;
|
||||
map<string, int> mTextureMap;
|
||||
|
||||
vector<JQuad *> mQuadList;
|
||||
map<string, int> mQuadMap;
|
||||
|
||||
// vector<JParticleEffect *> mParticleEffectList;
|
||||
// map<string, int> mParticleEffectMap;
|
||||
//
|
||||
// vector<JMotionEmitter *> mMotionEmitterList;
|
||||
// map<string, int> mMotionEmitterMap;
|
||||
|
||||
vector<JLBFont *> mFontList;
|
||||
map<string, int> mFontMap;
|
||||
|
||||
vector<JMusic *> mMusicList;
|
||||
map<string, int> mMusicMap;
|
||||
|
||||
vector<JSample *> mSampleList;
|
||||
map<string, int> mSampleMap;
|
||||
};
|
||||
|
||||
#endif
|
||||
//-------------------------------------------------------------------------------------
|
||||
//
|
||||
// JGE++ is a hardware accelerated 2D game SDK for PSP/Windows.
|
||||
//
|
||||
// Licensed under the BSD license, see LICENSE in JGE root for details.
|
||||
//
|
||||
// Copyright (c) 2007 James Hui (a.k.a. Dr.Watson) <jhkhui@gmail.com>
|
||||
//
|
||||
//-------------------------------------------------------------------------------------
|
||||
|
||||
#ifndef _RESOURCE_MANAGER_H_
|
||||
#define _RESOURCE_MANAGER_H_
|
||||
|
||||
#ifdef WIN32
|
||||
#pragma warning(disable : 4786)
|
||||
#endif
|
||||
|
||||
#include <stdio.h>
|
||||
#include <vector>
|
||||
#include <map>
|
||||
#include <string>
|
||||
|
||||
using namespace std;
|
||||
|
||||
|
||||
#define INVALID_ID -1
|
||||
|
||||
class JRenderer;
|
||||
class JSample;
|
||||
class JMusic;
|
||||
class JTexture;
|
||||
class JQuad;
|
||||
class JLBFont;
|
||||
|
||||
class JResourceManager
|
||||
{
|
||||
public:
|
||||
JResourceManager();
|
||||
virtual ~JResourceManager();
|
||||
|
||||
//void SetResourceRoot(const string& resourceRoot);
|
||||
bool LoadResource(const string& resourceName);
|
||||
|
||||
virtual void RemoveAll();
|
||||
|
||||
virtual int CreateTexture(const string &textureName);
|
||||
virtual JTexture* GetTexture(const string &textureName);
|
||||
virtual JTexture* GetTexture(int id);
|
||||
|
||||
virtual int CreateQuad(const string &quadName, const string &textureName, float x, float y, float width, float height);
|
||||
virtual JQuad* GetQuad(const string &quadName);
|
||||
virtual JQuad* GetQuad(int id);
|
||||
|
||||
virtual int LoadJLBFont(const string &fontName, int height);
|
||||
virtual JLBFont* GetJLBFont(const string &fontName);
|
||||
virtual JLBFont* GetJLBFont(int id);
|
||||
|
||||
// int RegisterParticleEffect(const string &effectName);
|
||||
// JParticleEffect* GetParticleEffect(const string &effectName);
|
||||
// JParticleEffect* GetParticleEffect(int id);
|
||||
//
|
||||
// int RegisterMotionEmitter(const string &emitterName);
|
||||
// JMotionEmitter* GetMotionEmitter(const string &emitterName);
|
||||
// JMotionEmitter* GetMotionEmitter(int id);
|
||||
|
||||
protected:
|
||||
|
||||
//JRenderer *mRenderer;
|
||||
|
||||
//string mResourceRoot;
|
||||
|
||||
vector<JTexture *> mTextureList;
|
||||
map<string, int> mTextureMap;
|
||||
|
||||
vector<JQuad *> mQuadList;
|
||||
map<string, int> mQuadMap;
|
||||
|
||||
// vector<JParticleEffect *> mParticleEffectList;
|
||||
// map<string, int> mParticleEffectMap;
|
||||
//
|
||||
// vector<JMotionEmitter *> mMotionEmitterList;
|
||||
// map<string, int> mMotionEmitterMap;
|
||||
|
||||
vector<JLBFont *> mFontList;
|
||||
map<string, int> mFontMap;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
1031
JGE/include/JTypes.h
1031
JGE/include/JTypes.h
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user