From 3bb7f1aa05a51da5bb0898b194850aa6963007ba Mon Sep 17 00:00:00 2001 From: Jan Laupetin Date: Sat, 7 Mar 2026 09:51:12 +0000 Subject: [PATCH] chore: use templated vertex decl compiler --- src/ObjCompiling/Game/IW4/ObjCompilerIW4.cpp | 4 +- .../IW4/Techset/CompilerVertexDeclIW4.cpp | 58 ------------------- .../Game/IW4/Techset/CompilerVertexDeclIW4.h | 13 ----- .../Techset/VertexDeclCompiler.cpp.template | 13 ++++- .../Techset/VertexDeclCompiler.h.template | 2 +- 5 files changed, 13 insertions(+), 77 deletions(-) delete mode 100644 src/ObjCompiling/Game/IW4/Techset/CompilerVertexDeclIW4.cpp delete mode 100644 src/ObjCompiling/Game/IW4/Techset/CompilerVertexDeclIW4.h diff --git a/src/ObjCompiling/Game/IW4/ObjCompilerIW4.cpp b/src/ObjCompiling/Game/IW4/ObjCompilerIW4.cpp index 3930a746..66f326d3 100644 --- a/src/ObjCompiling/Game/IW4/ObjCompilerIW4.cpp +++ b/src/ObjCompiling/Game/IW4/ObjCompilerIW4.cpp @@ -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 @@ -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, diff --git a/src/ObjCompiling/Game/IW4/Techset/CompilerVertexDeclIW4.cpp b/src/ObjCompiling/Game/IW4/Techset/CompilerVertexDeclIW4.cpp deleted file mode 100644 index a2762d59..00000000 --- a/src/ObjCompiling/Game/IW4/Techset/CompilerVertexDeclIW4.cpp +++ /dev/null @@ -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 - { - 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) - { - con::error("Vertex declaration can only have up to {} routing entries", std::extent_v); - return AssetCreationResult::Failure(); - } - - auto* vertexDecl = m_memory.Alloc(); - - 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(assetName, vertexDecl))); - } - - MemoryManager& m_memory; - }; -} // namespace - -namespace vertex_decl -{ - std::unique_ptr> CreateLoaderIW4(MemoryManager& memory) - { - return std::make_unique(memory); - } -} // namespace vertex_decl diff --git a/src/ObjCompiling/Game/IW4/Techset/CompilerVertexDeclIW4.h b/src/ObjCompiling/Game/IW4/Techset/CompilerVertexDeclIW4.h deleted file mode 100644 index 4713a652..00000000 --- a/src/ObjCompiling/Game/IW4/Techset/CompilerVertexDeclIW4.h +++ /dev/null @@ -1,13 +0,0 @@ -#pragma once - -#include "Asset/IAssetCreator.h" -#include "Game/IW4/IW4.h" -#include "SearchPath/ISearchPath.h" -#include "Utils/MemoryManager.h" - -#include - -namespace vertex_decl -{ - std::unique_ptr> CreateLoaderIW4(MemoryManager& memory); -} // namespace vertex_decl diff --git a/src/ObjCompiling/Techset/VertexDeclCompiler.cpp.template b/src/ObjCompiling/Techset/VertexDeclCompiler.cpp.template index 39e01cac..313f9ca3 100644 --- a/src/ObjCompiling/Techset/VertexDeclCompiler.cpp.template +++ b/src/ObjCompiling/Techset/VertexDeclCompiler.cpp.template @@ -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(); +#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(assetName, vertexDecl))); + return AssetCreationResult::Success(context.ADD_ASSET_METHOD(AssetRegistration(assetName, vertexDecl))); } private: diff --git a/src/ObjCompiling/Techset/VertexDeclCompiler.h.template b/src/ObjCompiling/Techset/VertexDeclCompiler.h.template index 1d20878b..d236b706 100644 --- a/src/ObjCompiling/Techset/VertexDeclCompiler.h.template +++ b/src/ObjCompiling/Techset/VertexDeclCompiler.h.template @@ -1,4 +1,4 @@ -#options GAME(T6) +#options GAME(IW4, T6) #filename "Game/" + GAME + "/Techset/VertexDeclCompiler" + GAME + ".h"