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
|
|
@ -2861,7 +2861,7 @@ namespace Server.Mobiles
|
|||
Delete();
|
||||
}
|
||||
|
||||
public override void GetProperties(ObjectPropertyList list)
|
||||
public override void GetProperties(IPropertyList list)
|
||||
{
|
||||
base.GetProperties(list);
|
||||
|
||||
|
|
|
|||
|
|
@ -128,7 +128,7 @@ namespace Server.Mobiles
|
|||
[CommandProperty(AccessLevel.GameMaster)]
|
||||
public bool IsRewardItem { get; set; }
|
||||
|
||||
public override void GetProperties(ObjectPropertyList list)
|
||||
public override void GetProperties(IPropertyList list)
|
||||
{
|
||||
base.GetProperties(list);
|
||||
|
||||
|
|
|
|||
|
|
@ -152,7 +152,7 @@ namespace Server.Mobiles
|
|||
|
||||
public override double GetControlChance(Mobile m, bool useBaseSkill = false) => 1.0;
|
||||
|
||||
public override void GetProperties(ObjectPropertyList list)
|
||||
public override void GetProperties(IPropertyList list)
|
||||
{
|
||||
base.GetProperties(list);
|
||||
|
||||
|
|
|
|||
|
|
@ -2784,7 +2784,7 @@ namespace Server.Mobiles
|
|||
base.OnDoubleClick(from);
|
||||
}
|
||||
|
||||
public override void AddNameProperties(ObjectPropertyList list)
|
||||
public override void AddNameProperties(IPropertyList list)
|
||||
{
|
||||
base.AddNameProperties(list);
|
||||
|
||||
|
|
|
|||
|
|
@ -219,7 +219,7 @@ namespace Server.Mobiles
|
|||
PrivateOverheadMessage(MessageType.Regular, 0x3B2, 1060768, from.NetState); // enraged
|
||||
}
|
||||
|
||||
public override void AddNameProperties(ObjectPropertyList list)
|
||||
public override void AddNameProperties(IPropertyList list)
|
||||
{
|
||||
base.AddNameProperties(list);
|
||||
list.Add(1060768); // enraged
|
||||
|
|
|
|||
|
|
@ -3511,7 +3511,7 @@ namespace Server.Mobiles
|
|||
DisguiseTimers.RemoveTimer(this);
|
||||
}
|
||||
|
||||
public override void GetProperties(ObjectPropertyList list)
|
||||
public override void GetProperties(IPropertyList list)
|
||||
{
|
||||
base.GetProperties(list);
|
||||
|
||||
|
|
@ -3531,32 +3531,26 @@ namespace Server.Mobiles
|
|||
{
|
||||
list.Add(
|
||||
1042734,
|
||||
"{0}\t{1}",
|
||||
pl.Sheriff.Definition.FriendlyName,
|
||||
faction.Definition.PropName
|
||||
$"{pl.Sheriff.Definition.FriendlyName}\t{faction.Definition.PropName}"
|
||||
); // The Sheriff of ~1_CITY~, ~2_FACTION_NAME~
|
||||
}
|
||||
else if (pl.Finance != null)
|
||||
{
|
||||
list.Add(
|
||||
1042735,
|
||||
"{0}\t{1}",
|
||||
pl.Finance.Definition.FriendlyName,
|
||||
faction.Definition.PropName
|
||||
); // The Finance Minister of ~1_CITY~, ~2_FACTION_NAME~
|
||||
1042735, // The Finance Minister of ~1_CITY~, ~2_FACTION_NAME~
|
||||
$"{pl.Finance.Definition.FriendlyName}\t{faction.Definition.PropName}"
|
||||
);
|
||||
}
|
||||
else if (pl.MerchantTitle != MerchantTitle.None)
|
||||
{
|
||||
list.Add(
|
||||
1060776,
|
||||
"{0}\t{1}",
|
||||
MerchantTitles.GetInfo(pl.MerchantTitle).Title,
|
||||
faction.Definition.PropName
|
||||
); // ~1_val~, ~2_val~
|
||||
1060776, // ~1_val~, ~2_val~
|
||||
$"{MerchantTitles.GetInfo(pl.MerchantTitle).Title}\t{faction.Definition.PropName}"
|
||||
);
|
||||
}
|
||||
else
|
||||
{
|
||||
list.Add(1060776, "{0}\t{1}", pl.Rank.Title, faction.Definition.PropName); // ~1_val~, ~2_val~
|
||||
list.Add(1060776, $"{pl.Rank.Title}\t{faction.Definition.PropName}"); // ~1_val~, ~2_val~
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -17,7 +17,7 @@ namespace Server.Mobiles
|
|||
|
||||
public override bool CanBeDamaged() => false;
|
||||
|
||||
public override void AddNameProperties(ObjectPropertyList list)
|
||||
public override void AddNameProperties(IPropertyList list)
|
||||
{
|
||||
base.AddNameProperties(list);
|
||||
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Server.Collections;
|
||||
using Server.ContextMenus;
|
||||
using Server.Engines.BulkOrders;
|
||||
using Server.Factions;
|
||||
|
|
@ -876,7 +877,7 @@ namespace Server.Mobiles
|
|||
var list = new List<BuyItemState>(buyInfo.Length);
|
||||
var cont = BuyPack;
|
||||
|
||||
var opls = EnableVendorBuyOPL ? new List<ObjectPropertyList>(buyInfo.Length) : null;
|
||||
using var opls = PooledRefQueue<ObjectPropertyList>.Create(EnableVendorBuyOPL ? buyInfo.Length : 0);
|
||||
|
||||
for (var idx = 0; idx < buyInfo.Length; idx++)
|
||||
{
|
||||
|
|
@ -906,9 +907,9 @@ namespace Server.Mobiles
|
|||
)
|
||||
);
|
||||
|
||||
if (disp is IPropertyListObject obj)
|
||||
if (disp is IObjectPropertyListEntity obj)
|
||||
{
|
||||
opls?.Add(obj.PropertyList);
|
||||
opls.Enqueue(obj.PropertyList);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -949,7 +950,7 @@ namespace Server.Mobiles
|
|||
if (name != null && list.Count < 250)
|
||||
{
|
||||
list.Add(new BuyItemState(name, cont.Serial, item.Serial, price, item.Amount, item.ItemID, item.Hue));
|
||||
opls?.Add(item.PropertyList);
|
||||
opls.Enqueue(item.PropertyList);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -978,12 +979,9 @@ namespace Server.Mobiles
|
|||
from.NetState.SendDisplayBuyList(Serial);
|
||||
from.NetState.SendMobileStatus(from); // make sure their gold amount is sent
|
||||
|
||||
if (opls != null)
|
||||
while (opls.Count > 0)
|
||||
{
|
||||
for (var i = 0; i < opls.Count; ++i)
|
||||
{
|
||||
from.NetState?.Send(opls[i].Buffer);
|
||||
}
|
||||
from.NetState?.Send(opls.Dequeue().Buffer);
|
||||
}
|
||||
|
||||
SayTo(from, 500186); // Greetings. Have a look around.
|
||||
|
|
|
|||
|
|
@ -155,7 +155,7 @@ namespace Server.Mobiles
|
|||
}
|
||||
}
|
||||
|
||||
public override void GetChildNameProperties(ObjectPropertyList list, Item item)
|
||||
public override void GetChildNameProperties(IPropertyList list, Item item)
|
||||
{
|
||||
base.GetChildNameProperties(list, item);
|
||||
|
||||
|
|
@ -182,7 +182,7 @@ namespace Server.Mobiles
|
|||
}
|
||||
}
|
||||
|
||||
public override void GetChildProperties(ObjectPropertyList list, Item item)
|
||||
public override void GetChildProperties(IPropertyList list, Item item)
|
||||
{
|
||||
base.GetChildProperties(list, item);
|
||||
|
||||
|
|
@ -735,7 +735,7 @@ namespace Server.Mobiles
|
|||
|
||||
public override bool IsSnoop(Mobile from) => false;
|
||||
|
||||
public override void GetProperties(ObjectPropertyList list)
|
||||
public override void GetProperties(IPropertyList list)
|
||||
{
|
||||
base.GetProperties(list);
|
||||
|
||||
|
|
@ -1652,7 +1652,7 @@ namespace Server.Mobiles
|
|||
[CommandProperty(AccessLevel.GameMaster)]
|
||||
public PlayerVendor Vendor { get; private set; }
|
||||
|
||||
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