fec2cd8d24
- serialization - chunks - parralelfor test
36 lines
915 B
C#
36 lines
915 B
C#
using MoonTools.ECS;
|
|
using System;
|
|
|
|
namespace Nerfed.Runtime.Scene.Streaming;
|
|
|
|
/// <summary>
|
|
/// A centralized cleanup system for slowly destroying chunk entities to avoid frame stutters.
|
|
/// </summary>
|
|
public class ChunkTeardownSystem : MoonTools.ECS.System
|
|
{
|
|
private readonly Filter _unloadedFilter;
|
|
|
|
// Adjustable limit to prevent massive stutters when unloading chunks.
|
|
public int MaxEntitiesToDestroyPerFrame { get; set; } = 250;
|
|
|
|
public ChunkTeardownSystem(World world) : base(world)
|
|
{
|
|
_unloadedFilter = FilterBuilder
|
|
.Include<ChunkUnloadPendingTag>()
|
|
.Build();
|
|
}
|
|
|
|
public override void Update(TimeSpan delta)
|
|
{
|
|
int destroyed = 0;
|
|
|
|
foreach (var entity in _unloadedFilter.Entities)
|
|
{
|
|
if (destroyed >= MaxEntitiesToDestroyPerFrame) break;
|
|
|
|
Destroy(entity);
|
|
destroyed++;
|
|
}
|
|
}
|
|
}
|