Added dynamic spawning and despawning of objects
This commit is contained in:
parent
adbb208436
commit
e0cf8d9755
23 changed files with 794 additions and 350 deletions
43
scripts/QueueManager.cs
Normal file
43
scripts/QueueManager.cs
Normal 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue