ZoneCodeGenerator: Add reusable statement for commands to be able to tell the generator that a member can be a fastfile offset and not nessecarly a following pointer

This commit is contained in:
Jan 2019-11-15 14:47:45 +01:00
parent 271c819e97
commit b15ce90fbb
4 changed files with 99 additions and 4 deletions

View File

@ -177,11 +177,17 @@ set count u::frames::frames size + 1;
use XModel; use XModel;
set string name; set string name;
set scriptstring boneNames; set scriptstring boneNames;
set reusable boneNames;
set count boneNames numBones; set count boneNames numBones;
set reusable parentList;
set count parentList numBones - numRootBones; set count parentList numBones - numRootBones;
set reusable quats;
set count quats numBones - numRootBones; set count quats numBones - numRootBones;
set reusable trans;
set count trans numBones - numRootBones; set count trans numBones - numRootBones;
set reusable partClassification;
set count partClassification numBones; set count partClassification numBones;
set reusable baseMat;
set count baseMat numBones; set count baseMat numBones;
set count surfs numsurfs; set count surfs numsurfs;
set count materialHandles numsurfs; set count materialHandles numsurfs;
@ -193,9 +199,12 @@ set count collmaps numCollmaps;
// XSurface // XSurface
use XSurface; use XSurface;
set condition verts0 !(flags & 1); set condition verts0 !(flags & 1);
set reusable verts0;
set count verts0 vertCount; set count verts0 vertCount;
set count vb0 0; set count vb0 0;
set reusable vertList;
set count vertList vertListCount; set count vertList vertListCount;
set reusable triIndices;
set count triIndices triCount; set count triIndices triCount;
set count indexBuffer 0; set count indexBuffer 0;
reorder: reorder:
@ -206,10 +215,12 @@ reorder:
// XSurfaceVertexInfo // XSurfaceVertexInfo
use XSurfaceVertexInfo; use XSurfaceVertexInfo;
set reusable vertsBlend;
set count vertsBlend vertCount[0] set count vertsBlend vertCount[0]
+ 3 * vertCount[1] + 3 * vertCount[1]
+ 5 * vertCount[2] + 5 * vertCount[2]
+ 7 * vertCount[3]; + 7 * vertCount[3];
set reusable tensionData;
set count tensionData vertCount[0] set count tensionData vertCount[0]
+ 3 * vertCount[1] + 3 * vertCount[1]
+ 5 * vertCount[2] + 5 * vertCount[2]
@ -233,24 +244,33 @@ set count Collmap::geomList 1;
set count PhysGeomList::geoms count; set count PhysGeomList::geoms count;
// PhysGeomInfo // PhysGeomInfo
set count PhysGeomInfo::brush 1; use PhysGeomInfo;
set reusable brush;
set count brush 1;
// BrushWrapper // BrushWrapper
use BrushWrapper; use BrushWrapper;
set count sides numsides; set count sides numsides;
set reusable verts;
set count verts numverts; set count verts numverts;
set reusable planes;
set count planes numsides; set count planes numsides;
// cbrushside_t // cbrushside_t
set count cbrushside_t::plane 1; use cbrushside_t;
set reusable plane;
set count plane 1;
// ========================================= // =========================================
// Material // Material
// ========================================= // =========================================
use Material; use Material;
set string info::name; set string info::name;
set reusable textureTable;
set count textureTable textureCount; set count textureTable textureCount;
set reusable constantTable;
set count constantTable constantCount; set count constantTable constantCount;
set reusable stateBitsTable;
set count stateBitsTable stateBitsCount; set count stateBitsTable stateBitsCount;
// GfxStateBits // GfxStateBits
@ -262,7 +282,9 @@ set count rasterizerState 0;
// ========================================= // =========================================
// MaterialTechniqueSet // MaterialTechniqueSet
// ========================================= // =========================================
set string MaterialTechniqueSet::name; use MaterialTechniqueSet;
set string name;
set reusable techniques;
// MaterialTechnique // MaterialTechnique
use MaterialTechnique; use MaterialTechnique;
@ -275,6 +297,9 @@ reorder:
// MaterialPass // MaterialPass
use MaterialPass; use MaterialPass;
set count args perPrimArgCount + perObjArgCount + stableArgCount; set count args perPrimArgCount + perObjArgCount + stableArgCount;
set reusable vertexShader;
set reusable vertexDecl;
set reusable pixelShader;
reorder: reorder:
vertexShader vertexShader
vertexDecl vertexDecl
@ -306,6 +331,7 @@ set count GfxPixelShaderLoadDef::program programSize;
use MaterialShaderArgument; use MaterialShaderArgument;
//set condition u::literalConst type == MTL_ARG_LITERAL_VERTEX_CONST || type == MTL_ARG_LITERAL_PIXEL_CONST; //set condition u::literalConst type == MTL_ARG_LITERAL_VERTEX_CONST || type == MTL_ARG_LITERAL_PIXEL_CONST;
//set condition u::literalConst type == 1 || type == 7; //set condition u::literalConst type == 1 || type == 7;
set reusable u::literalConst;
set count u::literalConst 1; set count u::literalConst 1;
// ========================================= // =========================================
@ -318,7 +344,9 @@ reorder:
texture; texture;
// GfxTexture // GfxTexture
set condition GfxTexture::loadDef always; use GfxTexture;
set reusable loadDef;
set condition loadDef always;
// GfxImageLoadDef // GfxImageLoadDef
set arraysize GfxImageLoadDef::data resourceSize; set arraysize GfxImageLoadDef::data resourceSize;
@ -337,6 +365,7 @@ set count scriptIdLookups scriptIdLookupCount;
// SndAliasList // SndAliasList
use SndAliasList; use SndAliasList;
set string name; set string name;
set reusable head;
set count head count; set count head count;
// SndAlias // SndAlias

View File

@ -11,6 +11,7 @@ namespace ZoneCodeGenerator.Domain.Information
public Variable Member { get; set; } public Variable Member { get; set; }
public bool IsString { get; set; } public bool IsString { get; set; }
public bool IsScriptString { get; set; } public bool IsScriptString { get; set; }
public bool IsReusable { get; set; }
public IEvaluation Condition { get; set; } public IEvaluation Condition { get; set; }
public MemberComputations Computations => new MemberComputations(this); public MemberComputations Computations => new MemberComputations(this);
@ -21,6 +22,7 @@ namespace ZoneCodeGenerator.Domain.Information
StructureType = structureType; StructureType = structureType;
IsString = false; IsString = false;
IsScriptString = false; IsScriptString = false;
IsReusable = false;
Condition = null; Condition = null;
} }

View File

@ -21,6 +21,7 @@ namespace ZoneCodeGenerator.Parsing.CommandFile.Impl
new TestCount(), new TestCount(),
new TestGame(), new TestGame(),
new TestReorder(), new TestReorder(),
new TestReusable(),
new TestScriptString(), new TestScriptString(),
new TestString(), new TestString(),
new TestUse() new TestUse()

View File

@ -0,0 +1,63 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using ZoneCodeGenerator.Domain;
using ZoneCodeGenerator.Parsing.Matching;
using ZoneCodeGenerator.Parsing.Matching.Matchers;
using ZoneCodeGenerator.Parsing.Testing;
namespace ZoneCodeGenerator.Parsing.CommandFile.Tests
{
class TestReusable : AbstractTokenTest<ICommandParserState>
{
private const string MemberTypeNameToken = "name";
private static readonly TokenMatcher[] matchers = {
new MatcherLiteral("set"),
new MatcherLiteral("reusable"),
new MatcherTypename().WithName(MemberTypeNameToken),
new MatcherLiteral(";")
};
public TestReusable() : base(matchers)
{
}
protected override void ProcessMatch(ICommandParserState state)
{
var typeName = NextMatch(MemberTypeNameToken);
var typeNameParts = typeName.Split(new[] { "::" }, StringSplitOptions.None);
if (state.DataTypeInUse != null &&
state.GetMembersFromParts(typeNameParts, state.DataTypeInUse, out var memberList))
{
// Do nothing
}
else if (state.GetTypenameAndMembersFromParts(typeNameParts, out _, 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 string.");
}
var lastMember = memberList.Last();
if (!lastMember.Computations.IsNonEmbeddedReference)
{
throw new TestFailedException($"Specified member '{lastMember.Member.Name}' is not a pointer reference and therefore cannot be reusable.");
}
lastMember.IsReusable = true;
}
}
}