mirror of
https://github.com/AssetRipper/AssetRipper.TextureDecoder.git
synced 2026-11-12 18:07:28 -10:00
More optimized code generation:
* Use Half.One instead of (Half)1 * No generic instantiation for GetChannels or SetChannels * In SetChannels, only set properties that are actually used
This commit is contained in:
1 parent
92d1909562
commit
e2fba56e81
26 files changed
+188
-58
No files matched your search
@@ -25,7 +25,7 @@ internal static class Program
|
||||
{ typeof(sbyte), "sbyte.MaxValue" },
|
||||
{ typeof(short), "short.MaxValue" },
|
||||
{ typeof(ushort), "ushort.MaxValue" },
|
||||
{ typeof(Half), "(Half)1" },
|
||||
{ typeof(Half), "Half.One" },
|
||||
{ typeof(float), "1f" },
|
||||
{ typeof(double), "1d" },
|
||||
};
|
||||
@@ -173,7 +173,7 @@ internal static class Program
|
||||
|
||||
WriteGetChannels(writer, typeName);
|
||||
writer.WriteLine();
|
||||
WriteSetChannels(writer, typeName);
|
||||
WriteSetChannels(writer, type, hasRed, hasGreen, hasBlue, hasAlpha);
|
||||
|
||||
writer.Indent--;
|
||||
writer.WriteLine('}');
|
||||
@@ -187,17 +187,36 @@ internal static class Program
|
||||
writer.WriteLine($"public void GetChannels(out {typeName} r, out {typeName} g, out {typeName} b, out {typeName} a)");
|
||||
writer.WriteLine('{');
|
||||
writer.Indent++;
|
||||
writer.WriteLine("DefaultColorMethods.GetChannels(this, out r, out g, out b, out a);");
|
||||
writer.WriteLine("r = R;");
|
||||
writer.WriteLine("g = G;");
|
||||
writer.WriteLine("b = B;");
|
||||
writer.WriteLine("a = A;");
|
||||
writer.Indent--;
|
||||
writer.WriteLine('}');
|
||||
}
|
||||
|
||||
private static void WriteSetChannels(IndentedTextWriter writer, string typeName)
|
||||
private static void WriteSetChannels(IndentedTextWriter writer, Type type, bool hasRed, bool hasGreen, bool hasBlue, bool hasAlpha)
|
||||
{
|
||||
string typeName = TypeNames[type];
|
||||
writer.WriteLine($"public void SetChannels({typeName} r, {typeName} g, {typeName} b, {typeName} a)");
|
||||
writer.WriteLine('{');
|
||||
writer.Indent++;
|
||||
writer.WriteLine("DefaultColorMethods.SetChannels(ref this, r, g, b, a);");
|
||||
if (hasRed)
|
||||
{
|
||||
writer.WriteLine("R = r;");
|
||||
}
|
||||
if (hasGreen)
|
||||
{
|
||||
writer.WriteLine("G = g;");
|
||||
}
|
||||
if (hasBlue)
|
||||
{
|
||||
writer.WriteLine("B = b;");
|
||||
}
|
||||
if (hasAlpha)
|
||||
{
|
||||
writer.WriteLine("A = a;");
|
||||
}
|
||||
writer.Indent--;
|
||||
writer.WriteLine('}');
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user