Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/master' into 2024-09-27-sprite…
Browse files Browse the repository at this point in the history
…-flick
  • Loading branch information
metalgearsloth committed Sep 28, 2024
2 parents 4c71a0e + 74e7e61 commit 34f2861
Show file tree
Hide file tree
Showing 11 changed files with 52 additions and 54 deletions.
1 change: 1 addition & 0 deletions RELEASE-NOTES.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ END TEMPLATE-->

### Bugfixes

* Auto-networked dictionaries now use `TryAdd()` to avoid duplicate key errors when a dictionary contains multiple unknown networked entities.
* Fixed `ICommonSession.Ping` always returning zero instead of the ping. Note that this will still return zero for client-side code when trying to get the ping of other players.

### Other
Expand Down
1 change: 0 additions & 1 deletion Robust.Client/Physics/PhysicsSystem.Predict.cs
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,6 @@ internal void UpdateIsTouching(List<Contact> toUpdate)

if (activeA == false && activeB == false)
{
contact.IsTouching = false;
continue;
}

Expand Down
45 changes: 12 additions & 33 deletions Robust.Client/UserInterface/Controls/TabContainer.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using System.Collections.Generic;
using System.Numerics;
using Robust.Client.Graphics;
using Robust.Shared.Input;
Expand All @@ -21,6 +22,8 @@ public class TabContainer : Container

private int _currentTab;
private bool _tabsVisible = true;
// The right-most coordinate of each tab header
private List<float> _tabRight = new();

public int CurrentTab
{
Expand Down Expand Up @@ -157,11 +160,14 @@ protected internal override void Draw(DrawingHandleScreen handle)

var headerOffset = 0f;

_tabRight.Clear();

// Then, draw the tabs.
for (var i = 0; i < ChildCount; i++)
{
if (!GetTabVisible(i))
{
_tabRight.Add(headerOffset);
continue;
}

Expand Down Expand Up @@ -214,6 +220,8 @@ protected internal override void Draw(DrawingHandleScreen handle)
}

headerOffset += boxAdvance;
// Remember the right-most point of this tab, for testing clicked areas
_tabRight.Add(headerOffset);
}
}

Expand Down Expand Up @@ -283,46 +291,17 @@ protected internal override void KeyBindDown(GUIBoundKeyEventArgs args)
args.Handle();

var relX = args.RelativePixelPosition.X;

var font = _getFont();
var boxActive = _getTabBoxActive();
var boxInactive = _getTabBoxInactive();

var headerOffset = 0f;

float tabLeft = 0;
for (var i = 0; i < ChildCount; i++)
{
if (!GetTabVisible(i))
if (relX > tabLeft && relX <= _tabRight[i])
{
continue;
}

var title = GetActualTabTitle(i);

var titleLength = 0;
// Get string length.
foreach (var rune in title.EnumerateRunes())
{
if (!font.TryGetCharMetrics(rune, UIScale, out var metrics))
{
continue;
}

titleLength += metrics.Advance;
}

var active = _currentTab == i;
var box = active ? boxActive : boxInactive;
var boxAdvance = titleLength + (box?.MinimumSize.X ?? 0);

if (headerOffset < relX && headerOffset + boxAdvance > relX)
{
// Got em.
CurrentTab = i;
return;
}

headerOffset += boxAdvance;
// Next tab starts here
tabLeft = _tabRight[i];
}
}

Expand Down
11 changes: 7 additions & 4 deletions Robust.Client/UserInterface/XAML/Proxy/XamlHotReloadManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,16 +58,16 @@ private FileSystemWatcher CreateWatcher(string location)
var watcher = new FileSystemWatcher(location)
{
IncludeSubdirectories = true,
NotifyFilter = NotifyFilters.LastWrite,
NotifyFilter = NotifyFilters.LastWrite | NotifyFilters.FileName,
};

watcher.Changed += (_, args) =>
void OnWatcherEvent(object sender, FileSystemEventArgs args)
{
switch (args.ChangeType)
{
case WatcherChangeTypes.Renamed:
case WatcherChangeTypes.Deleted:
return;
case WatcherChangeTypes.Renamed:
case WatcherChangeTypes.Created:
case WatcherChangeTypes.Changed:
case WatcherChangeTypes.All:
Expand Down Expand Up @@ -98,7 +98,10 @@ private FileSystemWatcher CreateWatcher(string location)
_xamlProxyManager.SetImplementation(resourceFileName, newText);
});
};
}

watcher.Changed += OnWatcherEvent;
watcher.Renamed += OnWatcherEvent;
watcher.EnableRaisingEvents = true;
return watcher;
}
Expand Down
10 changes: 6 additions & 4 deletions Robust.Server/GameStates/PvsChunk.cs
Original file line number Diff line number Diff line change
Expand Up @@ -141,9 +141,10 @@ public bool PopulateContents(EntityQuery<MetaDataComponent> meta, EntityQuery<Tr
{
// TODO ARCH multi-component queries
if (!meta.TryGetComponent(child, out var childMeta)
|| !xform.TryGetComponent(child, out var childXform))
|| !xform.TryGetComponent(child, out var childXform)
|| childMeta.EntityLifeStage >= EntityLifeStage.Terminating)
{
DebugTools.Assert($"PVS chunk contains a deleted entity: {child}");
DebugTools.Assert($"PVS chunk contains a delete or terminating entity: {child}");
MarkDirty();
return false;
}
Expand Down Expand Up @@ -188,9 +189,10 @@ public bool PopulateContents(EntityQuery<MetaDataComponent> meta, EntityQuery<Tr
{
// TODO ARCH multi-component queries
if (!meta.TryGetComponent(child, out var childMeta)
|| !xform.TryGetComponent(child, out var childXform))
|| !xform.TryGetComponent(child, out var childXform)
|| childMeta.EntityLifeStage >= EntityLifeStage.Terminating)
{
DebugTools.Assert($"PVS chunk contains a deleted entity: {child}");
DebugTools.Assert($"PVS chunk contains a delete or terminating entity: {child}");
MarkDirty();
return false;
}
Expand Down
1 change: 1 addition & 0 deletions Robust.Server/GameStates/PvsSystem.Chunks.cs
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,7 @@ internal void ProcessVisibleChunksSequential()
[MethodImpl(MethodImplOptions.AggressiveInlining)]
private void AddEntityToChunk(EntityUid uid, MetaDataComponent meta, PvsChunkLocation location)
{
DebugTools.Assert(meta.EntityLifeStage < EntityLifeStage.Terminating);
ref var chunk = ref CollectionsMarshal.GetValueRefOrAddDefault(_chunks, location, out var existing);
if (!existing)
{
Expand Down
3 changes: 2 additions & 1 deletion Robust.Server/GameStates/PvsSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -129,14 +129,14 @@ public override void Initialize()

SubscribeLocalEvent<MapChangedEvent>(OnMapChanged);
SubscribeLocalEvent<GridRemovalEvent>(OnGridRemoved);
SubscribeLocalEvent<EntityTerminatingEvent>(OnEntityTerminating);
SubscribeLocalEvent<TransformComponent, TransformStartupEvent>(OnTransformStartup);

_playerManager.PlayerStatusChanged += OnPlayerStatusChanged;
_transform.OnBeforeMoveEvent += OnEntityMove;
EntityManager.EntityAdded += OnEntityAdded;
EntityManager.EntityDeleted += OnEntityDeleted;
EntityManager.AfterEntityFlush += AfterEntityFlush;
EntityManager.BeforeEntityTerminating += OnEntityTerminating;

Subs.CVar(_configManager, CVars.NetPVS, SetPvs, true);
Subs.CVar(_configManager, CVars.NetMaxUpdateRange, OnViewsizeChanged, true);
Expand All @@ -162,6 +162,7 @@ public override void Shutdown()
EntityManager.EntityAdded -= OnEntityAdded;
EntityManager.EntityDeleted -= OnEntityDeleted;
EntityManager.AfterEntityFlush -= AfterEntityFlush;
EntityManager.BeforeEntityTerminating -= OnEntityTerminating;

_parallelMgr.ParallelCountChanged -= ResetParallelism;

Expand Down
12 changes: 6 additions & 6 deletions Robust.Shared/GameObjects/EntityManager.Network.cs
Original file line number Diff line number Diff line change
Expand Up @@ -391,7 +391,7 @@ public void EnsureEntityDictionary<TComp, TValue>(Dictionary<NetEntity, TValue>
entities.EnsureCapacity(netEntities.Count);
foreach (var pair in netEntities)
{
entities.Add(EnsureEntity<TComp>(pair.Key, callerEntity), pair.Value);
entities.TryAdd(EnsureEntity<TComp>(pair.Key, callerEntity), pair.Value);
}
}

Expand All @@ -402,7 +402,7 @@ public void EnsureEntityDictionaryNullableValue<TComp, TValue>(Dictionary<NetEnt
entities.EnsureCapacity(netEntities.Count);
foreach (var pair in netEntities)
{
entities.Add(EnsureEntity<TComp>(pair.Key, callerEntity), pair.Value);
entities.TryAdd(EnsureEntity<TComp>(pair.Key, callerEntity), pair.Value);
}
}

Expand All @@ -413,7 +413,7 @@ public void EnsureEntityDictionary<TComp, TKey>(Dictionary<TKey, NetEntity> netE
entities.EnsureCapacity(netEntities.Count);
foreach (var pair in netEntities)
{
entities.Add(pair.Key, EnsureEntity<TComp>(pair.Value, callerEntity));
entities.TryAdd(pair.Key, EnsureEntity<TComp>(pair.Value, callerEntity));
}
}

Expand All @@ -424,7 +424,7 @@ public void EnsureEntityDictionary<TComp, TKey>(Dictionary<TKey, NetEntity?> net
entities.EnsureCapacity(netEntities.Count);
foreach (var pair in netEntities)
{
entities.Add(pair.Key, EnsureEntity<TComp>(pair.Value, callerEntity));
entities.TryAdd(pair.Key, EnsureEntity<TComp>(pair.Value, callerEntity));
}
}

Expand All @@ -435,7 +435,7 @@ public void EnsureEntityDictionary<TComp>(Dictionary<NetEntity, NetEntity> netEn
entities.EnsureCapacity(netEntities.Count);
foreach (var pair in netEntities)
{
entities.Add(EnsureEntity<TComp>(pair.Key, callerEntity), EnsureEntity<TComp>(pair.Value, callerEntity));
entities.TryAdd(EnsureEntity<TComp>(pair.Key, callerEntity), EnsureEntity<TComp>(pair.Value, callerEntity));
}
}

Expand All @@ -446,7 +446,7 @@ public void EnsureEntityDictionary<TComp>(Dictionary<NetEntity, NetEntity?> netE
entities.EnsureCapacity(netEntities.Count);
foreach (var pair in netEntities)
{
entities.Add(EnsureEntity<TComp>(pair.Key, callerEntity), EnsureEntity<TComp>(pair.Value, callerEntity));
entities.TryAdd(EnsureEntity<TComp>(pair.Key, callerEntity), EnsureEntity<TComp>(pair.Value, callerEntity));
}
}

Expand Down
9 changes: 9 additions & 0 deletions Robust.Shared/GameObjects/EntityManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,14 @@ public abstract partial class EntityManager : IEntityManager
public event Action<Entity<MetaDataComponent>>? EntityAdded;
public event Action<Entity<MetaDataComponent>>? EntityInitialized;
public event Action<Entity<MetaDataComponent>>? EntityDeleted;

/// <summary>
/// Internal termination event handlers. This is mainly for exception tolerance, we want to ensure that PVS,
/// and other important engine systems can get updated before some content code throws an exception.
/// </summary>
internal event TerminatingEventHandler? BeforeEntityTerminating;
public delegate void TerminatingEventHandler(ref EntityTerminatingEvent ev);

public event Action? BeforeEntityFlush;
public event Action? AfterEntityFlush;

Expand Down Expand Up @@ -556,6 +564,7 @@ private void RecursiveFlagEntityTermination(EntityUid uid,
try
{
var ev = new EntityTerminatingEvent((uid, metadata));
BeforeEntityTerminating?.Invoke(ref ev);
EventBus.RaiseLocalEvent(uid, ref ev, true);
}
catch (Exception e)
Expand Down
4 changes: 2 additions & 2 deletions Robust.Shared/Localization/Loc.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
using System;
using System.Diagnostics.CodeAnalysis;
using System.Globalization;
using JetBrains.Annotations;
using Robust.Shared.ContentPack;
using Robust.Shared.IoC;

namespace Robust.Shared.Localization
Expand Down Expand Up @@ -36,6 +34,7 @@ public static string GetString(string messageId)
return LocalizationManager.GetString(messageId);
}

[Obsolete("Use ILocalizationManager")]
public static bool TryGetString(string messageId, [NotNullWhen(true)] out string? message)
{
return LocalizationManager.TryGetString(messageId, out message);
Expand All @@ -49,6 +48,7 @@ public static string GetString(string messageId, params (string,object)[] args)
return LocalizationManager.GetString(messageId, args);
}

[Obsolete("Use ILocalizationManager")]
public static bool TryGetString(
string messageId,
[NotNullWhen(true)] out string? value,
Expand Down
9 changes: 6 additions & 3 deletions Robust.Shared/Physics/Dynamics/Contacts/Contact.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,13 @@
using System.Collections.Generic;
using System.Numerics;
using Robust.Shared.GameObjects;
using Robust.Shared.IoC;
using Robust.Shared.Maths;
using Robust.Shared.Physics.Collision;
using Robust.Shared.Physics.Collision.Shapes;
using Robust.Shared.Physics.Components;
using Robust.Shared.Physics.Systems;
using Robust.Shared.ViewVariables;

namespace Robust.Shared.Physics.Dynamics.Contacts
{
Expand Down Expand Up @@ -94,11 +97,13 @@ internal Contact(IManifoldManager manifoldManager)
/// <summary>
/// Determines whether the contact is touching.
/// </summary>
[ViewVariables]
public bool IsTouching { get; internal set; }

/// Enable/disable this contact. This can be used inside the pre-solve
/// contact listener. The contact is only disabled for the current
/// time step (or sub-step in continuous collisions).
[ViewVariables]
public bool Enabled { get; set; }

/// <summary>
Expand Down Expand Up @@ -256,9 +261,7 @@ internal void UpdateIsTouching(Transform bodyATransform, Transform bodyBTransfor
{
var manifold = Manifold;
Evaluate(ref manifold, bodyATransform, bodyBTransform);

if (IsTouching)
IsTouching = manifold.PointCount > 0;
IsTouching = manifold.PointCount > 0;
}
}

Expand Down

0 comments on commit 34f2861

Please sign in to comment.