using System; using System.Collections.Concurrent; using Godot; public partial class QueueManager : Node { public static ConcurrentQueue LogQueue = new(); public static ConcurrentQueue ActionQueue = new(); public static ConcurrentQueue<(Sector, GameObject)> SectorReassignQueue = new(); public static ConcurrentQueue<(long, Godot.Collections.Dictionary)> NetworkSyncQueue = new(); private readonly int sectorReassignQueueRateLimit = 500; private readonly int networkSyncQueueRateLimit = 10; public override void _Process(double delta) { if (!GameManager.Instance.playerReady) { return; } while (LogQueue.TryDequeue(out string text)) { GD.Print(text); } while (ActionQueue.TryDequeue(out Action action)) { action(); } int sectorReassignQueueProcessed = 0; while ( !GameManager.Instance.simulatingFar && sectorReassignQueueProcessed++ < sectorReassignQueueRateLimit && SectorReassignQueue.TryDequeue(out var item) ) { var (sector, gameObject) = item; gameObject.CurrentSector.GameObjects.Remove(gameObject); sector.GameObjects.Add(gameObject); gameObject.AssignSector(sector); } int networkSyncQueueProcessed = 0; while ( networkSyncQueueProcessed++ < networkSyncQueueRateLimit && NetworkSyncQueue.TryDequeue(out var item) ) { var (clientId, gameObjectData) = item; RPCNode.Instance.RpcId(clientId, nameof(RPCNode.RpcSyncGameObject), gameObjectData); } } }