2
0
mirror of https://github.com/Laupetin/OpenAssetTools.git synced 2026-03-15 17:33:03 +00:00

chore: use templating for t6 techset compilation

This commit is contained in:
Jan Laupetin
2026-03-07 09:42:57 +00:00
parent 02a3394c2d
commit 5272b9060d
15 changed files with 301 additions and 121 deletions

View File

@@ -50,6 +50,9 @@ function ObjCompiling:project()
path.join(folder, "ObjCompiling")
}
}
ObjCommon:use()
useSourceTemplating("ObjCompiling")
self:include(includes)
minilzo:include(includes)

View File

@@ -1,12 +1,12 @@
#include "ObjCompilerT6.h"
#include "Game/T6/T6.h"
#include "Game/T6/Techset/TechniqueCompilerT6.h"
#include "Game/T6/Techset/TechsetCompilerT6.h"
#include "Game/T6/Techset/VertexDeclCompilerT6.h"
#include "Image/ImageIPakPostProcessor.h"
#include "Image/ImageIwdPostProcessor.h"
#include "KeyValuePairs/KeyValuePairsCompilerT6.h"
#include "Techset/TechniqueCompilerT6.h"
#include "Techset/TechsetCompilerT6.h"
#include "Techset/VertexDeclCompilerT6.h"
#include <memory>
@@ -23,7 +23,7 @@ namespace
auto& memory = zone.Memory();
collection.AddAssetCreator(key_value_pairs::CreateCompilerT6(memory, zone, zoneDefinition.m_zone_definition, zoneStates));
collection.AddAssetCreator(techset::CreateCompilerT6(memory, searchPath));
collection.AddAssetCreator(techset::CreateTechsetCompilerT6(memory, searchPath));
collection.AddSubAssetCreator(techset::CreateTechniqueCompilerT6(memory, zone, searchPath));
collection.AddSubAssetCreator(techset::CreateVertexDeclCompilerT6(memory));

View File

@@ -1,12 +0,0 @@
#pragma once
#include "Asset/IAssetCreator.h"
#include "SearchPath/ISearchPath.h"
#include "Utils/MemoryManager.h"
#include <memory>
namespace techset
{
std::unique_ptr<ISubAssetCreator> CreateTechniqueCompilerT6(MemoryManager& memory, Zone& zone, ISearchPath& searchPath);
}

View File

@@ -1,12 +0,0 @@
#pragma once
#include "Asset/IAssetCreator.h"
#include "SearchPath/ISearchPath.h"
#include "Utils/MemoryManager.h"
#include <memory>
namespace techset
{
std::unique_ptr<IAssetCreator> CreateCompilerT6(MemoryManager& memory, ISearchPath& searchPath);
} // namespace techset

View File

@@ -1,57 +0,0 @@
#include "VertexDeclCompilerT6.h"
#include "Game/T6/T6.h"
#include "Game/T6/Techset/TechsetConstantsT6.h"
#include "Techset/CommonVertexDeclCreator.h"
#include "Utils/Logging/Log.h"
using namespace T6;
namespace
{
class VertexDeclCompilerT6 final : public SubAssetCreator<SubAssetVertexDecl>
{
public:
explicit VertexDeclCompilerT6(MemoryManager& memory)
: m_memory(memory)
{
}
AssetCreationResult CreateSubAsset(const std::string& subAssetName, AssetCreationContext& context) override
{
const auto commonVertexDecl = techset::CreateVertexDeclFromName(subAssetName, commonRoutingInfos);
if (!commonVertexDecl)
return AssetCreationResult::Failure();
if (commonVertexDecl->m_routing.size() > std::extent_v<decltype(MaterialVertexStreamRouting::data)>)
{
con::error("Vertex declaration can only have up to {} routing entries", std::extent_v<decltype(MaterialVertexStreamRouting::data)>);
return AssetCreationResult::Failure();
}
auto* vertexDecl = m_memory.Alloc<MaterialVertexDeclaration>();
for (const auto& commonRoutingEntry : commonVertexDecl->m_routing)
{
vertexDecl->routing.data[vertexDecl->streamCount].source = commonRoutingEntry.m_source;
vertexDecl->routing.data[vertexDecl->streamCount].dest = commonRoutingEntry.m_destination;
vertexDecl->hasOptionalSource = vertexDecl->hasOptionalSource || commonRoutingEntry.m_source >= STREAM_SRC_OPTIONAL_BEGIN;
vertexDecl->streamCount++;
}
return AssetCreationResult::Success(context.AddSubAsset(AssetRegistration<SubAssetVertexDecl>(subAssetName, vertexDecl)));
}
private:
MemoryManager& m_memory;
};
} // namespace
namespace techset
{
std::unique_ptr<ISubAssetCreator> CreateVertexDeclCompilerT6(MemoryManager& memory)
{
return std::make_unique<VertexDeclCompilerT6>(memory);
}
} // namespace techset

View File

@@ -1,11 +0,0 @@
#pragma once
#include "Asset/IAssetCreator.h"
#include "Utils/MemoryManager.h"
#include <memory>
namespace techset
{
std::unique_ptr<ISubAssetCreator> CreateVertexDeclCompilerT6(MemoryManager& memory);
}

View File

@@ -326,7 +326,7 @@ namespace
const techset::CommonShaderArgCreatorDestination& input) override
{
assert(m_shader_info);
// TODO
return false;
}
@@ -577,7 +577,6 @@ namespace
return std::move(result);
}
// TODO
return NoResult{};
}

View File

@@ -1,19 +1,50 @@
#include "TechniqueCompilerT6.h"
#options GAME(T6)
#include "Game/T6/T6.h"
#include "Game/T6/Techset/TechsetConstantsT6.h"
#include "PrecompiledIndexT6.h"
#filename "Game/" + GAME + "/Techset/TechniqueCompiler" + GAME + ".cpp"
#set COMPILER_HEADER "\"TechniqueCompiler" + GAME + ".h\""
#set GAME_HEADER "\"Game/" + GAME + "/" + GAME + ".h\""
#set TECHSET_CONSTANTS_HEADER "\"Game/" + GAME + "/Techset/TechsetConstants" + GAME + ".h\""
#if GAME == "IW3"
#define FEATURE_IW3
#elif GAME == "IW4"
#define FEATURE_IW4
#elif GAME == "IW5"
#define FEATURE_IW5
#elif GAME == "T5"
#define FEATURE_T5
#elif GAME == "T6"
#define FEATURE_T6
#endif
// This file was templated.
// See TechniqueCompiler.cpp.template.
// Do not modify, changes will be lost.
#include COMPILER_HEADER
#include GAME_HEADER
#include TECHSET_CONSTANTS_HEADER
#include "Techset/CommonShaderArgCreator.h"
#include "Techset/CommonTechniqueLoader.h"
#include "Techset/LiteralConstsZoneState.h"
#include "Utils/StringUtils.h"
#if defined(FEATURE_T6)
#set PRECOMPILED_INDEX_HEADER "\"Game/" + GAME + "/Techset/PrecompiledIndex" + GAME + ".h\""
#include PRECOMPILED_INDEX_HEADER
#endif
#include <cassert>
#include <optional>
#include <sstream>
#include <vector>
using namespace T6;
using namespace GAME;
#set SHADER_LOADER_CLASS_NAME "TechniqueShaderLoader" + GAME
#set COMPILER_CLASS_NAME "TechniqueCompiler" + GAME
namespace
{
@@ -236,10 +267,10 @@ namespace
}
}
class TechniqueShaderLoaderT6 final : public techset::ITechniqueShaderLoader
class SHADER_LOADER_CLASS_NAME final : public techset::ITechniqueShaderLoader
{
public:
explicit TechniqueShaderLoaderT6(AssetCreationContext& context)
explicit SHADER_LOADER_CLASS_NAME(AssetCreationContext& context)
: m_context(context)
{
}
@@ -282,10 +313,10 @@ namespace
AssetCreationContext& m_context;
};
class TechniqueCompilerT6 final : public SubAssetCreator<SubAssetTechnique>
class COMPILER_CLASS_NAME final : public SubAssetCreator<SubAssetTechnique>
{
public:
TechniqueCompilerT6(MemoryManager& memory, Zone& zone, ISearchPath& searchPath)
COMPILER_CLASS_NAME(MemoryManager& memory, Zone& zone, ISearchPath& searchPath)
: m_memory(memory),
m_zone(zone),
m_search_path(searchPath)
@@ -295,7 +326,7 @@ namespace
AssetCreationResult CreateSubAsset(const std::string& subAssetName, AssetCreationContext& context) override
{
bool failure = false;
TechniqueShaderLoaderT6 shaderLoader(context);
SHADER_LOADER_CLASS_NAME shaderLoader(context);
const auto commonShaderArgCreator = techset::CommonShaderArgCreator::CreateDx11(shaderLoader, context, commonCodeSourceInfos);
const auto commonTechnique =
@@ -336,10 +367,12 @@ namespace
};
} // namespace
#set CREATE_COMPILER_METHOD "CreateTechniqueCompiler" + GAME
namespace techset
{
std::unique_ptr<ISubAssetCreator> CreateTechniqueCompilerT6(MemoryManager& memory, Zone& zone, ISearchPath& searchPath)
std::unique_ptr<ISubAssetCreator> CREATE_COMPILER_METHOD(MemoryManager& memory, Zone& zone, ISearchPath& searchPath)
{
return std::make_unique<TechniqueCompilerT6>(memory, zone, searchPath);
return std::make_unique<COMPILER_CLASS_NAME>(memory, zone, searchPath);
}
} // namespace techset

View File

@@ -0,0 +1,36 @@
#options GAME(T6)
#filename "Game/" + GAME + "/Techset/TechniqueCompiler" + GAME + ".h"
#set GAME_HEADER "\"Game/" + GAME + "/" + GAME + ".h\""
#if GAME == "IW3"
#define FEATURE_IW3
#elif GAME == "IW4"
#define FEATURE_IW4
#elif GAME == "IW5"
#define FEATURE_IW5
#elif GAME == "T5"
#define FEATURE_T5
#elif GAME == "T6"
#define FEATURE_T6
#endif
// This file was templated.
// See TechniqueCompiler.h.template.
// Do not modify, changes will be lost.
#pragma once
#include "Asset/IAssetCreator.h"
#include "SearchPath/ISearchPath.h"
#include "Utils/MemoryManager.h"
#include <memory>
#set CREATE_COMPILER_METHOD "CreateTechniqueCompiler" + GAME
namespace techset
{
std::unique_ptr<ISubAssetCreator> CREATE_COMPILER_METHOD(MemoryManager& memory, Zone& zone, ISearchPath& searchPath);
}

View File

@@ -1,11 +1,37 @@
#include "TechsetCompilerT6.h"
#options GAME(T6)
#include "Game/T6/T6.h"
#include "Game/T6/Techset/TechsetConstantsT6.h"
#filename "Game/" + GAME + "/Techset/TechsetCompiler" + GAME + ".cpp"
#set COMPILER_HEADER "\"TechsetCompiler" + GAME + ".h\""
#set GAME_HEADER "\"Game/" + GAME + "/" + GAME + ".h\""
#set TECHSET_CONSTANTS_HEADER "\"Game/" + GAME + "/Techset/TechsetConstants" + GAME + ".h\""
#if GAME == "IW3"
#define FEATURE_IW3
#elif GAME == "IW4"
#define FEATURE_IW4
#elif GAME == "IW5"
#define FEATURE_IW5
#elif GAME == "T5"
#define FEATURE_T5
#elif GAME == "T6"
#define FEATURE_T6
#endif
// This file was templated.
// See TechsetCompiler.cpp.template.
// Do not modify, changes will be lost.
#include COMPILER_HEADER
#include GAME_HEADER
#include TECHSET_CONSTANTS_HEADER
#include "Techset/CommonTechsetLoader.h"
#include "Techset/TechsetCommon.h"
using namespace T6;
using namespace GAME;
#set COMPILER_CLASS_NAME "TechsetCompiler" + GAME
namespace
{
@@ -71,10 +97,10 @@ namespace
return techset;
}
class TechsetCompilerT6 final : public AssetCreator<AssetTechniqueSet>
class COMPILER_CLASS_NAME final : public AssetCreator<AssetTechniqueSet>
{
public:
TechsetCompilerT6(ISearchPath& searchPath, MemoryManager& memory)
COMPILER_CLASS_NAME(ISearchPath& searchPath, MemoryManager& memory)
: m_search_path(searchPath),
m_memory(memory)
{
@@ -106,8 +132,6 @@ namespace
// but the game determines the material type by techset name.
// So this may just be a constraint that cannot be changed.
ApplyMaterialTypeToTechnique(*techset->techniques[techniqueIndex], materialType);
// Precompiled index?
}
return AssetCreationResult::Success(context.AddAsset(AssetRegistration<AssetTechniqueSet>(assetName, techset)));
@@ -119,10 +143,12 @@ namespace
};
} // namespace
#set CREATE_COMPILER_METHOD "CreateTechsetCompiler" + GAME
namespace techset
{
std::unique_ptr<IAssetCreator> CreateCompilerT6(MemoryManager& memory, ISearchPath& searchPath)
std::unique_ptr<IAssetCreator> CREATE_COMPILER_METHOD(MemoryManager& memory, ISearchPath& searchPath)
{
return std::make_unique<TechsetCompilerT6>(searchPath, memory);
return std::make_unique<COMPILER_CLASS_NAME>(searchPath, memory);
}
} // namespace techset

View File

@@ -0,0 +1,36 @@
#options GAME(T6)
#filename "Game/" + GAME + "/Techset/TechsetCompiler" + GAME + ".h"
#set GAME_HEADER "\"Game/" + GAME + "/" + GAME + ".h\""
#if GAME == "IW3"
#define FEATURE_IW3
#elif GAME == "IW4"
#define FEATURE_IW4
#elif GAME == "IW5"
#define FEATURE_IW5
#elif GAME == "T5"
#define FEATURE_T5
#elif GAME == "T6"
#define FEATURE_T6
#endif
// This file was templated.
// See TechsetCompiler.h.template.
// Do not modify, changes will be lost.
#pragma once
#include "Asset/IAssetCreator.h"
#include "SearchPath/ISearchPath.h"
#include "Utils/MemoryManager.h"
#include <memory>
#set CREATE_COMPILER_METHOD "CreateTechsetCompiler" + GAME
namespace techset
{
std::unique_ptr<IAssetCreator> CREATE_COMPILER_METHOD(MemoryManager& memory, ISearchPath& searchPath);
}

View File

@@ -0,0 +1,97 @@
#options GAME(T6)
#filename "Game/" + GAME + "/Techset/VertexDeclCompiler" + GAME + ".cpp"
#set COMPILER_HEADER "\"VertexDeclCompiler" + GAME + ".h\""
#set GAME_HEADER "\"Game/" + GAME + "/" + GAME + ".h\""
#set TECHSET_CONSTANTS_HEADER "\"Game/" + GAME + "/Techset/TechsetConstants" + GAME + ".h\""
#if GAME == "IW3"
#define FEATURE_IW3
#elif GAME == "IW4"
#define FEATURE_IW4
#elif GAME == "IW5"
#define FEATURE_IW5
#elif GAME == "T5"
#define FEATURE_T5
#elif GAME == "T6"
#define FEATURE_T6
#endif
// This file was templated.
// See VertexDeclCompiler.cpp.template.
// Do not modify, changes will be lost.
#include COMPILER_HEADER
#include GAME_HEADER
#include TECHSET_CONSTANTS_HEADER
#include "Techset/CommonVertexDeclCreator.h"
#include "Utils/Logging/Log.h"
using namespace GAME;
#set COMPILER_CLASS_NAME "VertexDeclCompiler" + GAME
#if defined(FEATURE_T6)
#define ABSTRACT_CREATOR_NAME SubAssetCreator
#define OVERRIDEN_CREATOR_METHOD CreateSubAsset
#define ASSET_NAME SubAssetVertexDecl
#define INTERFACE_NAME ISubAssetCreator
#else
#define ABSTRACT_CREATOR_NAME AssetCreator
#define OVERRIDEN_CREATOR_METHOD CreateAsset
#define ASSET_NAME AssetVertexDecl
#define INTERFACE_NAME IAssetCreator
#endif
namespace
{
class COMPILER_CLASS_NAME final : public ABSTRACT_CREATOR_NAME<ASSET_NAME>
{
public:
explicit COMPILER_CLASS_NAME(MemoryManager& memory)
: m_memory(memory)
{
}
AssetCreationResult OVERRIDEN_CREATOR_METHOD(const std::string& assetName, AssetCreationContext& context) override
{
const auto commonVertexDecl = techset::CreateVertexDeclFromName(assetName, commonRoutingInfos);
if (!commonVertexDecl)
return AssetCreationResult::Failure();
if (commonVertexDecl->m_routing.size() > std::extent_v<decltype(MaterialVertexStreamRouting::data)>)
{
con::error("Vertex declaration can only have up to {} routing entries", std::extent_v<decltype(MaterialVertexStreamRouting::data)>);
return AssetCreationResult::Failure();
}
auto* vertexDecl = m_memory.Alloc<MaterialVertexDeclaration>();
for (const auto& commonRoutingEntry : commonVertexDecl->m_routing)
{
vertexDecl->routing.data[vertexDecl->streamCount].source = commonRoutingEntry.m_source;
vertexDecl->routing.data[vertexDecl->streamCount].dest = commonRoutingEntry.m_destination;
vertexDecl->hasOptionalSource = vertexDecl->hasOptionalSource || commonRoutingEntry.m_source >= STREAM_SRC_OPTIONAL_BEGIN;
vertexDecl->streamCount++;
}
return AssetCreationResult::Success(context.AddSubAsset(AssetRegistration<ASSET_NAME>(assetName, vertexDecl)));
}
private:
MemoryManager& m_memory;
};
} // namespace
#set CREATE_COMPILER_METHOD "CreateVertexDeclCompiler" + GAME
namespace techset
{
std::unique_ptr<INTERFACE_NAME> CREATE_COMPILER_METHOD(MemoryManager& memory)
{
return std::make_unique<COMPILER_CLASS_NAME>(memory);
}
} // namespace techset

View File

@@ -0,0 +1,41 @@
#options GAME(T6)
#filename "Game/" + GAME + "/Techset/VertexDeclCompiler" + GAME + ".h"
#set GAME_HEADER "\"Game/" + GAME + "/" + GAME + ".h\""
#if GAME == "IW3"
#define FEATURE_IW3
#elif GAME == "IW4"
#define FEATURE_IW4
#elif GAME == "IW5"
#define FEATURE_IW5
#elif GAME == "T5"
#define FEATURE_T5
#elif GAME == "T6"
#define FEATURE_T6
#endif
// This file was templated.
// See VertexDeclCompiler.h.template.
// Do not modify, changes will be lost.
#pragma once
#include "Asset/IAssetCreator.h"
#include "Utils/MemoryManager.h"
#include <memory>
#set CREATE_COMPILER_METHOD "CreateVertexDeclCompiler" + GAME
#if defined(FEATURE_T6)
#define INTERFACE_NAME ISubAssetCreator
#else
#define INTERFACE_NAME IAssetCreator
#endif
namespace techset
{
std::unique_ptr<INTERFACE_NAME> CREATE_COMPILER_METHOD(MemoryManager& memory);
}