1#include "Game/System/ResourceInfo.hpp"
2#include "Game/Util.hpp"
7ResFileInfo::ResFileInfo() {
17 : mFileInfoTable(0), mCount(0) {
20void ResTable::newFileInfoTable(u32 count) {
24ResFileInfo* ResTable::add(
const char *pName,
void *pRes,
bool stripExt) {
26 curInfo->mResource = pRes;
27 curInfo->setName(pName, stripExt);
32const char* ResTable::getResName(u32 idx)
const {
33 return mFileInfoTable[idx].mName;
36void* ResTable::getRes(u32 idx)
const {
37 return mFileInfoTable[idx].mResource;
40void* ResTable::getRes(
const char *pName)
const {
41 return findRes(pName);
44ResFileInfo* ResTable::findFileInfo(
const char *pName)
const {
45 int resIdx = getResIndex(pName);
47 return &mFileInfoTable[resIdx];
54 return &mFileInfoTable[idx];
57bool ResTable::isExistRes(
const char *pRes)
const {
58 return getResIndex(pRes) != -1;
61void* ResTable::findRes(
const char *pName)
const {
62 int idx = getResIndex(pName);
65 return mFileInfoTable[idx].mResource;
71int ResTable::getResIndex(
const char *pName)
const {
72 u32 hash = MR::getHashCodeLower(pName);
74 for (
int i = 0; i < mCount; i++) {
75 u32 curHash = mFileInfoTable[i].mHashCode;
77 if (curHash == hash) {
85const char* ResTable::findResName(
const void *pRes)
const {
86 for (
int i = 0; i < mCount; i++) {
88 if (pRes == inf->mResource) {
96const char* ResTable::getResName(
const void *pResource)
const {
97 return findResName(pResource);
100void ResFileInfo::setName(
const char *pName,
bool stripExt) {
101 size_t len = strlen(pName) + 1;
102 mName =
new char[len];
104 snprintf(mName, len,
"%s", pName);
107 char* out = strrchr(mName,
'.');
114 mHashCode = MR::getHashCodeLower(mName);