Skip to content

Commit

Permalink
Make PVS ignore duplicate view subscriber
Browse files Browse the repository at this point in the history
  • Loading branch information
ElectroJr committed Oct 23, 2024
1 parent 32bca7c commit c64e9d6
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 11 deletions.
2 changes: 1 addition & 1 deletion RELEASE-NOTES.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ END TEMPLATE-->

### Breaking changes

*None yet*
* `SharedEyeSystem..SetTarget()` will now also automatically remove the old target from the session's ViewSubscriptions

### New features

Expand Down
6 changes: 3 additions & 3 deletions Robust.Server/GameStates/PvsSystem.Chunks.cs
Original file line number Diff line number Diff line change
Expand Up @@ -184,10 +184,9 @@ private void GetSessionViewers(PvsSession pvsSession)
return;
}

int i = 0;
var i = 0;
if (session.AttachedEntity is { } local)
{
DebugTools.Assert(!session.ViewSubscriptions.Contains(local));
Array.Resize(ref pvsSession.Viewers, session.ViewSubscriptions.Count + 1);
pvsSession.Viewers[i++] = (local, Transform(local), _eyeQuery.CompOrNull(local));
}
Expand All @@ -198,7 +197,8 @@ private void GetSessionViewers(PvsSession pvsSession)

foreach (var ent in session.ViewSubscriptions)
{
pvsSession.Viewers[i++] = (ent, Transform(ent), _eyeQuery.CompOrNull(ent));
if (ent != session.AttachedEntity)
pvsSession.Viewers[i++] = (ent, Transform(ent), _eyeQuery.CompOrNull(ent));
}
}

Expand Down
10 changes: 3 additions & 7 deletions Robust.Shared/GameObjects/Systems/SharedEyeSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -120,14 +120,10 @@ public void SetTarget(EntityUid uid, EntityUid? value, EyeComponent? eyeComponen
if (TryComp(uid, out ActorComponent? actorComp))
{
if (value != null)
{
_views.AddViewSubscriber(value.Value, actorComp.PlayerSession);
}
else
{
// Should never be null here
_views.RemoveViewSubscriber(eyeComponent.Target!.Value, actorComp.PlayerSession);
}

if (eyeComponent.Target is { } old)
_views.RemoveViewSubscriber(old, actorComp.PlayerSession);
}

eyeComponent.Target = value;
Expand Down

0 comments on commit c64e9d6

Please sign in to comment.