|
|
@@ -1,5 +1,8 @@ |
|
|
|
using System; |
|
|
|
using System.Collections.Generic; |
|
|
|
using System.Reflection; |
|
|
|
using HarmonyLib; |
|
|
|
using Svelto.DataStructures; |
|
|
|
using Svelto.ECS; |
|
|
|
using Svelto.Tasks; |
|
|
|
using Svelto.Tasks.Lean; |
|
|
@@ -79,7 +82,6 @@ namespace TechbloxModdingAPI.Utility |
|
|
|
public static void PublishEntityChangeDelayed<T>(this EntitiesDB entitiesDB, EGID id, int limit = 80) |
|
|
|
where T : unmanaged, IEntityComponent |
|
|
|
{ |
|
|
|
//TODO: Doesn't seem to help |
|
|
|
if (!ChangesToPublish.ContainsKey(typeof(T))) |
|
|
|
ChangesToPublish.Add(typeof(T), (0, new HashSet<EGID>())); |
|
|
|
var changes = ChangesToPublish[typeof(T)].Changes; |
|
|
@@ -94,6 +96,30 @@ namespace TechbloxModdingAPI.Utility |
|
|
|
yield return Yield.It; |
|
|
|
while (ChangesToPublish[typeof(T)].PublishedCount >= limit) |
|
|
|
yield return Yield.It; |
|
|
|
if (!entitiesDB._entityStream._streams.TryGetValue(TypeRefWrapper<T>.wrapper, out var result)) |
|
|
|
yield break; // There is no entity stream for this type |
|
|
|
var consumers = (result as EntityStream<T>)?._consumers; |
|
|
|
if (consumers == null) |
|
|
|
{ |
|
|
|
Console.WriteLine("Consumers is null"); |
|
|
|
yield break; |
|
|
|
} |
|
|
|
|
|
|
|
bool waitForConsumers; |
|
|
|
do |
|
|
|
{ |
|
|
|
waitForConsumers = false; |
|
|
|
for (int i = 0; i < consumers.count; i++) |
|
|
|
{ |
|
|
|
var buffer = consumers[i]._ringBuffer; |
|
|
|
if (buffer.Count + 1 <= buffer.Capacity) continue; |
|
|
|
waitForConsumers = true; |
|
|
|
Console.WriteLine($"Gonna have to wait for a consumer (capacity: {buffer.Capacity} count: {buffer.Count}"); |
|
|
|
break; |
|
|
|
} |
|
|
|
|
|
|
|
if (waitForConsumers) yield return Yield.It; |
|
|
|
} while (waitForConsumers); |
|
|
|
entitiesDB.PublishEntityChange<T>(id); |
|
|
|
var (count, changes) = ChangesToPublish[typeof(T)]; |
|
|
|
changes.Remove(id); |
|
|
|