mirror of
https://github.com/Laupetin/OpenAssetTools.git
synced 2025-04-19 15:52:53 +00:00
feat: recognize indirect asset refs when marking assets
This commit is contained in:
parent
2dd4eaf54f
commit
fef815e708
@ -243,6 +243,10 @@ namespace T6
|
||||
break;
|
||||
}
|
||||
|
||||
case WFT_ANIM_NAME:
|
||||
FillFromString(std::string(field.szName), field.iOffset);
|
||||
break;
|
||||
|
||||
case WFT_NUM_FIELD_TYPES:
|
||||
default:
|
||||
assert(false);
|
||||
|
@ -14,6 +14,7 @@ set reusable attachments;
|
||||
set count attachmentUniques 95;
|
||||
set reusable attachmentUniques;
|
||||
set string szXAnims;
|
||||
set assetref szXAnims ASSET_TYPE_XANIMPARTS;
|
||||
set count szXAnims NUM_WEAP_ANIMS;
|
||||
set reusable szXAnims;
|
||||
set scriptstring hideTags;
|
||||
|
@ -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;
|
||||
|
@ -10,12 +10,14 @@ AssetLoader::AssetLoader(const asset_type_t assetType, Zone* zone, IZoneInputStr
|
||||
{
|
||||
}
|
||||
|
||||
XAssetInfoGeneric*
|
||||
AssetLoader::LinkAsset(std::string name, void* asset, std::vector<scr_string_t> scriptStrings, std::vector<XAssetInfoGeneric*> dependencies) const
|
||||
XAssetInfoGeneric* AssetLoader::LinkAsset(std::string name,
|
||||
void* asset,
|
||||
std::vector<XAssetInfoGeneric*> dependencies,
|
||||
std::vector<scr_string_t> scriptStrings,
|
||||
std::vector<IndirectAssetReference> indirectAssetReferences) const
|
||||
{
|
||||
// TODO: Add indirect asset references here
|
||||
return m_zone->m_pools->AddAsset(
|
||||
m_asset_type, std::move(name), asset, std::move(dependencies), std::move(scriptStrings), std::vector<IndirectAssetReference>());
|
||||
m_asset_type, std::move(name), asset, std::move(dependencies), std::move(scriptStrings), std::move(indirectAssetReferences));
|
||||
}
|
||||
|
||||
XAssetInfoGeneric* AssetLoader::GetAssetInfo(std::string name) const
|
||||
|
@ -16,7 +16,11 @@ protected:
|
||||
|
||||
AssetLoader(asset_type_t assetType, Zone* zone, IZoneInputStream* stream);
|
||||
|
||||
XAssetInfoGeneric* LinkAsset(std::string name, void* asset, std::vector<scr_string_t> scriptStrings, std::vector<XAssetInfoGeneric*> dependencies) const;
|
||||
XAssetInfoGeneric* LinkAsset(std::string name,
|
||||
void* asset,
|
||||
std::vector<XAssetInfoGeneric*> dependencies,
|
||||
std::vector<scr_string_t> scriptStrings,
|
||||
std::vector<IndirectAssetReference> indirectAssetReferences) const;
|
||||
|
||||
_NODISCARD XAssetInfoGeneric* GetAssetInfo(std::string name) const;
|
||||
};
|
||||
|
@ -39,6 +39,22 @@ void AssetMarker::MarkArray_ScriptString(const scr_string_t* scrStringArray, con
|
||||
Mark_ScriptString(scrStringArray[index]);
|
||||
}
|
||||
|
||||
void AssetMarker::Mark_IndirectAssetRef(asset_type_t type, const char* assetRefName)
|
||||
{
|
||||
if (!assetRefName || !assetRefName[0])
|
||||
return;
|
||||
|
||||
m_indirect_asset_references.emplace(type, assetRefName);
|
||||
}
|
||||
|
||||
void AssetMarker::MarkArray_IndirectAssetRef(const asset_type_t type, const char** assetRefNames, const size_t count)
|
||||
{
|
||||
assert(assetRefNames != nullptr);
|
||||
|
||||
for (size_t index = 0; index < count; index++)
|
||||
Mark_IndirectAssetRef(type, assetRefNames[index]);
|
||||
}
|
||||
|
||||
XAssetInfoGeneric* AssetMarker::GetAssetInfoByName(std::string name) const
|
||||
{
|
||||
return m_zone->m_pools->GetAsset(m_asset_type, std::move(name));
|
||||
@ -71,3 +87,16 @@ std::vector<scr_string_t> AssetMarker::GetUsedScriptStrings() const
|
||||
|
||||
return usedScriptStrings;
|
||||
}
|
||||
|
||||
std::vector<IndirectAssetReference> AssetMarker::GetIndirectAssetReferences() const
|
||||
{
|
||||
std::vector<IndirectAssetReference> assetReferences;
|
||||
if (!m_indirect_asset_references.empty())
|
||||
{
|
||||
assetReferences.reserve(m_indirect_asset_references.size());
|
||||
for (const auto& assetReference : m_indirect_asset_references)
|
||||
assetReferences.emplace_back(assetReference);
|
||||
}
|
||||
|
||||
return assetReferences;
|
||||
}
|
||||
|
@ -13,6 +13,7 @@ class AssetMarker
|
||||
|
||||
std::unordered_set<XAssetInfoGeneric*> m_dependencies;
|
||||
std::unordered_set<scr_string_t> m_used_script_strings;
|
||||
std::unordered_set<IndirectAssetReference> m_indirect_asset_references;
|
||||
|
||||
protected:
|
||||
AssetMarker(asset_type_t assetType, Zone* zone);
|
||||
@ -22,6 +23,9 @@ protected:
|
||||
void Mark_ScriptString(scr_string_t scrString);
|
||||
void MarkArray_ScriptString(const scr_string_t* scrStringArray, size_t count);
|
||||
|
||||
void Mark_IndirectAssetRef(asset_type_t type, const char* assetRefName);
|
||||
void MarkArray_IndirectAssetRef(asset_type_t type, const char** assetRefNames, size_t count);
|
||||
|
||||
_NODISCARD XAssetInfoGeneric* GetAssetInfoByName(std::string name) const;
|
||||
|
||||
Zone* m_zone;
|
||||
@ -29,4 +33,5 @@ protected:
|
||||
public:
|
||||
_NODISCARD std::vector<XAssetInfoGeneric*> GetDependencies() const;
|
||||
_NODISCARD std::vector<scr_string_t> GetUsedScriptStrings() const;
|
||||
_NODISCARD std::vector<IndirectAssetReference> GetIndirectAssetReferences() const;
|
||||
};
|
||||
|
Loading…
x
Reference in New Issue
Block a user