Game Development Reference
In-Depth Information
protected:
ResHandleList m_lru; // LRU (least recently used) list
ResHandleMap m_resources; // STL map for fast resource lookup
ResourceLoaders m_resourceLoaders;
IResourceFile *m_file;
// Object that implements IResourceFile
unsigned int m_cacheSize;
// total memory size
unsigned int m_allocated;
// total memory allocated
shared_ptr<ResHandle> Find(Resource * r);
const void *Update(shared_ptr<ResHandle> handle);
shared_ptr<ResHandle> Load(Resource * r);
void Free(shared_ptr<ResHandle> gonner);
bool MakeRoom(unsigned int size);
char *Allocate(unsigned int size);
void FreeOneResource();
void MemoryHasBeenFreed(unsigned int size);
public:
ResCache(const unsigned int sizeInMb, IResourceFile *resFile);
~ResCache();
bool Init();
void RegisterLoader( shared_ptr<IResourceLoader> loader );
shared_ptr<ResHandle> GetHandle(Resource * r);
int Preload(const std::string pattern, void (*progressCallback)(int, bool &));
void Flush(void);
};
The first three members of the class have already been introduced. They are the least
recently used (LRU) list to track which resources are less frequently used than others,
the STL map, which is used to quickly find resources by name, and another STL list
of the resource loaders that match resource types with the loader that can process
them. There is a pointer to the resource file and two unsigned integers that track
the maximum size of the cache and the current size of the cache.
The m_file member points to an object that implements the IResourceFile
interface.
The two unsigned integers, m_cacheSize and m_allocated , keep track of the
cache size and how much of it is currently being used.
Search WWH ::




Custom Search