mirror of
https://github.com/Laupetin/OpenAssetTools.git
synced 2026-02-14 19:33:02 +00:00
chore: make sure TechsetCompilerT6 sets proper worldVertFormat
This commit is contained in:
@@ -1,16 +1,81 @@
|
||||
#include "TechsetCompilerT6.h"
|
||||
|
||||
#include "Game/T6/T6.h"
|
||||
#include "Game/T6/Techset/TechsetConstantsT6.h"
|
||||
#include "Techset/CommonTechsetLoader.h"
|
||||
#include "Techset/TechsetCommon.h"
|
||||
|
||||
using namespace T6;
|
||||
|
||||
namespace
|
||||
{
|
||||
class TechsetCompilerT6 final : public AssetCreator<T6::AssetTechniqueSet>
|
||||
MaterialWorldVertexFormat GetWorldVertexFormat(const std::string& name)
|
||||
{
|
||||
if (name.contains("lit_"))
|
||||
{
|
||||
size_t texCount = 0u, normalCount = 0u;
|
||||
techset::CountWorldVertFormatParameters(name, texCount, normalCount);
|
||||
|
||||
// 0 and 1 seem to be treated equally
|
||||
texCount = std::max(texCount, 1u);
|
||||
normalCount = std::max(normalCount, 1u);
|
||||
|
||||
if (texCount == 1 && normalCount == 1)
|
||||
return MTL_WORLDVERT_TEX_1_NRM_1;
|
||||
if (texCount == 2 && normalCount == 1)
|
||||
return MTL_WORLDVERT_TEX_2_NRM_1;
|
||||
if (texCount == 2 && normalCount == 2)
|
||||
return MTL_WORLDVERT_TEX_2_NRM_2;
|
||||
if (texCount == 3 && normalCount == 1)
|
||||
return MTL_WORLDVERT_TEX_3_NRM_1;
|
||||
if (texCount == 3 && normalCount == 2)
|
||||
return MTL_WORLDVERT_TEX_3_NRM_2;
|
||||
if (texCount == 3 && normalCount == 3)
|
||||
return MTL_WORLDVERT_TEX_3_NRM_3;
|
||||
if (texCount == 4 && normalCount == 1)
|
||||
return MTL_WORLDVERT_TEX_4_NRM_1;
|
||||
if (texCount == 4 && normalCount == 2)
|
||||
return MTL_WORLDVERT_TEX_4_NRM_2;
|
||||
if (texCount == 4 && normalCount == 3)
|
||||
return MTL_WORLDVERT_TEX_4_NRM_3;
|
||||
}
|
||||
|
||||
return static_cast<MaterialWorldVertexFormat>(0);
|
||||
}
|
||||
|
||||
MaterialTechniqueSet* ConvertTechniqueSet(const techset::CommonTechset& commonTechset, MemoryManager& memory)
|
||||
{
|
||||
auto* techset = memory.Alloc<MaterialTechniqueSet>();
|
||||
techset->name = memory.Dup(commonTechset.m_name.c_str());
|
||||
techset->worldVertFormat = GetWorldVertexFormat(commonTechset.m_name);
|
||||
|
||||
return techset;
|
||||
}
|
||||
|
||||
class TechsetCompilerT6 final : public AssetCreator<AssetTechniqueSet>
|
||||
{
|
||||
public:
|
||||
TechsetCompilerT6(ISearchPath& searchPath, MemoryManager& memory)
|
||||
: m_search_path(searchPath),
|
||||
m_memory(memory)
|
||||
{
|
||||
}
|
||||
|
||||
AssetCreationResult CreateAsset(const std::string& assetName, AssetCreationContext& context) override
|
||||
{
|
||||
return AssetCreationResult::NoAction();
|
||||
bool failure = false;
|
||||
const auto commonTechset = techset::LoadCommonTechset(assetName, commonTechniqueTypeNames, m_search_path, failure);
|
||||
if (!commonTechset)
|
||||
return failure ? AssetCreationResult::Failure() : AssetCreationResult::NoAction();
|
||||
|
||||
auto* techset = ConvertTechniqueSet(*commonTechset, m_memory);
|
||||
|
||||
return AssetCreationResult::Success(context.AddAsset(AssetRegistration<AssetTechniqueSet>(assetName, techset)));
|
||||
}
|
||||
|
||||
private:
|
||||
ISearchPath& m_search_path;
|
||||
MemoryManager& m_memory;
|
||||
};
|
||||
} // namespace
|
||||
|
||||
@@ -18,6 +83,6 @@ namespace techset
|
||||
{
|
||||
std::unique_ptr<IAssetCreator> CreateCompilerT6(MemoryManager& memory, ISearchPath& searchPath)
|
||||
{
|
||||
return std::make_unique<TechsetCompilerT6>();
|
||||
return std::make_unique<TechsetCompilerT6>(searchPath, memory);
|
||||
}
|
||||
} // namespace techset
|
||||
|
||||
@@ -20,7 +20,7 @@ namespace techset
|
||||
{
|
||||
failure = false;
|
||||
|
||||
const auto fileName = GetFileNameForTechniqueName(assetName);
|
||||
const auto fileName = GetFileNameForTechsetName(assetName);
|
||||
const auto techniqueFile = searchPath.Open(fileName);
|
||||
if (!techniqueFile.IsOpen())
|
||||
return nullptr;
|
||||
@@ -36,7 +36,7 @@ namespace techset
|
||||
CommentRemovingStreamProxy commentProxy(&baseStream);
|
||||
const auto lexer = std::make_unique<SimpleLexer>(&commentProxy, std::move(lexerConfig));
|
||||
|
||||
const auto parser = std::make_unique<TechsetParser>(*lexer, techniqueTypeNames);
|
||||
const auto parser = std::make_unique<TechsetParser>(*lexer, assetName, techniqueTypeNames);
|
||||
|
||||
const auto success = parser->Parse();
|
||||
if (success)
|
||||
|
||||
@@ -72,8 +72,8 @@ namespace
|
||||
|
||||
namespace techset
|
||||
{
|
||||
TechsetParser::TechsetParser(SimpleLexer& lexer, const CommonTechniqueTypeNames& techniqueTypeNames)
|
||||
: AbstractParser(&lexer, std::make_unique<TechsetParserState>(techniqueTypeNames))
|
||||
TechsetParser::TechsetParser(SimpleLexer& lexer, std::string techsetName, const CommonTechniqueTypeNames& techniqueTypeNames)
|
||||
: AbstractParser(&lexer, std::make_unique<TechsetParserState>(std::move(techsetName), techniqueTypeNames))
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
@@ -10,9 +10,9 @@ namespace techset
|
||||
class TechsetParser final : public AbstractParser<SimpleParserValue, TechsetParserState>
|
||||
{
|
||||
public:
|
||||
TechsetParser(SimpleLexer& lexer, const CommonTechniqueTypeNames& techniqueTypeNames);
|
||||
TechsetParser(SimpleLexer& lexer, std::string techsetName, const CommonTechniqueTypeNames& techniqueTypeNames);
|
||||
[[nodiscard]] std::unique_ptr<CommonTechset> GetParsingResult() const;
|
||||
|
||||
|
||||
protected:
|
||||
const std::vector<sequence_t*>& GetTestsForState() override;
|
||||
};
|
||||
|
||||
@@ -2,9 +2,9 @@
|
||||
|
||||
namespace techset
|
||||
{
|
||||
TechsetParserState::TechsetParserState(const CommonTechniqueTypeNames& techniqueTypeNames)
|
||||
TechsetParserState::TechsetParserState(std::string techsetName, const CommonTechniqueTypeNames& techniqueTypeNames)
|
||||
: m_technique_type_names(techniqueTypeNames),
|
||||
m_definition(std::make_unique<CommonTechset>(techniqueTypeNames.GetTechniqueTypeCount()))
|
||||
m_definition(std::make_unique<CommonTechset>(std::move(techsetName), techniqueTypeNames.GetTechniqueTypeCount()))
|
||||
{
|
||||
}
|
||||
} // namespace techset
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
|
||||
#include <cstddef>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
namespace techset
|
||||
@@ -11,7 +12,7 @@ namespace techset
|
||||
class TechsetParserState
|
||||
{
|
||||
public:
|
||||
explicit TechsetParserState(const CommonTechniqueTypeNames& techniqueTypeNames);
|
||||
TechsetParserState(std::string techsetName, const CommonTechniqueTypeNames& techniqueTypeNames);
|
||||
|
||||
const CommonTechniqueTypeNames& m_technique_type_names;
|
||||
std::unique_ptr<CommonTechset> m_definition;
|
||||
|
||||
Reference in New Issue
Block a user