From d290525099838082e345c139945802f0c0d0b57f Mon Sep 17 00:00:00 2001 From: JoePfeiffer Date: Fri, 11 Mar 2022 11:24:02 -0700 Subject: [PATCH 1/4] Process entire part tree when finding active contexts instead of bailing out early when an inactive component is found. --- .../rocketcomponent/FlightConfiguration.java | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/core/src/net/sf/openrocket/rocketcomponent/FlightConfiguration.java b/core/src/net/sf/openrocket/rocketcomponent/FlightConfiguration.java index 70f645ab1..99992072c 100644 --- a/core/src/net/sf/openrocket/rocketcomponent/FlightConfiguration.java +++ b/core/src/net/sf/openrocket/rocketcomponent/FlightConfiguration.java @@ -298,9 +298,7 @@ public class FlightConfiguration implements FlightConfigurableParameter Date: Fri, 11 Mar 2022 21:49:53 -0700 Subject: [PATCH 2/4] Remove 'active' field from InstanceContext The original plan was that there would be an InstanceContext for every instance of every RocketComponent, with some active and some not (just as RocketComponents may be active or not). The implementation has resulted in InstanceContexts only being created for active RocketComponents, so the active field is superfluous. --- .../rocketcomponent/FlightConfiguration.java | 23 ------------------- .../rocketcomponent/InstanceContext.java | 4 +--- .../rocketcomponent/InstanceMap.java | 2 +- .../gui/figure3d/RocketRenderer.java | 2 +- .../gui/scalefigure/RocketFigure.java | 6 +---- 5 files changed, 4 insertions(+), 33 deletions(-) diff --git a/core/src/net/sf/openrocket/rocketcomponent/FlightConfiguration.java b/core/src/net/sf/openrocket/rocketcomponent/FlightConfiguration.java index 99992072c..5d3ba0e07 100644 --- a/core/src/net/sf/openrocket/rocketcomponent/FlightConfiguration.java +++ b/core/src/net/sf/openrocket/rocketcomponent/FlightConfiguration.java @@ -604,35 +604,12 @@ public class FlightConfiguration implements FlightConfigurableParameter instanceCoordinates = component.getComponentBounds(); for (InstanceContext context : contexts) { - /* - * If the instance is not active in the current context, then - * skip the bound calculations. This is mildly confusing since - * getActiveInstances() implies that it will only return the - * instances that are active, but it returns all instances and - * the context indicates if it is active or not. - */ - if (!context.active) { - continue; - } - Collection transformedCoords = new ArrayList<>(instanceCoordinates); // mutating. Transforms coordinates in place. context.transform.transform(instanceCoordinates); diff --git a/core/src/net/sf/openrocket/rocketcomponent/InstanceContext.java b/core/src/net/sf/openrocket/rocketcomponent/InstanceContext.java index 2e7da00f9..e781182c8 100644 --- a/core/src/net/sf/openrocket/rocketcomponent/InstanceContext.java +++ b/core/src/net/sf/openrocket/rocketcomponent/InstanceContext.java @@ -26,9 +26,8 @@ public class InstanceContext { return component.hashCode(); } - public InstanceContext(final RocketComponent _component, final boolean _active, final int _instanceNumber, final Transformation _transform) { + public InstanceContext(final RocketComponent _component, final int _instanceNumber, final Transformation _transform) { component = _component; - active = _active; instanceNumber = _instanceNumber; transform = _transform; @@ -48,7 +47,6 @@ public class InstanceContext { // ==== public ==== final public RocketComponent component; - final public boolean active; final public int instanceNumber; final public Transformation transform; diff --git a/core/src/net/sf/openrocket/rocketcomponent/InstanceMap.java b/core/src/net/sf/openrocket/rocketcomponent/InstanceMap.java index 36cc79e8a..1538e69aa 100644 --- a/core/src/net/sf/openrocket/rocketcomponent/InstanceMap.java +++ b/core/src/net/sf/openrocket/rocketcomponent/InstanceMap.java @@ -34,7 +34,7 @@ public class InstanceMap extends HashMap()); } - final InstanceContext context = new InstanceContext(component, active, number, xform); + final InstanceContext context = new InstanceContext(component, number, xform); get(key).add(context); } diff --git a/swing/src/net/sf/openrocket/gui/figure3d/RocketRenderer.java b/swing/src/net/sf/openrocket/gui/figure3d/RocketRenderer.java index c6aef258e..f4b6662ae 100644 --- a/swing/src/net/sf/openrocket/gui/figure3d/RocketRenderer.java +++ b/swing/src/net/sf/openrocket/gui/figure3d/RocketRenderer.java @@ -186,7 +186,7 @@ public abstract class RocketRenderer { for(InstanceContext context: contextList ) { Geometry instanceGeometry = cr.getComponentGeometry( comp, context.transform ); - instanceGeometry.active = context.active; + instanceGeometry.active = true; treeGeometry.add( instanceGeometry ); } } diff --git a/swing/src/net/sf/openrocket/gui/scalefigure/RocketFigure.java b/swing/src/net/sf/openrocket/gui/scalefigure/RocketFigure.java index ab3330a0b..5275d8ad0 100644 --- a/swing/src/net/sf/openrocket/gui/scalefigure/RocketFigure.java +++ b/swing/src/net/sf/openrocket/gui/scalefigure/RocketFigure.java @@ -378,11 +378,7 @@ public class RocketFigure extends AbstractScaleFigure { for(InstanceContext context: contextList ) { final Transformation currentTransform = this.axialRotation.applyTransformation(context.transform); - - // generate shape for this component, if active - if( context.active ) { - allShapes = addThisShape( allShapes, this.currentViewType, comp, currentTransform); - } + allShapes = addThisShape( allShapes, this.currentViewType, comp, currentTransform); } } } From 584353463bde42f4236e085a85da41bee14ec718 Mon Sep 17 00:00:00 2001 From: JoePfeiffer Date: Mon, 14 Mar 2022 12:35:59 -0600 Subject: [PATCH 3/4] Update FlightConfiguration active instances whenever active components change, not every time get getActiveInstances() is called --- .../rocketcomponent/FlightConfiguration.java | 24 +++++++--- .../net/sf/openrocket/util/TestRockets.java | 45 ++++++++++--------- 2 files changed, 42 insertions(+), 27 deletions(-) diff --git a/core/src/net/sf/openrocket/rocketcomponent/FlightConfiguration.java b/core/src/net/sf/openrocket/rocketcomponent/FlightConfiguration.java index 5d3ba0e07..8e65f29c7 100644 --- a/core/src/net/sf/openrocket/rocketcomponent/FlightConfiguration.java +++ b/core/src/net/sf/openrocket/rocketcomponent/FlightConfiguration.java @@ -64,6 +64,7 @@ public class FlightConfiguration implements FlightConfigurableParameter stages = new HashMap(); final protected HashMap motors = new HashMap(); final private Collection activeMotors = new ArrayList(); + final private InstanceMap activeInstances = new InstanceMap(); private int boundsModID = -1; private BoundingBox cachedBounds = new BoundingBox(); @@ -101,6 +102,7 @@ public class FlightConfiguration implements FlightConfigurableParameter> entry: imap.entrySet() ) { - RocketComponent c = entry.getKey(); + RocketComponent c = null; + for(Map.Entry> entry: imap.entrySet() ) { + c = entry.getKey(); if (c instanceof TrapezoidFinSet) { - final TrapezoidFinSet fins = (TrapezoidFinSet) c; - final BodyTube body = (BodyTube) fins.getParent(); - body.removeChild(fins); - - // create a PodSet to hook the fins to - PodSet podset = new PodSet(); - podset.setInstanceCount(fins.getFinCount()); - - body.addChild(podset); - - // put a phantom body tube on the pods - BodyTube podBody = new BodyTube(fins.getRootChord(), 0); - podBody.setName("Pod Body"); - podset.addChild(podBody); - - // change the number of fins to 1 and put the revised - // finset on the podbody - fins.setFinCount(1); - podBody.addChild(fins); + break; } } + final TrapezoidFinSet fins = (TrapezoidFinSet) c; + final BodyTube body = (BodyTube) fins.getParent(); + body.removeChild(fins); + + // create a PodSet to hook the fins to + PodSet podset = new PodSet(); + podset.setInstanceCount(fins.getFinCount()); + + body.addChild(podset); + + // put a phantom body tube on the pods + BodyTube podBody = new BodyTube(fins.getRootChord(), 0); + podBody.setName("Pod Body"); + podset.addChild(podBody); + + // change the number of fins to 1 and put the revised + // finset on the podbody + fins.setFinCount(1); + podBody.addChild(fins); return rocket; } From 13fe3e104698572fc6f9d7906850dcdc9cfa4264 Mon Sep 17 00:00:00 2001 From: JoePfeiffer Date: Mon, 14 Mar 2022 12:47:21 -0600 Subject: [PATCH 4/4] Geometry active flag was also never false; eliminated it --- .../gui/figure3d/RocketRenderer.java | 45 ++++++++----------- .../gui/figure3d/geometry/Geometry.java | 2 - 2 files changed, 19 insertions(+), 28 deletions(-) diff --git a/swing/src/net/sf/openrocket/gui/figure3d/RocketRenderer.java b/swing/src/net/sf/openrocket/gui/figure3d/RocketRenderer.java index f4b6662ae..d144ef2c5 100644 --- a/swing/src/net/sf/openrocket/gui/figure3d/RocketRenderer.java +++ b/swing/src/net/sf/openrocket/gui/figure3d/RocketRenderer.java @@ -85,21 +85,19 @@ public abstract class RocketRenderer { if (ignore != null && ignore.contains(comp)) continue; - if( geom.active ) { - final int hashCode = comp.hashCode(); - - selectionMap.put(hashCode, comp); - - gl.glColor4ub((byte) ((hashCode >> 24) & 0xFF), // red channel (LSB) - (byte) ((hashCode >> 16) & 0xFF), // green channel - (byte) ((hashCode >> 8) & 0xFF), // blue channel - (byte) ((hashCode) & 0xFF)); // alpha channel (MSB) - - if (isDrawnTransparent(comp)) { - geom.render(gl, Surface.INSIDE); - } else { - geom.render(gl, Surface.ALL); - } + final int hashCode = comp.hashCode(); + + selectionMap.put(hashCode, comp); + + gl.glColor4ub((byte) ((hashCode >> 24) & 0xFF), // red channel (LSB) + (byte) ((hashCode >> 16) & 0xFF), // green channel + (byte) ((hashCode >> 8) & 0xFF), // blue channel + (byte) ((hashCode) & 0xFF)); // alpha channel (MSB) + + if (isDrawnTransparent(comp)) { + geom.render(gl, Surface.INSIDE); + } else { + geom.render(gl, Surface.ALL); } } @@ -186,7 +184,6 @@ public abstract class RocketRenderer { for(InstanceContext context: contextList ) { Geometry instanceGeometry = cr.getComponentGeometry( comp, context.transform ); - instanceGeometry.active = true; treeGeometry.add( instanceGeometry ); } } @@ -196,19 +193,15 @@ public abstract class RocketRenderer { private void renderTree( GL2 gl, final Collection geometryList){ //cycle through opaque components first, then transparent to preserve proper depth testing for(Geometry geom: geometryList ) { - if( geom.active ) { - //if not transparent - if( !isDrawnTransparent( (RocketComponent)geom.obj) ){ - renderComponent(gl, geom, 1.0f); - } + //if not transparent + if( !isDrawnTransparent( (RocketComponent)geom.obj) ){ + renderComponent(gl, geom, 1.0f); } } for(Geometry geom: geometryList ) { - if( geom.active ) { - if( isDrawnTransparent( (RocketComponent)geom.obj) ){ - // Draw T&T front faces blended, without depth test - renderComponent(gl, geom, 0.2f); - } + if( isDrawnTransparent( (RocketComponent)geom.obj) ){ + // Draw T&T front faces blended, without depth test + renderComponent(gl, geom, 0.2f); } } } diff --git a/swing/src/net/sf/openrocket/gui/figure3d/geometry/Geometry.java b/swing/src/net/sf/openrocket/gui/figure3d/geometry/Geometry.java index 4c4b9df62..41554e575 100644 --- a/swing/src/net/sf/openrocket/gui/figure3d/geometry/Geometry.java +++ b/swing/src/net/sf/openrocket/gui/figure3d/geometry/Geometry.java @@ -25,8 +25,6 @@ public abstract class Geometry { public final Object obj; public final Transformation transform; - public boolean active; - public abstract void render(GL2 gl, Surface which ); private Geometry() {