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

feat: template techset and shader dumping for IW4,T6

This commit is contained in:
Jan Laupetin
2026-03-06 21:55:26 +00:00
parent bb9dba4132
commit eae57d9da0
17 changed files with 313 additions and 690 deletions

View File

@@ -2,12 +2,9 @@
#include "Game/IW4/IW4.h"
#include "Game/IW4/Techset/TechsetConstantsIW4.h"
#include "Techset/CommonVertexDeclCreator.h"
#include "Utils/Logging/Log.h"
#include <cstring>
#include <format>
#include <iostream>
using namespace IW4;
namespace
@@ -15,78 +12,37 @@ namespace
class LoaderVertexDecl final : public AssetCreator<AssetVertexDecl>
{
public:
LoaderVertexDecl(MemoryManager& memory)
explicit LoaderVertexDecl(MemoryManager& memory)
: m_memory(memory)
{
}
AssetCreationResult CreateAsset(const std::string& assetName, AssetCreationContext& context) override
{
auto* decl = m_memory.Alloc<MaterialVertexDeclaration>();
decl->name = m_memory.Dup(assetName.c_str());
const auto commonVertexDecl = techset::CreateVertexDeclFromName(assetName, commonRoutingInfos);
if (!commonVertexDecl)
return AssetCreationResult::Failure();
size_t currentOffset = 0u;
std::string sourceAbbreviation;
while (NextAbbreviation(assetName, sourceAbbreviation, currentOffset))
if (commonVertexDecl->m_routing.size() > std::extent_v<decltype(MaterialVertexStreamRouting::data)>)
{
if (decl->streamCount >= std::extent_v<decltype(MaterialVertexStreamRouting::data)>)
{
con::error("Failed to add vertex decl stream. Too many abbreviations: {}", assetName);
return AssetCreationResult::Failure();
}
std::string destinationAbbreviation;
if (!NextAbbreviation(assetName, destinationAbbreviation, currentOffset))
{
con::error("Failed to detect vertex decl destination abbreviation: {}", assetName);
return AssetCreationResult::Failure();
}
const auto foundSourceAbbreviation = std::ranges::find(materialStreamSourceAbbreviation, sourceAbbreviation);
if (foundSourceAbbreviation == std::end(materialStreamSourceAbbreviation))
{
con::error("Unknown vertex decl source abbreviation: {}", sourceAbbreviation);
return AssetCreationResult::Failure();
}
const auto foundDestinationAbbreviation = std::ranges::find(materialStreamDestinationAbbreviation, destinationAbbreviation);
if (foundDestinationAbbreviation == std::end(materialStreamDestinationAbbreviation))
{
con::error("Unknown vertex decl destination abbreviation: {}", destinationAbbreviation);
return AssetCreationResult::Failure();
}
const auto sourceIndex = static_cast<MaterialStreamStreamSource_e>(foundSourceAbbreviation - std::begin(materialStreamSourceAbbreviation));
const auto destinationIndex =
static_cast<MaterialStreamDestination_e>(foundDestinationAbbreviation - std::begin(materialStreamDestinationAbbreviation));
decl->routing.data[decl->streamCount].source = sourceIndex;
decl->routing.data[decl->streamCount].dest = destinationIndex;
decl->hasOptionalSource = decl->hasOptionalSource || sourceIndex >= STREAM_SRC_OPTIONAL_BEGIN;
decl->streamCount++;
con::error("Vertex declaration can only have up to {} routing entries", std::extent_v<decltype(MaterialVertexStreamRouting::data)>);
return AssetCreationResult::Failure();
}
return AssetCreationResult::Success(context.AddAsset<AssetVertexDecl>(assetName, decl));
}
auto* vertexDecl = m_memory.Alloc<MaterialVertexDeclaration>();
static bool NextAbbreviation(const std::string& assetName, std::string& abbreviation, size_t& offset)
{
if (offset >= assetName.size())
return false;
vertexDecl->name = m_memory.Dup(assetName.c_str());
if (offset + 1 < assetName.size() && isdigit(assetName[offset + 1]))
for (const auto& commonRoutingEntry : commonVertexDecl->m_routing)
{
abbreviation = std::string(assetName, offset, 2);
offset += 2;
}
else
{
abbreviation = std::string(assetName, offset, 1);
offset += 1;
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 true;
return AssetCreationResult::Success(context.AddAsset(AssetRegistration<AssetVertexDecl>(assetName, vertexDecl)));
}
MemoryManager& m_memory;