2
0
mirror of https://github.com/Laupetin/OpenAssetTools.git synced 2026-03-15 17:33:03 +00:00
Files
OpenAssetTools/src/ObjCompiling/Techset/VertexDeclCompiler.cpp.template
2026-03-14 09:09:57 +01:00

105 lines
3.3 KiB
Plaintext

#options GAME(IW4, 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
#define IS_SUB_ASSET
#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(IS_SUB_ASSET)
#define ABSTRACT_CREATOR_NAME SubAssetCreator
#define OVERRIDDEN_CREATOR_METHOD CreateSubAsset
#define ADD_ASSET_METHOD AddSubAsset
#define ASSET_NAME SubAssetVertexDecl
#define INTERFACE_NAME ISubAssetCreator
#else
#define ABSTRACT_CREATOR_NAME AssetCreator
#define OVERRIDDEN_CREATOR_METHOD CreateAsset
#define ADD_ASSET_METHOD AddAsset
#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 OVERRIDDEN_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>();
#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;
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.ADD_ASSET_METHOD(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