engine refactor
This commit is contained in:
parent
9e663db9dc
commit
81b8e763bd
37 changed files with 3532 additions and 1639 deletions
|
|
@ -3,21 +3,26 @@ package engine
|
|||
// Profile is an ordered chain of propagators executed sequentially. Each
|
||||
// propagator picks up where the previous one finished.
|
||||
type Profile struct {
|
||||
// Stages are run in order. For Direction=Reverse they are still iterated
|
||||
// from index 0 onwards, but each propagator integrates with negative dt.
|
||||
// Stages are run in order. For Direction=Reverse they are still
|
||||
// iterated from index 0 onwards but each propagator integrates with
|
||||
// negative dt.
|
||||
Stages []*Propagator
|
||||
|
||||
// Direction controls the sign of dt across the whole profile.
|
||||
// Direction controls the sign of dt across the profile.
|
||||
Direction Direction
|
||||
|
||||
// Globals are constraints evaluated alongside each stage's local Constraints.
|
||||
// Useful for profile-wide bounds like "stop after N hours total".
|
||||
// Globals are constraints evaluated alongside each stage's local
|
||||
// Constraints. Useful for profile-wide bounds like "stop after N hours".
|
||||
Globals []Constraint
|
||||
}
|
||||
|
||||
// Run executes the profile from the given launch point. Returns one Result
|
||||
// per executed stage, including any Fallback chains that were activated.
|
||||
func (p *Profile) Run(t0 float64, launch State) []Result {
|
||||
// Run executes the profile from the given launch point. Returns one
|
||||
// Result per executed stage, including any Fallback chains that were
|
||||
// activated. The supplied EventSink is shared across stages and aggregates
|
||||
// non-fatal observations.
|
||||
//
|
||||
// events may be nil; pass NewEventSink() to capture observations.
|
||||
func (p *Profile) Run(t0 float64, launch State, events *EventSink) []Result {
|
||||
if p.Direction == 0 {
|
||||
p.Direction = Forward
|
||||
}
|
||||
|
|
@ -27,28 +32,36 @@ func (p *Profile) Run(t0 float64, launch State) []Result {
|
|||
|
||||
for i := 0; i < len(p.Stages); i++ {
|
||||
stage := p.Stages[i]
|
||||
res := stage.run(t, s, p.Direction, p.Globals)
|
||||
ctx := StageContext{
|
||||
ProfileStart: t0,
|
||||
PropagatorStart: t,
|
||||
Launch: launch,
|
||||
PropagatorState: s,
|
||||
Direction: p.Direction,
|
||||
}
|
||||
res := stage.run(ctx, t, s, p.Globals, events)
|
||||
results = append(results, res)
|
||||
|
||||
last := res.Points[len(res.Points)-1]
|
||||
t = last.Time
|
||||
s = State{Lat: last.Lat, Lng: last.Lng, Altitude: last.Altitude}
|
||||
|
||||
// Follow Fallback chains until none remains. Each fallback consumes
|
||||
// from the same point the previous stage stopped at.
|
||||
// Follow Fallback chains until none remains.
|
||||
for res.Outcome == OutcomeFallback && stage.Fallback != nil {
|
||||
stage = stage.Fallback
|
||||
res = stage.run(t, s, p.Direction, p.Globals)
|
||||
ctx = StageContext{
|
||||
ProfileStart: t0,
|
||||
PropagatorStart: t,
|
||||
Launch: launch,
|
||||
PropagatorState: s,
|
||||
Direction: p.Direction,
|
||||
}
|
||||
res = stage.run(ctx, t, s, p.Globals, events)
|
||||
results = append(results, res)
|
||||
last = res.Points[len(res.Points)-1]
|
||||
t = last.Time
|
||||
s = State{Lat: last.Lat, Lng: last.Lng, Altitude: last.Altitude}
|
||||
}
|
||||
|
||||
// If a propagator's stop fired (not a fallback), end the profile.
|
||||
if res.Outcome == OutcomeStopped {
|
||||
continue
|
||||
}
|
||||
}
|
||||
|
||||
return results
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue