diag (temporary)

This commit is contained in:
soul 2026-10-23 00:21:40 +02:00
commit a1519c9b2b
2 changed files with 6 additions and 3 deletions

View file

@ -64,6 +64,7 @@ public class InstantWeapon : Weapon, IProgressBehavior, IEventBehavior, IPowerCo
// The shooter asked for fire during this step (Activate): a weapon asked of for the whole step fires every round its
// cooldown allows inside it, rather than one per step. Cleared when the step ends.
private bool _pulled;
public string DiagBreak = ""; public int DiagRetriggers;
// The shortest cycle a countdown divides by: a cooldown of zero would otherwise fire without end in one step.
private const float ShortestCycle = .0005f;
@ -304,6 +305,7 @@ public class InstantWeapon : Weapon, IProgressBehavior, IEventBehavior, IPowerCo
if (!refused && !_burstPaid && (!TrySpendActivationEnergy() || !UseAmmo(dt)))
{
_burstRemaining = 0;
DiagBreak = $"spend failed charge={_capacitor.Charge} cap={_capacitor.Capacity}";
return false;
}
if (!refused)
@ -340,10 +342,11 @@ public class InstantWeapon : Weapon, IProgressBehavior, IEventBehavior, IPowerCo
ended |= FinishCountdown(dt);
// The trigger is held and the weapon is ready: the next burst starts now, at the moment the cooldown ended (what it
// ran past zero is how long ago, at the step's end), or at the step's start when the weapon was already ready.
if (!Repeats || _burstRemaining > 0 || !CanFire || (retriggered && !_burstStarted)) break;
if (!Repeats || _burstRemaining > 0 || !CanFire || (retriggered && !_burstStarted)) { DiagBreak = $"cond Repeats={Repeats} rem={_burstRemaining} can={CanFire} re={retriggered} started={_burstStarted} cd={_cooldown} cooling={_coolingDown}"; break; }
retriggered = true;
DiagRetriggers++;
Trigger();
if (_burstRemaining == 0) break;
if (_burstRemaining == 0) { DiagBreak = "trigger refused"; break; }
if (ended)
{
_burstTimer = TakeOvershoot();

View file

@ -293,7 +293,7 @@ public sealed partial class ContactRevealTests
var rounds = HoldTrigger(ship, Guns(ship)[0], dt, 10f, fireTimes);
var probe = (InstantWeapon) Guns(ship)[0].Behaviors.Single(b => b is InstantWeapon);
var cap = (InputCapacitor) typeof(InstantWeapon).GetField("_capacitor", BindingFlags.Instance | BindingFlags.NonPublic).GetValue(probe);
Assert.True(abs(rounds.Count - 1000f) <= 1.01f, $"dt {dt}: {rounds.Count} rounds in 10 s, expected 1000 +-1; capacity {cap.Capacity} rate {cap.Rate} charge {cap.Charge} cooldown {probe.Cooldown} canfire {probe.CanFire} firing {probe.Firing}");
Assert.True(abs(rounds.Count - 1000f) <= 1.01f, $"dt {dt}: {rounds.Count} rounds in 10 s, expected 1000 +-1; capacity {cap.Capacity} rate {cap.Rate} charge {cap.Charge} cooldown {probe.Cooldown} canfire {probe.CanFire} firing {probe.Firing} retriggers {probe.DiagRetriggers} break {probe.DiagBreak}");
Assert.Equal(rounds.Count, fireTimes.Count);
for (var i = 1; i < fireTimes.Count; i++)
Assert.True(abs(fireTimes[i] - fireTimes[i - 1] - .01f) < 2e-4f, $"dt {dt}: rounds {i - 1} and {i} born {fireTimes[i - 1]:R} and {fireTimes[i]:R}");