mirror of
https://github.com/Laupetin/OpenAssetTools.git
synced 2025-06-11 07:18:11 -05:00
feat: add post processors compiling iwds and ipaks
This commit is contained in:
@ -1,5 +1,37 @@
|
||||
#include "ObjCompilerIW3.h"
|
||||
|
||||
using namespace IW3;
|
||||
#include "Game/IW3/IW3.h"
|
||||
#include "Image/ImageIwdPostProcessor.h"
|
||||
|
||||
void ObjCompiler::ConfigureCreatorCollection(AssetCreatorCollection& collection, Zone& zone, const ZoneDefinition& zoneDefinition) const {}
|
||||
#include <memory>
|
||||
|
||||
using namespace IW3;
|
||||
namespace fs = std::filesystem;
|
||||
|
||||
namespace
|
||||
{
|
||||
void ConfigureCompilers(AssetCreatorCollection& collection, Zone& zone, ISearchPath& searchPath)
|
||||
{
|
||||
auto& memory = *zone.GetMemory();
|
||||
|
||||
// No compilers yet
|
||||
}
|
||||
|
||||
void ConfigurePostProcessors(AssetCreatorCollection& collection, Zone& zone, ISearchPath& searchPath, const fs::path& outDir)
|
||||
{
|
||||
auto& memory = *zone.GetMemory();
|
||||
|
||||
collection.AddAssetPostProcessor(std::make_unique<ImageIwdPostProcessor<AssetImage>>(searchPath, outDir));
|
||||
}
|
||||
} // namespace
|
||||
|
||||
void ObjCompiler::ConfigureCreatorCollection(AssetCreatorCollection& collection,
|
||||
Zone& zone,
|
||||
const ZoneDefinition& zoneDefinition,
|
||||
ISearchPath& searchPath,
|
||||
IGdtQueryable& gdt,
|
||||
const fs::path& outDir,
|
||||
const fs::path& cacheDir) const
|
||||
{
|
||||
ConfigurePostProcessors(collection, zone, searchPath, outDir);
|
||||
}
|
||||
|
@ -7,6 +7,12 @@ namespace IW3
|
||||
class ObjCompiler final : public IObjCompiler
|
||||
{
|
||||
public:
|
||||
void ConfigureCreatorCollection(AssetCreatorCollection& collection, Zone& zone, const ZoneDefinition& zoneDefinition) const override;
|
||||
void ConfigureCreatorCollection(AssetCreatorCollection& collection,
|
||||
Zone& zone,
|
||||
const ZoneDefinition& zoneDefinition,
|
||||
ISearchPath& searchPath,
|
||||
IGdtQueryable& gdt,
|
||||
const std::filesystem::path& outDir,
|
||||
const std::filesystem::path& cacheDir) const override;
|
||||
};
|
||||
} // namespace IW3
|
||||
|
@ -1,5 +1,37 @@
|
||||
#include "ObjCompilerIW4.h"
|
||||
|
||||
using namespace IW4;
|
||||
#include "Game/IW4/IW4.h"
|
||||
#include "Image/ImageIwdPostProcessor.h"
|
||||
|
||||
void ObjCompiler::ConfigureCreatorCollection(AssetCreatorCollection& collection, Zone& zone, const ZoneDefinition& zoneDefinition) const {}
|
||||
#include <memory>
|
||||
|
||||
using namespace IW4;
|
||||
namespace fs = std::filesystem;
|
||||
|
||||
namespace
|
||||
{
|
||||
void ConfigureCompilers(AssetCreatorCollection& collection, Zone& zone, ISearchPath& searchPath)
|
||||
{
|
||||
auto& memory = *zone.GetMemory();
|
||||
|
||||
// No compilers yet
|
||||
}
|
||||
|
||||
void ConfigurePostProcessors(AssetCreatorCollection& collection, Zone& zone, ISearchPath& searchPath, const fs::path& outDir)
|
||||
{
|
||||
auto& memory = *zone.GetMemory();
|
||||
|
||||
collection.AddAssetPostProcessor(std::make_unique<ImageIwdPostProcessor<AssetImage>>(searchPath, outDir));
|
||||
}
|
||||
} // namespace
|
||||
|
||||
void ObjCompiler::ConfigureCreatorCollection(AssetCreatorCollection& collection,
|
||||
Zone& zone,
|
||||
const ZoneDefinition& zoneDefinition,
|
||||
ISearchPath& searchPath,
|
||||
IGdtQueryable& gdt,
|
||||
const fs::path& outDir,
|
||||
const fs::path& cacheDir) const
|
||||
{
|
||||
ConfigurePostProcessors(collection, zone, searchPath, outDir);
|
||||
}
|
||||
|
@ -7,6 +7,12 @@ namespace IW4
|
||||
class ObjCompiler final : public IObjCompiler
|
||||
{
|
||||
public:
|
||||
void ConfigureCreatorCollection(AssetCreatorCollection& collection, Zone& zone, const ZoneDefinition& zoneDefinition) const override;
|
||||
void ConfigureCreatorCollection(AssetCreatorCollection& collection,
|
||||
Zone& zone,
|
||||
const ZoneDefinition& zoneDefinition,
|
||||
ISearchPath& searchPath,
|
||||
IGdtQueryable& gdt,
|
||||
const std::filesystem::path& outDir,
|
||||
const std::filesystem::path& cacheDir) const override;
|
||||
};
|
||||
} // namespace IW4
|
||||
|
@ -1,5 +1,37 @@
|
||||
#include "ObjCompilerIW5.h"
|
||||
|
||||
using namespace IW5;
|
||||
#include "Game/IW5/IW5.h"
|
||||
#include "Image/ImageIwdPostProcessor.h"
|
||||
|
||||
void ObjCompiler::ConfigureCreatorCollection(AssetCreatorCollection& collection, Zone& zone, const ZoneDefinition& zoneDefinition) const {}
|
||||
#include <memory>
|
||||
|
||||
using namespace IW5;
|
||||
namespace fs = std::filesystem;
|
||||
|
||||
namespace
|
||||
{
|
||||
void ConfigureCompilers(AssetCreatorCollection& collection, Zone& zone, ISearchPath& searchPath)
|
||||
{
|
||||
auto& memory = *zone.GetMemory();
|
||||
|
||||
// No compilers yet
|
||||
}
|
||||
|
||||
void ConfigurePostProcessors(AssetCreatorCollection& collection, Zone& zone, ISearchPath& searchPath, const fs::path& outDir)
|
||||
{
|
||||
auto& memory = *zone.GetMemory();
|
||||
|
||||
collection.AddAssetPostProcessor(std::make_unique<ImageIwdPostProcessor<AssetImage>>(searchPath, outDir));
|
||||
}
|
||||
} // namespace
|
||||
|
||||
void ObjCompiler::ConfigureCreatorCollection(AssetCreatorCollection& collection,
|
||||
Zone& zone,
|
||||
const ZoneDefinition& zoneDefinition,
|
||||
ISearchPath& searchPath,
|
||||
IGdtQueryable& gdt,
|
||||
const fs::path& outDir,
|
||||
const fs::path& cacheDir) const
|
||||
{
|
||||
ConfigurePostProcessors(collection, zone, searchPath, outDir);
|
||||
}
|
||||
|
@ -7,6 +7,12 @@ namespace IW5
|
||||
class ObjCompiler final : public IObjCompiler
|
||||
{
|
||||
public:
|
||||
void ConfigureCreatorCollection(AssetCreatorCollection& collection, Zone& zone, const ZoneDefinition& zoneDefinition) const override;
|
||||
void ConfigureCreatorCollection(AssetCreatorCollection& collection,
|
||||
Zone& zone,
|
||||
const ZoneDefinition& zoneDefinition,
|
||||
ISearchPath& searchPath,
|
||||
IGdtQueryable& gdt,
|
||||
const std::filesystem::path& outDir,
|
||||
const std::filesystem::path& cacheDir) const override;
|
||||
};
|
||||
} // namespace IW5
|
||||
|
@ -1,5 +1,37 @@
|
||||
#include "ObjCompilerT5.h"
|
||||
|
||||
using namespace T5;
|
||||
#include "Game/T5/T5.h"
|
||||
#include "Image/ImageIwdPostProcessor.h"
|
||||
|
||||
void ObjCompiler::ConfigureCreatorCollection(AssetCreatorCollection& collection, Zone& zone, const ZoneDefinition& zoneDefinition) const {}
|
||||
#include <memory>
|
||||
|
||||
using namespace T5;
|
||||
namespace fs = std::filesystem;
|
||||
|
||||
namespace
|
||||
{
|
||||
void ConfigureCompilers(AssetCreatorCollection& collection, Zone& zone, ISearchPath& searchPath)
|
||||
{
|
||||
auto& memory = *zone.GetMemory();
|
||||
|
||||
// No compilers yet
|
||||
}
|
||||
|
||||
void ConfigurePostProcessors(AssetCreatorCollection& collection, Zone& zone, ISearchPath& searchPath, const fs::path& outDir)
|
||||
{
|
||||
auto& memory = *zone.GetMemory();
|
||||
|
||||
collection.AddAssetPostProcessor(std::make_unique<ImageIwdPostProcessor<AssetImage>>(searchPath, outDir));
|
||||
}
|
||||
} // namespace
|
||||
|
||||
void ObjCompiler::ConfigureCreatorCollection(AssetCreatorCollection& collection,
|
||||
Zone& zone,
|
||||
const ZoneDefinition& zoneDefinition,
|
||||
ISearchPath& searchPath,
|
||||
IGdtQueryable& gdt,
|
||||
const fs::path& outDir,
|
||||
const fs::path& cacheDir) const
|
||||
{
|
||||
ConfigurePostProcessors(collection, zone, searchPath, outDir);
|
||||
}
|
||||
|
@ -7,6 +7,12 @@ namespace T5
|
||||
class ObjCompiler final : public IObjCompiler
|
||||
{
|
||||
public:
|
||||
void ConfigureCreatorCollection(AssetCreatorCollection& collection, Zone& zone, const ZoneDefinition& zoneDefinition) const override;
|
||||
void ConfigureCreatorCollection(AssetCreatorCollection& collection,
|
||||
Zone& zone,
|
||||
const ZoneDefinition& zoneDefinition,
|
||||
ISearchPath& searchPath,
|
||||
IGdtQueryable& gdt,
|
||||
const std::filesystem::path& outDir,
|
||||
const std::filesystem::path& cacheDir) const override;
|
||||
};
|
||||
} // namespace T5
|
||||
|
@ -1,7 +1,37 @@
|
||||
#include "ObjCompilerT6.h"
|
||||
|
||||
#include "Game/T6/T6.h"
|
||||
#include "Image/ImageIwdPostProcessor.h"
|
||||
|
||||
#include <memory>
|
||||
|
||||
using namespace T6;
|
||||
namespace fs = std::filesystem;
|
||||
|
||||
void ObjCompiler::ConfigureCreatorCollection(AssetCreatorCollection& collection, Zone& zone, const ZoneDefinition& zoneDefinition) const {}
|
||||
namespace
|
||||
{
|
||||
void ConfigureCompilers(AssetCreatorCollection& collection, Zone& zone, ISearchPath& searchPath)
|
||||
{
|
||||
auto& memory = *zone.GetMemory();
|
||||
|
||||
// No compilers yet
|
||||
}
|
||||
|
||||
void ConfigurePostProcessors(AssetCreatorCollection& collection, Zone& zone, ISearchPath& searchPath, const fs::path& outDir)
|
||||
{
|
||||
auto& memory = *zone.GetMemory();
|
||||
|
||||
collection.AddAssetPostProcessor(std::make_unique<ImageIwdPostProcessor<AssetImage>>(searchPath, outDir));
|
||||
}
|
||||
} // namespace
|
||||
|
||||
void ObjCompiler::ConfigureCreatorCollection(AssetCreatorCollection& collection,
|
||||
Zone& zone,
|
||||
const ZoneDefinition& zoneDefinition,
|
||||
ISearchPath& searchPath,
|
||||
IGdtQueryable& gdt,
|
||||
const fs::path& outDir,
|
||||
const fs::path& cacheDir) const
|
||||
{
|
||||
ConfigurePostProcessors(collection, zone, searchPath, outDir);
|
||||
}
|
||||
|
@ -7,6 +7,12 @@ namespace T6
|
||||
class ObjCompiler final : public IObjCompiler
|
||||
{
|
||||
public:
|
||||
void ConfigureCreatorCollection(AssetCreatorCollection& collection, Zone& zone, const ZoneDefinition& zoneDefinition) const override;
|
||||
void ConfigureCreatorCollection(AssetCreatorCollection& collection,
|
||||
Zone& zone,
|
||||
const ZoneDefinition& zoneDefinition,
|
||||
ISearchPath& searchPath,
|
||||
IGdtQueryable& gdt,
|
||||
const std::filesystem::path& outDir,
|
||||
const std::filesystem::path& cacheDir) const override;
|
||||
};
|
||||
} // namespace T6
|
||||
|
@ -1,11 +1,13 @@
|
||||
#pragma once
|
||||
|
||||
#include "Asset/AssetCreatorCollection.h"
|
||||
#include "Gdt/IGdtQueryable.h"
|
||||
#include "SearchPath/ISearchPath.h"
|
||||
#include "Zone/Definition/ZoneDefinition.h"
|
||||
#include "Zone/Zone.h"
|
||||
|
||||
#include <cstdint>
|
||||
#include <filesystem>
|
||||
#include <string>
|
||||
|
||||
class IObjCompiler
|
||||
@ -18,7 +20,13 @@ public:
|
||||
IObjCompiler& operator=(const IObjCompiler& other) = default;
|
||||
IObjCompiler& operator=(IObjCompiler&& other) noexcept = default;
|
||||
|
||||
virtual void ConfigureCreatorCollection(AssetCreatorCollection& collection, Zone& zone, const ZoneDefinition& zoneDefinition) const = 0;
|
||||
virtual void ConfigureCreatorCollection(AssetCreatorCollection& collection,
|
||||
Zone& zone,
|
||||
const ZoneDefinition& zoneDefinition,
|
||||
ISearchPath& searchPath,
|
||||
IGdtQueryable& gdt,
|
||||
const std::filesystem::path& outDir,
|
||||
const std::filesystem::path& cacheDir) const = 0;
|
||||
|
||||
static const IObjCompiler* GetObjCompilerForGame(GameId game);
|
||||
};
|
||||
|
17
src/ObjCompiling/Image/IPak/IPakCreator.cpp
Normal file
17
src/ObjCompiling/Image/IPak/IPakCreator.cpp
Normal file
@ -0,0 +1,17 @@
|
||||
#include "IPakCreator.h"
|
||||
|
||||
#include <format>
|
||||
#include <iostream>
|
||||
|
||||
void IPakCreator::AddImage(std::string imageName)
|
||||
{
|
||||
m_image_names.emplace_back(std::move(imageName));
|
||||
}
|
||||
|
||||
void IPakCreator::Finalize(ISearchPath& searchPath, const std::filesystem::path& outPath)
|
||||
{
|
||||
std::cout << std::format("Creating ipak with {} entries:\n", m_image_names.size());
|
||||
|
||||
for (const auto& imageName : m_image_names)
|
||||
std::cout << std::format(" {}\n", imageName);
|
||||
}
|
16
src/ObjCompiling/Image/IPak/IPakCreator.h
Normal file
16
src/ObjCompiling/Image/IPak/IPakCreator.h
Normal file
@ -0,0 +1,16 @@
|
||||
#pragma once
|
||||
|
||||
#include "Asset/IZoneAssetLoaderState.h"
|
||||
#include "SearchPath/ISearchPath.h"
|
||||
|
||||
#include <filesystem>
|
||||
|
||||
class IPakCreator : public IZoneAssetLoaderState
|
||||
{
|
||||
public:
|
||||
void AddImage(std::string imageName);
|
||||
void Finalize(ISearchPath& searchPath, const std::filesystem::path& outPath);
|
||||
|
||||
private:
|
||||
std::vector<std::string> m_image_names;
|
||||
};
|
25
src/ObjCompiling/Image/ImageIPakPostProcessor.cpp
Normal file
25
src/ObjCompiling/Image/ImageIPakPostProcessor.cpp
Normal file
@ -0,0 +1,25 @@
|
||||
#include "ImageIPakPostProcessor.h"
|
||||
|
||||
#include "IPak/IPakCreator.h"
|
||||
|
||||
#include <format>
|
||||
|
||||
AbstractImageIPakPostProcessor::AbstractImageIPakPostProcessor(ISearchPath& searchPath, const std::filesystem::path& outDir)
|
||||
: m_search_path(searchPath),
|
||||
m_out_dir(outDir)
|
||||
{
|
||||
}
|
||||
|
||||
void AbstractImageIPakPostProcessor::PostProcessAsset(XAssetInfoGeneric& assetInfo, AssetCreationContext& context)
|
||||
{
|
||||
if (assetInfo.m_name.empty() || assetInfo.m_name[0] == ',')
|
||||
return;
|
||||
|
||||
auto* ipakCreator = context.GetZoneAssetLoaderState<IPakCreator>();
|
||||
ipakCreator->AddImage(assetInfo.m_name);
|
||||
}
|
||||
|
||||
void AbstractImageIPakPostProcessor::FinalizeZone(AssetCreationContext& context)
|
||||
{
|
||||
context.GetZoneAssetLoaderState<IPakCreator>()->Finalize(m_search_path, m_out_dir);
|
||||
}
|
34
src/ObjCompiling/Image/ImageIPakPostProcessor.h
Normal file
34
src/ObjCompiling/Image/ImageIPakPostProcessor.h
Normal file
@ -0,0 +1,34 @@
|
||||
#pragma once
|
||||
|
||||
#include "Asset/IAssetPostProcessor.h"
|
||||
|
||||
#include <filesystem>
|
||||
|
||||
class AbstractImageIPakPostProcessor : public IAssetPostProcessor
|
||||
{
|
||||
public:
|
||||
AbstractImageIPakPostProcessor(ISearchPath& searchPath, const std::filesystem::path& outDir);
|
||||
|
||||
void PostProcessAsset(XAssetInfoGeneric& assetInfo, AssetCreationContext& context) override;
|
||||
void FinalizeZone(AssetCreationContext& context) override;
|
||||
|
||||
private:
|
||||
ISearchPath& m_search_path;
|
||||
const std::filesystem::path& m_out_dir;
|
||||
};
|
||||
|
||||
template<typename AssetType> class ImageIPakPostProcessor final : public AbstractImageIPakPostProcessor
|
||||
{
|
||||
public:
|
||||
static_assert(std::is_base_of_v<IAssetBase, AssetType>);
|
||||
|
||||
ImageIPakPostProcessor(ISearchPath& searchPath, const std::filesystem::path& outDir)
|
||||
: AbstractImageIPakPostProcessor(searchPath, outDir)
|
||||
{
|
||||
}
|
||||
|
||||
[[nodiscard]] asset_type_t GetHandlingAssetType() const override
|
||||
{
|
||||
return AssetType::EnumEntry;
|
||||
};
|
||||
};
|
25
src/ObjCompiling/Image/ImageIwdPostProcessor.cpp
Normal file
25
src/ObjCompiling/Image/ImageIwdPostProcessor.cpp
Normal file
@ -0,0 +1,25 @@
|
||||
#include "ImageIwdPostProcessor.h"
|
||||
|
||||
#include "Iwd/IwdCreator.h"
|
||||
|
||||
#include <format>
|
||||
|
||||
AbstractImageIwdPostProcessor::AbstractImageIwdPostProcessor(ISearchPath& searchPath, const std::filesystem::path& outDir)
|
||||
: m_search_path(searchPath),
|
||||
m_out_dir(outDir)
|
||||
{
|
||||
}
|
||||
|
||||
void AbstractImageIwdPostProcessor::PostProcessAsset(XAssetInfoGeneric& assetInfo, AssetCreationContext& context)
|
||||
{
|
||||
if (assetInfo.m_name.empty() || assetInfo.m_name[0] == ',')
|
||||
return;
|
||||
|
||||
auto* iwdCreator = context.GetZoneAssetLoaderState<IwdCreator>();
|
||||
iwdCreator->AddFile(std::format("images/{}.iwi", assetInfo.m_name));
|
||||
}
|
||||
|
||||
void AbstractImageIwdPostProcessor::FinalizeZone(AssetCreationContext& context)
|
||||
{
|
||||
context.GetZoneAssetLoaderState<IwdCreator>()->Finalize(m_search_path, m_out_dir);
|
||||
}
|
34
src/ObjCompiling/Image/ImageIwdPostProcessor.h
Normal file
34
src/ObjCompiling/Image/ImageIwdPostProcessor.h
Normal file
@ -0,0 +1,34 @@
|
||||
#pragma once
|
||||
|
||||
#include "Asset/IAssetPostProcessor.h"
|
||||
|
||||
#include <filesystem>
|
||||
|
||||
class AbstractImageIwdPostProcessor : public IAssetPostProcessor
|
||||
{
|
||||
public:
|
||||
AbstractImageIwdPostProcessor(ISearchPath& searchPath, const std::filesystem::path& outDir);
|
||||
|
||||
void PostProcessAsset(XAssetInfoGeneric& assetInfo, AssetCreationContext& context) override;
|
||||
void FinalizeZone(AssetCreationContext& context) override;
|
||||
|
||||
private:
|
||||
ISearchPath& m_search_path;
|
||||
const std::filesystem::path& m_out_dir;
|
||||
};
|
||||
|
||||
template<typename AssetType> class ImageIwdPostProcessor final : public AbstractImageIwdPostProcessor
|
||||
{
|
||||
public:
|
||||
static_assert(std::is_base_of_v<IAssetBase, AssetType>);
|
||||
|
||||
ImageIwdPostProcessor(ISearchPath& searchPath, const std::filesystem::path& outDir)
|
||||
: AbstractImageIwdPostProcessor(searchPath, outDir)
|
||||
{
|
||||
}
|
||||
|
||||
[[nodiscard]] asset_type_t GetHandlingAssetType() const override
|
||||
{
|
||||
return AssetType::EnumEntry;
|
||||
};
|
||||
};
|
17
src/ObjCompiling/Iwd/IwdCreator.cpp
Normal file
17
src/ObjCompiling/Iwd/IwdCreator.cpp
Normal file
@ -0,0 +1,17 @@
|
||||
#include "IwdCreator.h"
|
||||
|
||||
#include <format>
|
||||
#include <iostream>
|
||||
|
||||
void IwdCreator::AddFile(std::string filePath)
|
||||
{
|
||||
m_file_paths.emplace_back(std::move(filePath));
|
||||
}
|
||||
|
||||
void IwdCreator::Finalize(ISearchPath& searchPath, const std::filesystem::path& outPath)
|
||||
{
|
||||
std::cout << std::format("Creating iwd with {} entries:\n", m_file_paths.size());
|
||||
|
||||
for (const auto& filePath : m_file_paths)
|
||||
std::cout << std::format(" {}\n", filePath);
|
||||
}
|
16
src/ObjCompiling/Iwd/IwdCreator.h
Normal file
16
src/ObjCompiling/Iwd/IwdCreator.h
Normal file
@ -0,0 +1,16 @@
|
||||
#pragma once
|
||||
|
||||
#include "Asset/IZoneAssetLoaderState.h"
|
||||
#include "SearchPath/ISearchPath.h"
|
||||
|
||||
#include <filesystem>
|
||||
|
||||
class IwdCreator : public IZoneAssetLoaderState
|
||||
{
|
||||
public:
|
||||
void AddFile(std::string filePath);
|
||||
void Finalize(ISearchPath& searchPath, const std::filesystem::path& outPath);
|
||||
|
||||
private:
|
||||
std::vector<std::string> m_file_paths;
|
||||
};
|
Reference in New Issue
Block a user