refactor: make use of IOutputPath in ObjWriting

This commit is contained in:
Jan 2025-01-11 13:06:48 +01:00
parent b584cd7423
commit 2d58054ffc
No known key found for this signature in database
GPG Key ID: 44B581F78FF5C57C
25 changed files with 143 additions and 171 deletions

View File

@ -24,7 +24,7 @@ std::unique_ptr<std::ostream> OutputPathFilesystem::Open(const std::string& file
fs::create_directories(containingDirectory, ec);
if (ec)
{
std::cerr << std::format("Failed to create folder '{}' when try to open file '{}'\n", containingDirectory, fileName);
std::cerr << std::format("Failed to create folder '{}' when try to open file '{}'\n", containingDirectory.string(), fileName);
return nullptr;
}

View File

@ -4,35 +4,15 @@
#include <format>
#include <fstream>
AssetDumpingContext::AssetDumpingContext()
: m_zone(nullptr)
AssetDumpingContext::AssetDumpingContext(const Zone& zone, const std::string& basePath, IOutputPath& outputPath, ISearchPath& objSearchPath)
: m_zone(zone),
m_base_path(basePath),
m_output_path(outputPath),
m_obj_search_path(objSearchPath)
{
}
std::unique_ptr<std::ostream> AssetDumpingContext::OpenAssetFile(const std::string& fileName) const
{
std::filesystem::path assetFilePath(m_base_path);
assetFilePath.append(fileName);
auto assetFileFolder(assetFilePath);
assetFileFolder.replace_filename("");
std::error_code ec;
std::filesystem::create_directories(assetFileFolder, ec);
if (ec)
{
std::cerr << std::format("Failed to create folder '{}'. Asset '{}' won't be dumped\n", assetFilePath.string(), fileName);
return nullptr;
}
auto file = std::make_unique<std::ofstream>(assetFilePath, std::fstream::out | std::fstream::binary);
if (!file->is_open())
{
std::cerr << std::format("Failed to open file '{}' to dump asset '{}'\n", assetFilePath.string(), fileName);
return nullptr;
}
return std::move(file);
return m_output_path.Open(fileName);
}

View File

@ -2,8 +2,8 @@
#include "IZoneAssetDumperState.h"
#include "Obj/Gdt/GdtStream.h"
#include "SearchPath/IOutputPath.h"
#include "SearchPath/ISearchPath.h"
#include "Utils/ClassUtils.h"
#include "Zone/Zone.h"
#include <memory>
@ -13,17 +13,10 @@
class AssetDumpingContext
{
std::unordered_map<std::type_index, std::unique_ptr<IZoneAssetDumperState>> m_zone_asset_dumper_states;
public:
Zone* m_zone;
std::string m_base_path;
std::unique_ptr<GdtOutputStream> m_gdt;
ISearchPath* m_obj_search_path;
AssetDumpingContext(const Zone& zone, const std::string& basePath, IOutputPath& outputPath, ISearchPath& objSearchPath);
AssetDumpingContext();
_NODISCARD std::unique_ptr<std::ostream> OpenAssetFile(const std::string& fileName) const;
[[nodiscard]] std::unique_ptr<std::ostream> OpenAssetFile(const std::string& fileName) const;
template<typename T> T* GetZoneAssetDumperState()
{
@ -40,4 +33,13 @@ public:
m_zone_asset_dumper_states.emplace(std::make_pair<std::type_index, std::unique_ptr<IZoneAssetDumperState>>(typeid(T), std::move(newState)));
return newStatePtr;
}
const Zone& m_zone;
const std::string& m_base_path;
IOutputPath& m_output_path;
ISearchPath& m_obj_search_path;
std::unique_ptr<GdtOutputStream> m_gdt;
private:
std::unordered_map<std::type_index, std::unique_ptr<IZoneAssetDumperState>> m_zone_asset_dumper_states;
};

View File

@ -1,4 +1,5 @@
#pragma once
#include "Zone/Zone.h"
class IZoneAssetDumperState
@ -13,7 +14,7 @@ public:
IZoneAssetDumperState& operator=(const IZoneAssetDumperState& other) = default;
IZoneAssetDumperState& operator=(IZoneAssetDumperState&& other) noexcept = default;
virtual void SetZone(Zone* zone)
virtual void SetZone(const Zone& zone)
{
// Do nothing by default
}

View File

@ -4,7 +4,7 @@
#include <regex>
StringFileDumper::StringFileDumper(Zone* zone, std::ostream& stream)
StringFileDumper::StringFileDumper(const Zone& zone, std::ostream& stream)
: AbstractTextDumper(stream),
m_zone(zone),
m_language_caps("ENGLISH"),
@ -31,7 +31,7 @@ void StringFileDumper::SetNotes(std::string notes)
void StringFileDumper::WriteHeader()
{
m_stream << "// Dumped from fastfile \"" << m_zone->m_name << "\".\n";
m_stream << "// Dumped from fastfile \"" << m_zone.m_name << "\".\n";
m_stream << "// In their original format the strings might have been separated in multiple files.\n";
m_stream << "VERSION \"1\"\n";
m_stream << "CONFIG \"" << m_config_file << "\"\n";

View File

@ -5,19 +5,8 @@
class StringFileDumper : AbstractTextDumper
{
Zone* m_zone;
std::string m_config_file;
std::string m_notes;
std::string m_language_caps;
bool m_wrote_header;
void WriteHeader();
void WriteReference(const std::string& reference) const;
public:
StringFileDumper(Zone* zone, std::ostream& stream);
StringFileDumper(const Zone& zone, std::ostream& stream);
void SetConfigFile(std::string configFile);
void SetNotes(std::string notes);
@ -26,4 +15,16 @@ public:
void WriteLocalizeEntry(const std::string& reference, const std::string& value);
void Finalize();
private:
void WriteHeader();
void WriteReference(const std::string& reference) const;
const Zone& m_zone;
std::string m_config_file;
std::string m_notes;
std::string m_language_caps;
bool m_wrote_header;
};

View File

@ -17,11 +17,11 @@ using namespace IW3;
namespace
{
std::unique_ptr<Texture> LoadImageFromLoadDef(const GfxImage* image)
std::unique_ptr<Texture> LoadImageFromLoadDef(const GfxImage& image)
{
Dx9TextureLoader textureLoader;
const auto& loadDef = *image->texture.loadDef;
const auto& loadDef = *image.texture.loadDef;
textureLoader.Width(loadDef.dimensions[0]).Height(loadDef.dimensions[1]).Depth(loadDef.dimensions[2]);
if (loadDef.flags & iwi6::IMG_FLAG_VOLMAP)
@ -36,22 +36,22 @@ namespace
return textureLoader.LoadTexture(loadDef.data);
}
std::unique_ptr<Texture> LoadImageFromIwi(const GfxImage* image, ISearchPath* searchPath)
std::unique_ptr<Texture> LoadImageFromIwi(const GfxImage& image, ISearchPath& searchPath)
{
const auto imageFileName = std::format("images/{}.iwi", image->name);
const auto filePathImage = searchPath->Open(imageFileName);
const auto imageFileName = std::format("images/{}.iwi", image.name);
const auto filePathImage = searchPath.Open(imageFileName);
if (!filePathImage.IsOpen())
{
std::cerr << std::format("Could not find data for image \"{}\"\n", image->name);
std::cerr << std::format("Could not find data for image \"{}\"\n", image.name);
return nullptr;
}
return iwi::LoadIwi(*filePathImage.m_stream);
}
std::unique_ptr<Texture> LoadImageData(ISearchPath* searchPath, const GfxImage* image)
std::unique_ptr<Texture> LoadImageData(ISearchPath& searchPath, const GfxImage& image)
{
if (image->texture.loadDef && image->texture.loadDef->resourceSize > 0)
if (image.texture.loadDef && image.texture.loadDef->resourceSize > 0)
return LoadImageFromLoadDef(image);
return LoadImageFromIwi(image, searchPath);
@ -91,7 +91,7 @@ std::string AssetDumperGfxImage::GetAssetFileName(const XAssetInfo<GfxImage>& as
void AssetDumperGfxImage::DumpAsset(AssetDumpingContext& context, XAssetInfo<GfxImage>* asset)
{
const auto* image = asset->Asset();
const auto texture = LoadImageData(context.m_obj_search_path, image);
const auto texture = LoadImageData(context.m_obj_search_path, *image);
if (!texture)
return;

View File

@ -3,7 +3,8 @@
#include "Dumping/Localize/StringFileDumper.h"
#include "Localize/LocalizeCommon.h"
#include <sstream>
#include <format>
#include <iostream>
using namespace IW3;
@ -12,11 +13,8 @@ void AssetDumperLocalizeEntry::DumpPool(AssetDumpingContext& context, AssetPool<
if (pool->m_asset_lookup.empty())
return;
const auto language = LocalizeCommon::GetNameOfLanguage(context.m_zone->m_language);
std::ostringstream ss;
ss << language << "/localizedstrings/" << context.m_zone->m_name << ".str";
const auto assetFile = context.OpenAssetFile(ss.str());
const auto language = LocalizeCommon::GetNameOfLanguage(context.m_zone.m_language);
const auto assetFile = context.OpenAssetFile(std::format("{}/localizedstrings/{}.str", language, context.m_zone.m_name));
if (assetFile)
{
@ -38,6 +36,6 @@ void AssetDumperLocalizeEntry::DumpPool(AssetDumpingContext& context, AssetPool<
}
else
{
printf("Could not create string file for dumping localized strings of zone '%s'\n", context.m_zone->m_name.c_str());
std::cerr << std::format("Could not create string file for dumping localized strings of zone '{}'\n", context.m_zone.m_name);
}
}

View File

@ -107,8 +107,8 @@ namespace
for (auto boneNum = 0u; boneNum < model->numBones; boneNum++)
{
XModelBone bone;
if (model->boneNames[boneNum] < context.m_zone->m_script_strings.Count())
bone.name = context.m_zone->m_script_strings[model->boneNames[boneNum]];
if (model->boneNames[boneNum] < context.m_zone.m_script_strings.Count())
bone.name = context.m_zone.m_script_strings[model->boneNames[boneNum]];
else
bone.name = "INVALID_BONE_NAME";
@ -426,7 +426,7 @@ namespace
if (!mtlFile)
return;
const auto writer = obj::CreateMtlWriter(*mtlFile, context.m_zone->m_game->GetShortName(), context.m_zone->m_name);
const auto writer = obj::CreateMtlWriter(*mtlFile, context.m_zone.m_game->GetShortName(), context.m_zone.m_name);
DistinctMapper<Material*> materialMapper(model->numsurfs);
writer->Write(common);
@ -440,8 +440,7 @@ namespace
if (!assetFile)
return;
const auto writer =
obj::CreateObjWriter(*assetFile, std::format("{}.mtl", model->name), context.m_zone->m_game->GetShortName(), context.m_zone->m_name);
const auto writer = obj::CreateObjWriter(*assetFile, std::format("{}.mtl", model->name), context.m_zone.m_game->GetShortName(), context.m_zone.m_name);
DistinctMapper<Material*> materialMapper(model->numsurfs);
writer->Write(common);
@ -455,7 +454,7 @@ namespace
if (!assetFile)
return;
const auto writer = xmodel_export::CreateWriterForVersion6(*assetFile, context.m_zone->m_game->GetShortName(), context.m_zone->m_name);
const auto writer = xmodel_export::CreateWriterForVersion6(*assetFile, context.m_zone.m_game->GetShortName(), context.m_zone.m_name);
writer->Write(common);
}
@ -470,7 +469,7 @@ namespace
return;
const auto output = std::make_unique<T>(*assetFile);
const auto writer = gltf::Writer::CreateWriter(output.get(), context.m_zone->m_game->GetShortName(), context.m_zone->m_name);
const auto writer = gltf::Writer::CreateWriter(output.get(), context.m_zone.m_game->GetShortName(), context.m_zone.m_name);
writer->Write(common);
}

View File

@ -23,7 +23,7 @@ bool ObjWriter::DumpZone(AssetDumpingContext& context) const
dumper.DumpPool(context, assetPools->poolName.get()); \
}
const auto* assetPools = dynamic_cast<GameAssetPoolIW3*>(context.m_zone->m_pools.get());
const auto* assetPools = dynamic_cast<GameAssetPoolIW3*>(context.m_zone.m_pools.get());
// DUMP_ASSET_POOL(AssetDumperPhysPreset, m_phys_preset, ASSET_TYPE_PHYSPRESET)
// DUMP_ASSET_POOL(AssetDumperXAnimParts, m_xanim_parts, ASSET_TYPE_XANIMPARTS)

View File

@ -14,12 +14,12 @@ using namespace IW4;
namespace
{
std::unique_ptr<Texture> LoadImageFromLoadDef(const GfxImage* image)
std::unique_ptr<Texture> LoadImageFromLoadDef(const GfxImage& image)
{
Dx9TextureLoader textureLoader;
const auto& loadDef = *image->texture.loadDef;
textureLoader.Width(image->width).Height(image->height).Depth(image->depth);
const auto& loadDef = *image.texture.loadDef;
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);
@ -33,22 +33,22 @@ namespace
return textureLoader.LoadTexture(loadDef.data);
}
std::unique_ptr<Texture> LoadImageFromIwi(const GfxImage* image, ISearchPath* searchPath)
std::unique_ptr<Texture> LoadImageFromIwi(const GfxImage& image, ISearchPath& searchPath)
{
const auto imageFileName = std::format("images/{}.iwi", image->name);
const auto filePathImage = searchPath->Open(imageFileName);
const auto imageFileName = std::format("images/{}.iwi", image.name);
const auto filePathImage = searchPath.Open(imageFileName);
if (!filePathImage.IsOpen())
{
std::cerr << std::format("Could not find data for image \"{}\"\n", image->name);
std::cerr << std::format("Could not find data for image \"{}\"\n", image.name);
return nullptr;
}
return iwi::LoadIwi(*filePathImage.m_stream);
}
std::unique_ptr<Texture> LoadImageData(ISearchPath* searchPath, const GfxImage* image)
std::unique_ptr<Texture> LoadImageData(ISearchPath& searchPath, const GfxImage& image)
{
if (image->texture.loadDef && image->texture.loadDef->resourceSize > 0)
if (image.texture.loadDef && image.texture.loadDef->resourceSize > 0)
return LoadImageFromLoadDef(image);
return LoadImageFromIwi(image, searchPath);
@ -88,7 +88,7 @@ std::string AssetDumperGfxImage::GetAssetFileName(const XAssetInfo<GfxImage>& as
void AssetDumperGfxImage::DumpAsset(AssetDumpingContext& context, XAssetInfo<GfxImage>* asset)
{
const auto* image = asset->Asset();
const auto texture = LoadImageData(context.m_obj_search_path, image);
const auto texture = LoadImageData(context.m_obj_search_path, *image);
if (!texture)
return;

View File

@ -3,6 +3,7 @@
#include "Dumping/Localize/StringFileDumper.h"
#include "Localize/LocalizeCommon.h"
#include <format>
#include <sstream>
using namespace IW4;
@ -12,11 +13,8 @@ void AssetDumperLocalizeEntry::DumpPool(AssetDumpingContext& context, AssetPool<
if (pool->m_asset_lookup.empty())
return;
const auto language = LocalizeCommon::GetNameOfLanguage(context.m_zone->m_language);
std::ostringstream ss;
ss << language << "/localizedstrings/" << context.m_zone->m_name << ".str";
const auto assetFile = context.OpenAssetFile(ss.str());
const auto language = LocalizeCommon::GetNameOfLanguage(context.m_zone.m_language);
const auto assetFile = context.OpenAssetFile(std::format("{}/localizedstrings/{}.str", language, context.m_zone.m_name));
if (assetFile)
{
@ -38,6 +36,6 @@ void AssetDumperLocalizeEntry::DumpPool(AssetDumpingContext& context, AssetPool<
}
else
{
printf("Could not create string file for dumping localized strings of zone '%s'\n", context.m_zone->m_name.c_str());
std::cerr << std::format("Could not create string file for dumping localized strings of zone '{}'\n", context.m_zone.m_name);
}
}

View File

@ -102,8 +102,8 @@ namespace
for (auto boneNum = 0u; boneNum < model->numBones; boneNum++)
{
XModelBone bone;
if (model->boneNames[boneNum] < context.m_zone->m_script_strings.Count())
bone.name = context.m_zone->m_script_strings[model->boneNames[boneNum]];
if (model->boneNames[boneNum] < context.m_zone.m_script_strings.Count())
bone.name = context.m_zone.m_script_strings[model->boneNames[boneNum]];
else
bone.name = "INVALID_BONE_NAME";
@ -408,7 +408,7 @@ namespace
if (!mtlFile)
return;
const auto writer = obj::CreateMtlWriter(*mtlFile, context.m_zone->m_game->GetShortName(), context.m_zone->m_name);
const auto writer = obj::CreateMtlWriter(*mtlFile, context.m_zone.m_game->GetShortName(), context.m_zone.m_name);
DistinctMapper<Material*> materialMapper(model->numsurfs);
writer->Write(common);
@ -427,8 +427,7 @@ namespace
if (!assetFile)
return;
const auto writer =
obj::CreateObjWriter(*assetFile, std::format("{}.mtl", model->name), context.m_zone->m_game->GetShortName(), context.m_zone->m_name);
const auto writer = obj::CreateObjWriter(*assetFile, std::format("{}.mtl", model->name), context.m_zone.m_game->GetShortName(), context.m_zone.m_name);
DistinctMapper<Material*> materialMapper(model->numsurfs);
writer->Write(common);
@ -443,7 +442,7 @@ namespace
if (!assetFile)
return;
const auto writer = xmodel_export::CreateWriterForVersion6(*assetFile, context.m_zone->m_game->GetShortName(), context.m_zone->m_name);
const auto writer = xmodel_export::CreateWriterForVersion6(*assetFile, context.m_zone.m_game->GetShortName(), context.m_zone.m_name);
writer->Write(common);
}
@ -459,7 +458,7 @@ namespace
return;
const auto output = std::make_unique<T>(*assetFile);
const auto writer = gltf::Writer::CreateWriter(output.get(), context.m_zone->m_game->GetShortName(), context.m_zone->m_name);
const auto writer = gltf::Writer::CreateWriter(output.get(), context.m_zone.m_game->GetShortName(), context.m_zone.m_name);
writer->Write(common);
}

View File

@ -36,7 +36,7 @@ bool ObjWriter::DumpZone(AssetDumpingContext& context) const
dumper.DumpPool(context, assetPools->poolName.get()); \
}
const auto* assetPools = dynamic_cast<GameAssetPoolIW4*>(context.m_zone->m_pools.get());
const auto* assetPools = dynamic_cast<GameAssetPoolIW4*>(context.m_zone.m_pools.get());
DUMP_ASSET_POOL(AssetDumperPhysPreset, m_phys_preset, ASSET_TYPE_PHYSPRESET)
DUMP_ASSET_POOL(AssetDumperPhysCollmap, m_phys_collmap, ASSET_TYPE_PHYSCOLLMAP)

View File

@ -14,13 +14,13 @@ using namespace IW5;
namespace
{
std::unique_ptr<Texture> LoadImageFromLoadDef(const GfxImage* image)
std::unique_ptr<Texture> LoadImageFromLoadDef(const GfxImage& image)
{
Dx9TextureLoader textureLoader;
const auto& loadDef = *image->texture.loadDef;
const auto& loadDef = *image.texture.loadDef;
textureLoader.Width(image->width).Height(image->height).Depth(image->depth);
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);
@ -34,22 +34,22 @@ namespace
return textureLoader.LoadTexture(loadDef.data);
}
std::unique_ptr<Texture> LoadImageFromIwi(const GfxImage* image, ISearchPath* searchPath)
std::unique_ptr<Texture> LoadImageFromIwi(const GfxImage& image, ISearchPath& searchPath)
{
const auto imageFileName = std::format("images/{}.iwi", image->name);
const auto filePathImage = searchPath->Open(imageFileName);
const auto imageFileName = std::format("images/{}.iwi", image.name);
const auto filePathImage = searchPath.Open(imageFileName);
if (!filePathImage.IsOpen())
{
std::cerr << std::format("Could not find data for image \"{}\"\n", image->name);
std::cerr << std::format("Could not find data for image \"{}\"\n", image.name);
return nullptr;
}
return iwi::LoadIwi(*filePathImage.m_stream);
}
std::unique_ptr<Texture> LoadImageData(ISearchPath* searchPath, const GfxImage* image)
std::unique_ptr<Texture> LoadImageData(ISearchPath& searchPath, const GfxImage& image)
{
if (image->texture.loadDef && image->texture.loadDef->resourceSize > 0)
if (image.texture.loadDef && image.texture.loadDef->resourceSize > 0)
return LoadImageFromLoadDef(image);
return LoadImageFromIwi(image, searchPath);
@ -89,7 +89,7 @@ std::string AssetDumperGfxImage::GetAssetFileName(const XAssetInfo<GfxImage>& as
void AssetDumperGfxImage::DumpAsset(AssetDumpingContext& context, XAssetInfo<GfxImage>* asset)
{
const auto* image = asset->Asset();
const auto texture = LoadImageData(context.m_obj_search_path, image);
const auto texture = LoadImageData(context.m_obj_search_path, *image);
if (!texture)
return;

View File

@ -3,7 +3,8 @@
#include "Dumping/Localize/StringFileDumper.h"
#include "Localize/LocalizeCommon.h"
#include <sstream>
#include <format>
#include <iostream>
using namespace IW5;
@ -12,11 +13,8 @@ void AssetDumperLocalizeEntry::DumpPool(AssetDumpingContext& context, AssetPool<
if (pool->m_asset_lookup.empty())
return;
const auto language = LocalizeCommon::GetNameOfLanguage(context.m_zone->m_language);
std::ostringstream ss;
ss << language << "/localizedstrings/" << context.m_zone->m_name << ".str";
const auto assetFile = context.OpenAssetFile(ss.str());
const auto language = LocalizeCommon::GetNameOfLanguage(context.m_zone.m_language);
const auto assetFile = context.OpenAssetFile(std::format("{}/localizedstrings/{}.str", language, context.m_zone.m_name));
if (assetFile)
{
@ -38,6 +36,6 @@ void AssetDumperLocalizeEntry::DumpPool(AssetDumpingContext& context, AssetPool<
}
else
{
printf("Could not create string file for dumping localized strings of zone '%s'\n", context.m_zone->m_name.c_str());
std::cerr << std::format("Could not create string file for dumping localized strings of zone '{}'\n", context.m_zone.m_name);
}
}

View File

@ -28,7 +28,7 @@ bool ObjWriter::DumpZone(AssetDumpingContext& context) const
dumper.DumpPool(context, assetPools->poolName.get()); \
}
const auto* assetPools = dynamic_cast<GameAssetPoolIW5*>(context.m_zone->m_pools.get());
const auto* assetPools = dynamic_cast<GameAssetPoolIW5*>(context.m_zone.m_pools.get());
// DUMP_ASSET_POOL(AssetDumperPhysPreset, m_phys_preset, ASSET_TYPE_PHYSPRESET)
// DUMP_ASSET_POOL(AssetDumperPhysCollmap, m_phys_collmap, ASSET_TYPE_PHYSCOLLMAP)
// DUMP_ASSET_POOL(AssetDumperXAnimParts, m_xanim_parts, ASSET_TYPE_XANIMPARTS)

View File

@ -14,12 +14,12 @@ using namespace T5;
namespace
{
std::unique_ptr<Texture> LoadImageFromLoadDef(const GfxImage* image)
std::unique_ptr<Texture> LoadImageFromLoadDef(const GfxImage& image)
{
Dx9TextureLoader textureLoader;
const auto& loadDef = *image->texture.loadDef;
textureLoader.Width(image->width).Height(image->height).Depth(image->depth);
const auto& loadDef = *image.texture.loadDef;
textureLoader.Width(image.width).Height(image.height).Depth(image.depth);
if (loadDef.flags & iwi13::IMG_FLAG_VOLMAP)
textureLoader.Type(TextureType::T_3D);
@ -33,22 +33,22 @@ namespace
return textureLoader.LoadTexture(loadDef.data);
}
std::unique_ptr<Texture> LoadImageFromIwi(const GfxImage* image, ISearchPath* searchPath)
std::unique_ptr<Texture> LoadImageFromIwi(const GfxImage& image, ISearchPath& searchPath)
{
const auto imageFileName = std::format("images/{}.iwi", image->name);
const auto filePathImage = searchPath->Open(imageFileName);
const auto imageFileName = std::format("images/{}.iwi", image.name);
const auto filePathImage = searchPath.Open(imageFileName);
if (!filePathImage.IsOpen())
{
std::cerr << std::format("Could not find data for image \"{}\"\n", image->name);
std::cerr << std::format("Could not find data for image \"{}\"\n", image.name);
return nullptr;
}
return iwi::LoadIwi(*filePathImage.m_stream);
}
std::unique_ptr<Texture> LoadImageData(ISearchPath* searchPath, const GfxImage* image)
std::unique_ptr<Texture> LoadImageData(ISearchPath& searchPath, const GfxImage& image)
{
if (image->texture.loadDef && image->texture.loadDef->resourceSize > 0)
if (image.texture.loadDef && image.texture.loadDef->resourceSize > 0)
return LoadImageFromLoadDef(image);
return LoadImageFromIwi(image, searchPath);
@ -88,7 +88,7 @@ std::string AssetDumperGfxImage::GetAssetFileName(const XAssetInfo<GfxImage>& as
void AssetDumperGfxImage::DumpAsset(AssetDumpingContext& context, XAssetInfo<GfxImage>* asset)
{
const auto* image = asset->Asset();
const auto texture = LoadImageData(context.m_obj_search_path, image);
const auto texture = LoadImageData(context.m_obj_search_path, *image);
if (!texture)
return;

View File

@ -3,7 +3,8 @@
#include "Dumping/Localize/StringFileDumper.h"
#include "Localize/LocalizeCommon.h"
#include <sstream>
#include <format>
#include <iostream>
using namespace T5;
@ -12,11 +13,8 @@ void AssetDumperLocalizeEntry::DumpPool(AssetDumpingContext& context, AssetPool<
if (pool->m_asset_lookup.empty())
return;
const auto language = LocalizeCommon::GetNameOfLanguage(context.m_zone->m_language);
std::ostringstream ss;
ss << language << "/localizedstrings/" << context.m_zone->m_name << ".str";
const auto assetFile = context.OpenAssetFile(ss.str());
const auto language = LocalizeCommon::GetNameOfLanguage(context.m_zone.m_language);
const auto assetFile = context.OpenAssetFile(std::format("{}/localizedstrings/{}.str", language, context.m_zone.m_name));
if (assetFile)
{
@ -38,6 +36,6 @@ void AssetDumperLocalizeEntry::DumpPool(AssetDumpingContext& context, AssetPool<
}
else
{
printf("Could not create string file for dumping localized strings of zone '%s'\n", context.m_zone->m_name.c_str());
std::cerr << std::format("Could not create string file for dumping localized strings of zone '{}'\n", context.m_zone.m_name);
}
}

View File

@ -23,7 +23,7 @@ bool ObjWriter::DumpZone(AssetDumpingContext& context) const
dumper.DumpPool(context, assetPools->poolName.get()); \
}
const auto* assetPools = dynamic_cast<GameAssetPoolT5*>(context.m_zone->m_pools.get());
const auto* assetPools = dynamic_cast<GameAssetPoolT5*>(context.m_zone.m_pools.get());
// DUMP_ASSET_POOL(AssetDumperPhysPreset, m_phys_preset, ASSET_TYPE_PHYSPRESET)
// DUMP_ASSET_POOL(AssetDumperPhysConstraints, m_phys_constraints, ASSET_TYPE_PHYSCONSTRAINTS)

View File

@ -15,12 +15,12 @@ using namespace T6;
namespace
{
std::unique_ptr<Texture> LoadImageFromLoadDef(const GfxImage* image)
std::unique_ptr<Texture> LoadImageFromLoadDef(const GfxImage& image)
{
Dx12TextureLoader textureLoader;
const auto& loadDef = *image->texture.loadDef;
textureLoader.Width(image->width).Height(image->height).Depth(image->depth);
const auto& loadDef = *image.texture.loadDef;
textureLoader.Width(image.width).Height(image.height).Depth(image.depth);
if (loadDef.flags & iwi27::IMG_FLAG_VOLMAP)
textureLoader.Type(TextureType::T_3D);
@ -34,13 +34,13 @@ namespace
return textureLoader.LoadTexture(loadDef.data);
}
std::unique_ptr<Texture> LoadImageFromIwi(const GfxImage* image, ISearchPath* searchPath)
std::unique_ptr<Texture> LoadImageFromIwi(const GfxImage& image, ISearchPath& searchPath)
{
if (image->streamedPartCount > 0)
if (image.streamedPartCount > 0)
{
for (auto* ipak : IIPak::Repository)
{
auto ipakStream = ipak->GetEntryStream(image->hash, image->streamedParts[0].hash);
auto ipakStream = ipak->GetEntryStream(image.hash, image.streamedParts[0].hash);
if (ipakStream)
{
@ -53,20 +53,20 @@ namespace
}
}
const auto imageFileName = std::format("images/{}.iwi", image->name);
const auto filePathImage = searchPath->Open(imageFileName);
const auto imageFileName = std::format("images/{}.iwi", image.name);
const auto filePathImage = searchPath.Open(imageFileName);
if (!filePathImage.IsOpen())
{
std::cerr << std::format("Could not find data for image \"{}\"\n", image->name);
std::cerr << std::format("Could not find data for image \"{}\"\n", image.name);
return nullptr;
}
return iwi::LoadIwi(*filePathImage.m_stream);
}
std::unique_ptr<Texture> LoadImageData(ISearchPath* searchPath, const GfxImage* image)
std::unique_ptr<Texture> LoadImageData(ISearchPath& searchPath, const GfxImage& image)
{
if (image->texture.loadDef && image->texture.loadDef->resourceSize > 0)
if (image.texture.loadDef && image.texture.loadDef->resourceSize > 0)
return LoadImageFromLoadDef(image);
return LoadImageFromIwi(image, searchPath);
@ -106,7 +106,7 @@ std::string AssetDumperGfxImage::GetAssetFileName(const XAssetInfo<GfxImage>& as
void AssetDumperGfxImage::DumpAsset(AssetDumpingContext& context, XAssetInfo<GfxImage>* asset)
{
const auto* image = asset->Asset();
const auto texture = LoadImageData(context.m_obj_search_path, image);
const auto texture = LoadImageData(context.m_obj_search_path, *image);
if (!texture)
return;

View File

@ -3,7 +3,8 @@
#include "Dumping/Localize/StringFileDumper.h"
#include "Localize/LocalizeCommon.h"
#include <sstream>
#include <format>
#include <iostream>
using namespace T6;
@ -12,11 +13,8 @@ void AssetDumperLocalizeEntry::DumpPool(AssetDumpingContext& context, AssetPool<
if (pool->m_asset_lookup.empty())
return;
const auto language = LocalizeCommon::GetNameOfLanguage(context.m_zone->m_language);
std::ostringstream ss;
ss << language << "/localizedstrings/" << context.m_zone->m_name << ".str";
const auto assetFile = context.OpenAssetFile(ss.str());
const auto language = LocalizeCommon::GetNameOfLanguage(context.m_zone.m_language);
const auto assetFile = context.OpenAssetFile(std::format("{}/localizedstrings/{}.str", language, context.m_zone.m_name));
if (assetFile)
{
@ -38,6 +36,6 @@ void AssetDumperLocalizeEntry::DumpPool(AssetDumpingContext& context, AssetPool<
}
else
{
printf("Could not create string file for dumping localized strings of zone '%s'\n", context.m_zone->m_name.c_str());
std::cerr << std::format("Could not create string file for dumping localized strings of zone '{}'\n", context.m_zone.m_name);
}
}

View File

@ -37,7 +37,7 @@ bool ObjWriter::DumpZone(AssetDumpingContext& context) const
dumper.DumpPool(context, assetPools->poolName.get()); \
}
const auto* assetPools = dynamic_cast<GameAssetPoolT6*>(context.m_zone->m_pools.get());
const auto* assetPools = dynamic_cast<GameAssetPoolT6*>(context.m_zone.m_pools.get());
DUMP_ASSET_POOL(AssetDumperPhysPreset, m_phys_preset, ASSET_TYPE_PHYSPRESET)
DUMP_ASSET_POOL(AssetDumperPhysConstraints, m_phys_constraints, ASSET_TYPE_PHYSCONSTRAINTS)

View File

@ -204,8 +204,8 @@ namespace GAME
for (auto boneNum = 0u; boneNum < model->numBones; boneNum++)
{
XModelBone bone;
if (model->boneNames[boneNum] < context.m_zone->m_script_strings.Count())
bone.name = context.m_zone->m_script_strings[model->boneNames[boneNum]];
if (model->boneNames[boneNum] < context.m_zone.m_script_strings.Count())
bone.name = context.m_zone.m_script_strings[model->boneNames[boneNum]];
else
bone.name = "INVALID_BONE_NAME";
@ -543,7 +543,7 @@ namespace GAME
if (!mtlFile)
return;
const auto writer = obj::CreateMtlWriter(*mtlFile, context.m_zone->m_game->GetShortName(), context.m_zone->m_name);
const auto writer = obj::CreateMtlWriter(*mtlFile, context.m_zone.m_game->GetShortName(), context.m_zone.m_name);
DistinctMapper<Material*> materialMapper(model->numsurfs);
writer->Write(common);
@ -558,7 +558,7 @@ namespace GAME
return;
const auto writer =
obj::CreateObjWriter(*assetFile, std::format("{}.mtl", model->name), context.m_zone->m_game->GetShortName(), context.m_zone->m_name);
obj::CreateObjWriter(*assetFile, std::format("{}.mtl", model->name), context.m_zone.m_game->GetShortName(), context.m_zone.m_name);
DistinctMapper<Material*> materialMapper(model->numsurfs);
writer->Write(common);
@ -572,7 +572,7 @@ namespace GAME
if (!assetFile)
return;
const auto writer = xmodel_export::CreateWriterForVersion6(*assetFile, context.m_zone->m_game->GetShortName(), context.m_zone->m_name);
const auto writer = xmodel_export::CreateWriterForVersion6(*assetFile, context.m_zone.m_game->GetShortName(), context.m_zone.m_name);
writer->Write(common);
}
@ -587,7 +587,7 @@ namespace GAME
return;
const auto output = std::make_unique<T>(*assetFile);
const auto writer = gltf::Writer::CreateWriter(output.get(), context.m_zone->m_game->GetShortName(), context.m_zone->m_name);
const auto writer = gltf::Writer::CreateWriter(output.get(), context.m_zone.m_game->GetShortName(), context.m_zone.m_name);
writer->Write(common);
}

View File

@ -6,6 +6,7 @@
#include "IObjWriter.h"
#include "ObjWriting.h"
#include "SearchPath/IWD.h"
#include "SearchPath/OutputPathFilesystem.h"
#include "SearchPath/SearchPathFilesystem.h"
#include "SearchPath/SearchPaths.h"
#include "UnlinkerArgs.h"
@ -100,14 +101,14 @@ private:
void UpdateAssetIncludesAndExcludes(const AssetDumpingContext& context) const
{
const auto assetTypeCount = context.m_zone->m_pools->GetAssetTypeCount();
const auto assetTypeCount = context.m_zone.m_pools->GetAssetTypeCount();
ObjWriting::Configuration.AssetTypesToHandleBitfield = std::vector<bool>(assetTypeCount);
std::vector<bool> handledSpecifiedAssets(m_args.m_specified_asset_types.size());
for (auto i = 0; i < assetTypeCount; i++)
{
const auto assetTypeName = std::string(*context.m_zone->m_pools->GetAssetTypeName(i));
const auto assetTypeName = std::string(*context.m_zone.m_pools->GetAssetTypeName(i));
const auto foundSpecifiedEntry = m_args.m_specified_asset_type_map.find(assetTypeName);
if (foundSpecifiedEntry != m_args.m_specified_asset_type_map.end())
@ -137,7 +138,7 @@ private:
auto first = true;
for (auto i = 0; i < assetTypeCount; i++)
{
const auto assetTypeName = std::string(*context.m_zone->m_pools->GetAssetTypeName(i));
const auto assetTypeName = std::string(*context.m_zone.m_pools->GetAssetTypeName(i));
if (first)
first = false;
@ -164,7 +165,8 @@ private:
}
else if (m_args.m_task == UnlinkerArgs::ProcessingTask::DUMP)
{
const auto outputFolderPath = m_args.GetOutputFolderPathForZone(zone);
const auto outputFolderPathStr = m_args.GetOutputFolderPathForZone(zone);
const fs::path outputFolderPath(outputFolderPathStr);
fs::create_directories(outputFolderPath);
fs::path zoneDefinitionFileFolder(outputFolderPath);
@ -174,12 +176,10 @@ private:
if (!WriteZoneDefinitionFile(zone, zoneDefinitionFileFolder))
return false;
std::ofstream gdtStream;
AssetDumpingContext context;
context.m_zone = &zone;
context.m_base_path = outputFolderPath;
context.m_obj_search_path = &searchPath;
OutputPathFilesystem outputFolderOutputPath(outputFolderPath);
AssetDumpingContext context(zone, outputFolderPathStr, outputFolderOutputPath, searchPath);
std::ofstream gdtStream;
if (m_args.m_use_gdt)
{
if (!OpenGdtFile(zone, outputFolderPath, gdtStream))