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:
Kamron Batman 2022-06-02 10:09:53 -07:00 • committed by GitHub
parent fe31470f05
commit ecbee17690
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
227 changed files with 1426 additions and 1008 deletions

View file

@ -98,7 +98,7 @@ namespace Server.Items
}
}
public override void GetProperties(ObjectPropertyList list)
public override void GetProperties(IPropertyList list)
{
base.GetProperties(list);

View file

@ -217,7 +217,7 @@ namespace Server.Items
InvalidateProperties();
}
public override void GetProperties(ObjectPropertyList list)
public override void GetProperties(IPropertyList list)
{
base.GetProperties(list);
@ -232,23 +232,23 @@ namespace Server.Items
if (m_TargetMap == Map.Tokuno)
{
list.Add(House != null ? 1063260 : 1063259, RuneFormat, desc); // ~1_val~ (Tokuno Islands)[(House)]
list.Add(House != null ? 1063260 : 1063259, $"a recall rune for {desc}"); // ~1_val~ (Tokuno Islands)[(House)]
}
else if (m_TargetMap == Map.Malas)
{
list.Add(House != null ? 1062454 : 1060804, RuneFormat, desc); // ~1_val~ (Malas)[(House)]
list.Add(House != null ? 1062454 : 1060804, $"a recall rune for {desc}"); // ~1_val~ (Malas)[(House)]
}
else if (m_TargetMap == Map.Felucca)
{
list.Add(House != null ? 1062452 : 1060805, RuneFormat, desc); // ~1_val~ (Felucca)[(House)]
list.Add(House != null ? 1062452 : 1060805, $"a recall rune for {desc}"); // ~1_val~ (Felucca)[(House)]
}
else if (m_TargetMap == Map.Trammel)
{
list.Add(House != null ? 1062453 : 1060806, RuneFormat, desc); // ~1_val~ (Trammel)[(House)]
list.Add(House != null ? 1062453 : 1060806, $"a recall rune for {desc}"); // ~1_val~ (Trammel)[(House)]
}
else
{
list.Add(House != null ? "{0} ({1})(House)" : "{0} ({1})", string.Format(RuneFormat, desc), m_TargetMap);
list.Add(House != null ? $"a recall rune for {desc} ({m_TargetMap})(House)" : $"a recall rune for {desc} ({m_TargetMap})");
}
}
}
@ -263,33 +263,33 @@ namespace Server.Items
{
LabelTo(
from,
House != null ? 1063260 : 1063259,
House != null ? 1063260 : 1063259, // ~1_val~ (Tokuno Islands)[(House)]
string.Format(RuneFormat, desc)
); // ~1_val~ (Tokuno Islands)[(House)]
);
}
else if (m_TargetMap == Map.Malas)
{
LabelTo(
from,
House != null ? 1062454 : 1060804,
House != null ? 1062454 : 1060804, // ~1_val~ (Malas)[(House)]
string.Format(RuneFormat, desc)
); // ~1_val~ (Malas)[(House)]
);
}
else if (m_TargetMap == Map.Felucca)
{
LabelTo(
from,
House != null ? 1062452 : 1060805,
House != null ? 1062452 : 1060805, // ~1_val~ (Felucca)[(House)]
string.Format(RuneFormat, desc)
); // ~1_val~ (Felucca)[(House)]
);
}
else if (m_TargetMap == Map.Trammel)
{
LabelTo(
from,
House != null ? 1062453 : 1060806,
House != null ? 1062453 : 1060806, // ~1_val~ (Trammel)[(House)]
string.Format(RuneFormat, desc)
); // ~1_val~ (Trammel)[(House)]
);
}
else
{