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

chore: use templated vertex decl compiler

This commit is contained in:
Jan Laupetin
2026-03-07 09:51:12 +00:00
parent 5272b9060d
commit 3bb7f1aa05
5 changed files with 13 additions and 77 deletions

View File

@@ -1,10 +1,10 @@
#include "ObjCompilerIW4.h"
#include "Game/IW4/IW4.h"
#include "Game/IW4/Techset/VertexDeclCompilerIW4.h"
#include "Image/ImageIwdPostProcessor.h"
#include "Material/CompilerMaterialIW4.h"
#include "Techset/CompilerTechsetIW4.h"
#include "Techset/CompilerVertexDeclIW4.h"
#include <memory>
@@ -20,7 +20,7 @@ namespace
collection.AddAssetCreator(material::CreateCompilerIW4(memory, searchPath, gdt));
collection.AddAssetCreator(techset::CreateLoaderIW4(memory, searchPath));
#endif
collection.AddAssetCreator(vertex_decl::CreateLoaderIW4(memory));
collection.AddAssetCreator(techset::CreateVertexDeclCompilerIW4(memory));
}
void ConfigurePostProcessors(AssetCreatorCollection& collection,

View File

@@ -1,58 +0,0 @@
#include "CompilerVertexDeclIW4.h"
#include "Game/IW4/IW4.h"
#include "Game/IW4/Techset/TechsetConstantsIW4.h"
#include "Techset/CommonVertexDeclCreator.h"
#include "Utils/Logging/Log.h"
using namespace IW4;
namespace
{
class LoaderVertexDecl final : public AssetCreator<AssetVertexDecl>
{
public:
explicit LoaderVertexDecl(MemoryManager& memory)
: m_memory(memory)
{
}
AssetCreationResult CreateAsset(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>();
vertexDecl->name = m_memory.Dup(assetName.c_str());
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.AddAsset(AssetRegistration<AssetVertexDecl>(assetName, vertexDecl)));
}
MemoryManager& m_memory;
};
} // namespace
namespace vertex_decl
{
std::unique_ptr<AssetCreator<AssetVertexDecl>> CreateLoaderIW4(MemoryManager& memory)
{
return std::make_unique<LoaderVertexDecl>(memory);
}
} // namespace vertex_decl

View File

@@ -1,13 +0,0 @@
#pragma once
#include "Asset/IAssetCreator.h"
#include "Game/IW4/IW4.h"
#include "SearchPath/ISearchPath.h"
#include "Utils/MemoryManager.h"
#include <memory>
namespace vertex_decl
{
std::unique_ptr<AssetCreator<IW4::AssetVertexDecl>> CreateLoaderIW4(MemoryManager& memory);
} // namespace vertex_decl

View File

@@ -1,4 +1,4 @@
#options GAME(T6)
#options GAME(IW4, T6)
#filename "Game/" + GAME + "/Techset/VertexDeclCompiler" + GAME + ".cpp"
@@ -16,6 +16,7 @@
#define FEATURE_T5
#elif GAME == "T6"
#define FEATURE_T6
#define IS_SUB_ASSET
#endif
// This file was templated.
@@ -33,14 +34,16 @@ using namespace GAME;
#set COMPILER_CLASS_NAME "VertexDeclCompiler" + GAME
#if defined(FEATURE_T6)
#if defined(IS_SUB_ASSET)
#define ABSTRACT_CREATOR_NAME SubAssetCreator
#define OVERRIDEN_CREATOR_METHOD CreateSubAsset
#define ADD_ASSET_METHOD AddSubAsset
#define ASSET_NAME SubAssetVertexDecl
#define INTERFACE_NAME ISubAssetCreator
#else
#define ABSTRACT_CREATOR_NAME AssetCreator
#define OVERRIDEN_CREATOR_METHOD CreateAsset
#define ADD_ASSET_METHOD AddAsset
#define ASSET_NAME AssetVertexDecl
#define INTERFACE_NAME IAssetCreator
#endif
@@ -69,6 +72,10 @@ namespace
auto* vertexDecl = m_memory.Alloc<MaterialVertexDeclaration>();
#ifndef IS_SUB_ASSET
vertexDecl->name = m_memory.Dup(assetName.c_str());
#endif
for (const auto& commonRoutingEntry : commonVertexDecl->m_routing)
{
vertexDecl->routing.data[vertexDecl->streamCount].source = commonRoutingEntry.m_source;
@@ -78,7 +85,7 @@ namespace
vertexDecl->streamCount++;
}
return AssetCreationResult::Success(context.AddSubAsset(AssetRegistration<ASSET_NAME>(assetName, vertexDecl)));
return AssetCreationResult::Success(context.ADD_ASSET_METHOD(AssetRegistration<ASSET_NAME>(assetName, vertexDecl)));
}
private:

View File

@@ -1,4 +1,4 @@
#options GAME(T6)
#options GAME(IW4, T6)
#filename "Game/" + GAME + "/Techset/VertexDeclCompiler" + GAME + ".h"