Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/master' into 2024-08-22-bui-fix
Browse files Browse the repository at this point in the history
  • Loading branch information
metalgearsloth committed Aug 25, 2024
2 parents 993d5ab + 0bc3c51 commit f98b502
Show file tree
Hide file tree
Showing 16 changed files with 297 additions and 82 deletions.
2 changes: 1 addition & 1 deletion MSBuild/Robust.Engine.Version.props
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<Project>
<!-- This file automatically reset by Tools/version.py -->
<PropertyGroup><Version>230.1.0</Version></PropertyGroup>
<PropertyGroup><Version>230.2.0</Version></PropertyGroup>
</Project>
Expand Down
12 changes: 12 additions & 0 deletions RELEASE-NOTES.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,18 @@ END TEMPLATE-->
*None yet*


## 230.2.0

### New features

* Add ProcessNow for IRobustJob as a convenience method where you may not want to run a job in the background sometimes.
* Add Vector2i helpers to all 8 neighbouring directions.

### Other

* Remove IThreadPoolWorkItem interface from IRobustJob.


## 230.1.0

### New features
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
using Robust.Shared.GameObjects;

namespace Robust.Client.GameObjects;

public sealed class ViewSubscriberSystem : SharedViewSubscriberSystem;

This file was deleted.

128 changes: 63 additions & 65 deletions Robust.Server/GameObjects/EntitySystems/ViewSubscriberSystem.cs
Original file line number Diff line number Diff line change
@@ -1,89 +1,87 @@
using Robust.Shared.GameObjects;
using Robust.Shared.Player;

namespace Robust.Server.GameObjects
namespace Robust.Server.GameObjects;

/// <summary>
/// Entity System that handles subscribing and unsubscribing to PVS views.
/// </summary>
public sealed class ViewSubscriberSystem : SharedViewSubscriberSystem
{
public override void Initialize()
{
base.Initialize();
SubscribeLocalEvent<ViewSubscriberComponent, ComponentShutdown>(OnViewSubscriberShutdown);
}

/// <summary>
/// Entity System that handles subscribing and unsubscribing to PVS views.
/// Subscribes the session to get PVS updates from the point of view of the specified entity.
/// </summary>
public sealed class ViewSubscriberSystem : EntitySystem
public override void AddViewSubscriber(EntityUid uid, ICommonSession session)
{
public override void Initialize()
{
base.Initialize();

SubscribeLocalEvent<ViewSubscriberComponent, ComponentShutdown>(OnViewSubscriberShutdown);
}

/// <summary>
/// Subscribes the session to get PVS updates from the point of view of the specified entity.
/// </summary>
public void AddViewSubscriber(EntityUid uid, ICommonSession session)
{
// If the entity doesn't have the component, it will be added.
var viewSubscriber = EntityManager.EnsureComponent<ViewSubscriberComponent>(uid);
// If the entity doesn't have the component, it will be added.
var viewSubscriber = EntityManager.EnsureComponent<Shared.GameObjects.ViewSubscriberComponent>(uid);

if (viewSubscriber.SubscribedSessions.Contains(session))
return; // Already subscribed, do nothing else.
if (viewSubscriber.SubscribedSessions.Contains(session))
return; // Already subscribed, do nothing else.

viewSubscriber.SubscribedSessions.Add(session);
session.ViewSubscriptions.Add(uid);
viewSubscriber.SubscribedSessions.Add(session);
session.ViewSubscriptions.Add(uid);

RaiseLocalEvent(uid, new ViewSubscriberAddedEvent(uid, session), true);
}

/// <summary>
/// Unsubscribes the session from getting PVS updates from the point of view of the specified entity.
/// </summary>
public void RemoveViewSubscriber(EntityUid uid, ICommonSession session)
{
if(!EntityManager.TryGetComponent(uid, out ViewSubscriberComponent? viewSubscriber))
return; // Entity didn't have any subscriptions, do nothing.

if (!viewSubscriber.SubscribedSessions.Remove(session))
return; // Session wasn't subscribed, do nothing.

session.ViewSubscriptions.Remove(uid);
RaiseLocalEvent(uid, new ViewSubscriberRemovedEvent(uid, session), true);
}

private void OnViewSubscriberShutdown(EntityUid uid, ViewSubscriberComponent component, ComponentShutdown _)
{
foreach (var session in component.SubscribedSessions)
{
session.ViewSubscriptions.Remove(uid);
}
}
RaiseLocalEvent(uid, new ViewSubscriberAddedEvent(uid, session), true);
}

/// <summary>
/// Raised when a session subscribes to an entity's PVS view.
/// Unsubscribes the session from getting PVS updates from the point of view of the specified entity.
/// </summary>
public sealed class ViewSubscriberAddedEvent : EntityEventArgs
public override void RemoveViewSubscriber(EntityUid uid, ICommonSession session)
{
public EntityUid View { get; }
public ICommonSession Subscriber { get; }
if(!EntityManager.TryGetComponent(uid, out Shared.GameObjects.ViewSubscriberComponent? viewSubscriber))
return; // Entity didn't have any subscriptions, do nothing.

if (!viewSubscriber.SubscribedSessions.Remove(session))
return; // Session wasn't subscribed, do nothing.

public ViewSubscriberAddedEvent(EntityUid view, ICommonSession subscriber)
session.ViewSubscriptions.Remove(uid);
RaiseLocalEvent(uid, new ViewSubscriberRemovedEvent(uid, session), true);
}

private void OnViewSubscriberShutdown(EntityUid uid, ViewSubscriberComponent component, ComponentShutdown _)
{
foreach (var session in component.SubscribedSessions)
{
View = view;
Subscriber = subscriber;
session.ViewSubscriptions.Remove(uid);
}
}
}

/// <summary>
/// Raised when a session is unsubscribed from an entity's PVS view.
/// Not raised when sessions are unsubscribed due to the component being removed.
/// </summary>
public sealed class ViewSubscriberRemovedEvent : EntityEventArgs
/// <summary>
/// Raised when a session subscribes to an entity's PVS view.
/// </summary>
public sealed class ViewSubscriberAddedEvent : EntityEventArgs
{
public EntityUid View { get; }
public ICommonSession Subscriber { get; }

public ViewSubscriberAddedEvent(EntityUid view, ICommonSession subscriber)
{
public EntityUid View { get; }
public ICommonSession Subscriber { get; }
View = view;
Subscriber = subscriber;
}
}

public ViewSubscriberRemovedEvent(EntityUid view, ICommonSession subscriber)
{
View = view;
Subscriber = subscriber;
}
/// <summary>
/// Raised when a session is unsubscribed from an entity's PVS view.
/// Not raised when sessions are unsubscribed due to the component being removed.
/// </summary>
public sealed class ViewSubscriberRemovedEvent : EntityEventArgs
{
public EntityUid View { get; }
public ICommonSession Subscriber { get; }

public ViewSubscriberRemovedEvent(EntityUid view, ICommonSession subscriber)
{
View = view;
Subscriber = subscriber;
}
}
5 changes: 5 additions & 0 deletions Robust.Shared.Maths/Vector2i.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@ public struct Vector2i :
public static readonly Vector2i Left = (-1, 0);
public static readonly Vector2i Right = (1, 0);

public static readonly Vector2i DownLeft = (-1, -1);
public static readonly Vector2i DownRight = (1, -1);
public static readonly Vector2i UpRight = (1, 1);
public static readonly Vector2i UpLeft = (-1, 1);

/// <summary>
/// The X component of the Vector2i.
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
using System.Collections.Generic;
using Robust.Shared.Player;

namespace Robust.Shared.GameObjects;

// Not networked because doesn't do anything on client.
[RegisterComponent]
internal sealed partial class ViewSubscriberComponent : Component
{
internal readonly HashSet<ICommonSession> SubscribedSessions = new();
}
48 changes: 48 additions & 0 deletions Robust.Shared/GameObjects/Systems/SharedEyeSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,41 @@
using System.Numerics;
using Robust.Shared.IoC;
using Robust.Shared.Maths;
using Robust.Shared.Player;

namespace Robust.Shared.GameObjects;

public abstract class SharedEyeSystem : EntitySystem
{
[Dependency] private readonly SharedViewSubscriberSystem _views = default!;

public override void Initialize()
{
base.Initialize();
SubscribeLocalEvent<EyeComponent, PlayerAttachedEvent>(OnEyePlayerAttached);
SubscribeLocalEvent<EyeComponent, PlayerDetachedEvent>(OnEyePlayerDetached);
}

private void OnEyePlayerAttached(Entity<EyeComponent> ent, ref PlayerAttachedEvent args)
{
var value = ent.Comp.Target;

if (value != null && TryComp(ent.Owner, out ActorComponent? actorComp))
{
_views.AddViewSubscriber(value.Value, actorComp.PlayerSession);
}
}

private void OnEyePlayerDetached(Entity<EyeComponent> ent, ref PlayerDetachedEvent args)
{
var value = ent.Comp.Target;

if (value != null && TryComp(ent.Owner, out ActorComponent? actorComp))
{
_views.RemoveViewSubscriber(value.Value, actorComp.PlayerSession);
}
}

/// <summary>
/// Refreshes all values for IEye with the component.
/// </summary>
Expand Down Expand Up @@ -74,6 +104,10 @@ public void SetRotation(EntityUid uid, Angle rotation, EyeComponent? eyeComponen
eyeComponent.Eye.Rotation = rotation;
}

/// <summary>
/// Sets the eye component as tracking another entity.
/// Will also add the target to view subscribers so they can leave range and still work with PVS.
/// </summary>
public void SetTarget(EntityUid uid, EntityUid? value, EyeComponent? eyeComponent = null)
{
if (!Resolve(uid, ref eyeComponent))
Expand All @@ -82,6 +116,20 @@ public void SetTarget(EntityUid uid, EntityUid? value, EyeComponent? eyeComponen
if (eyeComponent.Target.Equals(value))
return;

// Automatically handle view subs.
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);
}
}

eyeComponent.Target = value;
Dirty(uid, eyeComponent);
}
Expand Down
18 changes: 18 additions & 0 deletions Robust.Shared/GameObjects/Systems/SharedViewSubscriberSystem.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
using Robust.Shared.Player;

namespace Robust.Shared.GameObjects;

public abstract class SharedViewSubscriberSystem : EntitySystem
{
// NOOP on client

/// <summary>
/// Subscribes the session to get PVS updates from the point of view of the specified entity.
/// </summary>
public virtual void AddViewSubscriber(EntityUid uid, ICommonSession session) {}

/// <summary>
/// Unsubscribes the session from getting PVS updates from the point of view of the specified entity.
/// </summary>
public virtual void RemoveViewSubscriber(EntityUid uid, ICommonSession session) {}
}
23 changes: 23 additions & 0 deletions Robust.Shared/Physics/Dynamics/Contacts/Contact.cs
Original file line number Diff line number Diff line change
Expand Up @@ -349,6 +349,29 @@ public override int GetHashCode()
// TODO: Need to suss this out
return HashCode.Combine(EntityA, EntityB);
}

/// <summary>
/// Gets the other ent for this contact.
/// </summary>
public EntityUid OtherEnt(EntityUid uid)
{
if (uid == EntityA)
return EntityB;
else if (uid == EntityB)
return EntityA;

throw new InvalidOperationException();
}

public (string Id, Fixture) OtherFixture(EntityUid uid)
{
if (uid == EntityA)
return (FixtureBId, FixtureB!);
else if (uid == EntityB)
return (FixtureAId, FixtureA!);

throw new InvalidOperationException();
}
}

[Flags]
Expand Down
1 change: 1 addition & 0 deletions Robust.Shared/Physics/Systems/FixtureSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ internal void CreateFixture(
// Don't need to ResetMassData as FixtureUpdate already does it.
Dirty(uid, manager);
}

// TODO: Set newcontacts to true.
}

Expand Down
2 changes: 1 addition & 1 deletion Robust.Shared/Physics/Systems/SharedBroadphaseSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -416,7 +416,7 @@ public void RegenerateContacts(EntityUid uid, PhysicsComponent body, FixturesCom
}
}

private void TouchProxies(EntityUid mapId, Matrix3x2 broadphaseMatrix, Fixture fixture)
internal void TouchProxies(EntityUid mapId, Matrix3x2 broadphaseMatrix, Fixture fixture)
{
foreach (var proxy in fixture.Proxies)
{
Expand Down
Loading

0 comments on commit f98b502

Please sign in to comment.