diff --git a/core/src/main/java/info/openrocket/core/simulation/BasicEventSimulationEngine.java b/core/src/main/java/info/openrocket/core/simulation/BasicEventSimulationEngine.java index 3afa1c157..cf4631e04 100644 --- a/core/src/main/java/info/openrocket/core/simulation/BasicEventSimulationEngine.java +++ b/core/src/main/java/info/openrocket/core/simulation/BasicEventSimulationEngine.java @@ -342,16 +342,6 @@ public class BasicEventSimulationEngine implements SimulationEngine { } } - // Ignore events for components that are no longer attached to the rocket - 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; - } - // Call simulation listeners, allow aborting event handling if (!SimulationListenerHelper.fireHandleFlightEvent(currentStatus, event)) { continue; @@ -526,10 +516,12 @@ public class BasicEventSimulationEngine implements SimulationEngine { // Mark the current status as having dropped the current stage and all stages // below it currentStatus.getConfiguration().clearStagesBelow(stageNumber); - + currentStatus.removeUnattachedEvents(); + // Mark the booster status as having no active stages above boosterStatus.getConfiguration().clearStagesAbove(stageNumber); - + boosterStatus.removeUnattachedEvents(); + toSimulate.push(boosterStatus); // Make sure upper stages can still be simulated diff --git a/core/src/main/java/info/openrocket/core/simulation/SimulationStatus.java b/core/src/main/java/info/openrocket/core/simulation/SimulationStatus.java index 597f25f7e..f2f0f6419 100644 --- a/core/src/main/java/info/openrocket/core/simulation/SimulationStatus.java +++ b/core/src/main/java/info/openrocket/core/simulation/SimulationStatus.java @@ -3,6 +3,7 @@ package info.openrocket.core.simulation; import java.util.ArrayList; import java.util.Collection; import java.util.HashMap; +import java.util.Iterator; import java.util.List; import java.util.Map; import java.util.Set; @@ -459,6 +460,35 @@ public class SimulationStatus implements Cloneable, Monitorable { return eventQueue; } + /** + * Remove all events that came from components which are no longer + * attached from the event queue. + */ + public void removeUnattachedEvents() { + Iterator i = getEventQueue().iterator(); + while (i.hasNext()) { + if (!isAttached(i.next())) { + i.remove(); + } + } + } + + /** + * Determine whether a FlightEvent came from a RocketComponent that is + * still attached to the current stage + * + * @param event the event to be tested + * return true if attached, false if not + */ + private boolean isAttached(FlightEvent event) { + if ((null == event.getSource()) || + (null == event.getSource().getParent()) || + getConfiguration().isComponentActive(event.getSource())) { + return true; + } + return false; + } + public void setSimulationConditions(SimulationConditions simulationConditions) { if (this.simulationConditions != null) this.modIDadd = new ModID();