diff --git a/src/Common/Game/T6/T6_Assets.h b/src/Common/Game/T6/T6_Assets.h index e41a5702..0f839ca8 100644 --- a/src/Common/Game/T6/T6_Assets.h +++ b/src/Common/Game/T6/T6_Assets.h @@ -765,10 +765,10 @@ namespace T6 int platform[2]; }; - struct GfxStreamedPartInfo { - unsigned int levelCountAndSize; + uint32_t levelCount : 4; + uint32_t levelSize : 28; unsigned int hash; uint16_t width; uint16_t height; diff --git a/src/ObjLoading/Game/T6/AssetLoaders/AssetLoaderGfxImage.cpp b/src/ObjLoading/Game/T6/AssetLoaders/AssetLoaderGfxImage.cpp new file mode 100644 index 00000000..dcd4ff82 --- /dev/null +++ b/src/ObjLoading/Game/T6/AssetLoaders/AssetLoaderGfxImage.cpp @@ -0,0 +1,71 @@ +#include "AssetLoaderGfxImage.h" + +#include +#include +#include +#include + +#include "Game/T6/CommonT6.h" +#include "Game/T6/T6.h" +#include "Image/IwiLoader.h" +#include "Pool/GlobalAssetPool.h" + +using namespace T6; + +void* AssetLoaderGfxImage::CreateEmptyAsset(const std::string& assetName, MemoryManager* memory) +{ + auto* image = memory->Create(); + memset(image, 0, sizeof(GfxImage)); + image->name = memory->Dup(assetName.c_str()); + return image; +} + +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 = "images/" + assetName + ".iwi"; + 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); + const auto dataHash = static_cast(crc32(0u, reinterpret_cast(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 << "Failed to load texture from: " << fileName << "\n"; + return false; + } + + auto* image = memory->Create(); + memset(image, 0, sizeof(GfxImage)); + + image->name = 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; + + manager->AddAsset(ASSET_TYPE_IMAGE, assetName, image); + + return true; +} diff --git a/src/ObjLoading/Game/T6/AssetLoaders/AssetLoaderGfxImage.h b/src/ObjLoading/Game/T6/AssetLoaders/AssetLoaderGfxImage.h new file mode 100644 index 00000000..f88f7685 --- /dev/null +++ b/src/ObjLoading/Game/T6/AssetLoaders/AssetLoaderGfxImage.h @@ -0,0 +1,16 @@ +#pragma once +#include "Game/T6/T6.h" +#include "AssetLoading/BasicAssetLoader.h" +#include "AssetLoading/IAssetLoadingManager.h" +#include "SearchPath/ISearchPath.h" + +namespace T6 +{ + class AssetLoaderGfxImage final : public BasicAssetLoader + { + public: + _NODISCARD void* CreateEmptyAsset(const std::string& assetName, MemoryManager* memory) override; + _NODISCARD bool CanLoadFromRaw() const override; + bool LoadFromRaw(const std::string& assetName, ISearchPath* searchPath, MemoryManager* memory, IAssetLoadingManager* manager, Zone* zone) const override; + }; +} diff --git a/src/ObjLoading/Game/T6/ObjLoaderT6.cpp b/src/ObjLoading/Game/T6/ObjLoaderT6.cpp index 13b385e7..bafa90bb 100644 --- a/src/ObjLoading/Game/T6/ObjLoaderT6.cpp +++ b/src/ObjLoading/Game/T6/ObjLoaderT6.cpp @@ -7,6 +7,7 @@ #include "ObjContainer/IPak/IPak.h" #include "ObjLoading.h" #include "AssetLoaders/AssetLoaderFontIcon.h" +#include "AssetLoaders/AssetLoaderGfxImage.h" #include "AssetLoaders/AssetLoaderLocalizeEntry.h" #include "AssetLoaders/AssetLoaderPhysConstraints.h" #include "AssetLoaders/AssetLoaderPhysPreset.h" @@ -45,7 +46,7 @@ namespace T6 REGISTER_ASSET_LOADER(BASIC_LOADER(ASSET_TYPE_XMODEL, XModel)) REGISTER_ASSET_LOADER(BASIC_LOADER(ASSET_TYPE_MATERIAL, Material)) REGISTER_ASSET_LOADER(BASIC_LOADER(ASSET_TYPE_TECHNIQUE_SET, MaterialTechniqueSet)) - REGISTER_ASSET_LOADER(BASIC_LOADER(ASSET_TYPE_IMAGE, GfxImage)) + REGISTER_ASSET_LOADER(AssetLoaderGfxImage) REGISTER_ASSET_LOADER(BASIC_LOADER(ASSET_TYPE_SOUND, SndBank)) REGISTER_ASSET_LOADER(BASIC_LOADER(ASSET_TYPE_SOUND_PATCH, SndPatch)) REGISTER_ASSET_LOADER(BASIC_LOADER(ASSET_TYPE_CLIPMAP, clipMap_t))