fix: Optimizes OPL using string interpolation (#1041)
## Breaking Changes (New API)
ObjectPropertyList supports the following API:
```cs
list.Add(500000);
list.Add(500001, stringArgument);
list.Add("Some text");
list.Add($"Some text with {argument}");
list.Add(500002, $"{arg1}\t{arg2}");
```
## Notes
1. All API uses that require a formatter like this:
```cs
list.Add(500002, "{0}\t{1}", arg1, arg2);
```
Should be changed to use string interpolation, for example:
```cs
list.Add(500002, $"{arg1}\t{arg2}");
```
2. The following paradigm should no longer be used:
```cs
list.Add(1061170, prop.ToString()); // strength requirement ~1_val~
```
The new string interpolation API will avoid having to convert the argument to a string before writing it to the packet. Instead use the following:
```cs
list.Add(1061170, $"{prop}"); // strength requirement ~1_val~
```
### Benchmarks
```cs
| Method | Mean | Error | StdDev | Gen 0 | Allocated |
|------------------------------- |---------:|--------:|--------:|-------:|----------:|
| BenchmarkOldOPL | 241.0 ns | 0.56 ns | 0.47 ns | 0.0105 | 88 B |
| BenchmarkStringInterpolatedOPL | 199.9 ns | 2.44 ns | 2.39 ns | - | - |
```
### Changes
- [X] Removes crash in STArray.Return when array is null.
- [X] Fixes NPE in OPL when entity is null. Serial in packet will be 0 when entity is null.
- [X] Fixes NPE in AosAttributes when Parent is null.
- [X] Changes OPL to use string interpolation.
- [X] Introduces `IPropertyList` to allow extending PropertyList for other uses.
This commit is contained in:
parent
fe31470f05
commit
ecbee17690
227 changed files with 1426 additions and 1008 deletions
|
|
@ -68,7 +68,7 @@ namespace Server.Items
|
|||
}
|
||||
}
|
||||
|
||||
public override void GetProperties(ObjectPropertyList list)
|
||||
public override void GetProperties(IPropertyList list)
|
||||
{
|
||||
base.GetProperties(list);
|
||||
list.Add(1060738, Core.ML ? $"{m_Worth:N0}" : m_Worth.ToString()); // value: ~1_val~)
|
||||
|
|
|
|||
|
|
@ -24,7 +24,7 @@ namespace Server.Items
|
|||
}
|
||||
}
|
||||
|
||||
public override void GetProperties(ObjectPropertyList list)
|
||||
public override void GetProperties(IPropertyList list)
|
||||
{
|
||||
base.GetProperties(list);
|
||||
|
||||
|
|
|
|||
|
|
@ -28,7 +28,7 @@ namespace Server.Items
|
|||
}
|
||||
}
|
||||
|
||||
public override void GetProperties(ObjectPropertyList list)
|
||||
public override void GetProperties(IPropertyList list)
|
||||
{
|
||||
base.GetProperties(list);
|
||||
|
||||
|
|
|
|||
|
|
@ -91,17 +91,17 @@ namespace Server.Items
|
|||
|
||||
public override bool HandlesOnSpeech => true;
|
||||
|
||||
public override void GetProperties(ObjectPropertyList list)
|
||||
public override void GetProperties(IPropertyList list)
|
||||
{
|
||||
base.GetProperties(list);
|
||||
|
||||
list.Add(Active ? 1060742 : 1060743); // active / inactive
|
||||
list.Add(1060745); // broadcast
|
||||
list.Add(1060741, Charges.ToString()); // charges: ~1_val~
|
||||
list.Add(1060741, $"{Charges}"); // charges: ~1_val~
|
||||
|
||||
if (Receivers.Count > 0)
|
||||
{
|
||||
list.Add(1060746, Receivers.Count.ToString()); // links: ~1_val~
|
||||
list.Add(1060746, $"{Receivers.Count}"); // links: ~1_val~
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -338,7 +338,7 @@ namespace Server.Items
|
|||
}
|
||||
}
|
||||
|
||||
public override void GetProperties(ObjectPropertyList list)
|
||||
public override void GetProperties(IPropertyList list)
|
||||
{
|
||||
base.GetProperties(list);
|
||||
|
||||
|
|
|
|||
|
|
@ -1130,7 +1130,7 @@ namespace Server.Items
|
|||
|
||||
public override bool CheckContentDisplay(Mobile from) => false;
|
||||
|
||||
public override void AddNameProperty(ObjectPropertyList list)
|
||||
public override void AddNameProperty(IPropertyList list)
|
||||
{
|
||||
if (ItemID == 0x2006) // Corpse form
|
||||
{
|
||||
|
|
|
|||
|
|
@ -43,7 +43,7 @@ namespace Server.Items
|
|||
// Do not display (x items, y stones)
|
||||
public override bool CheckContentDisplay(Mobile from) => false;
|
||||
|
||||
public override void AddNameProperty(ObjectPropertyList list)
|
||||
public override void AddNameProperty(IPropertyList list)
|
||||
{
|
||||
list.Add(1046414, Name); // the remains of ~1_NAME~
|
||||
}
|
||||
|
|
|
|||
|
|
@ -41,7 +41,7 @@ namespace Server.Items
|
|||
|
||||
public override int LabelNumber => 1041280; // an interior decorator
|
||||
|
||||
public override void GetProperties(ObjectPropertyList list)
|
||||
public override void GetProperties(IPropertyList list)
|
||||
{
|
||||
base.GetProperties(list);
|
||||
|
||||
|
|
|
|||
|
|
@ -218,7 +218,7 @@ public class Key : Item
|
|||
from.Target = t;
|
||||
}
|
||||
|
||||
public override void GetProperties(ObjectPropertyList list)
|
||||
public override void GetProperties(IPropertyList list)
|
||||
{
|
||||
base.GetProperties(list);
|
||||
|
||||
|
|
|
|||
|
|
@ -23,11 +23,11 @@ namespace Server.Items
|
|||
public override int LabelNumber => 1070997; // A promotional token
|
||||
public abstract Item CreateItemFor(Mobile from);
|
||||
|
||||
public override void GetProperties(ObjectPropertyList list)
|
||||
public override void GetProperties(IPropertyList list)
|
||||
{
|
||||
base.GetProperties(list);
|
||||
|
||||
list.Add(1070998, ItemName.ToString()); // Use this to redeem<br>your ~1_PROMO~
|
||||
list.Add(1070998, $"{ItemName}"); // Use this to redeem<br>your ~1_PROMO~
|
||||
}
|
||||
|
||||
public override void OnDoubleClick(Mobile from)
|
||||
|
|
|
|||
|
|
@ -153,7 +153,7 @@ namespace Server.Items
|
|||
|
||||
public override int LabelNumber => 1026095; // teleporter
|
||||
|
||||
public override void GetProperties(ObjectPropertyList list)
|
||||
public override void GetProperties(IPropertyList list)
|
||||
{
|
||||
base.GetProperties(list);
|
||||
|
||||
|
|
@ -168,15 +168,15 @@ namespace Server.Items
|
|||
|
||||
if (m_MapDest != null)
|
||||
{
|
||||
list.Add(1060658, "Map\t{0}", m_MapDest);
|
||||
list.Add(1060658, $"Map\t{m_MapDest}");
|
||||
}
|
||||
|
||||
if (m_PointDest != Point3D.Zero)
|
||||
{
|
||||
list.Add(1060659, "Coords\t{0}", m_PointDest);
|
||||
list.Add(1060659, $"Coords\t{m_PointDest}");
|
||||
}
|
||||
|
||||
list.Add(1060660, "Creatures\t{0}", m_Creatures ? "Yes" : "No");
|
||||
list.Add(1060660, $"Creatures\t{(m_Creatures ? "Yes" : "No")}");
|
||||
}
|
||||
|
||||
public override void OnSingleClick(Mobile from)
|
||||
|
|
@ -463,7 +463,7 @@ namespace Server.Items
|
|||
return true;
|
||||
}
|
||||
|
||||
public override void GetProperties(ObjectPropertyList list)
|
||||
public override void GetProperties(IPropertyList list)
|
||||
{
|
||||
base.GetProperties(list);
|
||||
|
||||
|
|
@ -479,15 +479,15 @@ namespace Server.Items
|
|||
skillName = "(Invalid)";
|
||||
}
|
||||
|
||||
list.Add(1060661, "{0}\t{1:F1}", skillName, m_Required);
|
||||
list.Add(1060661, $"{skillName}\t{m_Required:F1}");
|
||||
|
||||
if (m_MessageString != null)
|
||||
{
|
||||
list.Add(1060662, "Message\t{0}", m_MessageString);
|
||||
list.Add(1060662, $"Message\t{m_MessageString}");
|
||||
}
|
||||
else if (m_MessageNumber != 0)
|
||||
{
|
||||
list.Add(1060662, "Message\t#{0}", m_MessageNumber);
|
||||
list.Add(1060662, $"Message\t#{m_MessageNumber}");
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -621,20 +621,20 @@ namespace Server.Items
|
|||
|
||||
public override bool OnMoveOver(Mobile m) => true;
|
||||
|
||||
public override void GetProperties(ObjectPropertyList list)
|
||||
public override void GetProperties(IPropertyList list)
|
||||
{
|
||||
base.GetProperties(list);
|
||||
|
||||
list.Add(1060661, "Range\t{0}", m_Range);
|
||||
list.Add(1060661, $"Range\t{m_Range}");
|
||||
|
||||
if (m_Keyword >= 0)
|
||||
{
|
||||
list.Add(1060662, "Keyword\t{0}", m_Keyword);
|
||||
list.Add(1060662, $"Keyword\t{m_Keyword}");
|
||||
}
|
||||
|
||||
if (m_Substring != null)
|
||||
{
|
||||
list.Add(1060663, "Substring\t{0}", m_Substring);
|
||||
list.Add(1060663, $"Substring\t{m_Substring}");
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -1176,7 +1176,7 @@ namespace Server.Items
|
|||
return true;
|
||||
}
|
||||
|
||||
public override void GetProperties(ObjectPropertyList list)
|
||||
public override void GetProperties(IPropertyList list)
|
||||
{
|
||||
base.GetProperties(list);
|
||||
|
||||
|
|
|
|||
|
|
@ -42,7 +42,7 @@ namespace Server.Items
|
|||
base.OnMovement(m, oldLocation);
|
||||
}
|
||||
|
||||
public override void GetProperties(ObjectPropertyList list)
|
||||
public override void GetProperties(IPropertyList list)
|
||||
{
|
||||
base.GetProperties(list);
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue