From 799d3cbce7244c5c3ec7710ea4a01612507075fb Mon Sep 17 00:00:00 2001 From: Jan Date: Wed, 30 Oct 2019 15:01:45 +0100 Subject: [PATCH] ZoneCodeGenerator: Change block Statement to get the number of fastfileblock from the enum entry instead of manually specifying it --- src/ZoneCode/Game/T6/T6_Commands.txt | 14 +++++------ .../Domain/FastFileStructure/FastFileBlock.cs | 4 ++-- .../Parsing/CommandFile/Tests/TestBlock.cs | 24 +++++++++++-------- src/ZoneCommon/Game/T6/T6.h | 13 ---------- src/ZoneCommon/Game/T6/T6_Assets.h | 13 ++++++++++ 5 files changed, 36 insertions(+), 32 deletions(-) diff --git a/src/ZoneCode/Game/T6/T6_Commands.txt b/src/ZoneCode/Game/T6/T6_Commands.txt index 5828d1e9..116f0074 100644 --- a/src/ZoneCode/Game/T6/T6_Commands.txt +++ b/src/ZoneCode/Game/T6/T6_Commands.txt @@ -52,13 +52,13 @@ asset FootstepFXTableDef ASSET_TYPE_FOOTSTEPFX_TABLE; asset ZBarrierDef ASSET_TYPE_ZBARRIER; // Setup blocks -block 0 temp XFILE_BLOCK_TEMP default; -block 1 runtime XFILE_BLOCK_RUNTIME_VIRTUAL default; -block 2 runtime XFILE_BLOCK_RUNTIME_PHYSICAL; -block 3 delay XFILE_BLOCK_DELAY_VIRTUAL default; -block 4 delay XFILE_BLOCK_DELAY_PHYSICAL; -block 5 normal XFILE_BLOCK_VIRTUAL default; -block 6 normal XFILE_BLOCK_PHYSICAL; +block temp XFILE_BLOCK_TEMP default; +block runtime XFILE_BLOCK_RUNTIME_VIRTUAL default; +block runtime XFILE_BLOCK_RUNTIME_PHYSICAL; +block delay XFILE_BLOCK_DELAY_VIRTUAL default; +block delay XFILE_BLOCK_DELAY_PHYSICAL; +block normal XFILE_BLOCK_VIRTUAL default; +block normal XFILE_BLOCK_PHYSICAL; // ========================================= // XModelPieces diff --git a/src/ZoneCodeGenerator/Domain/FastFileStructure/FastFileBlock.cs b/src/ZoneCodeGenerator/Domain/FastFileStructure/FastFileBlock.cs index afacb5c2..558a409c 100644 --- a/src/ZoneCodeGenerator/Domain/FastFileStructure/FastFileBlock.cs +++ b/src/ZoneCodeGenerator/Domain/FastFileStructure/FastFileBlock.cs @@ -11,7 +11,7 @@ } public string Name { get; } - public int Index { get; } + public long Index { get; } public Type BlockType { get; } public bool IsDefault { get; } public bool IsTemp => BlockType == Type.Temp; @@ -19,7 +19,7 @@ public bool IsDelay => BlockType == Type.Delay; public bool IsNormal => BlockType == Type.Normal; - public FastFileBlock(string name, int index, Type blockType, bool isDefault) + public FastFileBlock(string name, long index, Type blockType, bool isDefault) { Name = name; Index = index; diff --git a/src/ZoneCodeGenerator/Parsing/CommandFile/Tests/TestBlock.cs b/src/ZoneCodeGenerator/Parsing/CommandFile/Tests/TestBlock.cs index 2c127335..ee72cb86 100644 --- a/src/ZoneCodeGenerator/Parsing/CommandFile/Tests/TestBlock.cs +++ b/src/ZoneCodeGenerator/Parsing/CommandFile/Tests/TestBlock.cs @@ -9,19 +9,17 @@ namespace ZoneCodeGenerator.Parsing.CommandFile.Tests { class TestBlock : AbstractTokenTest { - private const string BlockNumberToken = "num"; private const string BlockTypeToken = "type"; - private const string BlockNameToken = "name"; + private const string BlockEnumMemberToken = "enumEntry"; private const string DefaultToken = "default"; private static readonly TokenMatcher[] matchers = { - new MatcherLiteral("block"), - new MatcherNumber().WithName(BlockNumberToken), + new MatcherLiteral("block"), new MatcherName().WithName(BlockTypeToken), - new MatcherName().WithName(BlockNameToken), - new MatcherGroupLoop(MatcherGroupLoop.LoopMode.ZeroOneMultiple,new MatcherGroupOr( + new MatcherName().WithName(BlockEnumMemberToken), + new MatcherGroupOptional( new MatcherLiteral("default").WithName(DefaultToken) - )), + ), new MatcherLiteral(";") }; @@ -32,8 +30,14 @@ namespace ZoneCodeGenerator.Parsing.CommandFile.Tests protected override void ProcessMatch(ICommandParserState state) { - var blockName = NextMatch(BlockNameToken); - var blockNumber = int.Parse(NextMatch(BlockNumberToken)); + var blockEnumEntryName = NextMatch(BlockEnumMemberToken); + var blockEnumEntry = state.Repository.GetAllEnums() + .SelectMany(_enum => _enum.Members) + .FirstOrDefault(member => member.Name.Equals(blockEnumEntryName)); + if (blockEnumEntry == null) + { + throw new TestFailedException($"Could not find enum entry '{blockEnumEntryName}' for block."); + } var blockTypeInput = NextMatch(BlockTypeToken); if (!Enum.TryParse(blockTypeInput, true, out FastFileBlock.Type blockType)) @@ -44,7 +48,7 @@ namespace ZoneCodeGenerator.Parsing.CommandFile.Tests throw new TestFailedException($"Unknown fastfile block type '{blockTypeInput}'. Must be one of the following: {string.Join(", ", blockTypeValues)}"); } - var block = new FastFileBlock(blockName, blockNumber, blockType, HasMatcherTokens(DefaultToken)); + var block = new FastFileBlock(blockEnumEntry.Name, blockEnumEntry.Value, blockType, HasMatcherTokens(DefaultToken)); state.FastFileBlocks.Add(block); } diff --git a/src/ZoneCommon/Game/T6/T6.h b/src/ZoneCommon/Game/T6/T6.h index ac0a89b4..80f2d324 100644 --- a/src/ZoneCommon/Game/T6/T6.h +++ b/src/ZoneCommon/Game/T6/T6.h @@ -6,19 +6,6 @@ namespace T6 { #include "T6_Assets.h" - enum XFileBlock - { - XFILE_BLOCK_TEMP, - XFILE_BLOCK_RUNTIME_VIRTUAL, - XFILE_BLOCK_RUNTIME_PHYSICAL, - XFILE_BLOCK_DELAY_VIRTUAL, - XFILE_BLOCK_DELAY_PHYSICAL, - XFILE_BLOCK_VIRTUAL, - XFILE_BLOCK_PHYSICAL, - XFILE_BLOCK_STREAMER_RESERVE, - MAX_XFILE_COUNT, - }; - struct ScriptStringList { int count; diff --git a/src/ZoneCommon/Game/T6/T6_Assets.h b/src/ZoneCommon/Game/T6/T6_Assets.h index 039749d2..810303a6 100644 --- a/src/ZoneCommon/Game/T6/T6_Assets.h +++ b/src/ZoneCommon/Game/T6/T6_Assets.h @@ -285,6 +285,19 @@ enum XAssetType ASSET_TYPE_FULL_COUNT = 0x40, }; +enum XFileBlock +{ + XFILE_BLOCK_TEMP, + XFILE_BLOCK_RUNTIME_VIRTUAL, + XFILE_BLOCK_RUNTIME_PHYSICAL, + XFILE_BLOCK_DELAY_VIRTUAL, + XFILE_BLOCK_DELAY_PHYSICAL, + XFILE_BLOCK_VIRTUAL, + XFILE_BLOCK_PHYSICAL, + XFILE_BLOCK_STREAMER_RESERVE, + MAX_XFILE_COUNT, +}; + union XAssetHeader { //XModelPieces *xmodelPieces; // Not an asset