Optimized filter for transform entities with missing LocalToWorld components
This commit is contained in:
parent
567714a52d
commit
7225d13880
@ -17,7 +17,7 @@ public class LocalToWorldSystem : MoonTools.ECS.System
|
||||
{
|
||||
private readonly bool useParallelFor = true; // When having a low amount of transforms or when in debug mode this might be slower.
|
||||
private readonly Filter rootEntitiesFilter;
|
||||
private readonly Filter transformEntitiesFilter;
|
||||
private readonly Filter entitiesWithoutLocalToWorldFilter;
|
||||
private readonly Action<int> updateWorldTransform;
|
||||
|
||||
public LocalToWorldSystem(World world) : base(world)
|
||||
@ -25,7 +25,7 @@ public LocalToWorldSystem(World world) : base(world)
|
||||
rootEntitiesFilter = FilterBuilder.Include<LocalTransform>().Exclude<Child>().Build();
|
||||
if (useParallelFor)
|
||||
{
|
||||
transformEntitiesFilter = FilterBuilder.Include<LocalTransform>().Build();
|
||||
entitiesWithoutLocalToWorldFilter = FilterBuilder.Include<LocalTransform>().Exclude<LocalToWorld>().Build();
|
||||
updateWorldTransform = UpdateWorldTransformByIndex;
|
||||
}
|
||||
}
|
||||
@ -42,12 +42,7 @@ public override void Update(TimeSpan delta)
|
||||
Profiler.BeginSample("ParallelFor.LocalToWorldCheck");
|
||||
// This check is needed because some entities might not have a LocalToWorld component yet.
|
||||
// Adding this during the loop will break.
|
||||
foreach (Entity entity in transformEntitiesFilter.Entities) {
|
||||
if (Has<LocalToWorld>(entity))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
foreach (Entity entity in entitiesWithoutLocalToWorldFilter.Entities) {
|
||||
Set(entity, new LocalToWorld(Matrix4x4.Identity));
|
||||
}
|
||||
Profiler.EndSample();
|
||||
|
Loading…
Reference in New Issue
Block a user