Allow out of order stage separation

This commit is contained in:
JoePfeiffer 2022-10-03 11:39:00 -06:00
parent 0b7d9fe0ef
commit 0f3fffb21d
2 changed files with 43 additions and 8 deletions

View File

@ -146,6 +146,34 @@ public class FlightConfiguration implements FlightConfigurableParameter<FlightCo
updateMotors();
updateActiveInstances();
}
/**
* This method clears a stage and all stages below (higher stage number)
*
* @param stageNumber first stage number to turn off
*/
public void clearStagesBelow(int stageNumber) {
// I can't just use _setStageActive(stageNumber, false, true)
// because that won't clear side boosters' active flags (should it?)
for (int i = stageNumber; i < rocket.getStageCount(); i++) {
_setStageActive(i, false, false);
}
updateMotors();
updateActiveInstances();
}
/**
* This method clears all stages above (but not including) a stage
*
* @param stageNumber first stage number to stay active
*/
public void clearStagesAbove(int stageNumber) {
for (int i = 0; i < stageNumber; i++) {
_setStageActive(i, false, false);
}
updateMotors();
updateActiveInstances();
}
/**
* Activates all stages as active starting from the specified component
@ -187,7 +215,7 @@ public class FlightConfiguration implements FlightConfigurableParameter<FlightCo
}
/**
* This method flags the specified stage as requested. Other stages are unaffected.
* This method flags the specified stage as requested. Substages may be affected, depending on third parameter
*
* @param stageNumber stage number to flag
* @param _active inactive (<code>false</code>) or active (<code>true</code>)

View File

@ -305,6 +305,9 @@ public class BasicEventSimulationEngine implements SimulationEngine {
if (event.getSource() != null && event.getSource().getParent() != null &&
!currentStatus.getConfiguration().isComponentActive(event.getSource())) {
log.trace("Ignoring event from unattached component");
log.debug(" source " + event.getSource());
log.debug(" parent " + event.getSource().getParent());
log.debug(" active " + currentStatus.getConfiguration().isComponentActive(event.getSource()));
continue;
}
@ -381,7 +384,6 @@ public class BasicEventSimulationEngine implements SimulationEngine {
}
// and queue up the burnout for this motor, as well.
// double duration = motorState.getMotor().getBurnTimeEstimate();
double duration = motorState.getBurnTime();
double burnout = currentStatus.getSimulationTime() + duration;
addEvent(new FlightEvent(FlightEvent.Type.BURNOUT, burnout,
@ -436,19 +438,24 @@ public class BasicEventSimulationEngine implements SimulationEngine {
case STAGE_SEPARATION: {
RocketComponent boosterStage = event.getSource();
final int stageNumber = boosterStage.getStageNumber();
log.debug("separating at stage " + stageNumber);
if (currentStatus.getConfiguration().isStageActive(stageNumber-1)) {
// Record the event.
currentStatus.getFlightData().addEvent(event);
// Mark the status as having dropped the booster
currentStatus.getConfiguration().clearStage( stageNumber);
// Prepare the simulation branch
// Create a new simulation branch for the booster
SimulationStatus boosterStatus = new SimulationStatus(currentStatus);
// Prepare the new simulation branch
boosterStatus.setFlightData(new FlightDataBranch(boosterStage.getName(), FlightDataType.TYPE_TIME));
// Mark the booster status as only having the booster.
boosterStatus.getConfiguration().setOnlyStage(stageNumber);
// Mark the current status as having dropped the current stage and all stages below it
currentStatus.getConfiguration().clearStagesBelow( stageNumber);
// Mark the booster status as having no active stages above
boosterStatus.getConfiguration().clearStagesAbove(stageNumber);
toSimulate.push(boosterStatus);
log.info(String.format("==>> @ %g; from Branch: %s ---- Branching: %s ---- \n",
currentStatus.getSimulationTime(),