From 8a99a49486faa2f65ffa42062bb0cbe4860c883c Mon Sep 17 00:00:00 2001 From: Jan Date: Fri, 6 Dec 2019 16:14:27 +0100 Subject: [PATCH] ZoneCodeGenerator: Implement template code for pointer array methods --- .../Generating/RenderingContext.cs | 9 +++- .../Templates/Loading/ArrayPointer.stg | 42 +++++++++++++++---- .../Generating/Templates/ZoneLoad.stg | 13 ++---- 3 files changed, 46 insertions(+), 18 deletions(-) diff --git a/src/ZoneCodeGenerator/Generating/RenderingContext.cs b/src/ZoneCodeGenerator/Generating/RenderingContext.cs index e3dfefe1..9149513d 100644 --- a/src/ZoneCodeGenerator/Generating/RenderingContext.cs +++ b/src/ZoneCodeGenerator/Generating/RenderingContext.cs @@ -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; + } } } diff --git a/src/ZoneCodeGenerator/Generating/Templates/Loading/ArrayPointer.stg b/src/ZoneCodeGenerator/Generating/Templates/Loading/ArrayPointer.stg index e3914535..f389bdf0 100644 --- a/src/ZoneCodeGenerator/Generating/Templates/Loading/ArrayPointer.stg +++ b/src/ZoneCodeGenerator/Generating/Templates/Loading/ArrayPointer.stg @@ -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)$ -%> \ No newline at end of file +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)$++; + } +} +>> \ No newline at end of file diff --git a/src/ZoneCodeGenerator/Generating/Templates/ZoneLoad.stg b/src/ZoneCodeGenerator/Generating/Templates/ZoneLoad.stg index 27c183c9..1d27f9ad 100644 --- a/src/ZoneCodeGenerator/Generating/Templates/ZoneLoad.stg +++ b/src/ZoneCodeGenerator/Generating/Templates/ZoneLoad.stg @@ -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)$