Fix XModelSurfs being entirely loaded in temp block by adding the feature to specify a block for a struct to be able to make xmodelsurfs being loaded in normal block

This commit is contained in:
Jan 2020-09-09 11:47:09 +02:00
parent bdbfb7114e
commit 9108add01d
4 changed files with 47 additions and 25 deletions

View File

@ -199,6 +199,7 @@ set condition surfs never;
// XModelSurfs // XModelSurfs
use XModelSurfs; use XModelSurfs;
set block XFILE_BLOCK_VIRTUAL;
set string name; set string name;
set count surfs XModelLodInfo::numsurfs; // No this is not a mistake. This is how the game does it. set count surfs XModelLodInfo::numsurfs; // No this is not a mistake. This is how the game does it.

View File

@ -1,4 +1,5 @@
using System.Collections.Generic; using System.Collections.Generic;
using ZoneCodeGenerator.Domain.FastFileStructure;
using ZoneCodeGenerator.Generating.Computations; using ZoneCodeGenerator.Generating.Computations;
namespace ZoneCodeGenerator.Domain.Information namespace ZoneCodeGenerator.Domain.Information
@ -28,6 +29,7 @@ namespace ZoneCodeGenerator.Domain.Information
public bool ReferenceFromNonDefaultNormalBlockExists { get; set; } public bool ReferenceFromNonDefaultNormalBlockExists { get; set; }
public CustomAction PostLoadAction { get; set; } public CustomAction PostLoadAction { get; set; }
public FastFileBlock Block { get; set; }
public bool IsLeaf { get; set; } public bool IsLeaf { get; set; }

View File

@ -263,12 +263,15 @@ void $LoaderClassName(context.Asset)$::Load_$structure.Type.Name$(const bool atS
$else$ $else$
assert(atStreamStart);$\\$ assert(atStreamStart);$\\$
$endif$ $endif$
$if(structure.IsAsset)$ $if(structure.Block)$
m_stream->PushBlock($structure.Block.Name$);$\\$
$elseif(structure.IsAsset)$
m_stream->PushBlock($context.DefaultNormalBlock.Name$);$\\$ m_stream->PushBlock($context.DefaultNormalBlock.Name$);$\\$
$endif$ $endif$
$structure.OrderedMembers:{member | $LoadMemberIfNeedsTreatment(context, structure, member)$}$ $structure.OrderedMembers:{member | $LoadMemberIfNeedsTreatment(context, structure, member)$}$
$if(structure.IsAsset)$ $if(structure.Block || structure.IsAsset)$
m_stream->PopBlock(); m_stream->PopBlock();
$endif$ $endif$

View File

@ -1,10 +1,6 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Text;
using System.Threading.Tasks;
using ZoneCodeGenerator.Domain;
using ZoneCodeGenerator.Domain.FastFileStructure;
using ZoneCodeGenerator.Domain.Information; using ZoneCodeGenerator.Domain.Information;
using ZoneCodeGenerator.Parsing.Matching; using ZoneCodeGenerator.Parsing.Matching;
using ZoneCodeGenerator.Parsing.Matching.Matchers; using ZoneCodeGenerator.Parsing.Matching.Matchers;
@ -21,8 +17,11 @@ namespace ZoneCodeGenerator.Parsing.CommandFile.Tests
{ {
new MatcherLiteral("set"), new MatcherLiteral("set"),
new MatcherLiteral("block"), new MatcherLiteral("block"),
new MatcherTypename().WithName(TokenTypeName), new MatcherGroupOr(new MatcherGroupAnd(
new MatcherName().WithName(TokenBlockEnumEntry), new MatcherTypename().WithName(TokenTypeName),
new MatcherName().WithName(TokenBlockEnumEntry)
),
new MatcherName().WithName(TokenBlockEnumEntry)),
new MatcherLiteral(";") new MatcherLiteral(";")
}; };
@ -33,35 +32,52 @@ namespace ZoneCodeGenerator.Parsing.CommandFile.Tests
protected override void ProcessMatch(ICommandParserState state) protected override void ProcessMatch(ICommandParserState state)
{ {
var typeName = NextMatch(TokenTypeName); var typeName = NextMatch(TokenTypeName);
var typeNameParts = typeName.Split(new[] {"::"}, StringSplitOptions.None);
if (state.DataTypeInUse != null && StructureInformation typeInfo;
state.GetMembersFromParts(typeNameParts, state.DataTypeInUse, out var memberList)) List<MemberInformation> memberList;
if (typeName != null)
{ {
// Do nothing var typeNameParts = typeName.Split(new[] { "::" }, StringSplitOptions.None);
} if (state.DataTypeInUse != null &&
else if (state.GetTypenameAndMembersFromParts(typeNameParts, out _, out memberList)) state.GetMembersFromParts(typeNameParts, state.DataTypeInUse, out memberList))
{ {
// Do nothing typeInfo = state.DataTypeInUse;
}
else if (state.GetTypenameAndMembersFromParts(typeNameParts, out typeInfo, out memberList))
{
// Do nothing
}
else
{
throw new TestFailedException($"Could not find type '{typeName}'.");
}
} }
else else
{ {
throw new TestFailedException($"Could not find type '{typeName}'."); typeInfo = state.DataTypeInUse;
} memberList = new List<MemberInformation>();
if (!memberList.Any()) if(typeInfo == null)
{ throw new TestFailedException("Must specify a type or member.");
throw new TestFailedException("Must specify a member and not a type when setting a block.");
} }
var member = memberList.Last();
var blockName = NextMatch(TokenBlockEnumEntry); var blockName = NextMatch(TokenBlockEnumEntry);
var block = state.FastFileBlocks var block = state.FastFileBlocks
.FirstOrDefault(fastFileBlock => fastFileBlock.Name.Equals(blockName)); .FirstOrDefault(fastFileBlock => fastFileBlock.Name.Equals(blockName));
member.Block = if (block == null)
block ?? throw new TestFailedException($"Could not find fastfile block with name '{blockName}'"); throw new TestFailedException($"Could not find fastfile block with name '{blockName}'");
if (memberList.Any())
{
var member = memberList.Last();
member.Block = block;
}
else
{
typeInfo.Block = block;
}
} }
} }
} }