fix(core): Core cleanup, adds event loop synchronization, and fixes gumps (#429)

- [X] Cleans up gump packets
- [X] Adds event loop task synchronization
- [X] Moves timer pause and cleans up the delay task timer class
- [X] Cleans up the conserve cpu
- [X] Renames variables to make them consistent with the new style
- [X] Removes process delta recursion checking.
- [X] Properly diposes net states. This fixes edge cases that may cause hanging connections to stay open longer than they should.
- [X] Fixes an issue with gump items not compiling properly

Users can now utilize `Timer.Pause()` since the code will be executed on the proper thread.

```cs
public void async void Talk()
{
    _canTalk = false;
    await Timer.Pause(Utility.RandomMinMax(5000, 8000)); // Talk after 5-8 seconds
    DoTalk();
    await Timer.Pause(Utility.RandomMinMax(12000, 25000)); // Reset ability to talk after 12-25 seconds
    _canTalk = true;
}
```
This commit is contained in:
Kamron Batman 2021-01-25 21:06:46 -08:00 • committed by GitHub
parent 07751654b7
commit 6f0e1a22f9
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
24 changed files with 763 additions and 449 deletions

View file

@ -471,9 +471,6 @@ namespace Server
};
private static readonly Queue<Mobile> m_DeltaQueue = new();
private static readonly Queue<Mobile> m_DeltaQueueR = new();
private static bool _processing;
private static readonly string[] m_GuildTypes =
{
@ -7957,50 +7954,49 @@ namespace Server
if (!m_InDeltaQueue)
{
m_InDeltaQueue = true;
if (_processing)
{
lock (m_DeltaQueueR)
{
m_DeltaQueueR.Enqueue(this);
try
{
using (var op = new StreamWriter("delta-recursion.log", true))
{
op.WriteLine("# {0}", DateTime.UtcNow);
op.WriteLine(new StackTrace());
op.WriteLine();
}
}
catch
{
// ignored
}
}
}
else
{
m_DeltaQueue.Enqueue(this);
}
m_DeltaQueue.Enqueue(this);
}
}
public static void ProcessDeltaQueue()
public static int ProcessDeltaQueue()
{
_processing = true;
int count = 0;
while (m_DeltaQueue.TryDequeue(out var m))
var limit = m_DeltaQueue.Count;
while (m_DeltaQueue.Count > 0 && --limit >= 0)
{
m.ProcessDelta();
var mob = m_DeltaQueue.Dequeue();
if (mob == null)
{
continue;
}
count++;
mob.m_InDeltaQueue = false;
try
{
mob.ProcessDelta();
}
catch (Exception ex)
{
#if DEBUG
Console.WriteLine("Process Delta Queue for {0} failed: {1}", mob, ex);
#endif
}
}
_processing = false;
while (m_DeltaQueueR.TryDequeue(out var m))
if (m_DeltaQueue.Count > 0)
{
m.ProcessDelta();
Utility.PushColor(ConsoleColor.DarkYellow);
Console.WriteLine("Warning: {0} mobiles left in delta queue after processing.", m_DeltaQueue.Count);
Utility.PopColor();
}
return count;
}
public virtual void OnKillsChange(int oldValue)