Implement some field-level deltas (#28242)

* Update GasTileOverlayState

* Update DecalGridState

* Update NavMapState

* poke

* poke2

* poke3

* Implement field deltas for guns

* Content done

* Update

---------

Co-authored-by: ElectroJr <leonsfriedrich@gmail.com>
This commit is contained in:
metalgearsloth
2024-12-21 15:54:11 +11:00
committed by GitHub
parent 1f859167fd
commit 9f4aa1ebe0
12 changed files with 97 additions and 46 deletions

View File

@@ -119,7 +119,7 @@ public abstract partial class SharedGunSystem : EntitySystem
if (melee.NextAttack > component.NextFire)
{
component.NextFire = melee.NextAttack;
Dirty(uid, component);
EntityManager.DirtyField(uid, component, nameof(MeleeWeaponComponent.NextAttack));
}
}
@@ -200,7 +200,7 @@ public abstract partial class SharedGunSystem : EntitySystem
gun.ShotCounter = 0;
gun.ShootCoordinates = null;
gun.Target = null;
Dirty(uid, gun);
EntityManager.DirtyField(uid, gun, nameof(GunComponent.ShotCounter));
}
/// <summary>
@@ -211,6 +211,7 @@ public abstract partial class SharedGunSystem : EntitySystem
gun.ShootCoordinates = toCoordinates;
AttemptShoot(user, gunUid, gun);
gun.ShotCounter = 0;
EntityManager.DirtyField(gunUid, gun, nameof(GunComponent.ShotCounter));
}
/// <summary>
@@ -228,7 +229,9 @@ public abstract partial class SharedGunSystem : EntitySystem
{
if (gun.FireRateModified <= 0f ||
!_actionBlockerSystem.CanAttack(user))
{
return;
}
var toCoordinates = gun.ShootCoordinates;
@@ -277,7 +280,7 @@ public abstract partial class SharedGunSystem : EntitySystem
}
// NextFire has been touched regardless so need to dirty the gun.
Dirty(gunUid, gun);
EntityManager.DirtyField(gunUid, gun, nameof(GunComponent.NextFire));
// Get how many shots we're actually allowed to make, due to clip size or otherwise.
// Don't do this in the loop so we still reset NextFire.
@@ -331,6 +334,7 @@ public abstract partial class SharedGunSystem : EntitySystem
// Even if we don't actually shoot update the ShotCounter. This is to avoid spamming empty sounds
// where the gun may be SemiAuto or Burst.
gun.ShotCounter += shots;
EntityManager.DirtyField(gunUid, gun, nameof(GunComponent.ShotCounter));
if (ev.Ammo.Count <= 0)
{
@@ -387,8 +391,6 @@ public abstract partial class SharedGunSystem : EntitySystem
if (_gravity.IsWeightless(user, userPhysics))
CauseImpulse(fromCoordinates, toCoordinates.Value, user, userPhysics);
}
Dirty(gunUid, gun);
}
public void Shoot(
@@ -442,7 +444,7 @@ public abstract partial class SharedGunSystem : EntitySystem
protected void SetCartridgeSpent(EntityUid uid, CartridgeAmmoComponent cartridge, bool spent)
{
if (cartridge.Spent != spent)
Dirty(uid, cartridge);
DirtyField(uid, cartridge, nameof(CartridgeAmmoComponent.Spent));
cartridge.Spent = spent;
Appearance.SetData(uid, AmmoVisuals.Spent, spent);
@@ -541,17 +543,59 @@ public abstract partial class SharedGunSystem : EntitySystem
RaiseLocalEvent(gun, ref ev);
comp.SoundGunshotModified = ev.SoundGunshot;
comp.CameraRecoilScalarModified = ev.CameraRecoilScalar;
comp.AngleIncreaseModified = ev.AngleIncrease;
comp.AngleDecayModified = ev.AngleDecay;
comp.MaxAngleModified = ev.MaxAngle;
comp.MinAngleModified = ev.MinAngle;
comp.ShotsPerBurstModified = ev.ShotsPerBurst;
comp.FireRateModified = ev.FireRate;
comp.ProjectileSpeedModified = ev.ProjectileSpeed;
if (comp.SoundGunshotModified != ev.SoundGunshot)
{
comp.SoundGunshotModified = ev.SoundGunshot;
DirtyField(gun, nameof(GunComponent.SoundGunshotModified));
}
Dirty(gun);
if (!MathHelper.CloseTo(comp.CameraRecoilScalarModified, ev.CameraRecoilScalar))
{
comp.CameraRecoilScalarModified = ev.CameraRecoilScalar;
DirtyField(gun, nameof(GunComponent.CameraRecoilScalarModified));
}
if (!comp.AngleIncreaseModified.EqualsApprox(ev.AngleIncrease))
{
comp.AngleIncreaseModified = ev.AngleIncrease;
DirtyField(gun, nameof(GunComponent.AngleIncreaseModified));
}
if (!comp.AngleDecayModified.EqualsApprox(ev.AngleDecay))
{
comp.AngleDecayModified = ev.AngleDecay;
DirtyField(gun, nameof(GunComponent.AngleDecayModified));
}
if (!comp.MaxAngleModified.EqualsApprox(ev.MinAngle))
{
comp.MaxAngleModified = ev.MaxAngle;
DirtyField(gun, nameof(GunComponent.MaxAngleModified));
}
if (!comp.MinAngleModified.EqualsApprox(ev.MinAngle))
{
comp.MinAngleModified = ev.MinAngle;
DirtyField(gun, nameof(GunComponent.MinAngleModified));
}
if (comp.ShotsPerBurstModified != ev.ShotsPerBurst)
{
comp.ShotsPerBurstModified = ev.ShotsPerBurst;
DirtyField(gun, nameof(GunComponent.ShotsPerBurstModified));
}
if (!MathHelper.CloseTo(comp.FireRateModified, ev.FireRate))
{
comp.FireRateModified = ev.FireRate;
DirtyField(gun, nameof(GunComponent.FireRateModified));
}
if (!MathHelper.CloseTo(comp.ProjectileSpeedModified, ev.ProjectileSpeed))
{
comp.ProjectileSpeedModified = ev.ProjectileSpeed;
DirtyField(gun, nameof(GunComponent.ProjectileSpeedModified));
}
}
protected abstract void CreateEffect(EntityUid gunUid, MuzzleFlashEvent message, EntityUid? user = null);