Cache active motors instead of recalculating on each call

This commit is contained in:
JoePfeiffer 2022-03-07 09:59:14 -07:00
parent 24e1dcc7fe
commit 6a8d533070

View File

@ -63,6 +63,7 @@ public class FlightConfiguration implements FlightConfigurableParameter<FlightCo
/* Cached data */ /* Cached data */
final protected HashMap<Integer, StageFlags> stages = new HashMap<Integer, StageFlags>(); final protected HashMap<Integer, StageFlags> stages = new HashMap<Integer, StageFlags>();
final protected HashMap<MotorConfigurationId, MotorConfiguration> motors = new HashMap<MotorConfigurationId, MotorConfiguration>(); final protected HashMap<MotorConfigurationId, MotorConfiguration> motors = new HashMap<MotorConfigurationId, MotorConfiguration>();
final private Collection<MotorConfiguration> activeMotors = new ArrayList<MotorConfiguration>();
private int boundsModID = -1; private int boundsModID = -1;
private BoundingBox cachedBounds = new BoundingBox(); private BoundingBox cachedBounds = new BoundingBox();
@ -499,18 +500,12 @@ public class FlightConfiguration implements FlightConfigurableParameter<FlightCo
} }
public Collection<MotorConfiguration> getActiveMotors() { public Collection<MotorConfiguration> getActiveMotors() {
Collection<MotorConfiguration> activeMotors = new ArrayList<MotorConfiguration>();
for( MotorConfiguration config : this.motors.values() ){
if( isComponentActive( config.getMount() )){
activeMotors.add( config );
}
}
return activeMotors; return activeMotors;
} }
private void updateMotors() { private void updateMotors() {
this.motors.clear(); motors.clear();
for ( RocketComponent comp : getActiveComponents() ){ for ( RocketComponent comp : getActiveComponents() ){
if (( comp instanceof MotorMount )&&( ((MotorMount)comp).isMotorMount())){ if (( comp instanceof MotorMount )&&( ((MotorMount)comp).isMotorMount())){
@ -520,10 +515,16 @@ public class FlightConfiguration implements FlightConfigurableParameter<FlightCo
continue; continue;
} }
this.motors.put( motorConfig.getMID(), motorConfig); motors.put( motorConfig.getMID(), motorConfig);
} }
} }
activeMotors.clear();
for( MotorConfiguration config : motors.values() ){
if( isComponentActive( config.getMount() )){
activeMotors.add( config );
}
}
} }
@Override @Override