#include "AssetLoaderGfxImage.h" #include "Game/IW5/IW5.h" #include "Image/IwiLoader.h" #include "Pool/GlobalAssetPool.h" #include #include #include #include using namespace IW5; void* AssetLoaderGfxImage::CreateEmptyAsset(const std::string& assetName, MemoryManager* memory) { auto* asset = memory->Alloc(); asset->name = memory->Dup(assetName.c_str()); return asset; } bool AssetLoaderGfxImage::CanLoadFromRaw() const { return true; } bool AssetLoaderGfxImage::LoadFromRaw( const std::string& assetName, ISearchPath* searchPath, MemoryManager* memory, IAssetLoadingManager* manager, Zone* zone) const { const auto fileName = std::format("images/{}.iwi", assetName); const auto file = searchPath->Open(fileName); if (!file.IsOpen()) return false; const auto fileSize = static_cast(file.m_length); const auto fileData = std::make_unique(fileSize); file.m_stream->read(fileData.get(), fileSize); MemoryManager tempMemory; IwiLoader iwiLoader(&tempMemory); std::istringstream ss(std::string(fileData.get(), fileSize)); const auto texture = iwiLoader.LoadIwi(ss); if (!texture) { std::cerr << std::format("Failed to load texture from: {}\n", fileName); return false; } auto* image = memory->Create(); memset(image, 0, sizeof(GfxImage)); image->name = memory->Dup(assetName.c_str()); image->noPicmip = !texture->HasMipMaps(); image->width = static_cast(texture->GetWidth()); image->height = static_cast(texture->GetHeight()); image->depth = static_cast(texture->GetDepth()); image->texture.loadDef = memory->Alloc(); manager->AddAsset(assetName, image); return true; }