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:
parent
33b27b45ca
commit
0325274b88
@ -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
|
// Call simulation listeners, allow aborting event handling
|
||||||
if (!SimulationListenerHelper.fireHandleFlightEvent(currentStatus, event)) {
|
if (!SimulationListenerHelper.fireHandleFlightEvent(currentStatus, event)) {
|
||||||
continue;
|
continue;
|
||||||
@ -526,9 +516,11 @@ public class BasicEventSimulationEngine implements SimulationEngine {
|
|||||||
// Mark the current status as having dropped the current stage and all stages
|
// Mark the current status as having dropped the current stage and all stages
|
||||||
// below it
|
// below it
|
||||||
currentStatus.getConfiguration().clearStagesBelow(stageNumber);
|
currentStatus.getConfiguration().clearStagesBelow(stageNumber);
|
||||||
|
currentStatus.removeUnattachedEvents();
|
||||||
|
|
||||||
// Mark the booster status as having no active stages above
|
// Mark the booster status as having no active stages above
|
||||||
boosterStatus.getConfiguration().clearStagesAbove(stageNumber);
|
boosterStatus.getConfiguration().clearStagesAbove(stageNumber);
|
||||||
|
boosterStatus.removeUnattachedEvents();
|
||||||
|
|
||||||
toSimulate.push(boosterStatus);
|
toSimulate.push(boosterStatus);
|
||||||
|
|
||||||
|
@ -3,6 +3,7 @@ package info.openrocket.core.simulation;
|
|||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
import java.util.Iterator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
@ -459,6 +460,35 @@ public class SimulationStatus implements Cloneable, Monitorable {
|
|||||||
return eventQueue;
|
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) {
|
public void setSimulationConditions(SimulationConditions simulationConditions) {
|
||||||
if (this.simulationConditions != null)
|
if (this.simulationConditions != null)
|
||||||
this.modIDadd = new ModID();
|
this.modIDadd = new ModID();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user