Step-exact rules: timers keep their overshoot, passive sensing decays exactly (group B, 60 Hz, digest not repinned)

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
soul 2026-10-22 20:35:28 +02:00
commit f0362025d9
5 changed files with 216 additions and 12 deletions

View file

@ -148,7 +148,7 @@ public class ConstantWeapon : Weapon, IProgressBehavior, IEventBehavior, IPowerC
_ammoInterval -= dt / _data.AmmoInterval;
if (_ammoInterval < 0)
{
_ammoInterval = 1;
_ammoInterval += 1;
if (_data.MagazineSize > 1 && _ammo > 0) _ammo--;
else
{

View file

@ -48,7 +48,7 @@ public class Cooldown : Behavior, IAlwaysUpdatedBehavior, IProgressBehavior
{
if (_cooldown < 0)
{
_cooldown = 1;
_cooldown += 1;
return true;
}
@ -57,6 +57,8 @@ public class Cooldown : Behavior, IAlwaysUpdatedBehavior, IProgressBehavior
public void Update(float delta)
{
_cooldown -= delta / Evaluate(_data.Cooldown);
// A finished timer keeps what the last step overshot, at most one step, so the restart in Execute is exact.
var step = delta / Evaluate(_data.Cooldown);
_cooldown = max(_cooldown - step, -step);
}
}

View file

@ -58,6 +58,9 @@ public class InstantWeapon : Weapon, IProgressBehavior, IEventBehavior, IPowerCo
protected float _cooldown; // Normalized
private int _ammo = 0;
protected bool _coolingDown;
// Seconds the last countdown ran past zero (less than one step). The next countdown starts that far along, so a held
// trigger fires Cooldown apart on average at any step, never floor(Cooldown/dt)+1 steps apart.
private float _overshoot;
public float BurstCount { get; protected set; }
public float BurstTime { get; protected set; }
@ -183,6 +186,15 @@ public class InstantWeapon : Weapon, IProgressBehavior, IEventBehavior, IPowerCo
// would ever fill this capacitor -- bypass it entirely rather than starving such an instance forever.
protected bool TrySpendActivationEnergy() => Item == null || _capacitor.TrySpend(_capacitor.Capacity);
private float CountdownSpan => _data.MagazineSize > 0 && _ammo == 0 ? _data.ReloadTime : Cooldown;
private float TakeOvershoot()
{
var overshoot = _overshoot;
_overshoot = 0;
return overshoot;
}
private bool UseAmmo()
{
if (_data.MagazineSize <= 1) return true;
@ -208,7 +220,7 @@ public class InstantWeapon : Weapon, IProgressBehavior, IEventBehavior, IPowerCo
if(hasAmmo)
{
OnReloadBegin?.Invoke();
_cooldown = 1;
_cooldown = 1 - TakeOvershoot() / _data.ReloadTime;
_coolingDown = true;
_firing = false;
}
@ -226,9 +238,11 @@ public class InstantWeapon : Weapon, IProgressBehavior, IEventBehavior, IPowerCo
_capacitor.AddCharge(_capacitor.RequestedFill(dt) * Item.PowerSupply);
if (_coolingDown)
{
_cooldown -= dt / (_data.MagazineSize > 0 && _ammo == 0 ? _data.ReloadTime : Cooldown);
var span = CountdownSpan;
_cooldown -= dt / span;
if (_cooldown < 0)
{
_overshoot = -_cooldown * span;
_coolingDown = false;
if (_data.MagazineSize > 0 && _ammo == 0)
{
@ -260,8 +274,9 @@ public class InstantWeapon : Weapon, IProgressBehavior, IEventBehavior, IPowerCo
if (!_burstStarted)
{
_burstStarted = true;
_cooldown = 1 - dt / Cooldown;
// The round starts the cooldown after this tick's decrement above: charge the tick to it, so the cadence stays Cooldown
_cooldown = 1 - (dt + TakeOvershoot()) / CountdownSpan;
// The round starts the cooldown after this tick's decrement above: charge the tick and the last
// countdown's overshoot to it, so the cadence stays Cooldown
_coolingDown = true;
}
}

View file

@ -145,7 +145,7 @@ public class Sensor : Behavior, IEventBehavior, IPowerConsumer
{
_pinging = true;
_pingZone = Entity.Zone;
_pingCooldown = 1;
_pingCooldown += 1;
_pingLerp = 0;
_pingRadius = 0;
_reached.Clear();
@ -180,8 +180,14 @@ public class Sensor : Behavior, IEventBehavior, IPowerConsumer
if (_pingLerp > 1) EndPing();
}
_pingCooldown -= dt / Evaluate(_data.PingCooldown);
// A finished timer keeps what the last step overshot, at most one step, so the restart in Ping is exact.
var pingStep = dt / Evaluate(_data.PingCooldown);
_pingCooldown = max(_pingCooldown - pingStep, -pingStep);
var infoDecay = ItemManager.GameplaySettings.TargetInfoDecay;
var decay = exp(-infoDecay * dt);
var settle = infoDecay > 0 ? (1 - decay) / infoDecay : dt;
var forward = Direction.xz;
foreach (var entity in Entity.Zone.Entities)
{
@ -221,14 +227,16 @@ public class Sensor : Behavior, IEventBehavior, IPowerConsumer
credit += Gain(entity.Visibility, sensitivity, response, sqrt(r.IlluminatedRange * dist), dt, true, sqrt(r.IlluminatedObscuration * obscuration));
}
// The exact decay at this step: x <- x e^(-k dt) + (G / k)(1 - e^(-k dt)) for the passive gain G per second,
// which settles at G / k (Entity.PassiveInfo) at every dt. A ping's credit is an impulse added first.
if (heard)
next = saturate(previous + credit);
next = saturate(previous + credit) * decay;
else
{
var angle = acos(dot(forward, normalize(diff)));
next = saturate(previous + Gain(entity.Visibility, sensitivity, _data.SensitivityCurve.Evaluate(angle / PI), dist, dt, false, obscuration));
var passive = Gain(entity.Visibility, sensitivity, _data.SensitivityCurve.Evaluate(angle / PI), dist, 1f, false, obscuration);
next = saturate(previous * decay + passive * settle);
}
next *= 1 - ItemManager.GameplaySettings.TargetInfoDecay * dt;
//Context.Log($"{entity.Name} visibility {(int)(previous * 100)}% -> {(int)(next * 100)}%");
Entity.EntityInfoGathered[entity] = next;
}