43 lines
1,001 B
C#
43 lines
1,001 B
C#
using System;
|
|
using System.Collections.Concurrent;
|
|
using Godot;
|
|
|
|
public partial class QueueManager : Node
|
|
{
|
|
public static ConcurrentQueue<string> LogQueue = new();
|
|
public static ConcurrentQueue<Action> ActionQueue = new();
|
|
|
|
public static ConcurrentQueue<(Sector, GameObject)> SectorReassignQueue = new();
|
|
|
|
private readonly int sectorReassignQueueRateLimit = 500;
|
|
|
|
public override void _Process(double delta)
|
|
{
|
|
while (LogQueue.TryDequeue(out string text))
|
|
{
|
|
GD.Print(text);
|
|
}
|
|
|
|
while (ActionQueue.TryDequeue(out Action action))
|
|
{
|
|
action();
|
|
}
|
|
|
|
GD.Print(SectorReassignQueue.Count);
|
|
|
|
int sectorReassignQueueProcessed = 0;
|
|
while (
|
|
!GameManager.Singleton.simulating
|
|
&& sectorReassignQueueProcessed++ < sectorReassignQueueRateLimit
|
|
&& SectorReassignQueue.TryDequeue(out var item)
|
|
)
|
|
{
|
|
var (sector, gameObject) = item;
|
|
|
|
gameObject.CurrentSector.GameObjects.Remove(gameObject);
|
|
sector.GameObjects.Add(gameObject);
|
|
|
|
gameObject.AssignSector(sector);
|
|
}
|
|
}
|
|
}
|