Instead of checking each event as it is pulled from the queue to see if it came from a component that is no longer attached, filter all the events immediately after stage separation.

This commit is contained in:
JoePfeiffer 2024-11-15 13:08:08 -07:00
parent 33b27b45ca
commit 0325274b88
2 changed files with 34 additions and 12 deletions

View File

@ -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

View File

@ -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<FlightEvent> 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();