testing building some core systems
- serialization - chunks - parralelfor test
This commit is contained in:
@@ -0,0 +1,35 @@
|
||||
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++;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user