Added dynamic spawning and despawning of objects

This commit is contained in:
Aslan 2026-01-27 07:08:03 -05:00
parent adbb208436
commit e0cf8d9755
23 changed files with 794 additions and 350 deletions

43
scripts/QueueManager.cs Normal file
View file

@ -0,0 +1,43 @@
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);
}
}
}