Ballistic flight r3: DrawAhead draws a round from the sim's facts, a hit ends at its impact cell; FireControl draws nothing
FireControl.RoundEnd and RoundAt leave FireControl (RoundEnd to DrawAhead verbatim, RoundAt as DrawAhead's private Line); DrawAhead.Round takes the published outcome, steers a hit or burst from its frozen line at the commit tick onto its end (burst point, else the impact cell on the target's drawn pose), and RoundStop is deleted. Projectile caches the last published ShotOutcome and calls DrawAhead only. BallisticFlightTests move to the new signatures; the frozen-line moving-target test is replaced by impact-cell, steer and no-drawing-function tests. Unverified: not yet built or run. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
d98818ea0c
commit
2dcb7b2078
5 changed files with 288 additions and 146 deletions
|
|
@ -5,10 +5,11 @@
|
|||
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: 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.
|
||||
// Pure presentation statics over sim state, never called by ServerShared, with no state of their own: the sim owns every
|
||||
// pose and no presenter stores one, a previous state or a velocity of its own. Ships are drawn where the frame falls Lead
|
||||
// sim seconds after the last step, by their last step's velocity and turn. A ballistic round's flight is presentation
|
||||
// (ruling projectile-flight-is-presentation), drawn from the sim's facts: its frozen line, the published outcome, the
|
||||
// commit tick, the impact cell on the target's drawn pose, the burst point.
|
||||
public static class DrawAhead
|
||||
{
|
||||
// A ship in a wormhole animation has its pose scripted by the step, not integrated from Velocity and TurnRate,
|
||||
|
|
@ -39,19 +40,57 @@ public static class DrawAhead
|
|||
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 the moment of firing.
|
||||
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);
|
||||
// A ballistic round at a sim time (the clock's Zone.Time + Lead): on its frozen line while the outcome is unknown or a
|
||||
// miss, with the barrel's offset from that line decaying to nothing over blendTime sim seconds from the moment of firing.
|
||||
// A round the sim published as a hit or burst steers from its line, from the commit tick, onto where it ends by the
|
||||
// time damage lands: a burst's frozen point, else the impact cell on the target's drawn pose; and is held there after.
|
||||
public static float3 Round(in PendingShot shot, ShotOutcome known, float3 barrel, float blendTime, float simTime, float lead)
|
||||
{
|
||||
var time = simTime + lead;
|
||||
var drawn = Lifted(shot, Line(shot, known?.Result, time), barrel, blendTime, time);
|
||||
if (known == null || known.Result == ShotResult.Miss) return drawn;
|
||||
var end = known.HasBurstPoint
|
||||
? float3(known.BurstPoint.x, shot.FireOrigin.y, known.BurstPoint.y)
|
||||
: Impact(known.Target, known.Cell, lead);
|
||||
var commit = shot.ArrivalTime - known.ArrivalIn;
|
||||
var steer = shot.ArrivalTime > commit ? saturate((time - commit) / (shot.ArrivalTime - commit)) : 1f;
|
||||
return drawn + (end - drawn) * steer;
|
||||
}
|
||||
|
||||
// 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);
|
||||
// The impact cell's centre on the target's drawn pose: the cell at the sim pose, drawn ahead by the target's last
|
||||
// step velocity and turned by its last step turn for lead seconds, as Position and Rotation draw the entity.
|
||||
public static float3 Impact(Entity target, int2 cell, float lead)
|
||||
{
|
||||
var at = Position(target, lead);
|
||||
var offset = target.ToWorldPoint((float2) cell) - target.Position.xz;
|
||||
var turned = mul(offset, float2x2.Rotate(Turn(target, lead)));
|
||||
return float3(at.x + turned.x, at.y, at.z + turned.y);
|
||||
}
|
||||
|
||||
// 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);
|
||||
public static bool RoundOver(in PendingShot shot, ShotOutcome known, float simTime, float lead) =>
|
||||
known != null && known.Result == ShotResult.Miss && simTime + lead >= RoundEnd(shot, ShotResult.Miss);
|
||||
|
||||
// The sim time a round's drawn line ends, for what is known of its outcome. 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).
|
||||
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;
|
||||
|
||||
// The frozen line a round follows until it steers: from its frozen origin along its 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.
|
||||
private static float2 Line(in PendingShot shot, ShotResult? known, float time)
|
||||
{
|
||||
if (shot.Speed <= .01f) return shot.FireOrigin.xz;
|
||||
var flown = clamp(time - shot.FireTime, 0f, RoundEnd(shot, known) - shot.FireTime);
|
||||
return shot.FireOrigin.xz + shot.TravelDirection * (shot.Speed * flown);
|
||||
}
|
||||
|
||||
private static float Turn(Entity entity, float lead) =>
|
||||
entity is Ship { WormholeAnimationInProgress: true } ? 0f : entity.TurnRate * lead;
|
||||
|
||||
private static float3 Lifted(in PendingShot shot, float2 planar, float3 barrel, float blendTime, float time)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -514,26 +514,6 @@ 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 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, RoundEnd(shot, known) - shot.FireTime);
|
||||
return shot.FireOrigin.xz + shot.TravelDirection * (shot.Speed * flown);
|
||||
}
|
||||
|
||||
// How far a target can and does move off the line of fire in the solution window: the term DeviationProbability
|
||||
// and HitProbability both add. Behaviour (its observed unpredictability across the line of sight) realises the
|
||||
// evasion and capability (its envelope's reach) caps it, so a coasting ship evades nothing whatever it could do
|
||||
|
|
@ -2023,9 +2003,9 @@ public struct PendingShot
|
|||
public float3 FireTargetPosition;
|
||||
public float3 FireTargetVelocity;
|
||||
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.
|
||||
// The weapon's Velocity at Fire, frozen with the rest so a presenter draws the same line whatever happens to the stat later.
|
||||
public float Speed;
|
||||
// The weapon's Range at Fire, likewise frozen: how far a round that misses flies on, read only by RoundEnd. FireRange above
|
||||
// The weapon's Range at Fire, likewise frozen: how far a presenter may draw a round that misses. 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;
|
||||
|
|
|
|||
Loading…
Reference in a new issue