Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void ResourceManager::LoadArchive(Pack& pack, ResourceType type, const std::filesystem::path& path)
- {
- using namespace util;
- HND_LOG_DEBUG("ARCHIVE: " + path.filename().string());
- std::string spath = path.string();
- rresCentralDir dir = rresLoadCentralDirectory(spath.c_str());
- if (dir.count == 0) HND_LOG_DEBUG("ARCHIVE: No central directory");
- unsigned int chunkCount = 0;
- rresResourceChunkInfo* infos = rresLoadResourceChunkInfoAll(spath.c_str(), &chunkCount);
- unsigned int prevId = 0;
- for (unsigned int i = 0; i < chunkCount; i++)
- {
- // skips fonts in tex/obj dirs and tex/obj in font dir
- if ((SameFourCC(infos[i].type, FOURCC_IMAGE) && type == ResourceType::Font) ||
- SameFourCC(infos[i].type, FOURCC_FONT) && (type == ResourceType::Texture|| type==ResourceType::Object))
- continue;
- std::string name;
- for (unsigned int j = 0; j < dir.count; j++)
- {
- if ((infos[i].id == dir.entries[j].id) && (infos[i].id != prevId))
- {
- name = std::string(dir.entries[j].fileName);
- prevId = dir.entries[j].id;
- break;
- }
- }
- if(SameFourCC(infos[i].type, FOURCC_IMAGE))
- {
- rresResourceChunk chunk = rresLoadResourceChunk(spath.c_str(), infos[i].id);
- int result = UnpackResourceChunk(&chunk);
- if (result == 0)
- {
- Image img = LoadImageFromResource(chunk);
- if (type == ResourceType::Texture)
- {
- pack.textures[GenerateHandle(pack.name, type, name)] =
- TextureData(name,std::make_shared<Texture2D>(LoadTextureFromImage(img)));
- HND_LOG_DEBUG("ARCHIVE: loaded texture " + name);
- }
- else
- {
- pack.objects[GenerateHandle(pack.name, type, name)] =
- TextureData(name, std::make_shared<Texture2D>(LoadTextureFromImage(img)));
- HND_LOG_DEBUG("ARCHIVE: loaded object " + name);
- }
- UnloadImage(img);
- }
- else HND_LOG_ERROR(
- std::format("Failed to unpack resource chunk (id:{})", infos[i].id));
- rresUnloadResourceChunk(chunk);
- }
- else if (SameFourCC(infos[i].type, FOURCC_FONT))
- {
- rresResourceMulti multi = rresLoadResourceMulti(spath.c_str(), infos[i].id);
- int result = -1;
- for (unsigned int i = 0; i < multi.count; i++)
- {
- result = UnpackResourceChunk(&multi.chunks[i]);
- if (result != 0) HND_LOG_ERROR(
- std::format("Failed to unpack multi resource chunk (id:{}, i:{})", infos[i].id, i));
- }
- if (result == 0)
- {
- pack.fonts[GenerateHandle(pack.name, type, name)]=
- FontData(name, std::make_shared<Font>(LoadFontFromResource(multi)));
- HND_LOG_DEBUG("ARCHIVE: loaded font " + name);
- }
- rresUnloadResourceMulti(multi);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement