Files
wagic/JGE/include/JResourceManager.h
T
wagic.jeck f220d2e9b9 Jeck - Cache and resource manager merged, streamlined.
This is pretty major, so there'll probably be something wrong with it... even though I did spend a few hours looking.
NOTES:
 * If you've Retrieved it, don't delete it--- Use resources.Release(Whatever). 
    Textures automatically release subordinate quads.
 * Most of the time, use resources.RetrieveQuad to grab a quad. Should handle everything for you.
    RetrieveQuad will load the required texture, if needed.
    Only managed resources have a resource name ("back", "simon", etc). 
    Managed resources can be retrieved with GetTexture/GetQuad/GetWhatever.
    Non managed quads lookup by position/dimensions, defaulting to the whole texture.
 * Use resources.RetrieveTexture only when you need to do something special to it. 
    Calling retrieve texture with RETRIEVE_MANAGE will permanently add a texture to the manager
    RETRIEVE_LOCK and RETRIEVE_VRAM will lock a texture. It will not leave the cache until
    Release(JTexture*) is called, or as a last resort during cache overflow.
 * Try to only store (as a class member) pointers to textures retrieved with RETRIEVE_MANAGE. 
    All others may become invalid, although locked textures do have a high degree of stability. It's
    pretty safe to store a locked texture if you're not going to load much between uses.

There's a lot going on here, so I might have missed something... but it runs through the test suite alright.

TODO: 
 * When called without any arguments, RetrieveQuad sometimes leaves a thin border around the image. 
    This can be bypassed by specifying a quad one or two pixels less than the image size. Why?
 * I've had a crash while runing the Demo mode, something to do with receiveEventMinus? 
    This hasn't exactly reproduced on a clean SVN copy, (being a hang, rather than a crash) so 
    I've probably done something to worsen the problem somehow? I'll look into it tomorrow.
 * Clean up lock/unlock system, memory usage. Streamline interface, consider phasing out calls using GetWhatever() format.
2009-09-03 09:28:16 +00:00

103 lines
2.6 KiB
C++

//-------------------------------------------------------------------------------------
//
// 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