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:
parent
07751654b7
commit
6f0e1a22f9
24 changed files with 763 additions and 449 deletions
|
|
@ -195,10 +195,7 @@ namespace Server
|
|||
{
|
||||
public const int QuestItemHue = 0x4EA; // Hmmmm... "for EA"?
|
||||
public static readonly List<Item> EmptyItems = new();
|
||||
|
||||
private static readonly List<Item> m_DeltaQueue = new();
|
||||
|
||||
private static bool _processing;
|
||||
private static readonly Queue<Item> m_DeltaQueue = new();
|
||||
|
||||
private static int m_OpenSlots;
|
||||
private int m_Amount;
|
||||
|
|
@ -2498,6 +2495,7 @@ namespace Server
|
|||
}
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
private static bool GetSaveFlag(SaveFlag flags, SaveFlag toGet) => (flags & toGet) != 0;
|
||||
|
||||
public IPooledEnumerable<IEntity> GetObjectsInRange(int range)
|
||||
|
|
@ -3243,69 +3241,55 @@ namespace Server
|
|||
if (!GetFlag(ImplFlag.InQueue))
|
||||
{
|
||||
SetFlag(ImplFlag.InQueue, true);
|
||||
|
||||
if (_processing)
|
||||
{
|
||||
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.Add(this);
|
||||
}
|
||||
m_DeltaQueue.Enqueue(this);
|
||||
}
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public void RemDelta(ItemDelta flags)
|
||||
{
|
||||
m_DeltaFlags &= ~flags;
|
||||
|
||||
if (GetFlag(ImplFlag.InQueue) && m_DeltaFlags == ItemDelta.None)
|
||||
{
|
||||
SetFlag(ImplFlag.InQueue, false);
|
||||
|
||||
if (_processing)
|
||||
{
|
||||
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.Remove(this);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void ProcessDeltaQueue()
|
||||
public static int ProcessDeltaQueue()
|
||||
{
|
||||
_processing = true;
|
||||
int count = 0;
|
||||
|
||||
for (var i = 0; i < m_DeltaQueue.Count; i++)
|
||||
var limit = m_DeltaQueue.Count;
|
||||
|
||||
while (m_DeltaQueue.Count > 0 && --limit >= 0)
|
||||
{
|
||||
m_DeltaQueue[i].ProcessDelta();
|
||||
var item = m_DeltaQueue.Dequeue();
|
||||
|
||||
if (item == null)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
count++;
|
||||
|
||||
item.SetFlag(ImplFlag.InQueue, false);
|
||||
|
||||
try
|
||||
{
|
||||
item.ProcessDelta();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
#if DEBUG
|
||||
Console.WriteLine("Process Delta Queue for {0} failed: {1}", item, ex);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
m_DeltaQueue.Clear();
|
||||
if (m_DeltaQueue.Count > 0)
|
||||
{
|
||||
Utility.PushColor(ConsoleColor.DarkYellow);
|
||||
Console.WriteLine("Warning: {0} items left in delta queue after processing.", m_DeltaQueue.Count);
|
||||
Utility.PopColor();
|
||||
}
|
||||
|
||||
_processing = false;
|
||||
return count;
|
||||
}
|
||||
|
||||
public virtual void OnDelete()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue