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

feat: add t6 vertexdecl sub asset creator

This commit is contained in:
Jan Laupetin
2026-02-27 21:28:28 +01:00
parent 3ef8cc7260
commit 9a527c16fa
15 changed files with 179 additions and 8 deletions

View File

@@ -18,6 +18,7 @@ namespace
constexpr const char* SUB_ASSET_TYPE_NAMES[]{ constexpr const char* SUB_ASSET_TYPE_NAMES[]{
"technique", "technique",
"vertexdecl",
"vertexshader", "vertexshader",
"pixelshader", "pixelshader",
}; };

View File

@@ -53,6 +53,7 @@ namespace IW3
enum SubAssetType enum SubAssetType
{ {
SUB_ASSET_TYPE_TECHNIQUE, SUB_ASSET_TYPE_TECHNIQUE,
SUB_ASSET_TYPE_VERTEX_DECL,
SUB_ASSET_TYPE_VERTEX_SHADER, SUB_ASSET_TYPE_VERTEX_SHADER,
SUB_ASSET_TYPE_PIXEL_SHADER, SUB_ASSET_TYPE_PIXEL_SHADER,

View File

@@ -21,6 +21,7 @@ namespace
constexpr const char* SUB_ASSET_TYPE_NAMES[]{ constexpr const char* SUB_ASSET_TYPE_NAMES[]{
"technique", "technique",
"vertexdecl",
"vertexshader", "vertexshader",
"pixelshader", "pixelshader",
}; };

View File

@@ -63,6 +63,7 @@ namespace T5
enum SubAssetType enum SubAssetType
{ {
SUB_ASSET_TYPE_TECHNIQUE, SUB_ASSET_TYPE_TECHNIQUE,
SUB_ASSET_TYPE_VERTEX_DECL,
SUB_ASSET_TYPE_VERTEX_SHADER, SUB_ASSET_TYPE_VERTEX_SHADER,
SUB_ASSET_TYPE_PIXEL_SHADER, SUB_ASSET_TYPE_PIXEL_SHADER,

View File

@@ -74,6 +74,7 @@ namespace
constexpr const char* SUB_ASSET_TYPE_NAMES[]{ constexpr const char* SUB_ASSET_TYPE_NAMES[]{
"technique", "technique",
"vertexdecl",
"vertexshader", "vertexshader",
"pixelshader", "pixelshader",
}; };

View File

@@ -83,6 +83,7 @@ namespace T6
enum SubAssetType enum SubAssetType
{ {
SUB_ASSET_TYPE_TECHNIQUE, SUB_ASSET_TYPE_TECHNIQUE,
SUB_ASSET_TYPE_VERTEX_DECL,
SUB_ASSET_TYPE_VERTEX_SHADER, SUB_ASSET_TYPE_VERTEX_SHADER,
SUB_ASSET_TYPE_PIXEL_SHADER, SUB_ASSET_TYPE_PIXEL_SHADER,
@@ -288,8 +289,9 @@ namespace T6
using AssetZBarrier = Asset<ASSET_TYPE_ZBARRIER, ZBarrierDef>; using AssetZBarrier = Asset<ASSET_TYPE_ZBARRIER, ZBarrierDef>;
using SubAssetTechnique = SubAsset<SUB_ASSET_TYPE_TECHNIQUE, MaterialTechnique>; using SubAssetTechnique = SubAsset<SUB_ASSET_TYPE_TECHNIQUE, MaterialTechnique>;
using SubAssetVertexShader = SubAsset<SUB_ASSET_TYPE_VERTEX_SHADER, MaterialTechnique>; using SubAssetVertexDecl = SubAsset<SUB_ASSET_TYPE_VERTEX_DECL, MaterialVertexDeclaration>;
using SubAssetPixelShader = SubAsset<SUB_ASSET_TYPE_PIXEL_SHADER, MaterialTechnique>; using SubAssetVertexShader = SubAsset<SUB_ASSET_TYPE_VERTEX_SHADER, MaterialVertexShader>;
using SubAssetPixelShader = SubAsset<SUB_ASSET_TYPE_PIXEL_SHADER, MaterialPixelShader>;
} // namespace T6 } // namespace T6
DEFINE_ASSET_NAME_ACCESSOR(T6::AssetPhysPreset, name); DEFINE_ASSET_NAME_ACCESSOR(T6::AssetPhysPreset, name);

View File

@@ -207,4 +207,18 @@ namespace techset
return std::nullopt; return std::nullopt;
} }
CommonVertexDeclaration::CommonVertexDeclaration(std::vector<CommonStreamRouting> routing)
: m_routing(std::move(routing))
{
}
void CommonVertexDeclaration::SortRoutingEntries()
{
std::ranges::sort(m_routing,
[](const CommonStreamRouting& r1, const CommonStreamRouting& r2)
{
return r1.m_source < r2.m_source;
});
}
} // namespace techset } // namespace techset

View File

@@ -234,6 +234,11 @@ namespace techset
class CommonVertexDeclaration class CommonVertexDeclaration
{ {
public: public:
CommonVertexDeclaration() = default;
explicit CommonVertexDeclaration(std::vector<CommonStreamRouting> routing);
void SortRoutingEntries();
std::vector<CommonStreamRouting> m_routing; std::vector<CommonStreamRouting> m_routing;
}; };

View File

@@ -0,0 +1,67 @@
#include "CommonVertexDeclCreator.h"
#include "Utils/Logging/Log.h"
#include <algorithm>
namespace
{
bool NextAbbreviation(const std::string& assetName, std::string& abbreviation, size_t& offset)
{
if (offset >= assetName.size())
return false;
if (offset + 1 < assetName.size() && isdigit(assetName[offset + 1]))
{
abbreviation = std::string(assetName, offset, 2);
offset += 2;
}
else
{
abbreviation = std::string(assetName, offset, 1);
offset += 1;
}
return true;
}
} // namespace
namespace techset
{
std::optional<CommonVertexDeclaration> CreateVertexDeclFromName(const std::string& name, const CommonStreamRoutingInfos& routingInfos)
{
CommonVertexDeclaration result;
size_t currentOffset = 0u;
std::string sourceAbbreviation;
while (NextAbbreviation(name, sourceAbbreviation, currentOffset))
{
std::string destinationAbbreviation;
if (!NextAbbreviation(name, destinationAbbreviation, currentOffset))
{
con::error("Failed to detect vertex decl destination abbreviation: {}", name);
return std::nullopt;
}
const auto maybeSource = routingInfos.GetSourceByAbbreviation(sourceAbbreviation);
if (!maybeSource)
{
con::error("Unknown vertex decl source abbreviation: {}", sourceAbbreviation);
return std::nullopt;
}
const auto maybeDestination = routingInfos.GetDestinationByAbbreviation(destinationAbbreviation);
if (!maybeDestination)
{
con::error("Unknown vertex decl destination abbreviation: {}", destinationAbbreviation);
return std::nullopt;
}
result.m_routing.emplace_back(*maybeSource, *maybeDestination);
}
result.SortRoutingEntries();
return result;
}
} // namespace techset

View File

@@ -0,0 +1,11 @@
#pragma once
#include "CommonTechnique.h"
#include <optional>
#include <string>
namespace techset
{
std::optional<CommonVertexDeclaration> CreateVertexDeclFromName(const std::string& name, const CommonStreamRoutingInfos& routingInfos);
}

View File

@@ -5,6 +5,7 @@
#include "Image/ImageIwdPostProcessor.h" #include "Image/ImageIwdPostProcessor.h"
#include "KeyValuePairs/KeyValuePairsCompilerT6.h" #include "KeyValuePairs/KeyValuePairsCompilerT6.h"
#include "Techset/TechsetCompilerT6.h" #include "Techset/TechsetCompilerT6.h"
#include "Techset/VertexDeclCompilerT6.h"
#include <memory> #include <memory>
@@ -22,6 +23,8 @@ namespace
collection.AddAssetCreator(key_value_pairs::CreateCompilerT6(memory, zone, zoneDefinition.m_zone_definition, zoneStates)); collection.AddAssetCreator(key_value_pairs::CreateCompilerT6(memory, zone, zoneDefinition.m_zone_definition, zoneStates));
collection.AddAssetCreator(techset::CreateCompilerT6(memory, searchPath)); collection.AddAssetCreator(techset::CreateCompilerT6(memory, searchPath));
collection.AddSubAssetCreator(techset::CreateVertexDeclCompilerT6(memory));
} }
void ConfigurePostProcessors(AssetCreatorCollection& collection, void ConfigurePostProcessors(AssetCreatorCollection& collection,

View File

@@ -0,0 +1,57 @@
#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

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

View File

@@ -74,9 +74,7 @@ namespace
} }
} }
return techset::CommonVertexDeclaration{ return techset::CommonVertexDeclaration(std::move(commonRouting));
.m_routing = std::move(commonRouting),
};
} }
techset::CommonShaderArg ConvertToCommonArg(const MaterialShaderArgument& arg) techset::CommonShaderArg ConvertToCommonArg(const MaterialShaderArgument& arg)

View File

@@ -73,9 +73,7 @@ namespace
} }
} }
return techset::CommonVertexDeclaration{ return techset::CommonVertexDeclaration(std::move(commonRouting));
.m_routing = std::move(commonRouting),
};
} }
techset::CommonShaderArg ConvertToCommonArg(const MaterialShaderArgument& arg) techset::CommonShaderArg ConvertToCommonArg(const MaterialShaderArgument& arg)