mirror of
https://github.com/Laupetin/OpenAssetTools.git
synced 2025-06-10 14:58:10 -05:00
feat: recognize indirect asset refs when marking assets
This commit is contained in:
@ -8,6 +8,7 @@ MemberInformation::MemberInformation(StructureInformation* parent, StructureInfo
|
||||
m_is_script_string(false),
|
||||
m_is_reusable(false),
|
||||
m_is_leaf(false),
|
||||
m_fast_file_block(nullptr)
|
||||
m_fast_file_block(nullptr),
|
||||
m_asset_ref(nullptr)
|
||||
{
|
||||
}
|
||||
|
@ -23,6 +23,7 @@ public:
|
||||
std::unique_ptr<IEvaluation> m_condition;
|
||||
std::unique_ptr<IEvaluation> m_alloc_alignment;
|
||||
const FastFileBlock* m_fast_file_block;
|
||||
const EnumMember* m_asset_ref;
|
||||
|
||||
MemberInformation(StructureInformation* parent, StructureInformation* type, Variable* member);
|
||||
};
|
||||
|
@ -1075,7 +1075,8 @@ class ZoneLoadTemplate::Internal final : BaseTemplate
|
||||
LINE("marker.Mark(*pAsset);")
|
||||
LINE("")
|
||||
LINE("m_asset_info = reinterpret_cast<XAssetInfo<"
|
||||
<< info->m_definition->GetFullName() << ">*>(LinkAsset(GetAssetName(*pAsset), *pAsset, marker.GetUsedScriptStrings(), marker.GetDependencies()));")
|
||||
<< info->m_definition->GetFullName()
|
||||
<< ">*>(LinkAsset(GetAssetName(*pAsset), *pAsset, marker.GetDependencies(), marker.GetUsedScriptStrings(), marker.GetIndirectAssetReferences()));")
|
||||
LINE("*pAsset = m_asset_info->Asset();")
|
||||
|
||||
m_intendation--;
|
||||
|
@ -225,6 +225,27 @@ class ZoneMarkTemplate::Internal final : BaseTemplate
|
||||
}
|
||||
}
|
||||
|
||||
void MarkMember_AssetRef(StructureInformation* info,
|
||||
MemberInformation* member,
|
||||
const DeclarationModifierComputations& modifier,
|
||||
const MemberLoadType loadType) const
|
||||
{
|
||||
if (loadType == MemberLoadType::POINTER_ARRAY)
|
||||
{
|
||||
LINE("MarkArray_IndirectAssetRef(" << member->m_asset_ref->m_name << ", " << MakeMemberAccess(info, member, modifier) << ", "
|
||||
<< MakeEvaluation(modifier.GetArrayPointerCountEvaluation()) << ");")
|
||||
}
|
||||
else if (loadType == MemberLoadType::SINGLE_POINTER)
|
||||
{
|
||||
LINE("Mark_IndirectAssetRef(" << member->m_asset_ref->m_name << ", " << MakeMemberAccess(info, member, modifier) << ");")
|
||||
}
|
||||
else
|
||||
{
|
||||
assert(false);
|
||||
LINE("#error unsupported loadType " << static_cast<int>(loadType) << " for scriptstring")
|
||||
}
|
||||
}
|
||||
|
||||
void MarkMember_Asset(StructureInformation* info,
|
||||
MemberInformation* member,
|
||||
const DeclarationModifierComputations& modifier,
|
||||
@ -308,6 +329,10 @@ class ZoneMarkTemplate::Internal final : BaseTemplate
|
||||
{
|
||||
MarkMember_ScriptString(info, member, modifier, loadType);
|
||||
}
|
||||
else if (member->m_asset_ref)
|
||||
{
|
||||
MarkMember_AssetRef(info, member, modifier, loadType);
|
||||
}
|
||||
else if (member->m_type && StructureComputations(member->m_type).IsAsset())
|
||||
{
|
||||
MarkMember_Asset(info, member, modifier, loadType);
|
||||
@ -541,7 +566,8 @@ class ZoneMarkTemplate::Internal final : BaseTemplate
|
||||
if (computations.ShouldIgnore() || computations.IsInRuntimeBlock())
|
||||
return;
|
||||
|
||||
if (member->m_is_script_string || member->m_type && (member->m_type->m_requires_marking || StructureComputations(member->m_type).IsAsset()))
|
||||
if (member->m_is_script_string || member->m_asset_ref
|
||||
|| member->m_type && (member->m_type->m_requires_marking || StructureComputations(member->m_type).IsAsset()))
|
||||
{
|
||||
if (info->m_definition->GetType() == DataDefinitionType::UNION)
|
||||
MarkMember_Condition_Union(info, member);
|
||||
|
@ -6,6 +6,7 @@
|
||||
#include "Parsing/Commands/Sequence/SequenceArrayCount.h"
|
||||
#include "Parsing/Commands/Sequence/SequenceArraySize.h"
|
||||
#include "Parsing/Commands/Sequence/SequenceAsset.h"
|
||||
#include "Parsing/Commands/Sequence/SequenceAssetRef.h"
|
||||
#include "Parsing/Commands/Sequence/SequenceBlock.h"
|
||||
#include "Parsing/Commands/Sequence/SequenceCondition.h"
|
||||
#include "Parsing/Commands/Sequence/SequenceCount.h"
|
||||
@ -33,6 +34,7 @@ const std::vector<CommandsParser::sequence_t*>& CommandsParser::GetTestsForState
|
||||
new SequenceArrayCount(),
|
||||
new SequenceArraySize(),
|
||||
new SequenceAsset(),
|
||||
new SequenceAssetRef(),
|
||||
new SequenceBlock(),
|
||||
new SequenceCondition(),
|
||||
new SequenceCount(),
|
||||
|
@ -0,0 +1,72 @@
|
||||
#include "SequenceAssetRef.h"
|
||||
|
||||
#include "Parsing/Commands/Matcher/CommandsCommonMatchers.h"
|
||||
#include "Parsing/Commands/Matcher/CommandsMatcherFactory.h"
|
||||
|
||||
#include <algorithm>
|
||||
|
||||
SequenceAssetRef::SequenceAssetRef()
|
||||
{
|
||||
const CommandsMatcherFactory create(this);
|
||||
|
||||
AddLabeledMatchers(CommandsCommonMatchers::Typename(this), CommandsCommonMatchers::LABEL_TYPENAME);
|
||||
AddMatchers({
|
||||
create.Keyword("set"),
|
||||
create.Keyword("assetref"),
|
||||
create.Label(CommandsCommonMatchers::LABEL_TYPENAME).Capture(CAPTURE_TYPE),
|
||||
create.Identifier().Capture(CAPTURE_ASSET_TYPE_ENUM_ENTRY),
|
||||
create.Char(';'),
|
||||
});
|
||||
}
|
||||
|
||||
void SequenceAssetRef::ProcessMatch(CommandsParserState* state, SequenceResult<CommandsParserValue>& result) const
|
||||
{
|
||||
const auto& enumEntryToken = result.NextCapture(CAPTURE_ASSET_TYPE_ENUM_ENTRY);
|
||||
const auto* enumMember = state->GetRepository()->GetEnumMemberByName(enumEntryToken.IdentifierValue());
|
||||
if (enumMember == nullptr)
|
||||
throw ParsingException(enumEntryToken.GetPos(), "Unknown asset type enum entry");
|
||||
|
||||
const auto& typeNameToken = result.NextCapture(CAPTURE_TYPE);
|
||||
|
||||
StructureInformation* type;
|
||||
std::vector<MemberInformation*> members;
|
||||
if (!state->GetTypenameAndMembersFromTypename(typeNameToken.TypeNameValue(), type, members))
|
||||
throw ParsingException(typeNameToken.GetPos(), "Unknown type");
|
||||
|
||||
if (members.empty())
|
||||
throw ParsingException(typeNameToken.GetPos(), "Need to specify a member when trying to mark as string.");
|
||||
|
||||
auto* lastMember = members.back();
|
||||
const auto* typeDecl = lastMember->m_member->m_type_declaration.get();
|
||||
auto hasPointerRef = false;
|
||||
|
||||
while (true)
|
||||
{
|
||||
if (!hasPointerRef)
|
||||
{
|
||||
const auto& modifiers = typeDecl->m_declaration_modifiers;
|
||||
hasPointerRef = std::any_of(modifiers.begin(),
|
||||
modifiers.end(),
|
||||
[](const std::unique_ptr<DeclarationModifier>& modifier)
|
||||
{
|
||||
return modifier->GetType() == DeclarationModifierType::POINTER;
|
||||
});
|
||||
}
|
||||
|
||||
if (typeDecl->m_type->GetType() == DataDefinitionType::TYPEDEF)
|
||||
{
|
||||
const auto* typedefDef = dynamic_cast<const TypedefDefinition*>(typeDecl->m_type);
|
||||
typeDecl = typedefDef->m_type_declaration.get();
|
||||
}
|
||||
else
|
||||
break;
|
||||
}
|
||||
|
||||
if (!hasPointerRef)
|
||||
throw ParsingException(typeNameToken.GetPos(), "Invalid type for string, must be a pointer");
|
||||
|
||||
if (typeDecl->m_type->GetType() != DataDefinitionType::BASE_TYPE)
|
||||
throw ParsingException(typeNameToken.GetPos(), "Invalid type for string, must be a base type");
|
||||
|
||||
lastMember->m_asset_ref = enumMember;
|
||||
}
|
@ -0,0 +1,17 @@
|
||||
#pragma once
|
||||
|
||||
#include "Parsing/Commands/Impl/CommandsParser.h"
|
||||
|
||||
class SequenceAssetRef final : public CommandsParser::sequence_t
|
||||
{
|
||||
static constexpr auto TAG_DEFAULT = 1;
|
||||
|
||||
static constexpr auto CAPTURE_TYPE = 1;
|
||||
static constexpr auto CAPTURE_ASSET_TYPE_ENUM_ENTRY = 2;
|
||||
|
||||
protected:
|
||||
void ProcessMatch(CommandsParserState* state, SequenceResult<CommandsParserValue>& result) const override;
|
||||
|
||||
public:
|
||||
SequenceAssetRef();
|
||||
};
|
@ -44,8 +44,8 @@ bool MarkingRequiredPostProcessor::CalculateRequiresMarking(std::unordered_set<c
|
||||
if (skip)
|
||||
continue;
|
||||
|
||||
// Any ScriptStrings or Strings need to be processed.
|
||||
if (member->m_is_script_string || member->m_type && member->m_type->m_asset_enum_entry)
|
||||
// Any script strings, asset refs and assets need to be processed.
|
||||
if (member->m_is_script_string || member->m_asset_ref || member->m_type && member->m_type->m_asset_enum_entry)
|
||||
{
|
||||
info->m_requires_marking = true;
|
||||
return true;
|
||||
|
Reference in New Issue
Block a user