ZoneCodeGenerator: Remove PostProcessor for asset names and instead add a statement for command files due to different member names for names

This commit is contained in:
Jan 2019-11-21 13:35:38 +01:00
parent 9b9256d2cb
commit c547520ae8
7 changed files with 188 additions and 64 deletions

View File

@ -65,17 +65,22 @@ block normal XFILE_BLOCK_PHYSICAL;
// ========================================= // =========================================
use XModelPieces; use XModelPieces;
set string name; set string name;
set name name;
set count pieces numpieces; set count pieces numpieces;
// ========================================= // =========================================
// PhysPreset // PhysPreset
// ========================================= // =========================================
set string PhysPreset::name; use PhysPreset;
set string name;
set name name;
// ========================================= // =========================================
// PhysConstraints // PhysConstraints
// ========================================= // =========================================
set string PhysConstraints::name; use PhysConstraints;
set string name;
set name name;
use PhysConstraint; use PhysConstraint;
set scriptstring targetname; set scriptstring targetname;
@ -87,6 +92,7 @@ set scriptstring target_ent2;
// ========================================= // =========================================
use DestructibleDef; use DestructibleDef;
set string name; set string name;
set name name;
set count pieces numPieces; set count pieces numPieces;
// DestructiblePiece // DestructiblePiece
@ -100,6 +106,7 @@ set scriptstring DestructibleStage::showBone;
// ========================================= // =========================================
use XAnimParts; use XAnimParts;
set string name; set string name;
set name name;
set scriptstring names; set scriptstring names;
set count names boneCount[9]; set count names boneCount[9];
set count notify notifyCount; set count notify notifyCount;
@ -176,6 +183,7 @@ set count u::frames::frames size + 1;
// ========================================= // =========================================
use XModel; use XModel;
set string name; set string name;
set name name;
set scriptstring boneNames; set scriptstring boneNames;
set reusable boneNames; set reusable boneNames;
set count boneNames numBones; set count boneNames numBones;
@ -266,6 +274,7 @@ set count plane 1;
// ========================================= // =========================================
use Material; use Material;
set string info::name; set string info::name;
set name info::name;
set reusable textureTable; set reusable textureTable;
set count textureTable textureCount; set count textureTable textureCount;
set reusable constantTable; set reusable constantTable;
@ -284,6 +293,7 @@ set count rasterizerState 0;
// ========================================= // =========================================
use MaterialTechniqueSet; use MaterialTechniqueSet;
set string name; set string name;
set name name;
set reusable techniques; set reusable techniques;
// MaterialTechnique // MaterialTechnique
@ -338,6 +348,7 @@ set count u::literalConst 1;
// ========================================= // =========================================
use GfxImage; use GfxImage;
set string name; set string name;
set name name;
reorder: reorder:
name name
texture; texture;
@ -355,6 +366,7 @@ set arraysize GfxImageLoadDef::data resourceSize;
// ========================================= // =========================================
use SndBank; use SndBank;
set string name; set string name;
set name name;
set count alias aliasCount; set count alias aliasCount;
set count aliasIndex aliasCount; set count aliasIndex aliasCount;
set count radverbs radverbCount; set count radverbs radverbCount;
@ -389,50 +401,86 @@ set count data dataSize;
// ========================================= // =========================================
// SndPatch // SndPatch
// ========================================= // =========================================
use SndPatch;
set string name;
set name name;
// ========================================= // =========================================
// clipMap_t // clipMap_t
// ========================================= // =========================================
use clipMap_t;
set string name;
set name name;
// ========================================= // =========================================
// ComWorld // ComWorld
// ========================================= // =========================================
use ComWorld;
set string name;
set name name;
// ========================================= // =========================================
// GameWorldSp // GameWorldSp
// ========================================= // =========================================
use GameWorldSp;
set string name;
set name name;
// ========================================= // =========================================
// GameWorldMp // GameWorldMp
// ========================================= // =========================================
use GameWorldMp;
set string name;
set name name;
// ========================================= // =========================================
// MapEnts // MapEnts
// ========================================= // =========================================
use MapEnts;
set string name;
set name name;
// ========================================= // =========================================
// GfxWorld // GfxWorld
// ========================================= // =========================================
use GfxWorld;
set string name;
set name name;
// ========================================= // =========================================
// GfxLightDef // GfxLightDef
// ========================================= // =========================================
use GfxLightDef;
set string name;
set name name;
// ========================================= // =========================================
// Font_s // Font_s
// ========================================= // =========================================
use Font_s;
set string fontName;
set name fontName;
// ========================================= // =========================================
// FontIcon // FontIcon
// ========================================= // =========================================
use FontIcon;
set string name;
set name name;
// ========================================= // =========================================
// MenuList // MenuList
// ========================================= // =========================================
use MenuList;
set string name;
set name name;
// ========================================= // =========================================
// menuDef_t // menuDef_t
// ========================================= // =========================================
use menuDef_t;
set string window::name;
set name window::name;
// ========================================= // =========================================
// LocalizeEntry // LocalizeEntry
@ -440,42 +488,67 @@ set count data dataSize;
use LocalizeEntry; use LocalizeEntry;
set string value; set string value;
set string name; set string name;
set name name;
// ========================================= // =========================================
// WeaponVariantDef // WeaponVariantDef
// ========================================= // =========================================
use WeaponVariantDef;
set string szInternalName;
set name szInternalName;
// ========================================= // =========================================
// WeaponAttachment // WeaponAttachment
// ========================================= // =========================================
use WeaponAttachment;
set string szInternalName;
set name szInternalName;
// ========================================= // =========================================
// WeaponAttachmentUnique // WeaponAttachmentUnique
// ========================================= // =========================================
use WeaponAttachmentUnique;
set string szInternalName;
set name szInternalName;
// ========================================= // =========================================
// WeaponCamo // WeaponCamo
// ========================================= // =========================================
use WeaponCamo;
set string name;
set name name;
// ========================================= // =========================================
// SndDriverGlobals // SndDriverGlobals
// ========================================= // =========================================
use SndDriverGlobals;
set string name;
set name name;
// ========================================= // =========================================
// FxEffectDef // FxEffectDef
// ========================================= // =========================================
use FxEffectDef;
set string name;
set name name;
// FxElemVisuals
use FxElemVisuals; use FxElemVisuals;
set condition anonymous never; set condition anonymous never;
// ========================================= // =========================================
// FxImpactTable // FxImpactTable
// ========================================= // =========================================
use FxImpactTable;
set string name;
set name name;
// ========================================= // =========================================
// RawFile // RawFile
// ========================================= // =========================================
use RawFile; use RawFile;
set string name; set string name;
set name name;
set count buffer len + 1; set count buffer len + 1;
// ========================================= // =========================================
@ -483,6 +556,7 @@ set count buffer len + 1;
// ========================================= // =========================================
use StringTable; use StringTable;
set string name; set string name;
set name name;
set count values columnCount * rowCount; set count values columnCount * rowCount;
set count cellIndex columnCount * rowCount; set count cellIndex columnCount * rowCount;
@ -492,16 +566,23 @@ set string StringTableCell::string;
// ========================================= // =========================================
// LeaderboardDef // LeaderboardDef
// ========================================= // =========================================
use LeaderboardDef;
set string name;
set name name;
// ========================================= // =========================================
// XGlobals // XGlobals
// ========================================= // =========================================
use XGlobals;
set string name;
set name name;
// ========================================= // =========================================
// ddlRoot_t // ddlRoot_t
// ========================================= // =========================================
use ddlRoot_t; use ddlRoot_t;
set string name; set string name;
set name name;
set count ddlDef 1; set count ddlDef 1;
// ddlDef_t // ddlDef_t
@ -526,6 +607,13 @@ set string members;
set count members memberCount; set count members memberCount;
set count hashTable memberCount; set count hashTable memberCount;
// =========================================
// Glasses
// =========================================
use Glasses;
set string name;
set name name;
// ========================================= // =========================================
// EmblemSet // EmblemSet
// ========================================= // =========================================
@ -535,6 +623,7 @@ set count hashTable memberCount;
// ========================================= // =========================================
use ScriptParseTree; use ScriptParseTree;
set string name; set string name;
set name name;
set count buffer len + 1; set count buffer len + 1;
// ========================================= // =========================================
@ -542,6 +631,7 @@ set count buffer len + 1;
// ========================================= // =========================================
use KeyValuePairs; use KeyValuePairs;
set string name; set string name;
set name name;
set count keyValuePairs numVariables; set count keyValuePairs numVariables;
// KeyValuePair // KeyValuePair
@ -552,6 +642,7 @@ set string KeyValuePair::value;
// ========================================= // =========================================
use VehicleDef; use VehicleDef;
set string name; set string name;
set name name;
set string turretWeapon; set string turretWeapon;
set string gunnerWeapon; set string gunnerWeapon;
set string sndNames; set string sndNames;
@ -578,25 +669,37 @@ set string accelGraphName;
// ========================================= // =========================================
// MemoryBlock // MemoryBlock
// ========================================= // =========================================
use MemoryBlock;
set string name;
set name name;
// ========================================= // =========================================
// AddonMapEnts // AddonMapEnts
// ========================================= // =========================================
use AddonMapEnts;
set string name;
set name name;
// ========================================= // =========================================
// TracerDef // TracerDef
// ========================================= // =========================================
use TracerDef;
set string name;
set name name;
// ========================================= // =========================================
// SkinnedVertsDef // SkinnedVertsDef
// ========================================= // =========================================
set string SkinnedVertsDef::name; use SkinnedVertsDef;
set string name;
set name name;
// ========================================= // =========================================
// Qdb // Qdb
// ========================================= // =========================================
use Qdb; use Qdb;
set string name; set string name;
set name name;
set count buffer len + 1; set count buffer len + 1;
// ========================================= // =========================================
@ -604,18 +707,28 @@ set count buffer len + 1;
// ========================================= // =========================================
use Slug; use Slug;
set string name; set string name;
set name name;
set count buffer len + 1; set count buffer len + 1;
// ========================================= // =========================================
// FootstepTableDef // FootstepTableDef
// ========================================= // =========================================
use FootstepTableDef;
set string name;
set name name;
// ========================================= // =========================================
// FootstepFXTableDef // FootstepFXTableDef
// ========================================= // =========================================
use FootstepFXTableDef;
set string name;
set name name;
// ========================================= // =========================================
// ZBarrierDef // ZBarrierDef
// ========================================= // =========================================
use ZBarrierDef;
set string name;
set name name;
// EOF // EOF

View File

@ -16,7 +16,7 @@ HeaderSinglePtrLoadMethodDeclaration(structure) ::= "void LoadPtr_$structure.Typ
HeaderArrayPtrLoadMethodDeclaration(structure) ::= "void LoadArray_$structure.Type.Name$(bool atStreamStart, size_t count);" HeaderArrayPtrLoadMethodDeclaration(structure) ::= "void LoadArray_$structure.Type.Name$(bool atStreamStart, size_t count);"
HeaderLoadMethodDeclaration(structure) ::= "void Load_$structure.Type.Name$(bool atStreamStart);" HeaderLoadMethodDeclaration(structure) ::= "void Load_$structure.Type.Name$(bool atStreamStart);"
HeaderGetNameMethodDeclaration(asset) ::= "static std::string GetAssetName($asset.Type.FullName$* p$asset.Type.Name$);" HeaderGetNameMethodDeclaration(asset) ::= "static std::string GetAssetName($asset.Type.FullName$* pAsset);"
HeaderAssetLoadMethodDeclaration(asset) ::= "void LoadAsset_$asset.Type.Name$($asset.Type.FullName$** pAsset);" HeaderAssetLoadMethodDeclaration(asset) ::= "void LoadAsset_$asset.Type.Name$($asset.Type.FullName$** pAsset);"
HeaderMainLoadMethodDeclaration(asset) ::= "void Load($asset.Type.FullName$** pAsset);" HeaderMainLoadMethodDeclaration(asset) ::= "void Load($asset.Type.FullName$** pAsset);"
@ -246,10 +246,10 @@ void $LoaderClassName(context.Asset)$::Load($context.Asset.Type.FullName$** pAss
>> >>
GetNameMethod(context) ::= << GetNameMethod(context) ::= <<
std::string $LoaderClassName(context.Asset)$::GetAssetName($context.Asset.Type.FullName$* p$context.Asset.Type.Name$) std::string $LoaderClassName(context.Asset)$::GetAssetName($context.Asset.Type.FullName$* pAsset)
{ {
$if(context.Asset.NameChain)$ $if(context.Asset.NameChain)$
return p$context.Asset.Type.Name$->$first(context.Asset.NameChain):{member | $member.Member.Name$}$$rest(context.Asset.NameChain):{member | .$member.Member.Name$}$; return pAsset->$first(context.Asset.NameChain):{member | $member.Member.Name$}$$rest(context.Asset.NameChain):{member | .$member.Member.Name$}$;
$else$ $else$
return "$context.Asset.Type.Name$"; return "$context.Asset.Type.Name$";
$endif$ $endif$

View File

@ -13,7 +13,6 @@ namespace ZoneCodeGenerator.Parsing.CommandFile
{ {
private static readonly IDataPostProcessor[] postProcessors = private static readonly IDataPostProcessor[] postProcessors =
{ {
new PostProcessorAssetName(),
new PostProcessorDefaultBlock(), new PostProcessorDefaultBlock(),
new PostProcessorUsages(), new PostProcessorUsages(),
new PostProcessorLeafs() new PostProcessorLeafs()

View File

@ -20,6 +20,7 @@ namespace ZoneCodeGenerator.Parsing.CommandFile.Impl
new TestCondition(), new TestCondition(),
new TestCount(), new TestCount(),
new TestGame(), new TestGame(),
new TestName(),
new TestReorder(), new TestReorder(),
new TestReusable(), new TestReusable(),
new TestScriptString(), new TestScriptString(),

View File

@ -1,56 +0,0 @@
using System.Collections.Generic;
using System.Linq;
using ZoneCodeGenerator.Domain;
using ZoneCodeGenerator.Domain.Information;
using ZoneCodeGenerator.Persistence;
namespace ZoneCodeGenerator.Parsing.CommandFile.PostProcessor
{
class PostProcessorAssetName : IDataPostProcessor
{
private const string NameMemberName = "name";
private static List<MemberInformation> FindNameMember(StructureInformation information)
{
var nameMemberInformation =
information.OrderedMembers.FirstOrDefault(memberInformation =>
memberInformation.Member.Name.Equals(NameMemberName));
if (nameMemberInformation != null)
{
var result = new List<MemberInformation> {nameMemberInformation};
return result;
}
foreach (var embeddedMembers in information.OrderedMembers.Where(memberInformation =>
memberInformation.Computations.IsEmbeddedReference && memberInformation.StructureType != null))
{
var embeddedMemberName = FindNameMember(embeddedMembers.StructureType);
if (embeddedMemberName == null) continue;
embeddedMemberName.Insert(0, embeddedMembers);
return embeddedMemberName;
}
return null;
}
public bool PostProcess(IDataRepository repository)
{
var assetDataTypes =
repository.GetAllStructs()
.AsEnumerable<DataTypeWithMembers>()
.Concat(repository.GetAllUnions())
.Select(repository.GetInformationFor)
.Where(information => information.IsAsset);
foreach (var assetInformation in assetDataTypes)
{
assetInformation.NameChain = FindNameMember(assetInformation);
}
return true;
}
}
}

View File

@ -0,0 +1,67 @@
using System;
using System.Linq;
using ZoneCodeGenerator.Domain.Information;
using ZoneCodeGenerator.Parsing.Matching;
using ZoneCodeGenerator.Parsing.Matching.Matchers;
using ZoneCodeGenerator.Parsing.Testing;
namespace ZoneCodeGenerator.Parsing.CommandFile.Tests
{
class TestName : AbstractTokenTest<ICommandParserState>
{
private const string MemberTypeNameToken = "name";
private static readonly TokenMatcher[] matchers = {
new MatcherLiteral("set"),
new MatcherLiteral("name"),
new MatcherTypename().WithName(MemberTypeNameToken),
new MatcherLiteral(";")
};
public TestName() : base(matchers)
{
}
protected override void ProcessMatch(ICommandParserState state)
{
var typeName = NextMatch(MemberTypeNameToken);
var typeNameParts = typeName.Split(new[] { "::" }, StringSplitOptions.None);
StructureInformation structure;
if (state.DataTypeInUse != null &&
state.GetMembersFromParts(typeNameParts, state.DataTypeInUse, out var memberList))
{
structure = state.DataTypeInUse;
}
else if (state.GetTypenameAndMembersFromParts(typeNameParts, out structure, out memberList))
{
// Do nothing
}
else
{
throw new TestFailedException($"Could not find type '{typeName}'.");
}
if (memberList == null || !memberList.Any())
{
throw new TestFailedException("Need to specify a member when trying to set to a structure name.");
}
for (var i = 0; i < memberList.Count - 1; i++)
{
if (!memberList[i].Computations.IsEmbeddedReference)
{
throw new TestFailedException("Can only add embedded members to name chain.");
}
}
if (!memberList[memberList.Count - 1].IsString)
{
throw new TestFailedException("Final name member must be a string.");
}
structure.NameChain = memberList;
}
}
}

View File

@ -789,7 +789,7 @@ struct SndBank
struct SndPatch struct SndPatch
{ {
char *name; const char *name;
unsigned int elementCount; unsigned int elementCount;
unsigned int *elements; unsigned int *elements;
}; };