mirror of
https://github.com/Laupetin/OpenAssetTools.git
synced 2025-04-20 16:15:43 +00:00
ZoneCodeGenerator: Implement template code for pointer array methods
This commit is contained in:
parent
406cfae0f5
commit
8a99a49486
@ -18,6 +18,7 @@ namespace ZoneCodeGenerator.Generating
|
||||
public bool NonEmbeddedReferenceExists { get; set; }
|
||||
public bool ArrayReferenceExists { get; set; }
|
||||
public bool PointerArrayReferenceExists { get; set; }
|
||||
public bool PointerArrayReferenceIsReusable { get; set; }
|
||||
|
||||
public UsedType(DataType type, StructureInformation information)
|
||||
{
|
||||
@ -27,6 +28,7 @@ namespace ZoneCodeGenerator.Generating
|
||||
NonEmbeddedReferenceExists = false;
|
||||
ArrayReferenceExists = false;
|
||||
PointerArrayReferenceExists = false;
|
||||
PointerArrayReferenceIsReusable = false;
|
||||
}
|
||||
}
|
||||
|
||||
@ -87,8 +89,13 @@ namespace ZoneCodeGenerator.Generating
|
||||
if (member.Computations.ContainsArrayPointerReference || member.Computations.ContainsArrayReference)
|
||||
usedType.ArrayReferenceExists = true;
|
||||
|
||||
if (member.Computations.ContainsPointerArrayReference)
|
||||
if (member.Computations.ContainsPointerArrayReference && !member.IsString)
|
||||
{
|
||||
usedType.PointerArrayReferenceExists = true;
|
||||
|
||||
if (member.IsReusable)
|
||||
usedType.PointerArrayReferenceIsReusable = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -58,14 +58,42 @@ if ($TypeVarName(structure.Type)$->$member.Member.Name$$PrintArrayIndices(refere
|
||||
LoadArrayPointer_Condition(context, structure, member, reference) ::= <<
|
||||
$if(member.Condition)$$\\$
|
||||
if($PrintEvaluation(member.Condition)$)
|
||||
|
||||
LoadPointerArrayMethod_PointerCheck(context, type, structure, reusable) ::= <<
|
||||
if (*$TypePtrVarName(type)$)
|
||||
{
|
||||
$LoadArrayPointer_PointerCheck(context, structure, member, reference)$
|
||||
$if(structure && structure.IsAsset)$
|
||||
$LoadPointerArrayMethod_Asset(context, type, structure)$
|
||||
$else$
|
||||
$if(reusable)$
|
||||
if(*$TypePtrVarName(type)$ == PTR_FOLLOWING)
|
||||
{
|
||||
$LoadPointerArrayMethod_Loading(context, type, structure)$
|
||||
}
|
||||
else
|
||||
{
|
||||
*$TypePtrVarName(type)$ = m_stream->ConvertOffsetToPointer(*$TypePtrVarName(type)$);
|
||||
}
|
||||
$else$
|
||||
$LoadPointerArrayMethod_Loading(context, type, structure)$
|
||||
$endif$
|
||||
$endif$
|
||||
}
|
||||
$else$$\\$
|
||||
$LoadArrayPointer_PointerCheck(context, structure, member, reference)$$\\$
|
||||
$endif$
|
||||
>>
|
||||
|
||||
LoadArrayPointer(context, structure, member, reference) ::= <%
|
||||
$LoadArrayPointer_Condition(context, structure, member, reference)$
|
||||
%>
|
||||
LoadPointerArrayMethod(context, type, structure, reusable) ::= <<
|
||||
void $LoaderClassName(context.Asset)$::LoadPtrArray_$SafeTypeName(type)$(const bool atStreamStart, const size_t count)
|
||||
{
|
||||
assert($TypePtrVarName(type)$ != nullptr);
|
||||
|
||||
if(atStreamStart)
|
||||
m_stream->Load<$type.FullName$*>($TypePtrVarName(type)$, count);
|
||||
|
||||
for(size_t index = 0; index < count; index++)
|
||||
{
|
||||
$LoadPointerArrayMethod_PointerCheck(context, type, structure, reusable)$
|
||||
|
||||
$TypePtrVarName(type)$++;
|
||||
}
|
||||
}
|
||||
>>
|
@ -167,13 +167,6 @@ void $LoaderClassName(context.Asset)$::LoadPtr_$structure.Type.Name$(const bool
|
||||
}
|
||||
>>
|
||||
|
||||
LoadPointerArrayMethod(context, type, structure) ::= <<
|
||||
void $LoaderClassName(context.Asset)$::LoadPtrArray_$SafeTypeName(type)$(const bool atStreamStart, const size_t count)
|
||||
{
|
||||
|
||||
}
|
||||
>>
|
||||
|
||||
LoadArrayMethod(context, type, structure) ::= <<
|
||||
void $LoaderClassName(context.Asset)$::LoadArray_$type.Name$(const bool atStreamStart, const size_t count)
|
||||
{
|
||||
@ -200,12 +193,12 @@ void $LoaderClassName(context.Asset)$::Load_$structure.Type.Name$(const bool atS
|
||||
|
||||
if(atStreamStart)
|
||||
m_stream->Load<$structure.Type.FullName$>($TypeVarName(structure.Type)$);$\\$
|
||||
$if(structure.Block.IsTemp)$
|
||||
$if(structure.ReferenceFromNonDefaultNormalBlockExists || structure.IsAsset)$
|
||||
|
||||
m_stream->PushBlock($context.DefaultNormalBlock.Name$);$\\$
|
||||
$endif$
|
||||
$structure.OrderedMembers:{member | $LoadMemberIfNeedsTreatment(context, structure, member)$}$
|
||||
$if(structure.Block.IsTemp)$
|
||||
$if(structure.ReferenceFromNonDefaultNormalBlockExists || structure.IsAsset)$
|
||||
|
||||
m_stream->PopBlock();
|
||||
$endif$
|
||||
@ -288,7 +281,7 @@ using namespace $context.Game$;
|
||||
|
||||
$ConstructorMethod(context)$
|
||||
|
||||
$context.UsedTypes:{usedType | $if(usedType.PointerArrayReferenceExists)$$LoadPointerArrayMethod(context, usedType.Type, usedType.Information)$$\n$$\n$$endif$}$
|
||||
$context.UsedTypes:{usedType | $if(usedType.PointerArrayReferenceExists)$$LoadPointerArrayMethod(context, usedType.Type, usedType.Information, usedType.PointerArrayReferenceIsReusable)$$\n$$\n$$endif$}$
|
||||
$context.UsedTypes:{usedType | $if(usedType.ArrayReferenceExists && usedType.Information && !usedType.Information.IsLeaf)$$LoadArrayMethod(context, usedType.Type, usedType.Information)$$\n$$\n$$endif$}$
|
||||
$context.UsedStructures:{usedStructure | $if(!usedStructure.IsLeaf && !usedStructure.IsAsset)$$LoadMethod(context, usedStructure)$$\n$$\n$$endif$}$
|
||||
$LoadMethod(context, context.Asset)$
|
||||
|
Loading…
x
Reference in New Issue
Block a user