Skip to content

Commit

Permalink
LightOnCollide entityquery (space-wizards#33886)
Browse files Browse the repository at this point in the history
  • Loading branch information
metalgearsloth authored Dec 16, 2024
1 parent 2635888 commit 386e431
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions Content.Shared/Light/EntitySystems/LightCollideSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -35,7 +40,7 @@ private void OnCollideShutdown(Entity<LightOnCollideColliderComponent> ent, ref

var other = contact.OtherEnt(ent.Owner);

if (HasComp<LightOnCollideComponent>(other))
if (_lightQuery.HasComp(other))
{
_physics.RegenerateContacts(other);
}
Expand All @@ -46,7 +51,7 @@ private void OnCollideShutdown(Entity<LightOnCollideColliderComponent> ent, ref
// 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;
}
Expand All @@ -57,7 +62,7 @@ private void OnEnd(Entity<LightOnCollideColliderComponent> ent, ref EndCollideEv
if (args.OurFixtureId != ent.Comp.FixtureId)
return;

if (!HasComp<LightOnCollideComponent>(args.OtherEntity))
if (!_lightQuery.HasComp(args.OtherEntity))
return;

// TODO: Engine bug IsTouching box2d yay.
Expand All @@ -74,7 +79,7 @@ private void OnStart(Entity<LightOnCollideColliderComponent> ent, ref StartColli
if (args.OurFixtureId != ent.Comp.FixtureId)
return;

if (!HasComp<LightOnCollideComponent>(args.OtherEntity))
if (!_lightQuery.HasComp(args.OtherEntity))
return;

_lights.SetEnabled(args.OtherEntity, true);
Expand Down

0 comments on commit 386e431

Please sign in to comment.