mirror of
https://github.com/Laupetin/OpenAssetTools.git
synced 2025-12-07 03:37:48 +00:00
feat: dump techsets for t6
This commit is contained in:
0
src/ObjCommon/Techset/CommonShader.cpp
Normal file
0
src/ObjCommon/Techset/CommonShader.cpp
Normal file
0
src/ObjCommon/Techset/CommonShader.h
Normal file
0
src/ObjCommon/Techset/CommonShader.h
Normal file
0
src/ObjCommon/Techset/CommonTechnique.cpp
Normal file
0
src/ObjCommon/Techset/CommonTechnique.cpp
Normal file
0
src/ObjCommon/Techset/CommonTechnique.h
Normal file
0
src/ObjCommon/Techset/CommonTechnique.h
Normal file
22
src/ObjCommon/Techset/CommonTechset.cpp
Normal file
22
src/ObjCommon/Techset/CommonTechset.cpp
Normal file
@@ -0,0 +1,22 @@
|
||||
#include "CommonTechset.h"
|
||||
|
||||
#include <algorithm>
|
||||
|
||||
techset::CommonTechniqueTypeNames::CommonTechniqueTypeNames(const char** names, const size_t nameCount)
|
||||
: m_names(nameCount)
|
||||
{
|
||||
std::copy(names, &names[nameCount], m_names.data());
|
||||
}
|
||||
|
||||
const char* techset::CommonTechniqueTypeNames::GetTechniqueTypeName(const size_t techniqueTypeIndex) const
|
||||
{
|
||||
if (techniqueTypeIndex >= m_names.size())
|
||||
return nullptr;
|
||||
|
||||
return m_names[techniqueTypeIndex];
|
||||
}
|
||||
|
||||
size_t techset::CommonTechniqueTypeNames::GetTechniqueTypeCount() const
|
||||
{
|
||||
return m_names.size();
|
||||
}
|
||||
27
src/ObjCommon/Techset/CommonTechset.h
Normal file
27
src/ObjCommon/Techset/CommonTechset.h
Normal file
@@ -0,0 +1,27 @@
|
||||
#pragma once
|
||||
|
||||
#include <cstdint>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
namespace techset
|
||||
{
|
||||
class CommonTechniqueTypeNames
|
||||
{
|
||||
public:
|
||||
CommonTechniqueTypeNames(const char** names, size_t nameCount);
|
||||
|
||||
[[nodiscard]] const char* GetTechniqueTypeName(size_t techniqueTypeIndex) const;
|
||||
[[nodiscard]] size_t GetTechniqueTypeCount() const;
|
||||
|
||||
private:
|
||||
std::vector<const char*> m_names;
|
||||
};
|
||||
|
||||
class CommonTechset
|
||||
{
|
||||
public:
|
||||
std::string m_name;
|
||||
std::vector<std::string> m_technique_names;
|
||||
};
|
||||
} // namespace techset
|
||||
@@ -5,7 +5,7 @@
|
||||
#include "Game/IW4/MaterialConstantsIW4.h"
|
||||
#include "Game/IW4/ObjConstantsIW4.h"
|
||||
#include "Game/IW4/Techset/CompilerTechsetIW4.h"
|
||||
#include "Game/IW4/TechsetConstantsIW4.h"
|
||||
#include "Game/IW4/Techset/TechsetConstantsIW4.h"
|
||||
#include "Gdt/AbstractGdtEntryReader.h"
|
||||
#include "Gdt/IGdtQueryable.h"
|
||||
#include "ObjLoading.h"
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
#include "Game/IW4/IW4.h"
|
||||
#include "Game/IW4/Shader/LoaderPixelShaderIW4.h"
|
||||
#include "Game/IW4/Shader/LoaderVertexShaderIW4.h"
|
||||
#include "Game/IW4/TechsetConstantsIW4.h"
|
||||
#include "Game/IW4/Techset/TechsetConstantsIW4.h"
|
||||
#include "Shader/D3D9ShaderAnalyser.h"
|
||||
#include "Shader/ShaderCommon.h"
|
||||
#include "StateMap/StateMapReader.h"
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
#include "CompilerVertexDeclIW4.h"
|
||||
|
||||
#include "Game/IW4/IW4.h"
|
||||
#include "Game/IW4/TechsetConstantsIW4.h"
|
||||
#include "Game/IW4/Techset/TechsetConstantsIW4.h"
|
||||
#include "Utils/Logging/Log.h"
|
||||
|
||||
#include <cstring>
|
||||
|
||||
@@ -2,8 +2,7 @@
|
||||
|
||||
#include "Game/IW4/MaterialConstantsIW4.h"
|
||||
#include "Game/IW4/ObjConstantsIW4.h"
|
||||
#include "Game/IW4/TechsetConstantsIW4.h"
|
||||
#include "Utils/ClassUtils.h"
|
||||
#include "Game/IW4/Techset/TechsetConstantsIW4.h"
|
||||
#include "Utils/Logging/Log.h"
|
||||
|
||||
#pragma warning(push, 0)
|
||||
|
||||
@@ -1,9 +1,12 @@
|
||||
#include "TechsetDumperIW4.h"
|
||||
|
||||
#include "Dumping/AbstractTextDumper.h"
|
||||
#include "Game/IW4/TechsetConstantsIW4.h"
|
||||
#include "Game/IW4/Techset/TechsetConstantsIW4.h"
|
||||
#include "Pool/GlobalAssetPool.h"
|
||||
#include "Shader/D3D9ShaderAnalyser.h"
|
||||
#include "Techset/CommonTechset.h"
|
||||
#include "Techset/CommonTechsetDumper.h"
|
||||
#include "Techset/TechniqueDumpingZoneState.h"
|
||||
#include "Techset/TechsetCommon.h"
|
||||
#include "Utils/Logging/Log.h"
|
||||
|
||||
@@ -16,23 +19,8 @@
|
||||
|
||||
using namespace IW4;
|
||||
|
||||
namespace IW4
|
||||
namespace
|
||||
{
|
||||
class TechniqueDumpingZoneState final : public IZoneAssetDumperState
|
||||
{
|
||||
std::set<const MaterialTechnique*> m_dumped_techniques;
|
||||
|
||||
public:
|
||||
bool ShouldDumpTechnique(const MaterialTechnique* technique)
|
||||
{
|
||||
if (m_dumped_techniques.find(technique) != m_dumped_techniques.end())
|
||||
return false;
|
||||
|
||||
m_dumped_techniques.emplace(technique);
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
class TechniqueFileWriter : public AbstractTextDumper
|
||||
{
|
||||
void DumpStateMap() const
|
||||
@@ -472,67 +460,31 @@ namespace IW4
|
||||
}
|
||||
};
|
||||
|
||||
class TechsetFileWriter : public AbstractTextDumper
|
||||
techset::CommonTechset ConvertToCommonTechset(const MaterialTechniqueSet& techset)
|
||||
{
|
||||
bool m_last_write_was_value;
|
||||
std::vector<std::string> techniqueNames(std::extent_v<decltype(techniqueTypeNames)>);
|
||||
|
||||
public:
|
||||
explicit TechsetFileWriter(std::ostream& stream)
|
||||
: AbstractTextDumper(stream),
|
||||
m_last_write_was_value(false)
|
||||
for (auto techniqueIndex = 0u; techniqueIndex < std::extent_v<decltype(techniqueTypeNames)>; techniqueIndex++)
|
||||
{
|
||||
const auto* technique = techset.techniques[techniqueIndex];
|
||||
if (technique && technique->name)
|
||||
techniqueNames[techniqueIndex] = technique->name;
|
||||
}
|
||||
|
||||
void WriteTechniqueType(const size_t techniqueIndex)
|
||||
{
|
||||
assert(techniqueIndex < std::extent_v<decltype(techniqueTypeNames)>);
|
||||
|
||||
if (m_last_write_was_value)
|
||||
{
|
||||
m_stream << "\n";
|
||||
m_last_write_was_value = false;
|
||||
}
|
||||
m_stream << '"' << techniqueTypeNames[techniqueIndex] << "\":\n";
|
||||
}
|
||||
|
||||
void WriteTechniqueValue(const char* value)
|
||||
{
|
||||
m_last_write_was_value = true;
|
||||
|
||||
IncIndent();
|
||||
Indent();
|
||||
m_stream << value << ";\n";
|
||||
DecIndent();
|
||||
}
|
||||
|
||||
void DumpTechset(const MaterialTechniqueSet* techset)
|
||||
{
|
||||
std::vector<bool> dumpedTechniques(std::extent_v<decltype(MaterialTechniqueSet::techniques)>);
|
||||
|
||||
for (auto techniqueIndex = 0u; techniqueIndex < std::extent_v<decltype(MaterialTechniqueSet::techniques)>; techniqueIndex++)
|
||||
{
|
||||
const auto* technique = techset->techniques[techniqueIndex];
|
||||
if (technique == nullptr || dumpedTechniques[techniqueIndex])
|
||||
continue;
|
||||
|
||||
dumpedTechniques[techniqueIndex] = true;
|
||||
WriteTechniqueType(techniqueIndex);
|
||||
|
||||
for (auto nextTechniqueIndex = techniqueIndex + 1; nextTechniqueIndex < std::extent_v<decltype(MaterialTechniqueSet::techniques)>;
|
||||
nextTechniqueIndex++)
|
||||
{
|
||||
if (techset->techniques[nextTechniqueIndex] != technique)
|
||||
continue;
|
||||
|
||||
dumpedTechniques[nextTechniqueIndex] = true;
|
||||
WriteTechniqueType(nextTechniqueIndex);
|
||||
}
|
||||
|
||||
WriteTechniqueValue(technique->name);
|
||||
}
|
||||
}
|
||||
return techset::CommonTechset{
|
||||
.m_name = techset.name,
|
||||
.m_technique_names = std::move(techniqueNames),
|
||||
};
|
||||
} // namespace IW4
|
||||
}
|
||||
|
||||
void DumpTechset(const AssetDumpingContext& context, const MaterialTechniqueSet& techset)
|
||||
{
|
||||
static techset::CommonTechniqueTypeNames commonNames(techniqueTypeNames, std::extent_v<decltype(techniqueTypeNames)>);
|
||||
const auto commonTechset = ConvertToCommonTechset(techset);
|
||||
|
||||
techset::DumpCommon(commonNames, context, commonTechset);
|
||||
}
|
||||
} // namespace
|
||||
|
||||
namespace techset
|
||||
{
|
||||
@@ -543,18 +495,11 @@ namespace techset
|
||||
|
||||
void DumperIW4::DumpAsset(AssetDumpingContext& context, const XAssetInfo<AssetTechniqueSet::Type>& asset)
|
||||
{
|
||||
const auto* techset = asset.Asset();
|
||||
|
||||
const auto techsetFile = context.OpenAssetFile(GetFileNameForTechsetName(techset->name));
|
||||
|
||||
if (techsetFile)
|
||||
{
|
||||
TechsetFileWriter writer(*techsetFile);
|
||||
writer.DumpTechset(techset);
|
||||
}
|
||||
const auto* techniqueSet = asset.Asset();
|
||||
DumpTechset(context, *techniqueSet);
|
||||
|
||||
auto* techniqueState = context.GetZoneAssetDumperState<TechniqueDumpingZoneState>();
|
||||
for (const auto* technique : techset->techniques)
|
||||
for (const auto* technique : techniqueSet->techniques)
|
||||
{
|
||||
if (technique && techniqueState->ShouldDumpTechnique(technique))
|
||||
{
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
#include "TechsetDumperT6.h"
|
||||
|
||||
#include "Game/T6/Techset/TechsetConstantsT6.h"
|
||||
#include "Shader/ShaderCommon.h"
|
||||
#include "Techset/CommonTechsetDumper.h"
|
||||
|
||||
#include <sstream>
|
||||
#include <unordered_set>
|
||||
@@ -73,6 +75,31 @@ namespace
|
||||
|
||||
shaderFile->write(vertexShader.prog.loadDef.program, vertexShader.prog.loadDef.programSize);
|
||||
}
|
||||
|
||||
techset::CommonTechset ConvertToCommonTechset(const MaterialTechniqueSet& techset)
|
||||
{
|
||||
std::vector<std::string> techniqueNames(std::extent_v<decltype(techniqueTypeNames)>);
|
||||
|
||||
for (auto techniqueIndex = 0u; techniqueIndex < std::extent_v<decltype(techniqueTypeNames)>; techniqueIndex++)
|
||||
{
|
||||
const auto* technique = techset.techniques[techniqueIndex];
|
||||
if (technique && technique->name)
|
||||
techniqueNames[techniqueIndex] = technique->name;
|
||||
}
|
||||
|
||||
return techset::CommonTechset{
|
||||
.m_name = techset.name,
|
||||
.m_technique_names = std::move(techniqueNames),
|
||||
};
|
||||
}
|
||||
|
||||
void DumpTechset(const AssetDumpingContext& context, const MaterialTechniqueSet& techset)
|
||||
{
|
||||
static techset::CommonTechniqueTypeNames commonNames(techniqueTypeNames, std::extent_v<decltype(techniqueTypeNames)>);
|
||||
const auto commonTechset = ConvertToCommonTechset(techset);
|
||||
|
||||
techset::DumpCommon(commonNames, context, commonTechset);
|
||||
}
|
||||
} // namespace
|
||||
|
||||
namespace techset
|
||||
@@ -85,6 +112,8 @@ namespace techset
|
||||
void DumperT6::DumpAsset(AssetDumpingContext& context, const XAssetInfo<AssetTechniqueSet::Type>& asset)
|
||||
{
|
||||
const auto* techniqueSet = asset.Asset();
|
||||
DumpTechset(context, *techniqueSet);
|
||||
|
||||
auto* shaderState = context.GetZoneAssetDumperState<ShaderZoneState>();
|
||||
|
||||
for (const auto* technique : techniqueSet->techniques)
|
||||
|
||||
0
src/ObjWriting/Techset/CommonTechniqueDumper.cpp
Normal file
0
src/ObjWriting/Techset/CommonTechniqueDumper.cpp
Normal file
0
src/ObjWriting/Techset/CommonTechniqueDumper.h
Normal file
0
src/ObjWriting/Techset/CommonTechniqueDumper.h
Normal file
92
src/ObjWriting/Techset/CommonTechsetDumper.cpp
Normal file
92
src/ObjWriting/Techset/CommonTechsetDumper.cpp
Normal file
@@ -0,0 +1,92 @@
|
||||
#include "CommonTechsetDumper.h"
|
||||
|
||||
#include "Dumping/AbstractTextDumper.h"
|
||||
#include "Game/IW3/Material/MaterialConstantZoneStateIW3.h"
|
||||
#include "Techset/TechsetCommon.h"
|
||||
|
||||
#include <cassert>
|
||||
|
||||
using namespace techset;
|
||||
|
||||
namespace
|
||||
{
|
||||
class TechsetFileWriter : public AbstractTextDumper
|
||||
{
|
||||
public:
|
||||
TechsetFileWriter(const CommonTechniqueTypeNames& techniqueTypeNames, std::ostream& stream)
|
||||
: AbstractTextDumper(stream),
|
||||
m_last_write_was_value(false),
|
||||
m_technique_type_names(techniqueTypeNames)
|
||||
{
|
||||
}
|
||||
|
||||
void DumpTechset(const CommonTechset& techset)
|
||||
{
|
||||
const auto techniqueCount = m_technique_type_names.GetTechniqueTypeCount();
|
||||
assert(techset.m_technique_names.size() == techniqueCount);
|
||||
|
||||
std::vector<bool> dumpedTechniques(techniqueCount);
|
||||
|
||||
for (auto techniqueIndex = 0u; techniqueIndex < techniqueCount; techniqueIndex++)
|
||||
{
|
||||
const auto& technique = techset.m_technique_names[techniqueIndex];
|
||||
if (technique.empty() || dumpedTechniques[techniqueIndex])
|
||||
continue;
|
||||
|
||||
dumpedTechniques[techniqueIndex] = true;
|
||||
WriteTechniqueType(techniqueIndex);
|
||||
|
||||
for (auto nextTechniqueIndex = techniqueIndex + 1; nextTechniqueIndex < std::extent_v<decltype(IW3::MaterialTechniqueSet::techniques)>;
|
||||
nextTechniqueIndex++)
|
||||
{
|
||||
if (techset.m_technique_names[nextTechniqueIndex] != technique)
|
||||
continue;
|
||||
|
||||
dumpedTechniques[nextTechniqueIndex] = true;
|
||||
WriteTechniqueType(nextTechniqueIndex);
|
||||
}
|
||||
|
||||
WriteTechniqueValue(technique);
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
void WriteTechniqueType(const size_t techniqueIndex)
|
||||
{
|
||||
if (m_last_write_was_value)
|
||||
{
|
||||
m_stream << "\n";
|
||||
m_last_write_was_value = false;
|
||||
}
|
||||
|
||||
m_stream << '"' << m_technique_type_names.GetTechniqueTypeName(techniqueIndex) << "\":\n";
|
||||
}
|
||||
|
||||
void WriteTechniqueValue(const std::string& value)
|
||||
{
|
||||
m_last_write_was_value = true;
|
||||
|
||||
IncIndent();
|
||||
Indent();
|
||||
m_stream << value << ";\n";
|
||||
DecIndent();
|
||||
}
|
||||
|
||||
bool m_last_write_was_value;
|
||||
const CommonTechniqueTypeNames& m_technique_type_names;
|
||||
};
|
||||
} // namespace
|
||||
|
||||
namespace techset
|
||||
{
|
||||
void DumpCommon(const CommonTechniqueTypeNames& techniqueTypeNames, const AssetDumpingContext& context, const CommonTechset& techset)
|
||||
{
|
||||
const auto techsetFile = context.OpenAssetFile(GetFileNameForTechsetName(techset.m_name));
|
||||
|
||||
if (techsetFile)
|
||||
{
|
||||
TechsetFileWriter writer(techniqueTypeNames, *techsetFile);
|
||||
writer.DumpTechset(techset);
|
||||
}
|
||||
}
|
||||
} // namespace techset
|
||||
9
src/ObjWriting/Techset/CommonTechsetDumper.h
Normal file
9
src/ObjWriting/Techset/CommonTechsetDumper.h
Normal file
@@ -0,0 +1,9 @@
|
||||
#pragma once
|
||||
|
||||
#include "Dumping/AssetDumpingContext.h"
|
||||
#include "Techset/CommonTechset.h"
|
||||
|
||||
namespace techset
|
||||
{
|
||||
void DumpCommon(const CommonTechniqueTypeNames& techniqueTypeNames, const AssetDumpingContext& context, const CommonTechset& techset);
|
||||
} // namespace techset
|
||||
13
src/ObjWriting/Techset/TechniqueDumpingZoneState.cpp
Normal file
13
src/ObjWriting/Techset/TechniqueDumpingZoneState.cpp
Normal file
@@ -0,0 +1,13 @@
|
||||
#include "TechniqueDumpingZoneState.h"
|
||||
|
||||
namespace techset
|
||||
{
|
||||
bool TechniqueDumpingZoneState::ShouldDumpTechnique(const void* technique)
|
||||
{
|
||||
if (m_dumped_techniques.find(technique) != m_dumped_techniques.end())
|
||||
return false;
|
||||
|
||||
m_dumped_techniques.emplace(technique);
|
||||
return true;
|
||||
}
|
||||
} // namespace techset
|
||||
17
src/ObjWriting/Techset/TechniqueDumpingZoneState.h
Normal file
17
src/ObjWriting/Techset/TechniqueDumpingZoneState.h
Normal file
@@ -0,0 +1,17 @@
|
||||
#pragma once
|
||||
|
||||
#include "Dumping/IZoneAssetDumperState.h"
|
||||
|
||||
#include <unordered_set>
|
||||
|
||||
namespace techset
|
||||
{
|
||||
class TechniqueDumpingZoneState final : public IZoneAssetDumperState
|
||||
{
|
||||
public:
|
||||
bool ShouldDumpTechnique(const void* technique);
|
||||
|
||||
private:
|
||||
std::unordered_set<const void*> m_dumped_techniques;
|
||||
};
|
||||
} // namespace techset
|
||||
Reference in New Issue
Block a user