From d51d74d9341077ae6af7ca2ab5bf4c77dc271d7e Mon Sep 17 00:00:00 2001 From: metalgearsloth <31366439+metalgearsloth@users.noreply.github.com> Date: Mon, 1 May 2023 14:49:25 +1000 Subject: [PATCH] Content fixes for timeoffsets (#15934) --- .../Weapons/Ranged/Systems/GunSystem.cs | 4 ++-- .../Tests/PrototypeSaveTest.cs | 10 ++++++++-- .../TileAtmosCollectionSerializer.cs | 4 +++- .../Charges/Components/AutoRechargeComponent.cs | 2 +- .../EntitySystems/SolutionPurgeSystem.cs | 7 ------- .../Fluids/EntitySystems/SmokeSystem.cs | 6 ------ Content.Server/NPC/NPCBlackboardSerializer.cs | 1 + .../Pinpointer/ProximityBeeperSystem.cs | 7 ------- Content.Server/PowerCell/PowerCellSystem.cs | 7 ------- .../Shuttles/Systems/ThrusterSystem.cs | 7 ------- Content.Server/Spreader/SpreaderSystem.cs | 6 ------ .../Weapons/Ranged/Systems/GunSystem.cs | 10 +++++----- .../Anomaly/Components/AnomalyComponent.cs | 2 +- Content.Shared/Damage/Systems/StaminaSystem.cs | 8 +++++++- .../Components/EmitSoundOnCollideComponent.cs | 4 ++-- Content.Shared/Sound/SharedEmitSoundSystem.cs | 7 +++++++ .../Weapons/Melee/SharedMeleeWeaponSystem.cs | 8 +++++++- .../Weapons/Ranged/Systems/SharedGunSystem.cs | 16 +++++++++------- 18 files changed, 53 insertions(+), 63 deletions(-) diff --git a/Content.Client/Weapons/Ranged/Systems/GunSystem.cs b/Content.Client/Weapons/Ranged/Systems/GunSystem.cs index d6f068fcb1..fce3139b62 100644 --- a/Content.Client/Weapons/Ranged/Systems/GunSystem.cs +++ b/Content.Client/Weapons/Ranged/Systems/GunSystem.cs @@ -158,7 +158,7 @@ public sealed partial class GunSystem : SharedGunSystem } // Define target coordinates relative to gun entity, so that network latency on moving grids doesn't fuck up the target location. - var coordinates = EntityCoordinates.FromMap(entity, mousePos, Transform, EntityManager); + var coordinates = EntityCoordinates.FromMap(entity, mousePos, TransformSystem, EntityManager); Sawmill.Debug($"Sending shoot request tick {Timing.CurTick} / {Timing.CurTime}"); @@ -175,7 +175,7 @@ public sealed partial class GunSystem : SharedGunSystem // Rather than splitting client / server for every ammo provider it's easier // to just delete the spawned entities. This is for programmer sanity despite the wasted perf. // This also means any ammo specific stuff can be grabbed as necessary. - var direction = fromCoordinates.ToMapPos(EntityManager, Transform) - toCoordinates.ToMapPos(EntityManager, Transform); + var direction = fromCoordinates.ToMapPos(EntityManager, TransformSystem) - toCoordinates.ToMapPos(EntityManager, TransformSystem); foreach (var (ent, shootable) in ammo) { diff --git a/Content.IntegrationTests/Tests/PrototypeSaveTest.cs b/Content.IntegrationTests/Tests/PrototypeSaveTest.cs index 5d64ca1a4e..15c3416ae1 100644 --- a/Content.IntegrationTests/Tests/PrototypeSaveTest.cs +++ b/Content.IntegrationTests/Tests/PrototypeSaveTest.cs @@ -4,6 +4,7 @@ using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; using Content.Shared.Coordinates; +using Content.Shared.Sound.Components; using NUnit.Framework; using Robust.Shared.GameObjects; using Robust.Shared.IoC; @@ -18,6 +19,7 @@ using Robust.Shared.Serialization.Markdown.Mapping; using Robust.Shared.Serialization.Markdown.Validation; using Robust.Shared.Serialization.Markdown.Value; using Robust.Shared.Serialization.TypeSerializers.Interfaces; +using Robust.Shared.Timing; namespace Content.IntegrationTests.Tests; @@ -166,16 +168,19 @@ public sealed class PrototypeSaveTest foreach (var prototype in prototypes) { uid = entityMan.SpawnEntity(prototype.ID, testLocation); - server.RunTicks(1); // get default prototype data Dictionary protoData = new(); try { + context.WritingReadingPrototypes = true; + foreach (var (compType, comp) in prototype.Components) { - protoData.Add(compType, seriMan.WriteValueAs(comp.Component.GetType(), comp.Component, alwaysWrite:true, context: context)); + protoData.Add(compType, seriMan.WriteValueAs(comp.Component.GetType(), comp.Component, alwaysWrite: true, context: context)); } + + context.WritingReadingPrototypes = false; } catch (Exception e) { @@ -239,6 +244,7 @@ public sealed class PrototypeSaveTest ITypeSerializer { public SerializationManager.SerializerProvider SerializerProvider { get; } + public bool WritingReadingPrototypes { get; set; } public TestEntityUidContext() { diff --git a/Content.Server/Atmos/Serialization/TileAtmosCollectionSerializer.cs b/Content.Server/Atmos/Serialization/TileAtmosCollectionSerializer.cs index f0cbefa86b..c3a6aec3e9 100644 --- a/Content.Server/Atmos/Serialization/TileAtmosCollectionSerializer.cs +++ b/Content.Server/Atmos/Serialization/TileAtmosCollectionSerializer.cs @@ -175,7 +175,9 @@ public sealed class TileAtmosCollectionSerializer : ITypeSerializer Data = new(); } - public void CopyTo(ISerializationManager serializationManager, Dictionary source, ref Dictionary target, SerializationHookContext hookCtx, + public void CopyTo(ISerializationManager serializationManager, Dictionary source, ref Dictionary target, + IDependencyCollection dependencies, + SerializationHookContext hookCtx, ISerializationContext? context = null) { target.Clear(); diff --git a/Content.Server/Charges/Components/AutoRechargeComponent.cs b/Content.Server/Charges/Components/AutoRechargeComponent.cs index 6a64c159a8..911145062b 100644 --- a/Content.Server/Charges/Components/AutoRechargeComponent.cs +++ b/Content.Server/Charges/Components/AutoRechargeComponent.cs @@ -21,5 +21,5 @@ public sealed class AutoRechargeComponent : Component /// The time when the next charge will be added /// [DataField("nextChargeTime", customTypeSerializer: typeof(TimeOffsetSerializer))] - public TimeSpan NextChargeTime = TimeSpan.MaxValue; + public TimeSpan NextChargeTime; } diff --git a/Content.Server/Chemistry/EntitySystems/SolutionPurgeSystem.cs b/Content.Server/Chemistry/EntitySystems/SolutionPurgeSystem.cs index 41bde84870..4dde86eadb 100644 --- a/Content.Server/Chemistry/EntitySystems/SolutionPurgeSystem.cs +++ b/Content.Server/Chemistry/EntitySystems/SolutionPurgeSystem.cs @@ -15,7 +15,6 @@ public sealed class SolutionPurgeSystem : EntitySystem base.Initialize(); SubscribeLocalEvent(OnUnpaused); - SubscribeLocalEvent(OnMapInit); } public override void Update(float frameTime) @@ -39,10 +38,4 @@ public sealed class SolutionPurgeSystem : EntitySystem { comp.NextPurgeTime += args.PausedTime; } - - private void OnMapInit(EntityUid uid, SolutionPurgeComponent comp, MapInitEvent args) - { - if (comp.NextPurgeTime < _timing.CurTime) - comp.NextPurgeTime = _timing.CurTime; - } } diff --git a/Content.Server/Fluids/EntitySystems/SmokeSystem.cs b/Content.Server/Fluids/EntitySystems/SmokeSystem.cs index b489cbc2a4..f9564612de 100644 --- a/Content.Server/Fluids/EntitySystems/SmokeSystem.cs +++ b/Content.Server/Fluids/EntitySystems/SmokeSystem.cs @@ -45,7 +45,6 @@ public sealed class SmokeSystem : EntitySystem { base.Initialize(); SubscribeLocalEvent(OnSmokeUnpaused); - SubscribeLocalEvent(OnSmokeMapInit); SubscribeLocalEvent(OnReactionAttempt); SubscribeLocalEvent(OnSmokeSpread); SubscribeLocalEvent(OnSmokeDissipate); @@ -166,11 +165,6 @@ public sealed class SmokeSystem : EntitySystem } } - private void OnSmokeMapInit(EntityUid uid, SmokeComponent component, MapInitEvent args) - { - component.NextReact = _timing.CurTime; - } - private void OnSmokeUnpaused(EntityUid uid, SmokeComponent component, ref EntityUnpausedEvent args) { component.NextReact += args.PausedTime; diff --git a/Content.Server/NPC/NPCBlackboardSerializer.cs b/Content.Server/NPC/NPCBlackboardSerializer.cs index 8a02508b91..276e1d072b 100644 --- a/Content.Server/NPC/NPCBlackboardSerializer.cs +++ b/Content.Server/NPC/NPCBlackboardSerializer.cs @@ -85,6 +85,7 @@ public sealed class NPCBlackboardSerializer : ITypeReader(OnUseInHand); - SubscribeLocalEvent(OnInit); SubscribeLocalEvent(OnUnpaused); SubscribeLocalEvent(OnPowerCellSlotEmpty); } @@ -34,12 +33,6 @@ public sealed class ProximityBeeperSystem : EntitySystem args.Handled = TryToggle(uid, component, args.User); } - private void OnInit(EntityUid uid, ProximityBeeperComponent component, MapInitEvent args) - { - if (component.NextBeepTime < _timing.CurTime) - component.NextBeepTime = _timing.CurTime; - } - private void OnUnpaused(EntityUid uid, ProximityBeeperComponent component, ref EntityUnpausedEvent args) { component.NextBeepTime += args.PausedTime; diff --git a/Content.Server/PowerCell/PowerCellSystem.cs b/Content.Server/PowerCell/PowerCellSystem.cs index f85da633ca..b28ea159ec 100644 --- a/Content.Server/PowerCell/PowerCellSystem.cs +++ b/Content.Server/PowerCell/PowerCellSystem.cs @@ -42,7 +42,6 @@ public sealed class PowerCellSystem : SharedPowerCellSystem SubscribeLocalEvent(OnCellExamined); - SubscribeLocalEvent(OnMapInit); SubscribeLocalEvent(OnUnpaused); // funny @@ -136,12 +135,6 @@ public sealed class PowerCellSystem : SharedPowerCellSystem RaiseLocalEvent(uid, ref ev); } - private void OnMapInit(EntityUid uid, PowerCellDrawComponent component, MapInitEvent args) - { - if (component.NextUpdateTime < _timing.CurTime) - component.NextUpdateTime = _timing.CurTime; - } - private void OnUnpaused(EntityUid uid, PowerCellDrawComponent component, ref EntityUnpausedEvent args) { component.NextUpdateTime += args.PausedTime; diff --git a/Content.Server/Shuttles/Systems/ThrusterSystem.cs b/Content.Server/Shuttles/Systems/ThrusterSystem.cs index 6311d0e8c0..51d6d9217b 100644 --- a/Content.Server/Shuttles/Systems/ThrusterSystem.cs +++ b/Content.Server/Shuttles/Systems/ThrusterSystem.cs @@ -44,7 +44,6 @@ public sealed class ThrusterSystem : EntitySystem SubscribeLocalEvent(OnActivateThruster); SubscribeLocalEvent(OnThrusterInit); SubscribeLocalEvent(OnThrusterShutdown); - SubscribeLocalEvent(OnThrusterMapInit); SubscribeLocalEvent(OnPowerChange); SubscribeLocalEvent(OnAnchorChange); SubscribeLocalEvent(OnThrusterReAnchor); @@ -201,12 +200,6 @@ public sealed class ThrusterSystem : EntitySystem EnableThruster(uid, component); } - private void OnThrusterMapInit(EntityUid uid, ThrusterComponent component, MapInitEvent args) - { - if (component.NextFire < _timing.CurTime) - component.NextFire = _timing.CurTime; - } - private void OnThrusterInit(EntityUid uid, ThrusterComponent component, ComponentInit args) { _ambient.SetAmbience(uid, false); diff --git a/Content.Server/Spreader/SpreaderSystem.cs b/Content.Server/Spreader/SpreaderSystem.cs index b39f83e4a2..9bdf71dfd7 100644 --- a/Content.Server/Spreader/SpreaderSystem.cs +++ b/Content.Server/Spreader/SpreaderSystem.cs @@ -36,7 +36,6 @@ public sealed class SpreaderSystem : EntitySystem { SubscribeLocalEvent(OnAirtightChanged); SubscribeLocalEvent(OnGridInit); - SubscribeLocalEvent(OnSpreaderGridMapInit); SubscribeLocalEvent(OnGridUnpaused); @@ -44,11 +43,6 @@ public sealed class SpreaderSystem : EntitySystem _prototype.PrototypesReloaded += OnPrototypeReload; } - private void OnSpreaderGridMapInit(EntityUid uid, SpreaderGridComponent component, MapInitEvent args) - { - component.NextUpdate = _timing.CurTime; - } - public override void Shutdown() { base.Shutdown(); diff --git a/Content.Server/Weapons/Ranged/Systems/GunSystem.cs b/Content.Server/Weapons/Ranged/Systems/GunSystem.cs index 3eaf9d8bf4..8e4a291f33 100644 --- a/Content.Server/Weapons/Ranged/Systems/GunSystem.cs +++ b/Content.Server/Weapons/Ranged/Systems/GunSystem.cs @@ -93,8 +93,8 @@ public sealed partial class GunSystem : SharedGunSystem } } - var fromMap = fromCoordinates.ToMap(EntityManager, Transform); - var toMap = toCoordinates.ToMapPos(EntityManager, Transform); + var fromMap = fromCoordinates.ToMap(EntityManager, TransformSystem); + var toMap = toCoordinates.ToMapPos(EntityManager, TransformSystem); var mapDirection = toMap - fromMap.Position; var mapAngle = mapDirection.ToAngle(); var angle = GetRecoilAngle(Timing.CurTime, gun, mapDirection.ToAngle()); @@ -299,7 +299,7 @@ public sealed partial class GunSystem : SharedGunSystem Projectiles.SetShooter(projectile, user.Value); } - Transform.SetWorldRotation(uid, direction.ToWorldAngle()); + TransformSystem.SetWorldRotation(uid, direction.ToWorldAngle()); } /// @@ -398,10 +398,10 @@ public sealed partial class GunSystem : SharedGunSystem if (xformQuery.TryGetComponent(gridUid, out var gridXform)) { - var (_, gridRot, gridInvMatrix) = Transform.GetWorldPositionRotationInvMatrix(gridUid.Value, xformQuery); + var (_, gridRot, gridInvMatrix) = TransformSystem.GetWorldPositionRotationInvMatrix(gridUid.Value, xformQuery); fromCoordinates = new EntityCoordinates(gridUid.Value, - gridInvMatrix.Transform(fromCoordinates.ToMapPos(EntityManager, Transform))); + gridInvMatrix.Transform(fromCoordinates.ToMapPos(EntityManager, TransformSystem))); // Use the fallback angle I guess? angle -= gridRot; diff --git a/Content.Shared/Anomaly/Components/AnomalyComponent.cs b/Content.Shared/Anomaly/Components/AnomalyComponent.cs index cf2e12524e..8df708dda8 100644 --- a/Content.Shared/Anomaly/Components/AnomalyComponent.cs +++ b/Content.Shared/Anomaly/Components/AnomalyComponent.cs @@ -85,7 +85,7 @@ public sealed class AnomalyComponent : Component /// The time at which the next artifact pulse will occur. /// [DataField("nextPulseTime", customTypeSerializer: typeof(TimeOffsetSerializer)), ViewVariables(VVAccess.ReadWrite)] - public TimeSpan NextPulseTime = TimeSpan.MaxValue; + public TimeSpan NextPulseTime = TimeSpan.Zero; /// /// The minimum interval between pulses. diff --git a/Content.Shared/Damage/Systems/StaminaSystem.cs b/Content.Shared/Damage/Systems/StaminaSystem.cs index 368f286d4e..30e974a2f1 100644 --- a/Content.Shared/Damage/Systems/StaminaSystem.cs +++ b/Content.Shared/Damage/Systems/StaminaSystem.cs @@ -41,6 +41,7 @@ public sealed class StaminaSystem : EntitySystem public override void Initialize() { base.Initialize(); + SubscribeLocalEvent(OnStamUnpaused); SubscribeLocalEvent(OnStartup); SubscribeLocalEvent(OnShutdown); SubscribeLocalEvent(OnStamGetState); @@ -51,6 +52,11 @@ public sealed class StaminaSystem : EntitySystem SubscribeLocalEvent(OnHit); } + private void OnStamUnpaused(EntityUid uid, StaminaComponent component, ref EntityUnpausedEvent args) + { + component.NextUpdate += args.PausedTime; + } + private void OnStamGetState(EntityUid uid, StaminaComponent component, ref ComponentGetState args) { args.State = new StaminaComponentState() @@ -206,7 +212,7 @@ public sealed class StaminaSystem : EntitySystem { if (!args.OurFixture.ID.Equals(CollideFixture)) return; - TakeStaminaDamage(args.OtherFixture.Body.Owner, component.Damage, source:args.OurFixture.Body.Owner); + TakeStaminaDamage(args.OtherEntity, component.Damage, source:args.OurEntity); } private void SetStaminaAlert(EntityUid uid, StaminaComponent? component = null) diff --git a/Content.Shared/Sound/Components/EmitSoundOnCollideComponent.cs b/Content.Shared/Sound/Components/EmitSoundOnCollideComponent.cs index 671868d02c..95db14427d 100644 --- a/Content.Shared/Sound/Components/EmitSoundOnCollideComponent.cs +++ b/Content.Shared/Sound/Components/EmitSoundOnCollideComponent.cs @@ -17,6 +17,6 @@ public sealed class EmitSoundOnCollideComponent : BaseEmitSoundComponent /// /// To avoid sound spam add a cooldown to it. /// - [ViewVariables(VVAccess.ReadWrite), DataField("nextSound", customTypeSerializer:typeof(TimeOffsetSerializer))] - public TimeSpan NextSound; + [ViewVariables(VVAccess.ReadWrite), DataField("nextSound", customTypeSerializer: typeof(TimeOffsetSerializer))] + public TimeSpan NextSound = TimeSpan.FromSeconds(0.2); } diff --git a/Content.Shared/Sound/SharedEmitSoundSystem.cs b/Content.Shared/Sound/SharedEmitSoundSystem.cs index 86433d4967..3dc1cb793f 100644 --- a/Content.Shared/Sound/SharedEmitSoundSystem.cs +++ b/Content.Shared/Sound/SharedEmitSoundSystem.cs @@ -39,6 +39,8 @@ public abstract class SharedEmitSoundSystem : EntitySystem SubscribeLocalEvent(OnEmitSoundOnActivateInWorld); SubscribeLocalEvent(OnEmitSoundOnPickup); SubscribeLocalEvent(OnEmitSoundOnDrop); + + SubscribeLocalEvent(OnEmitSoundUnpaused); SubscribeLocalEvent(OnEmitSoundOnCollide); } @@ -112,6 +114,11 @@ public abstract class SharedEmitSoundSystem : EntitySystem } } + private void OnEmitSoundUnpaused(EntityUid uid, EmitSoundOnCollideComponent component, ref EntityUnpausedEvent args) + { + component.NextSound += args.PausedTime; + } + private void OnEmitSoundOnCollide(EntityUid uid, EmitSoundOnCollideComponent component, ref StartCollideEvent args) { if (!args.OurFixture.Hard || diff --git a/Content.Shared/Weapons/Melee/SharedMeleeWeaponSystem.cs b/Content.Shared/Weapons/Melee/SharedMeleeWeaponSystem.cs index da8e23584d..ef9be4d9cf 100644 --- a/Content.Shared/Weapons/Melee/SharedMeleeWeaponSystem.cs +++ b/Content.Shared/Weapons/Melee/SharedMeleeWeaponSystem.cs @@ -59,6 +59,7 @@ public abstract class SharedMeleeWeaponSystem : EntitySystem base.Initialize(); Sawmill = Logger.GetSawmill("melee"); + SubscribeLocalEvent(OnMeleeUnpaused); SubscribeLocalEvent(OnGetState); SubscribeLocalEvent(OnHandleState); SubscribeLocalEvent(OnMeleeDropped); @@ -77,11 +78,16 @@ public abstract class SharedMeleeWeaponSystem : EntitySystem private void OnMapInit(EntityUid uid, MeleeWeaponComponent component, MapInitEvent args) { - if (component.NextAttack > TimeSpan.Zero) + if (component.NextAttack > Timing.CurTime) Logger.Warning($"Initializing a map that contains an entity that is on cooldown. Entity: {ToPrettyString(uid)}"); #endif } + private void OnMeleeUnpaused(EntityUid uid, MeleeWeaponComponent component, ref EntityUnpausedEvent args) + { + component.NextAttack += args.PausedTime; + } + private void OnMeleeSelected(EntityUid uid, MeleeWeaponComponent component, HandSelectedEvent args) { if (component.AttackRate.Equals(0f)) diff --git a/Content.Shared/Weapons/Ranged/Systems/SharedGunSystem.cs b/Content.Shared/Weapons/Ranged/Systems/SharedGunSystem.cs index 65bb9e6a53..2810019f5b 100644 --- a/Content.Shared/Weapons/Ranged/Systems/SharedGunSystem.cs +++ b/Content.Shared/Weapons/Ranged/Systems/SharedGunSystem.cs @@ -52,7 +52,7 @@ public abstract partial class SharedGunSystem : EntitySystem [Dependency] protected readonly SharedAudioSystem Audio = default!; [Dependency] private readonly SharedGravitySystem _gravity = default!; [Dependency] protected readonly SharedProjectileSystem Projectiles = default!; - [Dependency] protected readonly SharedTransformSystem Transform = default!; + [Dependency] protected readonly SharedTransformSystem TransformSystem = default!; protected ISawmill Sawmill = default!; @@ -85,7 +85,7 @@ public abstract partial class SharedGunSystem : EntitySystem SubscribeLocalEvent>(OnAltVerb); SubscribeLocalEvent(OnExamine); SubscribeLocalEvent(OnCycleMode); - SubscribeLocalEvent(OnGunInit); + SubscribeLocalEvent(OnGunUnpaused); #if DEBUG SubscribeLocalEvent(OnMapInit); @@ -93,14 +93,16 @@ public abstract partial class SharedGunSystem : EntitySystem private void OnMapInit(EntityUid uid, GunComponent component, MapInitEvent args) { - if (component.NextFire > TimeSpan.Zero) + if (component.NextFire > Timing.CurTime) Logger.Warning($"Initializing a map that contains an entity that is on cooldown. Entity: {ToPrettyString(uid)}"); + + DebugTools.Assert((component.AvailableModes & component.SelectedMode) != 0x0); #endif } - private void OnGunInit(EntityUid uid, GunComponent component, ComponentInit args) + private void OnGunUnpaused(EntityUid uid, GunComponent component, ref EntityUnpausedEvent args) { - DebugTools.Assert((component.AvailableModes & component.SelectedMode) != 0x0); + component.NextFire += args.PausedTime; } private void OnGunMeleeAttempt(EntityUid uid, GunComponent component, ref MeleeAttackAttemptEvent args) @@ -378,8 +380,8 @@ public abstract partial class SharedGunSystem : EntitySystem public void CauseImpulse(EntityCoordinates fromCoordinates, EntityCoordinates toCoordinates, EntityUid user, PhysicsComponent userPhysics) { - var fromMap = fromCoordinates.ToMapPos(EntityManager, Transform); - var toMap = toCoordinates.ToMapPos(EntityManager, Transform); + var fromMap = fromCoordinates.ToMapPos(EntityManager, TransformSystem); + var toMap = toCoordinates.ToMapPos(EntityManager, TransformSystem); var shotDirection = (toMap - fromMap).Normalized; const float impulseStrength = 25.0f;