Files
wagic/JGE/include/JResourceManager.h
wrenczes@gmail.com 832f11c153 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.
2010-10-17 16:54:08 +00:00

74 lines
1.7 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
#define ALREADY_EXISTS -2
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 void RemoveJLBFonts();
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 JLBFont * LoadJLBFont(const string &fontName, int height);
virtual JLBFont* GetJLBFont(const string &fontName);
virtual JLBFont* GetJLBFont(int id);
protected:
vector<JTexture *> mTextureList;
map<string, int> mTextureMap;
vector<JQuad *> mQuadList;
map<string, int> mQuadMap;
vector<JLBFont *> mFontList;
map<string, int> mFontMap;
};
#endif