Fix client mispredict on some storage operations (#44612)

* Fix client mispredict on some storage operations

* Actually not needed

* retry

* Review
This commit is contained in:
B_Kirill 2026-07-12 00:26:56 +10:00 • committed by GitHub
parent 0552b28cf5
commit acad100b88
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 20 additions and 12 deletions

View file

@ -1,15 +1,16 @@
using System.Numerics;
using Content.Shared.Hands.EntitySystems;
using Content.Shared.Interaction;
using Content.Shared.Random.Helpers;
using Content.Shared.Storage;
using Content.Shared.Storage.Components;
using Robust.Shared.Random;
using Robust.Shared.Timing;
namespace Content.Shared.Placeable;
public sealed partial class PlaceableSurfaceSystem : EntitySystem
{
[Dependency] private IRobustRandom _random = default!;
[Dependency] private IGameTiming _timing = default!;
[Dependency] private SharedHandsSystem _handsSystem = default!;
[Dependency] private SharedTransformSystem _transformSystem = default!;
@ -109,7 +110,8 @@ public sealed partial class PlaceableSurfaceSystem : EntitySystem
foreach (var entity in args.DumpQueue)
{
_transformSystem.SetWorldPositionRotation(entity, targetPos + _random.NextVector2Box() / 4, targetRot);
var rand = SharedRandomExtensions.PredictedRandom(_timing, GetNetEntity(entity));
_transformSystem.SetWorldPositionRotation(entity, targetPos + rand.NextVector2Box() / 4, targetRot);
}
}
}

View file

@ -2,17 +2,18 @@ using System.Linq;
using Content.Shared.DoAfter;
using Content.Shared.Interaction;
using Content.Shared.Item;
using Content.Shared.Random.Helpers;
using Content.Shared.Storage.Components;
using Content.Shared.Verbs;
using Robust.Shared.Audio.Systems;
using Robust.Shared.Random;
using Robust.Shared.Timing;
using Robust.Shared.Utility;
namespace Content.Shared.Storage.EntitySystems;
public sealed partial class DumpableSystem : EntitySystem
{
[Dependency] private IRobustRandom _random = default!;
[Dependency] private IGameTiming _timing = default!;
[Dependency] private SharedAudioSystem _audio = default!;
[Dependency] private SharedDoAfterSystem _doAfterSystem = default!;
[Dependency] private SharedTransformSystem _transformSystem = default!;
@ -64,7 +65,7 @@ public sealed partial class DumpableSystem : EntitySystem
StartDoAfter(uid, args.Target, args.User, dumpable);//Had multiplier of 0.6f
},
Text = Loc.GetString("dump-verb-name"),
Icon = new SpriteSpecifier.Texture(new ("/Textures/Interface/VerbIcons/drop.svg.192dpi.png")),
Icon = new SpriteSpecifier.Texture(new("/Textures/Interface/VerbIcons/drop.svg.192dpi.png")),
};
args.Verbs.Add(verb);
}
@ -113,7 +114,7 @@ public sealed partial class DumpableSystem : EntitySystem
delay += itemSize.Weight;
}
delay *= (float) dumpable.DelayPerItem.TotalSeconds * dumpable.Multiplier;
delay *= (float)dumpable.DelayPerItem.TotalSeconds * dumpable.Multiplier;
_doAfterSystem.TryStartDoAfter(new DoAfterArgs(EntityManager, userUid, delay, new DumpableDoAfterEvent(), storageUid, target: targetUid, used: storageUid)
{
@ -127,7 +128,8 @@ public sealed partial class DumpableSystem : EntitySystem
if (args.Handled || args.Cancelled || !TryComp<StorageComponent>(uid, out var storage) || storage.Container.ContainedEntities.Count == 0 || args.Args.Target is not { } target)
return;
var dumpQueue = new Queue<EntityUid>(storage.Container.ContainedEntities);
// TODO: Remove OrderBy when this issue is fixed in RT https://github.com/space-wizards/RobustToolbox/issues/6241
var dumpQueue = new Queue<EntityUid>(storage.Container.ContainedEntities.OrderBy(e => GetNetEntity(e)));
var evt = new DumpEvent(dumpQueue, args.Args.User, false, false);
RaiseLocalEvent(target, ref evt);
@ -139,7 +141,8 @@ public sealed partial class DumpableSystem : EntitySystem
foreach (var entity in dumpQueue)
{
var transform = Transform(entity);
_transformSystem.SetWorldPositionRotation(entity, targetPos + _random.NextVector2Box() / 4, _random.NextAngle(), transform);
var rand = SharedRandomExtensions.PredictedRandom(_timing, GetNetEntity(entity));
_transformSystem.SetWorldPositionRotation(entity, targetPos + rand.NextVector2Box() / 4, rand.NextAngle(), transform);
}
return;

View file

@ -568,7 +568,8 @@ public abstract partial class SharedStorageSystem : EntitySystem
_entityLookupSystem.GetEntitiesInRange(args.ClickLocation, storageComp.AreaInsertRadius, _entSet, LookupFlags.Dynamic | LookupFlags.Sundries);
var delay = 0f;
foreach (var entity in _entSet)
// TODO: Remove OrderBy when this issue is fixed in RT https://github.com/space-wizards/RobustToolbox/issues/6241
foreach (var entity in _entSet.OrderBy(e => GetNetEntity(e)))
{
if (entity == args.User
|| !_itemQuery.TryGetComponent(entity, out var itemComp) // Need comp to get item size to get weight
@ -1009,7 +1010,8 @@ public abstract partial class SharedStorageSystem : EntitySystem
|| Resolve(target, ref targetLock, false) && targetLock.Locked)
return;
foreach (var entity in entities.ToArray())
// TODO: Remove OrderBy when this issue is fixed in RT https://github.com/space-wizards/RobustToolbox/issues/6241
foreach (var entity in entities.ToArray().OrderBy(e => GetNetEntity(e)))
{
Insert(target, entity, out _, user: user, targetComp, playSound: false);
}
@ -1208,7 +1210,8 @@ public abstract partial class SharedStorageSystem : EntitySystem
var toInsertCount = insertStack.Count;
foreach (var ent in storageComp.Container.ContainedEntities)
// TODO: Remove OrderBy when this issue is fixed in RT https://github.com/space-wizards/RobustToolbox/issues/6241
foreach (var ent in storageComp.Container.ContainedEntities.OrderBy(e => GetNetEntity(e)))
{
if (!_stackQuery.TryGetComponent(ent, out var containedStack))
continue;