Content fixes for timeoffsets (#15934)

This commit is contained in:
metalgearsloth
2023-05-01 14:49:25 +10:00
committed by GitHub
parent 2cf883b56a
commit d51d74d934
18 changed files with 53 additions and 63 deletions

View File

@@ -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)
{

View File

@@ -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<string, MappingDataNode> protoData = new();
try
{
context.WritingReadingPrototypes = true;
foreach (var (compType, comp) in prototype.Components)
{
protoData.Add(compType, seriMan.WriteValueAs<MappingDataNode>(comp.Component.GetType(), comp.Component, alwaysWrite:true, context: context));
protoData.Add(compType, seriMan.WriteValueAs<MappingDataNode>(comp.Component.GetType(), comp.Component, alwaysWrite: true, context: context));
}
context.WritingReadingPrototypes = false;
}
catch (Exception e)
{
@@ -239,6 +244,7 @@ public sealed class PrototypeSaveTest
ITypeSerializer<EntityUid, ValueDataNode>
{
public SerializationManager.SerializerProvider SerializerProvider { get; }
public bool WritingReadingPrototypes { get; set; }
public TestEntityUidContext()
{

View File

@@ -175,7 +175,9 @@ public sealed class TileAtmosCollectionSerializer : ITypeSerializer<Dictionary<V
public readonly Dictionary<int, uint> Data = new();
}
public void CopyTo(ISerializationManager serializationManager, Dictionary<Vector2i, TileAtmosphere> source, ref Dictionary<Vector2i, TileAtmosphere> target, SerializationHookContext hookCtx,
public void CopyTo(ISerializationManager serializationManager, Dictionary<Vector2i, TileAtmosphere> source, ref Dictionary<Vector2i, TileAtmosphere> target,
IDependencyCollection dependencies,
SerializationHookContext hookCtx,
ISerializationContext? context = null)
{
target.Clear();

View File

@@ -21,5 +21,5 @@ public sealed class AutoRechargeComponent : Component
/// The time when the next charge will be added
/// </summary>
[DataField("nextChargeTime", customTypeSerializer: typeof(TimeOffsetSerializer))]
public TimeSpan NextChargeTime = TimeSpan.MaxValue;
public TimeSpan NextChargeTime;
}

View File

@@ -15,7 +15,6 @@ public sealed class SolutionPurgeSystem : EntitySystem
base.Initialize();
SubscribeLocalEvent<SolutionPurgeComponent, EntityUnpausedEvent>(OnUnpaused);
SubscribeLocalEvent<SolutionPurgeComponent, MapInitEvent>(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;
}
}

View File

@@ -45,7 +45,6 @@ public sealed class SmokeSystem : EntitySystem
{
base.Initialize();
SubscribeLocalEvent<SmokeComponent, EntityUnpausedEvent>(OnSmokeUnpaused);
SubscribeLocalEvent<SmokeComponent, MapInitEvent>(OnSmokeMapInit);
SubscribeLocalEvent<SmokeComponent, ReactionAttemptEvent>(OnReactionAttempt);
SubscribeLocalEvent<SmokeComponent, SpreadNeighborsEvent>(OnSmokeSpread);
SubscribeLocalEvent<SmokeDissipateSpawnComponent, TimedDespawnEvent>(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;

View File

@@ -85,6 +85,7 @@ public sealed class NPCBlackboardSerializer : ITypeReader<NPCBlackboard, Mapping
ISerializationManager serializationManager,
NPCBlackboard source,
ref NPCBlackboard target,
IDependencyCollection dependencies,
SerializationHookContext hookCtx,
ISerializationContext? context = null)
{

View File

@@ -22,7 +22,6 @@ public sealed class ProximityBeeperSystem : EntitySystem
public override void Initialize()
{
SubscribeLocalEvent<ProximityBeeperComponent, UseInHandEvent>(OnUseInHand);
SubscribeLocalEvent<ProximityBeeperComponent, MapInitEvent>(OnInit);
SubscribeLocalEvent<ProximityBeeperComponent, EntityUnpausedEvent>(OnUnpaused);
SubscribeLocalEvent<ProximityBeeperComponent, PowerCellSlotEmptyEvent>(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;

View File

@@ -42,7 +42,6 @@ public sealed class PowerCellSystem : SharedPowerCellSystem
SubscribeLocalEvent<PowerCellComponent, ExaminedEvent>(OnCellExamined);
SubscribeLocalEvent<PowerCellDrawComponent, MapInitEvent>(OnMapInit);
SubscribeLocalEvent<PowerCellDrawComponent, EntityUnpausedEvent>(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;

View File

@@ -44,7 +44,6 @@ public sealed class ThrusterSystem : EntitySystem
SubscribeLocalEvent<ThrusterComponent, ActivateInWorldEvent>(OnActivateThruster);
SubscribeLocalEvent<ThrusterComponent, ComponentInit>(OnThrusterInit);
SubscribeLocalEvent<ThrusterComponent, ComponentShutdown>(OnThrusterShutdown);
SubscribeLocalEvent<ThrusterComponent, MapInitEvent>(OnThrusterMapInit);
SubscribeLocalEvent<ThrusterComponent, PowerChangedEvent>(OnPowerChange);
SubscribeLocalEvent<ThrusterComponent, AnchorStateChangedEvent>(OnAnchorChange);
SubscribeLocalEvent<ThrusterComponent, ReAnchorEvent>(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);

View File

@@ -36,7 +36,6 @@ public sealed class SpreaderSystem : EntitySystem
{
SubscribeLocalEvent<AirtightChanged>(OnAirtightChanged);
SubscribeLocalEvent<GridInitializeEvent>(OnGridInit);
SubscribeLocalEvent<SpreaderGridComponent, MapInitEvent>(OnSpreaderGridMapInit);
SubscribeLocalEvent<SpreaderGridComponent, EntityUnpausedEvent>(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();

View File

@@ -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());
}
/// <summary>
@@ -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;

View File

@@ -85,7 +85,7 @@ public sealed class AnomalyComponent : Component
/// The time at which the next artifact pulse will occur.
/// </summary>
[DataField("nextPulseTime", customTypeSerializer: typeof(TimeOffsetSerializer)), ViewVariables(VVAccess.ReadWrite)]
public TimeSpan NextPulseTime = TimeSpan.MaxValue;
public TimeSpan NextPulseTime = TimeSpan.Zero;
/// <summary>
/// The minimum interval between pulses.

View File

@@ -41,6 +41,7 @@ public sealed class StaminaSystem : EntitySystem
public override void Initialize()
{
base.Initialize();
SubscribeLocalEvent<StaminaComponent, EntityUnpausedEvent>(OnStamUnpaused);
SubscribeLocalEvent<StaminaComponent, ComponentStartup>(OnStartup);
SubscribeLocalEvent<StaminaComponent, ComponentShutdown>(OnShutdown);
SubscribeLocalEvent<StaminaComponent, ComponentGetState>(OnStamGetState);
@@ -51,6 +52,11 @@ public sealed class StaminaSystem : EntitySystem
SubscribeLocalEvent<StaminaDamageOnHitComponent, MeleeHitEvent>(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)

View File

@@ -17,6 +17,6 @@ public sealed class EmitSoundOnCollideComponent : BaseEmitSoundComponent
/// <summary>
/// To avoid sound spam add a cooldown to it.
/// </summary>
[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);
}

View File

@@ -39,6 +39,8 @@ public abstract class SharedEmitSoundSystem : EntitySystem
SubscribeLocalEvent<EmitSoundOnActivateComponent, ActivateInWorldEvent>(OnEmitSoundOnActivateInWorld);
SubscribeLocalEvent<EmitSoundOnPickupComponent, GotEquippedHandEvent>(OnEmitSoundOnPickup);
SubscribeLocalEvent<EmitSoundOnDropComponent, DroppedEvent>(OnEmitSoundOnDrop);
SubscribeLocalEvent<EmitSoundOnCollideComponent, EntityUnpausedEvent>(OnEmitSoundUnpaused);
SubscribeLocalEvent<EmitSoundOnCollideComponent, StartCollideEvent>(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 ||

View File

@@ -59,6 +59,7 @@ public abstract class SharedMeleeWeaponSystem : EntitySystem
base.Initialize();
Sawmill = Logger.GetSawmill("melee");
SubscribeLocalEvent<MeleeWeaponComponent, EntityUnpausedEvent>(OnMeleeUnpaused);
SubscribeLocalEvent<MeleeWeaponComponent, ComponentGetState>(OnGetState);
SubscribeLocalEvent<MeleeWeaponComponent, ComponentHandleState>(OnHandleState);
SubscribeLocalEvent<MeleeWeaponComponent, HandDeselectedEvent>(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))

View File

@@ -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<GunComponent, GetVerbsEvent<AlternativeVerb>>(OnAltVerb);
SubscribeLocalEvent<GunComponent, ExaminedEvent>(OnExamine);
SubscribeLocalEvent<GunComponent, CycleModeEvent>(OnCycleMode);
SubscribeLocalEvent<GunComponent, ComponentInit>(OnGunInit);
SubscribeLocalEvent<GunComponent, EntityUnpausedEvent>(OnGunUnpaused);
#if DEBUG
SubscribeLocalEvent<GunComponent, MapInitEvent>(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;