fix: Streamlines gump compilation (#969)
Changes gump compilation to use string interpolation. .NET 6 uses code generation and compile time tricks to speed up string interpolation between 15 and 30% and reduce allocations dramatically.
This commit is contained in:
parent
14b63ca48e
commit
c166e113b1
34 changed files with 853 additions and 2258 deletions
|
|
@ -1,6 +1,6 @@
|
|||
/*************************************************************************
|
||||
* ModernUO *
|
||||
* Copyright (C) 2019-2021 - ModernUO Development Team *
|
||||
* Copyright (C) 2019-2022 - ModernUO Development Team *
|
||||
* Email: hi@modernuo.com *
|
||||
* File: GumpImageTileButton.cs *
|
||||
* *
|
||||
|
|
@ -16,100 +16,55 @@
|
|||
using System.Buffers;
|
||||
using Server.Collections;
|
||||
|
||||
namespace Server.Gumps
|
||||
namespace Server.Gumps;
|
||||
|
||||
public class GumpImageTileButton : GumpEntry
|
||||
{
|
||||
public class GumpImageTileButton : GumpEntry
|
||||
public GumpImageTileButton(
|
||||
int x, int y, int normalID, int pressedID, int buttonID, GumpButtonType type, int param,
|
||||
int itemID, int hue, int width, int height
|
||||
)
|
||||
{
|
||||
public static readonly byte[] LayoutName = Gump.StringToBuffer("buttontileart");
|
||||
public static readonly byte[] LayoutTooltip = Gump.StringToBuffer(" }{ tooltip");
|
||||
X = x;
|
||||
Y = y;
|
||||
NormalID = normalID;
|
||||
PressedID = pressedID;
|
||||
ButtonID = buttonID;
|
||||
Type = type;
|
||||
Param = param;
|
||||
|
||||
// Note, on OSI, the tooltip supports ONLY clilocs as far as I can figure out,
|
||||
// and the tooltip ONLY works after the buttonTileArt (as far as I can tell from testing)
|
||||
ItemID = itemID;
|
||||
Hue = hue;
|
||||
Width = width;
|
||||
Height = height;
|
||||
}
|
||||
|
||||
public GumpImageTileButton(
|
||||
int x, int y, int normalID, int pressedID, int buttonID, GumpButtonType type, int param,
|
||||
int itemID, int hue, int width, int height, int localizedTooltip = -1
|
||||
)
|
||||
{
|
||||
X = x;
|
||||
Y = y;
|
||||
NormalID = normalID;
|
||||
PressedID = pressedID;
|
||||
ButtonID = buttonID;
|
||||
Type = type;
|
||||
Param = param;
|
||||
public int X { get; set; }
|
||||
|
||||
ItemID = itemID;
|
||||
Hue = hue;
|
||||
Width = width;
|
||||
Height = height;
|
||||
public int Y { get; set; }
|
||||
|
||||
LocalizedTooltip = localizedTooltip;
|
||||
}
|
||||
public int NormalID { get; set; }
|
||||
|
||||
public int X { get; set; }
|
||||
public int PressedID { get; set; }
|
||||
|
||||
public int Y { get; set; }
|
||||
public int ButtonID { get; set; }
|
||||
|
||||
public int NormalID { get; set; }
|
||||
public GumpButtonType Type { get; set; }
|
||||
|
||||
public int PressedID { get; set; }
|
||||
public int Param { get; set; }
|
||||
|
||||
public int ButtonID { get; set; }
|
||||
public int ItemID { get; set; }
|
||||
|
||||
public GumpButtonType Type { get; set; }
|
||||
public int Hue { get; set; }
|
||||
|
||||
public int Param { get; set; }
|
||||
public int Width { get; set; }
|
||||
|
||||
public int ItemID { get; set; }
|
||||
public int Height { get; set; }
|
||||
|
||||
public int Hue { get; set; }
|
||||
|
||||
public int Width { get; set; }
|
||||
|
||||
public int Height { get; set; }
|
||||
|
||||
public int LocalizedTooltip { get; set; }
|
||||
|
||||
public override string Compile(OrderedHashSet<string> strings) =>
|
||||
LocalizedTooltip > 0 ?
|
||||
$"{{ buttontileart {X} {Y} {NormalID} {PressedID} {(int)Type} {Param} {ButtonID} {ItemID} {Hue} {Width} {Height} }}{{ tooltip {LocalizedTooltip} }}" :
|
||||
$"{{ buttontileart {X} {Y} {NormalID} {PressedID} {(int)Type} {Param} {ButtonID} {ItemID} {Hue} {Width} {Height} }}";
|
||||
|
||||
public override void AppendTo(ref SpanWriter writer, OrderedHashSet<string> strings, ref int entries, ref int switches)
|
||||
{
|
||||
writer.Write((ushort)0x7B20); // "{ "
|
||||
writer.Write(LayoutName);
|
||||
writer.WriteAscii(' ');
|
||||
writer.WriteAscii(X.ToString());
|
||||
writer.WriteAscii(' ');
|
||||
writer.WriteAscii(Y.ToString());
|
||||
writer.WriteAscii(' ');
|
||||
writer.WriteAscii(NormalID.ToString());
|
||||
writer.WriteAscii(' ');
|
||||
writer.WriteAscii(PressedID.ToString());
|
||||
writer.WriteAscii(' ');
|
||||
writer.WriteAscii(((int)Type).ToString());
|
||||
writer.WriteAscii(' ');
|
||||
writer.WriteAscii(Param.ToString());
|
||||
writer.WriteAscii(' ');
|
||||
writer.WriteAscii(ButtonID.ToString());
|
||||
writer.WriteAscii(' ');
|
||||
writer.WriteAscii(ItemID.ToString());
|
||||
writer.WriteAscii(' ');
|
||||
writer.WriteAscii(Hue.ToString());
|
||||
writer.WriteAscii(' ');
|
||||
writer.WriteAscii(Width.ToString());
|
||||
writer.WriteAscii(' ');
|
||||
writer.WriteAscii(Height.ToString());
|
||||
|
||||
if (LocalizedTooltip > 0)
|
||||
{
|
||||
writer.Write(LayoutTooltip);
|
||||
writer.WriteAscii(LocalizedTooltip.ToString());
|
||||
}
|
||||
|
||||
writer.Write((ushort)0x207D); // " }"
|
||||
}
|
||||
public override void AppendTo(ref SpanWriter writer, OrderedHashSet<string> strings, ref int entries, ref int switches)
|
||||
{
|
||||
writer.WriteAscii(
|
||||
$"{{ buttontileart {X} {Y} {NormalID} {PressedID} {(int)Type} {Param} {ButtonID} {ItemID} {Hue} {Width} {Height} }}"
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue