mirror of
https://github.com/Laupetin/OpenAssetTools.git
synced 2025-06-10 23:08:05 -05:00
refactor: image and obj data loading
This commit is contained in:
@ -820,10 +820,10 @@ namespace IW4
|
||||
m_material->techniqueSet = techset->Asset();
|
||||
|
||||
auto* loadingContext = m_manager->GetAssetLoadingContext();
|
||||
auto* searchPath = loadingContext->m_raw_search_path;
|
||||
auto& searchPath = loadingContext->m_raw_search_path;
|
||||
auto* definitionCache = loadingContext->GetZoneAssetLoaderState<techset::TechsetDefinitionCache>();
|
||||
|
||||
const auto* techsetDefinition = AssetLoaderTechniqueSet::LoadTechsetDefinition(techsetName, searchPath, definitionCache);
|
||||
const auto* techsetDefinition = AssetLoaderTechniqueSet::LoadTechsetDefinition(techsetName, &searchPath, definitionCache);
|
||||
if (techsetDefinition == nullptr)
|
||||
{
|
||||
std::ostringstream ss;
|
||||
@ -1375,7 +1375,7 @@ bool AssetLoaderMaterial::LoadFromGdt(
|
||||
if (!entry)
|
||||
return false;
|
||||
|
||||
MaterialGdtLoader loader(*entry, memory, manager->GetAssetLoadingContext()->m_raw_search_path, manager);
|
||||
MaterialGdtLoader loader(*entry, memory, &manager->GetAssetLoadingContext()->m_raw_search_path, manager);
|
||||
|
||||
try
|
||||
{
|
||||
|
@ -227,7 +227,7 @@ bool AssetLoaderMenuList::LoadFromRaw(
|
||||
return true;
|
||||
}
|
||||
|
||||
void AssetLoaderMenuList::FinalizeAssetsForZone(AssetLoadingContext* context) const
|
||||
void AssetLoaderMenuList::FinalizeAssetsForZone(AssetLoadingContext& context) const
|
||||
{
|
||||
context->GetZoneAssetLoaderState<MenuConversionZoneState>()->FinalizeSupportingData();
|
||||
context.GetZoneAssetLoaderState<MenuConversionZoneState>()->FinalizeSupportingData();
|
||||
}
|
||||
|
@ -14,6 +14,6 @@ namespace IW4
|
||||
_NODISCARD bool CanLoadFromRaw() const override;
|
||||
bool
|
||||
LoadFromRaw(const std::string& assetName, ISearchPath* searchPath, MemoryManager* memory, IAssetLoadingManager* manager, Zone* zone) const override;
|
||||
void FinalizeAssetsForZone(AssetLoadingContext* context) const override;
|
||||
void FinalizeAssetsForZone(AssetLoadingContext& context) const override;
|
||||
};
|
||||
} // namespace IW4
|
||||
|
@ -37,14 +37,9 @@
|
||||
#include "AssetLoaders/AssetLoaderXModel.h"
|
||||
#include "AssetLoaders/AssetLoaderXModelSurfs.h"
|
||||
#include "AssetLoading/AssetLoadingManager.h"
|
||||
#include "Game/IW4/GameAssetPoolIW4.h"
|
||||
#include "Game/IW4/GameIW4.h"
|
||||
#include "Image/Dx9TextureLoader.h"
|
||||
#include "Image/IwiLoader.h"
|
||||
#include "Image/IwiTypes.h"
|
||||
#include "Image/Texture.h"
|
||||
#include "ObjContainer/IPak/IPak.h"
|
||||
#include "ObjLoading.h"
|
||||
|
||||
using namespace IW4;
|
||||
|
||||
@ -97,129 +92,32 @@ ObjLoader::ObjLoader()
|
||||
#undef REGISTER_ASSET_LOADER
|
||||
}
|
||||
|
||||
bool ObjLoader::SupportsZone(Zone* zone) const
|
||||
bool ObjLoader::SupportsZone(const Zone& zone) const
|
||||
{
|
||||
return zone->m_game == &g_GameIW4;
|
||||
return zone.m_game == &g_GameIW4;
|
||||
}
|
||||
|
||||
bool ObjLoader::IsMpZone(Zone* zone)
|
||||
bool ObjLoader::IsMpZone(const Zone& zone)
|
||||
{
|
||||
return zone->m_name.compare(0, 3, "mp_") == 0 || zone->m_name.compare(zone->m_name.length() - 3, 3, "_mp") == 0;
|
||||
return zone.m_name.compare(0, 3, "mp_") == 0 || zone.m_name.compare(zone.m_name.length() - 3, 3, "_mp") == 0;
|
||||
}
|
||||
|
||||
bool ObjLoader::IsZmZone(Zone* zone)
|
||||
bool ObjLoader::IsZmZone(const Zone& zone)
|
||||
{
|
||||
return zone->m_name.compare(0, 3, "zm_") == 0 || zone->m_name.compare(zone->m_name.length() - 3, 3, "_zm") == 0;
|
||||
return zone.m_name.compare(0, 3, "zm_") == 0 || zone.m_name.compare(zone.m_name.length() - 3, 3, "_zm") == 0;
|
||||
}
|
||||
|
||||
void ObjLoader::LoadReferencedContainersForZone(ISearchPath* searchPath, Zone* zone) const {}
|
||||
void ObjLoader::LoadReferencedContainersForZone(ISearchPath& searchPath, Zone& zone) const {}
|
||||
|
||||
void ObjLoader::UnloadContainersOfZone(Zone* zone) const {}
|
||||
void ObjLoader::UnloadContainersOfZone(Zone& zone) const {}
|
||||
|
||||
void ObjLoader::LoadImageFromLoadDef(GfxImage* image, Zone* zone)
|
||||
bool ObjLoader::LoadAssetForZone(AssetLoadingContext& context, asset_type_t assetType, const std::string& assetName) const
|
||||
{
|
||||
const auto* loadDef = image->texture.loadDef;
|
||||
Dx9TextureLoader textureLoader(zone->GetMemory());
|
||||
|
||||
textureLoader.Width(image->width).Height(image->height).Depth(image->depth);
|
||||
|
||||
if ((loadDef->flags & iwi8::IMG_FLAG_MAPTYPE_MASK) == iwi8::IMG_FLAG_MAPTYPE_3D)
|
||||
textureLoader.Type(TextureType::T_3D);
|
||||
else if ((loadDef->flags & iwi8::IMG_FLAG_MAPTYPE_MASK) == iwi8::IMG_FLAG_MAPTYPE_CUBE)
|
||||
textureLoader.Type(TextureType::T_CUBE);
|
||||
else
|
||||
textureLoader.Type(TextureType::T_2D);
|
||||
|
||||
textureLoader.Format(static_cast<oat::D3DFORMAT>(loadDef->format));
|
||||
textureLoader.HasMipMaps(!(loadDef->flags & iwi8::IMG_FLAG_NOMIPMAPS));
|
||||
Texture* loadedTexture = textureLoader.LoadTexture(image->texture.loadDef->data);
|
||||
|
||||
if (loadedTexture != nullptr)
|
||||
{
|
||||
image->texture.texture = loadedTexture;
|
||||
image->cardMemory.platform[0] = 0;
|
||||
|
||||
const auto textureMipCount = loadedTexture->GetMipMapCount();
|
||||
for (auto mipLevel = 0; mipLevel < textureMipCount; mipLevel++)
|
||||
image->cardMemory.platform[0] += static_cast<int>(loadedTexture->GetSizeOfMipLevel(mipLevel) * loadedTexture->GetFaceCount());
|
||||
}
|
||||
}
|
||||
|
||||
void ObjLoader::LoadImageFromIwi(GfxImage* image, ISearchPath* searchPath, Zone* zone)
|
||||
{
|
||||
Texture* loadedTexture = nullptr;
|
||||
IwiLoader loader(zone->GetMemory());
|
||||
|
||||
const auto imageFileName = "images/" + std::string(image->name) + ".iwi";
|
||||
|
||||
{
|
||||
const auto filePathImage = searchPath->Open(imageFileName);
|
||||
if (filePathImage.IsOpen())
|
||||
{
|
||||
loadedTexture = loader.LoadIwi(*filePathImage.m_stream);
|
||||
}
|
||||
}
|
||||
|
||||
if (loadedTexture != nullptr)
|
||||
{
|
||||
image->texture.texture = loadedTexture;
|
||||
image->cardMemory.platform[0] = 0;
|
||||
|
||||
const auto textureMipCount = loadedTexture->GetMipMapCount();
|
||||
for (auto mipLevel = 0; mipLevel < textureMipCount; mipLevel++)
|
||||
image->cardMemory.platform[0] += static_cast<int>(loadedTexture->GetSizeOfMipLevel(mipLevel) * loadedTexture->GetFaceCount());
|
||||
}
|
||||
else
|
||||
{
|
||||
printf("Could not find data for image \"%s\"\n", image->name);
|
||||
}
|
||||
}
|
||||
|
||||
void ObjLoader::LoadImageData(ISearchPath* searchPath, Zone* zone)
|
||||
{
|
||||
auto* assetPool = dynamic_cast<GameAssetPoolIW4*>(zone->m_pools.get());
|
||||
|
||||
if (assetPool && assetPool->m_image != nullptr)
|
||||
{
|
||||
for (auto* imageEntry : *assetPool->m_image)
|
||||
{
|
||||
auto* image = imageEntry->Asset();
|
||||
|
||||
if (image->cardMemory.platform[0] > 0)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
// Do not load linked assets
|
||||
if (image->name && image->name[0] == ',')
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
if (image->texture.loadDef && image->texture.loadDef->resourceSize > 0)
|
||||
{
|
||||
LoadImageFromLoadDef(image, zone);
|
||||
}
|
||||
else
|
||||
{
|
||||
LoadImageFromIwi(image, searchPath, zone);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void ObjLoader::LoadObjDataForZone(ISearchPath* searchPath, Zone* zone) const
|
||||
{
|
||||
LoadImageData(searchPath, zone);
|
||||
}
|
||||
|
||||
bool ObjLoader::LoadAssetForZone(AssetLoadingContext* context, asset_type_t assetType, const std::string& assetName) const
|
||||
{
|
||||
AssetLoadingManager assetLoadingManager(m_asset_loaders_by_type, *context);
|
||||
AssetLoadingManager assetLoadingManager(m_asset_loaders_by_type, context);
|
||||
return assetLoadingManager.LoadAssetFromLoader(assetType, assetName);
|
||||
}
|
||||
|
||||
void ObjLoader::FinalizeAssetsForZone(AssetLoadingContext* context) const
|
||||
void ObjLoader::FinalizeAssetsForZone(AssetLoadingContext& context) const
|
||||
{
|
||||
for (const auto& [type, loader] : m_asset_loaders_by_type)
|
||||
loader->FinalizeAssetsForZone(context);
|
||||
|
@ -1,37 +1,31 @@
|
||||
#pragma once
|
||||
|
||||
#include "AssetLoading/IAssetLoader.h"
|
||||
#include "Game/IW4/IW4.h"
|
||||
#include "IObjLoader.h"
|
||||
#include "SearchPath/ISearchPath.h"
|
||||
|
||||
#include <map>
|
||||
#include <memory>
|
||||
#include <unordered_map>
|
||||
|
||||
namespace IW4
|
||||
{
|
||||
class ObjLoader final : public IObjLoader
|
||||
{
|
||||
std::map<asset_type_t, std::unique_ptr<IAssetLoader>> m_asset_loaders_by_type;
|
||||
|
||||
static void LoadImageFromIwi(GfxImage* image, ISearchPath* searchPath, Zone* zone);
|
||||
static void LoadImageFromLoadDef(GfxImage* image, Zone* zone);
|
||||
static void LoadImageData(ISearchPath* searchPath, Zone* zone);
|
||||
|
||||
static bool IsMpZone(Zone* zone);
|
||||
static bool IsZmZone(Zone* zone);
|
||||
|
||||
public:
|
||||
ObjLoader();
|
||||
|
||||
bool SupportsZone(Zone* zone) const override;
|
||||
[[nodiscard]] bool SupportsZone(const Zone& zone) const override;
|
||||
|
||||
void LoadReferencedContainersForZone(ISearchPath* searchPath, Zone* zone) const override;
|
||||
void UnloadContainersOfZone(Zone* zone) const override;
|
||||
void LoadReferencedContainersForZone(ISearchPath& searchPath, Zone& zone) const override;
|
||||
void UnloadContainersOfZone(Zone& zone) const override;
|
||||
|
||||
void LoadObjDataForZone(ISearchPath* searchPath, Zone* zone) const override;
|
||||
bool LoadAssetForZone(AssetLoadingContext& context, asset_type_t assetType, const std::string& assetName) const override;
|
||||
void FinalizeAssetsForZone(AssetLoadingContext& context) const override;
|
||||
|
||||
bool LoadAssetForZone(AssetLoadingContext* context, asset_type_t assetType, const std::string& assetName) const override;
|
||||
void FinalizeAssetsForZone(AssetLoadingContext* context) const override;
|
||||
private:
|
||||
static bool IsMpZone(const Zone& zone);
|
||||
static bool IsZmZone(const Zone& zone);
|
||||
|
||||
std::unordered_map<asset_type_t, std::unique_ptr<IAssetLoader>> m_asset_loaders_by_type;
|
||||
};
|
||||
} // namespace IW4
|
||||
|
Reference in New Issue
Block a user