]> git.smokeofanarchy.ru Git - space-station-14.git/commitdiff
LightOnCollide entityquery (#33886)
authormetalgearsloth <31366439+metalgearsloth@users.noreply.github.com>
Mon, 16 Dec 2024 12:24:00 +0000 (23:24 +1100)
committerGitHub <noreply@github.com>
Mon, 16 Dec 2024 12:24:00 +0000 (13:24 +0100)
Content.Shared/Light/EntitySystems/LightCollideSystem.cs

index f09ae6824ea8ac043038914059fc8e3eed530034..2de7c5591fdb9c216670a8645831d0b344689e7b 100644 (file)
@@ -9,9 +9,14 @@ public sealed class LightCollideSystem : EntitySystem
     [Dependency] private readonly SharedPhysicsSystem _physics = default!;
     [Dependency] private readonly SlimPoweredLightSystem _lights = default!;
 
+    private EntityQuery<LightOnCollideComponent> _lightQuery;
+
     public override void Initialize()
     {
         base.Initialize();
+
+        _lightQuery = GetEntityQuery<LightOnCollideComponent>();
+
         SubscribeLocalEvent<LightOnCollideColliderComponent, PreventCollideEvent>(OnPreventCollide);
         SubscribeLocalEvent<LightOnCollideColliderComponent, StartCollideEvent>(OnStart);
         SubscribeLocalEvent<LightOnCollideColliderComponent, EndCollideEvent>(OnEnd);
@@ -35,7 +40,7 @@ public sealed class LightCollideSystem : EntitySystem
 
             var other = contact.OtherEnt(ent.Owner);
 
-            if (HasComp<LightOnCollideComponent>(other))
+            if (_lightQuery.HasComp(other))
             {
                 _physics.RegenerateContacts(other);
             }
@@ -46,7 +51,7 @@ public sealed class LightCollideSystem : EntitySystem
     // At the moment there's no easy way to do collision whitelists based on components.
     private void OnPreventCollide(Entity<LightOnCollideColliderComponent> ent, ref PreventCollideEvent args)
     {
-        if (!HasComp<LightOnCollideComponent>(args.OtherEntity))
+        if (!_lightQuery.HasComp(args.OtherEntity))
         {
             args.Cancelled = true;
         }
@@ -57,7 +62,7 @@ public sealed class LightCollideSystem : EntitySystem
         if (args.OurFixtureId != ent.Comp.FixtureId)
             return;
 
-        if (!HasComp<LightOnCollideComponent>(args.OtherEntity))
+        if (!_lightQuery.HasComp(args.OtherEntity))
             return;
 
         // TODO: Engine bug IsTouching box2d yay.
@@ -74,7 +79,7 @@ public sealed class LightCollideSystem : EntitySystem
         if (args.OurFixtureId != ent.Comp.FixtureId)
             return;
 
-        if (!HasComp<LightOnCollideComponent>(args.OtherEntity))
+        if (!_lightQuery.HasComp(args.OtherEntity))
             return;
 
         _lights.SetEnabled(args.OtherEntity, true);