mirror of
https://github.com/Laupetin/OpenAssetTools.git
synced 2026-08-01 21:00:33 +00:00
fix: various wrong alignment values (#823)
* fix: alignment mistakes on various games * chore: reduce overhead of zcg definition with members fields * fix: make sure Material alloc alignment is 4
This commit is contained in:
@@ -42,7 +42,7 @@ namespace
|
||||
for (const auto* structure : m_env.m_used_structures)
|
||||
{
|
||||
StructureComputations computations(structure->m_info);
|
||||
if (!structure->m_info->m_definition->m_anonymous && !computations.IsAsset() && structure->m_info->m_has_matching_cross_platform_structure)
|
||||
if (!structure->m_info->m_definition->IsAnonymous() && !computations.IsAsset() && structure->m_info->m_has_matching_cross_platform_structure)
|
||||
TestMethod(structure->m_info);
|
||||
}
|
||||
|
||||
|
||||
@@ -256,6 +256,14 @@ void BaseTemplate::MakeEvaluationInternal(const IEvaluation* evaluation, std::os
|
||||
MakeOperandDynamic(dynamic_cast<const OperandDynamic*>(evaluation), str);
|
||||
}
|
||||
|
||||
std::string BaseTemplate::MakeAllocAlignment(const StructureInformation& info)
|
||||
{
|
||||
if (info.m_alloc_alignment)
|
||||
return MakeEvaluation(info.m_alloc_alignment.get());
|
||||
|
||||
return std::to_string(info.m_definition->GetAlignment());
|
||||
}
|
||||
|
||||
std::string BaseTemplate::MakeEvaluation(const IEvaluation* evaluation)
|
||||
{
|
||||
std::ostringstream str;
|
||||
|
||||
@@ -33,6 +33,7 @@ protected:
|
||||
static std::string MakeArrayIndices(const DeclarationModifierComputations& modifierComputations);
|
||||
static std::string MakeCustomActionCall(const CustomAction* action);
|
||||
static std::string MakeArrayCount(const ArrayDeclarationModifier* arrayModifier);
|
||||
static std::string MakeAllocAlignment(const StructureInformation& info);
|
||||
static std::string MakeEvaluation(const IEvaluation* evaluation);
|
||||
|
||||
static bool ShouldGenerateFillMethod(const RenderingUsedType& type);
|
||||
|
||||
@@ -138,7 +138,7 @@ namespace
|
||||
// Variable Declarations: type varType;
|
||||
for (const auto* type : m_env.m_used_types)
|
||||
{
|
||||
if (type->m_info && !type->m_info->m_definition->m_anonymous
|
||||
if (type->m_info && !type->m_info->m_definition->IsAnonymous()
|
||||
&& (!type->m_info->m_is_leaf || !type->m_info->m_has_matching_cross_platform_structure) && !StructureComputations(type->m_info).IsAsset())
|
||||
{
|
||||
LINE(VariableDecl(type->m_type))
|
||||
@@ -345,7 +345,7 @@ namespace
|
||||
|
||||
for (const auto* type : m_env.m_used_types)
|
||||
{
|
||||
if (type->m_info && !type->m_info->m_definition->m_anonymous
|
||||
if (type->m_info && !type->m_info->m_definition->IsAnonymous()
|
||||
&& (!type->m_info->m_is_leaf || !type->m_info->m_has_matching_cross_platform_structure) && !StructureComputations(type->m_info).IsAsset())
|
||||
{
|
||||
PrintVariableInitialization(type->m_type);
|
||||
@@ -480,7 +480,7 @@ namespace
|
||||
const DeclarationModifierComputations& modifier,
|
||||
const size_t nestedBaseOffset)
|
||||
{
|
||||
const auto hasAnonymousType = memberInfo.m_type && memberInfo.m_type->m_definition->m_anonymous;
|
||||
const auto hasAnonymousType = memberInfo.m_type && memberInfo.m_type->m_definition->IsAnonymous();
|
||||
|
||||
if (!hasAnonymousType)
|
||||
{
|
||||
@@ -888,10 +888,12 @@ namespace
|
||||
|
||||
void PrintLoadPtrArrayMethod_Loading(const DataDefinition* def, const StructureInformation* info) const
|
||||
{
|
||||
const auto alignment = info && def == info->m_definition ? MakeAllocAlignment(*info) : std::to_string(def->GetAlignment());
|
||||
if (info && !info->m_has_matching_cross_platform_structure && StructureComputations(info).GetDynamicMember())
|
||||
{
|
||||
assert(def == info->m_definition);
|
||||
LINE("// Alloc first for alignment, then proceed to read as game does")
|
||||
LINEF("m_stream.Alloc({0});", def->GetAlignment())
|
||||
LINEF("m_stream.Alloc({0});", alignment)
|
||||
LINEF("const auto allocSize = LoadDynamicFill_{0}(m_stream.LoadWithFill(0));", MakeSafeTypeName(def))
|
||||
LINEF("*{0} = static_cast<{1}*>(m_stream.AllocOutOfBlock(0, allocSize));", MakeTypePtrVarName(def), def->GetFullName())
|
||||
}
|
||||
@@ -901,7 +903,7 @@ namespace
|
||||
MakeTypePtrVarName(def),
|
||||
m_env.m_word_size_mismatch ? "AllocOutOfBlock" : "Alloc",
|
||||
def->GetFullName(),
|
||||
def->GetAlignment())
|
||||
alignment)
|
||||
}
|
||||
|
||||
if (info && !info->m_is_leaf)
|
||||
@@ -1989,7 +1991,7 @@ namespace
|
||||
MakeTypePtrVarName(info->m_definition),
|
||||
m_env.m_word_size_mismatch ? "AllocOutOfBlock" : "Alloc",
|
||||
info->m_definition->GetFullName(),
|
||||
info->m_definition->GetAlignment())
|
||||
MakeAllocAlignment(*info))
|
||||
|
||||
if (inTemp)
|
||||
{
|
||||
|
||||
@@ -114,7 +114,7 @@ namespace
|
||||
// Variable Declarations: type varType;
|
||||
for (const auto* type : m_env.m_used_types)
|
||||
{
|
||||
if (type->m_info && !type->m_info->m_definition->m_anonymous && !type->m_info->m_is_leaf && !StructureComputations(type->m_info).IsAsset())
|
||||
if (type->m_info && !type->m_info->m_definition->IsAnonymous() && !type->m_info->m_is_leaf && !StructureComputations(type->m_info).IsAsset())
|
||||
{
|
||||
LINE(VariableDecl(type->m_type))
|
||||
}
|
||||
@@ -267,7 +267,7 @@ namespace
|
||||
|
||||
for (const auto* type : m_env.m_used_types)
|
||||
{
|
||||
if (type->m_info && !type->m_info->m_definition->m_anonymous && !type->m_info->m_is_leaf && !StructureComputations(type->m_info).IsAsset())
|
||||
if (type->m_info && !type->m_info->m_definition->IsAnonymous() && !type->m_info->m_is_leaf && !StructureComputations(type->m_info).IsAsset())
|
||||
{
|
||||
PrintVariableInitialization(type->m_type);
|
||||
}
|
||||
|
||||
@@ -124,7 +124,7 @@ namespace
|
||||
// Variable Declarations: type varType;
|
||||
for (const auto* type : m_env.m_used_types)
|
||||
{
|
||||
if (type->m_info && !type->m_info->m_definition->m_anonymous
|
||||
if (type->m_info && !type->m_info->m_definition->IsAnonymous()
|
||||
&& (!type->m_info->m_is_leaf || !type->m_info->m_has_matching_cross_platform_structure) && !StructureComputations(type->m_info).IsAsset())
|
||||
LINE(VariableDecl(type->m_type))
|
||||
}
|
||||
@@ -138,7 +138,7 @@ namespace
|
||||
|
||||
for (const auto* type : m_env.m_used_types)
|
||||
{
|
||||
if (type->m_info && !type->m_info->m_definition->m_anonymous && !type->m_info->m_is_leaf && !StructureComputations(type->m_info).IsAsset())
|
||||
if (type->m_info && !type->m_info->m_definition->IsAnonymous() && !type->m_info->m_is_leaf && !StructureComputations(type->m_info).IsAsset())
|
||||
LINE(WrittenVariableDecl(type->m_type))
|
||||
}
|
||||
for (const auto* type : m_env.m_used_types)
|
||||
@@ -370,7 +370,7 @@ namespace
|
||||
|
||||
for (const auto* type : m_env.m_used_types)
|
||||
{
|
||||
if (type->m_info && !type->m_info->m_definition->m_anonymous
|
||||
if (type->m_info && !type->m_info->m_definition->IsAnonymous()
|
||||
&& (!type->m_info->m_is_leaf || !type->m_info->m_has_matching_cross_platform_structure) && !StructureComputations(type->m_info).IsAsset())
|
||||
PrintVariableInitialization(type->m_type);
|
||||
}
|
||||
@@ -1201,7 +1201,7 @@ namespace
|
||||
LINE("{")
|
||||
m_intendation++;
|
||||
|
||||
LINEF("m_stream->Align({0});", info->m_definition->GetAlignment())
|
||||
LINEF("m_stream->Align({0});", MakeAllocAlignment(*info))
|
||||
LINEF("m_stream->ReusableAddOffset(*{0});", MakeTypePtrVarName(info->m_definition))
|
||||
LINE("")
|
||||
if (!info->m_is_leaf)
|
||||
@@ -1282,7 +1282,7 @@ namespace
|
||||
const DeclarationModifierComputations& modifier,
|
||||
const size_t nestedBaseOffset)
|
||||
{
|
||||
const auto hasAnonymousType = memberInfo.m_type && memberInfo.m_type->m_definition->m_anonymous;
|
||||
const auto hasAnonymousType = memberInfo.m_type && memberInfo.m_type->m_definition->IsAnonymous();
|
||||
|
||||
if (!hasAnonymousType)
|
||||
{
|
||||
@@ -1478,7 +1478,8 @@ namespace
|
||||
|
||||
void PrintWritePtrArrayMethod_Loading(const DataDefinition* def, const StructureInformation* info, const bool reusable) const
|
||||
{
|
||||
LINEF("m_stream->Align({0});", def->GetAlignment())
|
||||
const auto alignment = info && def == info->m_definition ? MakeAllocAlignment(*info) : std::to_string(def->GetAlignment());
|
||||
LINEF("m_stream->Align({0});", alignment)
|
||||
|
||||
if (reusable)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user