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:
@@ -18,6 +18,7 @@ namespace
|
||||
|
||||
constexpr const char* SUB_ASSET_TYPE_NAMES[]{
|
||||
"technique",
|
||||
"vertexdecl",
|
||||
"vertexshader",
|
||||
"pixelshader",
|
||||
};
|
||||
|
||||
@@ -53,6 +53,7 @@ namespace IW3
|
||||
enum SubAssetType
|
||||
{
|
||||
SUB_ASSET_TYPE_TECHNIQUE,
|
||||
SUB_ASSET_TYPE_VERTEX_DECL,
|
||||
SUB_ASSET_TYPE_VERTEX_SHADER,
|
||||
SUB_ASSET_TYPE_PIXEL_SHADER,
|
||||
|
||||
|
||||
@@ -21,6 +21,7 @@ namespace
|
||||
|
||||
constexpr const char* SUB_ASSET_TYPE_NAMES[]{
|
||||
"technique",
|
||||
"vertexdecl",
|
||||
"vertexshader",
|
||||
"pixelshader",
|
||||
};
|
||||
|
||||
@@ -63,6 +63,7 @@ namespace T5
|
||||
enum SubAssetType
|
||||
{
|
||||
SUB_ASSET_TYPE_TECHNIQUE,
|
||||
SUB_ASSET_TYPE_VERTEX_DECL,
|
||||
SUB_ASSET_TYPE_VERTEX_SHADER,
|
||||
SUB_ASSET_TYPE_PIXEL_SHADER,
|
||||
|
||||
|
||||
@@ -74,6 +74,7 @@ namespace
|
||||
|
||||
constexpr const char* SUB_ASSET_TYPE_NAMES[]{
|
||||
"technique",
|
||||
"vertexdecl",
|
||||
"vertexshader",
|
||||
"pixelshader",
|
||||
};
|
||||
|
||||
@@ -83,6 +83,7 @@ namespace T6
|
||||
enum SubAssetType
|
||||
{
|
||||
SUB_ASSET_TYPE_TECHNIQUE,
|
||||
SUB_ASSET_TYPE_VERTEX_DECL,
|
||||
SUB_ASSET_TYPE_VERTEX_SHADER,
|
||||
SUB_ASSET_TYPE_PIXEL_SHADER,
|
||||
|
||||
@@ -288,8 +289,9 @@ namespace T6
|
||||
using AssetZBarrier = Asset<ASSET_TYPE_ZBARRIER, ZBarrierDef>;
|
||||
|
||||
using SubAssetTechnique = SubAsset<SUB_ASSET_TYPE_TECHNIQUE, MaterialTechnique>;
|
||||
using SubAssetVertexShader = SubAsset<SUB_ASSET_TYPE_VERTEX_SHADER, MaterialTechnique>;
|
||||
using SubAssetPixelShader = SubAsset<SUB_ASSET_TYPE_PIXEL_SHADER, MaterialTechnique>;
|
||||
using SubAssetVertexDecl = SubAsset<SUB_ASSET_TYPE_VERTEX_DECL, MaterialVertexDeclaration>;
|
||||
using SubAssetVertexShader = SubAsset<SUB_ASSET_TYPE_VERTEX_SHADER, MaterialVertexShader>;
|
||||
using SubAssetPixelShader = SubAsset<SUB_ASSET_TYPE_PIXEL_SHADER, MaterialPixelShader>;
|
||||
} // namespace T6
|
||||
|
||||
DEFINE_ASSET_NAME_ACCESSOR(T6::AssetPhysPreset, name);
|
||||
|
||||
@@ -207,4 +207,18 @@ namespace techset
|
||||
|
||||
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
|
||||
|
||||
@@ -234,6 +234,11 @@ namespace techset
|
||||
class CommonVertexDeclaration
|
||||
{
|
||||
public:
|
||||
CommonVertexDeclaration() = default;
|
||||
explicit CommonVertexDeclaration(std::vector<CommonStreamRouting> routing);
|
||||
|
||||
void SortRoutingEntries();
|
||||
|
||||
std::vector<CommonStreamRouting> m_routing;
|
||||
};
|
||||
|
||||
|
||||
67
src/ObjCommon/Techset/CommonVertexDeclCreator.cpp
Normal file
67
src/ObjCommon/Techset/CommonVertexDeclCreator.cpp
Normal 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
|
||||
11
src/ObjCommon/Techset/CommonVertexDeclCreator.h
Normal file
11
src/ObjCommon/Techset/CommonVertexDeclCreator.h
Normal 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);
|
||||
}
|
||||
@@ -5,6 +5,7 @@
|
||||
#include "Image/ImageIwdPostProcessor.h"
|
||||
#include "KeyValuePairs/KeyValuePairsCompilerT6.h"
|
||||
#include "Techset/TechsetCompilerT6.h"
|
||||
#include "Techset/VertexDeclCompilerT6.h"
|
||||
|
||||
#include <memory>
|
||||
|
||||
@@ -22,6 +23,8 @@ namespace
|
||||
|
||||
collection.AddAssetCreator(key_value_pairs::CreateCompilerT6(memory, zone, zoneDefinition.m_zone_definition, zoneStates));
|
||||
collection.AddAssetCreator(techset::CreateCompilerT6(memory, searchPath));
|
||||
|
||||
collection.AddSubAssetCreator(techset::CreateVertexDeclCompilerT6(memory));
|
||||
}
|
||||
|
||||
void ConfigurePostProcessors(AssetCreatorCollection& collection,
|
||||
|
||||
57
src/ObjCompiling/Game/T6/Techset/VertexDeclCompilerT6.cpp
Normal file
57
src/ObjCompiling/Game/T6/Techset/VertexDeclCompilerT6.cpp
Normal 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
|
||||
11
src/ObjCompiling/Game/T6/Techset/VertexDeclCompilerT6.h
Normal file
11
src/ObjCompiling/Game/T6/Techset/VertexDeclCompilerT6.h
Normal 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);
|
||||
}
|
||||
@@ -74,9 +74,7 @@ namespace
|
||||
}
|
||||
}
|
||||
|
||||
return techset::CommonVertexDeclaration{
|
||||
.m_routing = std::move(commonRouting),
|
||||
};
|
||||
return techset::CommonVertexDeclaration(std::move(commonRouting));
|
||||
}
|
||||
|
||||
techset::CommonShaderArg ConvertToCommonArg(const MaterialShaderArgument& arg)
|
||||
|
||||
@@ -73,9 +73,7 @@ namespace
|
||||
}
|
||||
}
|
||||
|
||||
return techset::CommonVertexDeclaration{
|
||||
.m_routing = std::move(commonRouting),
|
||||
};
|
||||
return techset::CommonVertexDeclaration(std::move(commonRouting));
|
||||
}
|
||||
|
||||
techset::CommonShaderArg ConvertToCommonArg(const MaterialShaderArgument& arg)
|
||||
|
||||
Reference in New Issue
Block a user