From 7225d138807c3482fc79549512c77808bdece254 Mon Sep 17 00:00:00 2001 From: max Date: Mon, 21 Oct 2024 22:48:57 +0200 Subject: [PATCH] Optimized filter for transform entities with missing LocalToWorld components --- Nerfed.Runtime/Systems/LocalToWorldSystem.cs | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/Nerfed.Runtime/Systems/LocalToWorldSystem.cs b/Nerfed.Runtime/Systems/LocalToWorldSystem.cs index 56947a4..1949807 100644 --- a/Nerfed.Runtime/Systems/LocalToWorldSystem.cs +++ b/Nerfed.Runtime/Systems/LocalToWorldSystem.cs @@ -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 updateWorldTransform; public LocalToWorldSystem(World world) : base(world) @@ -25,7 +25,7 @@ public LocalToWorldSystem(World world) : base(world) rootEntitiesFilter = FilterBuilder.Include().Exclude().Build(); if (useParallelFor) { - transformEntitiesFilter = FilterBuilder.Include().Build(); + entitiesWithoutLocalToWorldFilter = FilterBuilder.Include().Exclude().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(entity)) - { - continue; - } - + foreach (Entity entity in entitiesWithoutLocalToWorldFilter.Entities) { Set(entity, new LocalToWorld(Matrix4x4.Identity)); } Profiler.EndSample();