FireControl.RoundEnd states a round's end; DrawAhead draws rounds as pure statics
RoundEnd(shot, known) is the one statement of when a ballistic round's drawn flight ends: arrival for a hit, burst or unpublished outcome, the frozen range (never short of arrival) for a miss. RoundAt takes the known outcome and clamps at RoundEnd. DrawAhead gains Round, RoundStop, RoundOver (pure, no state) so the blend, stop and done rules are headless-testable. Seven new tests (ten cases). Unity build: Projectile.cs still calls the old RoundAt, so this commit does not compile in Unity (the headless test project does not include Projectile). The next commit moves Projectile onto the statics. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
e56f9c8be5
commit
60aacfdc35
3 changed files with 313 additions and 26 deletions
|
|
@ -5,8 +5,9 @@
|
|||
using CultMath;
|
||||
using static CultMath.math;
|
||||
|
||||
// Where a presenter draws the latest sim state when the frame falls Lead sim seconds after the last step. Pure reads
|
||||
// of the simulation for presenters (never called by ServerShared): the sim owns every pose and no presenter stores
|
||||
// Where a presenter draws the latest sim state when the frame falls Lead sim seconds after the last step: ships by
|
||||
// their last step's velocity, ballistic rounds on FireControl's RoundAt and RoundEnd. Pure reads of the simulation for
|
||||
// presenters (never called by ServerShared, no state of their own): the sim owns every pose and no presenter stores
|
||||
// one, a previous state or a velocity of its own.
|
||||
public static class DrawAhead
|
||||
{
|
||||
|
|
@ -37,4 +38,24 @@ public static class DrawAhead
|
|||
t.w * q.z + t.x * q.y - t.y * q.x + t.z * q.w,
|
||||
t.w * q.w - t.x * q.x - t.y * q.y - t.z * q.z));
|
||||
}
|
||||
|
||||
// A ballistic round at a sim time (the clock's Zone.Time + Lead): on FireControl's line for what the sim has published
|
||||
// of its outcome, with the barrel's offset from that line decaying to nothing over blendTime sim seconds from FireTime.
|
||||
public static float3 Round(in PendingShot shot, ShotResult? known, float3 barrel, float blendTime, float time) =>
|
||||
Lifted(shot, FireControl.RoundAt(shot, known, time), barrel, blendTime, time);
|
||||
|
||||
// Where a round that hit or burst stops: the outcome's burst point, else where it arrives on its line.
|
||||
public static float3 RoundStop(in PendingShot shot, ShotOutcome outcome, float3 barrel, float blendTime) =>
|
||||
Lifted(shot, outcome.HasBurstPoint ? outcome.BurstPoint : FireControl.RoundAt(shot, outcome.Result, shot.ArrivalTime),
|
||||
barrel, blendTime, shot.ArrivalTime);
|
||||
|
||||
// Whether the drawn flight is over by time: only a published miss ends by the clock. A hit or burst ends on ShotResolved.
|
||||
public static bool RoundOver(in PendingShot shot, ShotResult? known, float time) =>
|
||||
known == ShotResult.Miss && time >= FireControl.RoundEnd(shot, ShotResult.Miss);
|
||||
|
||||
private static float3 Lifted(in PendingShot shot, float2 planar, float3 barrel, float blendTime, float time)
|
||||
{
|
||||
var blend = blendTime > 0 ? saturate(1 - (time - shot.FireTime) / blendTime) : 0f;
|
||||
return float3(planar.x, shot.FireOrigin.y, planar.y) + (barrel - shot.FireOrigin) * blend;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -514,13 +514,23 @@ public static class FireControl
|
|||
return shot.Target == null ? 1f : PDeviation(deviation, shot.Tracking);
|
||||
}
|
||||
|
||||
// The sim time a ballistic round's drawn flight ends, for what is known of its outcome: the one statement of a round's
|
||||
// end. A round that hit or burst (or whose outcome is not yet published) ends at its ArrivalTime. A round the sim has
|
||||
// published as a Miss flies on to the weapon's frozen range and never ends short of its own arrival (a direct round's
|
||||
// FireRange is measured to any target, in range or not). Pure: it reads the shot alone, and the simulation's own
|
||||
// arithmetic (Step, Commit, Apply) does not call it. Presenters end rounds here, through DrawAhead.
|
||||
public static float RoundEnd(in PendingShot shot, ShotResult? known) =>
|
||||
known == ShotResult.Miss
|
||||
? max(shot.ArrivalTime, shot.FireTime + (shot.Speed > .01f ? shot.MaxRange / shot.Speed : 0f))
|
||||
: shot.ArrivalTime;
|
||||
|
||||
// Where a ballistic round is at a sim time: the one statement of the round's line, from its frozen origin along its
|
||||
// frozen direction at its frozen speed, held at the MaxRange point once it has flown that far. Pure: it reads the
|
||||
// shot alone, and the simulation's own arithmetic (Step, Commit, Apply) does not call it. Presenters draw rounds here.
|
||||
public static float2 RoundAt(in PendingShot shot, float time)
|
||||
// frozen direction at its frozen speed, held at RoundEnd once it has flown that far. With no outcome known the round is
|
||||
// drawn no further than its arrival point and waits there for the sim to publish one. Pure, like RoundEnd.
|
||||
public static float2 RoundAt(in PendingShot shot, ShotResult? known, float time)
|
||||
{
|
||||
if (shot.Speed <= .01f) return shot.FireOrigin.xz;
|
||||
var flown = clamp(time - shot.FireTime, 0f, shot.MaxRange / shot.Speed);
|
||||
var flown = clamp(time - shot.FireTime, 0f, RoundEnd(shot, known) - shot.FireTime);
|
||||
return shot.FireOrigin.xz + shot.TravelDirection * (shot.Speed * flown);
|
||||
}
|
||||
|
||||
|
|
@ -865,6 +875,8 @@ public static class FireControl
|
|||
// A contact burst short of max range arrives when the round has flown that far, not at the frozen
|
||||
// max-range time (CommitBurst). Never later than the frozen time.
|
||||
if (shot.Outcome.Result == ShotResult.Burst) shot.ArrivalTime = min(shot.ArrivalTime, now + shot.Outcome.ArrivalIn);
|
||||
// Written back before ShotCommitted fires: a presenter re-reading the record there (Zone.TryGetShot) sees
|
||||
// the committed ArrivalTime a contact burst has just shortened.
|
||||
shots[i] = shot;
|
||||
zone.ShotCommitted.OnNext(shot.Outcome);
|
||||
}
|
||||
|
|
@ -2013,8 +2025,8 @@ public struct PendingShot
|
|||
public float FireTime;
|
||||
// The weapon's Velocity at Fire: frozen with the rest, so RoundAt states the same line whatever happens to the stat later.
|
||||
public float Speed;
|
||||
// The weapon's Range at Fire, likewise frozen: how far the round can fly, which RoundAt clamps at. FireRange above is the
|
||||
// distance to the engaged target (0 for a round with none), not how far a round that misses flies on.
|
||||
// The weapon's Range at Fire, likewise frozen: how far a round that misses flies on, read only by RoundEnd. FireRange above
|
||||
// is the distance to the engaged target (0 for a round with none), not how far a round that misses flies on.
|
||||
public float MaxRange;
|
||||
public float CommitTime;
|
||||
public float ArrivalTime;
|
||||
|
|
|
|||
Loading…
Reference in a new issue