Skip to content

Commit

Permalink
refactor F3DEX (ToString)
Browse files Browse the repository at this point in the history
  • Loading branch information
akopetsch committed Jun 30, 2024
1 parent 14288c6 commit d6d1a28
Show file tree
Hide file tree
Showing 7 changed files with 74 additions and 76 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
// SPDX-License-Identifier: MIT

using System;

namespace SWE1R.Assets.Blocks.ModelBlock.F3DEX2
{
/// <summary>
Expand All @@ -21,10 +23,17 @@ public class GdpSetCombineLerpCommand : GraphicsCommand

#endregion

#region Properties (: GraphicsCommand)

protected override object[] MacroArguments =>
throw new NotImplementedException();

#endregion

#region Constructor

public GdpSetCombineLerpCommand() :
base(GraphicsCommandByte.G_SETCOMBINE)
base(GraphicsCommandByte.G_SETCOMBINE, "gDPSetCombineLERP")
{ }

#endregion
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
// SPDX-License-Identifier: MIT

using System;

namespace SWE1R.Assets.Blocks.ModelBlock.F3DEX2
{
/// <summary>
Expand All @@ -21,10 +23,17 @@ public class GdpSetRenderModeCommand : GraphicsCommand

#endregion

#region Properties (: GraphicsCommand)

protected override object[] MacroArguments =>
throw new NotImplementedException();

#endregion

#region Constructor

public GdpSetRenderModeCommand() :
base(GraphicsCommandByte.G_SETOTHERMODE_L)
base(GraphicsCommandByte.G_SETOTHERMODE_L, "gDPSetRenderMode")
{ }

#endregion
Expand Down
34 changes: 11 additions & 23 deletions src/SWE1R.Assets.Blocks/ModelBlock/F3DEX2/GraphicsCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,25 +26,6 @@ namespace SWE1R.Assets.Blocks.ModelBlock.F3DEX2
[Sizeof(8)]
public abstract class GraphicsCommand
{
#region Classes (helper)

protected class PropertyNameAndValue // TODO: !!!!!!! refactor class PropertyNameAndValue
{
public string Name { get; set; }
public object Value { get; set; }

public PropertyNameAndValue(string name, object value)
{
Name = name;
Value = value;
}

public override string ToString() =>
$"{Name} = {Value}";
}

#endregion

#region Properties (serialized)

[RecordTypeIdentifier(GraphicsCommandByte.G_VTX, typeof(GspVertexCommand))]
Expand All @@ -54,14 +35,21 @@ public override string ToString() =>
[RecordTypeIdentifier(GraphicsCommandByte.G_SETCOMBINE, typeof(GdpSetCombineLerpCommand))]
[RecordTypeIdentifier(GraphicsCommandByte.G_SETOTHERMODE_L, typeof(GdpSetRenderModeCommand))]
[Order(0)]
public GraphicsCommandByte Byte { get; set; }
public GraphicsCommandByte Byte { get; private set; }

public string MacroName { get; private set; }

protected abstract object[] MacroArguments { get; }

#endregion

#region Constructor

protected GraphicsCommand(GraphicsCommandByte commandByte) =>
protected GraphicsCommand(GraphicsCommandByte commandByte, string macroName)
{
Byte = commandByte;
MacroName = macroName;
}

#endregion

Expand All @@ -77,8 +65,8 @@ public virtual void Deserialize(EndianBinaryReader reader) =>

#region Methods (helper)

protected string GetString(params PropertyNameAndValue[] propertyNamesAndValues) =>
$"{GetType().Name}({string.Join(", ", propertyNamesAndValues.Select(x => x.ToString()))})";
public override string ToString() =>
$"{MacroName}({string.Join(", ", MacroArguments)})";

#endregion
}
Expand Down
23 changes: 10 additions & 13 deletions src/SWE1R.Assets.Blocks/ModelBlock/F3DEX2/Gsp1TriangleCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public class Gsp1TriangleCommand : GraphicsCommand, ITrianglesGraphicsCommand, I

#endregion

#region Properties
#region Properties (serialized)

[Order(0)]
private byte V0Padded { get; set; }
Expand All @@ -39,14 +39,21 @@ public class Gsp1TriangleCommand : GraphicsCommand, ITrianglesGraphicsCommand, I

#endregion

#region Properties (C struct)
#region Properties (C macro)

public byte V0 { get => (byte)(V0Padded >> 1); set => V0Padded = Convert.ToByte(value << 1); }
public byte V1 { get => (byte)(V1Padded >> 1); set => V1Padded = Convert.ToByte(value << 1); }
public byte V2 { get => (byte)(V2Padded >> 1); set => V2Padded = Convert.ToByte(value << 1); }

#endregion

#region Properties (: GraphicsCommand)

protected override object[] MacroArguments =>
new object[] { V0, V1, V2 };

#endregion

#region Properties (: IN64GspTrianglesCommand)

public IEnumerable<byte> Indices
Expand Down Expand Up @@ -75,7 +82,7 @@ public IEnumerable<Triangle> Triangles
#region Constructor

public Gsp1TriangleCommand() :
base(GraphicsCommandByte.G_TRI1)
base(GraphicsCommandByte.G_TRI1, "gSP1Triangle")
{ }

public Gsp1TriangleCommand(byte v0, byte v1, byte v2) :
Expand Down Expand Up @@ -110,15 +117,5 @@ public override void Deserialize(EndianBinaryReader reader)
}

#endregion

#region Methods (: object)

public override string ToString() =>
GetString(
new PropertyNameAndValue(nameof(V0), V0),
new PropertyNameAndValue(nameof(V1), V1),
new PropertyNameAndValue(nameof(V2), V2));

#endregion
}
}
24 changes: 9 additions & 15 deletions src/SWE1R.Assets.Blocks/ModelBlock/F3DEX2/Gsp2TrianglesCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public class Gsp2TrianglesCommand : GraphicsCommand, ITrianglesGraphicsCommand,

#endregion

#region Properties (C struct)
#region Properties (C macro)

public byte V00 { get => (byte)(V00Padded >> 1); set => V00Padded = Convert.ToByte(value << 1); }
public byte V01 { get => (byte)(V01Padded >> 1); set => V01Padded = Convert.ToByte(value << 1); }
Expand All @@ -56,6 +56,13 @@ public class Gsp2TrianglesCommand : GraphicsCommand, ITrianglesGraphicsCommand,

#endregion

#region Properties (: GraphicsCommand)

protected override object[] MacroArguments =>
new object[] { V00, V01, V02, V10, V11, V12 };

#endregion

#region Properties (: IN64GspTrianglesCommand)

public IEnumerable<byte> Indices
Expand Down Expand Up @@ -90,7 +97,7 @@ public IEnumerable<Triangle> Triangles
#region Constructor

public Gsp2TrianglesCommand() :
base(GraphicsCommandByte.G_TRI2)
base(GraphicsCommandByte.G_TRI2, "gSP2Triangles")
{ }

public Gsp2TrianglesCommand(
Expand Down Expand Up @@ -137,18 +144,5 @@ public override void Deserialize(EndianBinaryReader reader)
}

#endregion

#region Methods (: object)

public override string ToString() =>
GetString(
new PropertyNameAndValue(nameof(V00), V00),
new PropertyNameAndValue(nameof(V01), V01),
new PropertyNameAndValue(nameof(V02), V02),
new PropertyNameAndValue(nameof(V10), V10),
new PropertyNameAndValue(nameof(V11), V11),
new PropertyNameAndValue(nameof(V12), V12));

#endregion
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,17 +36,24 @@ public class GspCullDisplayListCommand : GraphicsCommand, ICustomSerializable

#endregion

#region Properties (C struct)
#region Properties (C macro)

public byte V0 { get => (byte)(V0Padded >> 1); set => V0Padded = Convert.ToByte(value << 1); }
public byte VN { get => (byte)(VNPadded >> 1); set => VNPadded = Convert.ToByte(value << 1); }

#endregion

#region Properties (: GraphicsCommand)

protected override object[] MacroArguments =>
new object[] { V0, VN };

#endregion

#region Constructor

public GspCullDisplayListCommand() :
base(GraphicsCommandByte.G_CULLDL)
base(GraphicsCommandByte.G_CULLDL, "gSPCullDisplayList")
{ }

public GspCullDisplayListCommand(byte v0, byte vn) :
Expand Down Expand Up @@ -80,14 +87,5 @@ public override void Deserialize(EndianBinaryReader reader)
}

#endregion

#region Methods (: object)

public override string ToString() =>
GetString(
new PropertyNameAndValue(nameof(V0), V0),
new PropertyNameAndValue(nameof(VN), VN));

#endregion
}
}
27 changes: 15 additions & 12 deletions src/SWE1R.Assets.Blocks/ModelBlock/F3DEX2/GspVertexCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,21 @@ public class GspVertexCommand : GraphicsCommand

#endregion

#region Properties (helper)
#region Properties (C macro)

public byte N
{
get => Convert.ToByte(NPadded >> NPadding);
set => NPadded = (short)(value << NPadding);
}

public int V0 =>
V0PlusN - N;

#endregion

#region Properties (helper)

public byte V0PlusN
{
get => (byte)(V0PlusNPadded >> 1);
Expand All @@ -62,14 +69,19 @@ public int VerticesStartIndex
set => V.Index = value;
}

public int V0 => V0PlusN - N;
#endregion

#region Properties (: GraphicsCommand)

protected override object[] MacroArguments =>
new object[] { $"allVertices + {V.Index}", N, V0 }; // TODO: string literal

#endregion

#region Constructor

public GspVertexCommand() :
base(GraphicsCommandByte.G_VTX)
base(GraphicsCommandByte.G_VTX, "gSPVertex")
{ }

public GspVertexCommand(IList<Vtx> vertices, int verticesStartIndex, int n, int v0PlusN) :
Expand All @@ -85,14 +97,5 @@ public GspVertexCommand(IList<Vtx> vertices, int verticesStartIndex, int n, int
}

#endregion

#region Methods (: object)

public override string ToString() =>
GetString(
new PropertyNameAndValue(nameof(N), N),
new PropertyNameAndValue(nameof(VerticesStartIndex), VerticesStartIndex));

#endregion
}
}

0 comments on commit d6d1a28

Please sign in to comment.