#include "LoaderImageT6.h" #include "Game/T6/CommonT6.h" #include "Game/T6/T6.h" #include "Image/ImageCommon.h" #include "Image/IwiLoader.h" #include "Utils/Logging/Log.h" #include #include #include #include #include using namespace T6; namespace { class ImageLoader final : public AssetCreator { public: ImageLoader(MemoryManager& memory, ISearchPath& searchPath) : m_memory(memory), m_search_path(searchPath) { } AssetCreationResult CreateAsset(const std::string& assetName, AssetCreationContext& context) override { const auto fileName = image::GetFileNameForAsset(assetName, ".iwi"); const auto file = m_search_path.Open(fileName); if (!file.IsOpen()) return AssetCreationResult::NoAction(); const auto fileSize = static_cast(file.m_length); const auto fileData = std::make_unique(fileSize); file.m_stream->read(fileData.get(), static_cast(fileSize)); const auto dataHash = static_cast(crc32(0u, reinterpret_cast(fileData.get()), static_cast(fileSize))); std::istringstream ss(std::string(fileData.get(), fileSize)); const auto texture = iwi::LoadIwi(ss); if (!texture) { con::error("Failed to load texture from: {}", fileName); return AssetCreationResult::Failure(); } auto* image = m_memory.Alloc(); image->name = m_memory.Dup(assetName.c_str()); image->hash = Common::R_HashString(image->name, 0); image->delayLoadPixels = true; image->noPicmip = !texture->HasMipMaps(); image->width = static_cast(texture->GetWidth()); image->height = static_cast(texture->GetHeight()); image->depth = static_cast(texture->GetDepth()); image->streaming = 1; image->streamedParts[0].levelCount = 1; image->streamedParts[0].levelSize = static_cast(fileSize); image->streamedParts[0].hash = dataHash & 0x1FFFFFFF; image->streamedPartCount = 1; return AssetCreationResult::Success(context.AddAsset(assetName, image)); } private: MemoryManager& m_memory; ISearchPath& m_search_path; }; } // namespace namespace image { std::unique_ptr> CreateLoaderT6(MemoryManager& memory, ISearchPath& searchPath) { return std::make_unique(memory, searchPath); } } // namespace image