feat: Adds tidy option for serialization. Codegens ballotbox. Fixes pooled timer leaking (#681)
* Fixes pooled timer leaking * Fixes `[dumptimers` command so it outputs properly, adds spacing, and stacktraces * Adds `[Tidy]` for serializing Lists. This will remove deleted entities during world save before serializing the list. * Adds helpers for managing Lists/Sets/Dictionaries ### New API ```cs // Creates the list if it is null, then adds Utility.Add(ref list, value); Utility.Add(ref set, value); Utility.Add(ref dict, key, value); // Nulls the variable if the count is zero Utility.Remove(ref list, value); Utility.Remove(ref set, value); Utility.Remove(ref dict, key); // Marks entity as dirty in addition to doing the action entity.Add(list, value); // Marks entity as dirty, and will create list if it doesn't exist entity.Add(ref list, value); // Marks entity as dirty in addition to doing the action entity.Remove(list, value); // Marks entity as dirty, and will null the list count is zero entity.Remove(ref list, value); ``` ### Updates to [dumptimers <img width="825" alt="Screen Shot 2021-08-14 at 2 55 10 AM" src="https://user-images.githubusercontent.com/3953314/129442449-ccf7fe14-29d6-4f3f-9366-c8eb7b9828a7.png">
This commit is contained in:
parent
84cbd52a2a
commit
360143478a
53 changed files with 627 additions and 464 deletions
|
|
@ -66,76 +66,28 @@ namespace Server
|
|||
|
||||
public int Y { get; }
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
private static void Add<T>(ref List<T> list, T value)
|
||||
{
|
||||
list ??= new List<T>();
|
||||
|
||||
list.Add(value);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
private static void Remove<T>(ref List<T> list, T value)
|
||||
{
|
||||
if (list != null)
|
||||
{
|
||||
list.Remove(value);
|
||||
|
||||
if (list.Count == 0)
|
||||
{
|
||||
list = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
private static void Replace<T>(ref List<T> list, T oldValue, T newValue)
|
||||
{
|
||||
if (oldValue != null && newValue != null)
|
||||
{
|
||||
var index = list?.IndexOf(oldValue) ?? -1;
|
||||
|
||||
if (index >= 0)
|
||||
{
|
||||
list![index] = newValue;
|
||||
}
|
||||
else
|
||||
{
|
||||
Add(ref list, newValue);
|
||||
}
|
||||
}
|
||||
else if (oldValue != null)
|
||||
{
|
||||
Remove(ref list, oldValue);
|
||||
}
|
||||
else if (newValue != null)
|
||||
{
|
||||
Add(ref list, newValue);
|
||||
}
|
||||
}
|
||||
|
||||
public void OnClientChange(NetState oldState, NetState newState)
|
||||
{
|
||||
Replace(ref m_Clients, oldState, newState);
|
||||
Utility.Replace(ref m_Clients, oldState, newState);
|
||||
}
|
||||
|
||||
public void OnEnter(Item item)
|
||||
{
|
||||
Add(ref m_Items, item);
|
||||
Utility.Add(ref m_Items, item);
|
||||
}
|
||||
|
||||
public void OnLeave(Item item)
|
||||
{
|
||||
Remove(ref m_Items, item);
|
||||
Utility.Remove(ref m_Items, item);
|
||||
}
|
||||
|
||||
public void OnEnter(Mobile mob)
|
||||
{
|
||||
Add(ref m_Mobiles, mob);
|
||||
Utility.Add(ref m_Mobiles, mob);
|
||||
|
||||
if (mob.NetState != null)
|
||||
{
|
||||
Add(ref m_Clients, mob.NetState);
|
||||
Utility.Add(ref m_Clients, mob.NetState);
|
||||
|
||||
Owner.ActivateSectors(X, Y);
|
||||
}
|
||||
|
|
@ -143,11 +95,11 @@ namespace Server
|
|||
|
||||
public void OnLeave(Mobile mob)
|
||||
{
|
||||
Remove(ref m_Mobiles, mob);
|
||||
Utility.Remove(ref m_Mobiles, mob);
|
||||
|
||||
if (mob.NetState != null)
|
||||
{
|
||||
Remove(ref m_Clients, mob.NetState);
|
||||
Utility.Remove(ref m_Clients, mob.NetState);
|
||||
|
||||
Owner.DeactivateSectors(X, Y);
|
||||
}
|
||||
|
|
@ -155,7 +107,7 @@ namespace Server
|
|||
|
||||
public void OnEnter(Region region, Rectangle3D rect)
|
||||
{
|
||||
Add(ref m_RegionRects, new RegionRect(region, rect));
|
||||
Utility.Add(ref m_RegionRects, new RegionRect(region, rect));
|
||||
|
||||
m_RegionRects.Sort();
|
||||
|
||||
|
|
@ -200,12 +152,12 @@ namespace Server
|
|||
|
||||
public void OnMultiEnter(BaseMulti multi)
|
||||
{
|
||||
Add(ref m_Multis, multi);
|
||||
Utility.Add(ref m_Multis, multi);
|
||||
}
|
||||
|
||||
public void OnMultiLeave(BaseMulti multi)
|
||||
{
|
||||
Remove(ref m_Multis, multi);
|
||||
Utility.Remove(ref m_Multis, multi);
|
||||
}
|
||||
|
||||
public void Activate()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue