Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

LightOnCollide entityquery #33886

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading