-
Notifications
You must be signed in to change notification settings - Fork 29
Fix/null program #537
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Fix/null program #537
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -70,7 +70,7 @@ | |
| * @author Dennis Cosgrove | ||
| */ | ||
| public class SceneImp extends EntityImp { | ||
| private static final Transformable createDirectionalLightTransformable(DirectionalLight sgDirectionalLight, Angle yaw, Angle pitch, float brightness) { | ||
| private static Transformable createDirectionalLightTransformable(DirectionalLight sgDirectionalLight, Angle yaw, Angle pitch, float brightness) { | ||
| Transformable rv = new Transformable(); | ||
| rv.applyRotationAboutYAxis(yaw); | ||
| rv.applyRotationAboutXAxis(pitch); | ||
|
|
@@ -128,24 +128,17 @@ private void fireSceneActivationListeners() { | |
| this.eventManager.sceneActivated(); | ||
| } | ||
|
|
||
| private void changeActiveStatus(ProgramImp programImp, boolean isActive, int activationCount) { | ||
| double prevSimulationSpeedFactor = program.getSimulationSpeedFactor(); | ||
| program.setSimulationSpeedFactor(Double.POSITIVE_INFINITY); | ||
| private void changeActiveStatus(boolean isActive) { | ||
| double prevSimulationSpeedFactor = 0; | ||
| if (program != null) { | ||
| prevSimulationSpeedFactor = program.getSimulationSpeedFactor(); | ||
| program.setSimulationSpeedFactor(Double.POSITIVE_INFINITY); | ||
| } | ||
| if (ACCEPTABLE_HACK_FOR_SCENE_EDITOR_performMinimalInitializationCount <= 0) { | ||
| this.getAbstraction().handleActiveChanged(isActive, activationCount); | ||
| this.getAbstraction().handleActiveChanged(isActive, activeCount); | ||
| } | ||
| program.setSimulationSpeedFactor(prevSimulationSpeedFactor); | ||
| if (isActive) { | ||
| //This forces the scene to initialize itself to make sure we can properly query bounding boxes and other render dependent things | ||
| //All this info is critical to a scene running | ||
| AdapterFactory.getAdapterFor(this.sgScene); | ||
|
|
||
| this.addCamerasTo(programImp); | ||
| if (ACCEPTABLE_HACK_FOR_SCENE_EDITOR_performMinimalInitializationCount <= 0) { | ||
| this.fireSceneActivationListeners(); | ||
| } | ||
| } else { | ||
| this.removeCamerasFrom(programImp); | ||
| if (program != null) { | ||
| program.setSimulationSpeedFactor(prevSimulationSpeedFactor); | ||
| } | ||
| } | ||
|
|
||
|
|
@@ -156,20 +149,49 @@ public void activate(ProgramImp programImp) { | |
| if (this.isGlobalLightBrightnessAnimationDesired) { | ||
| this.setGlobalBrightness(0.0f); | ||
| } | ||
| this.changeActiveStatus(program, true, activeCount); | ||
| this.changeActiveStatus(true); | ||
| initializeScene(); | ||
| if (this.isGlobalLightBrightnessAnimationDesired) { | ||
| this.animateGlobalBrightness(1.0f, 0.5, TraditionalStyle.BEGIN_AND_END_GENTLY); | ||
| } | ||
| } | ||
|
|
||
| public void deactivate(ProgramImp programImp) { | ||
| private void setProgram(ProgramImp newImp) { | ||
| if (newImp.equals(this.program)) { | ||
| //no change | ||
| return; | ||
| } | ||
| if (program != null) { | ||
| eventManager.removeListenersFrom(program.getOnscreenRenderTarget()); | ||
| } | ||
| this.program = newImp; | ||
| eventManager.addListenersTo(program.getOnscreenRenderTarget()); | ||
| } | ||
|
|
||
| private void initializeScene() { | ||
| //This forces the scene to initialize itself to make sure we can properly query bounding boxes and other render dependent things | ||
| //All this info is critical to a scene running | ||
| AdapterFactory.getAdapterFor(this.sgScene); | ||
|
|
||
| this.addCamerasTo(program); | ||
| if (ACCEPTABLE_HACK_FOR_SCENE_EDITOR_performMinimalInitializationCount <= 0) { | ||
| this.fireSceneActivationListeners(); | ||
| } | ||
| } | ||
|
|
||
| public void deactivate() { | ||
| deactiveCount++; | ||
| assert deactiveCount == activeCount; | ||
| if (this.isGlobalLightBrightnessAnimationDesired) { | ||
| this.animateGlobalBrightness(0.0f, 0.25, TraditionalStyle.BEGIN_AND_END_GENTLY); | ||
| } | ||
| this.changeActiveStatus(programImp, false, activeCount); | ||
| this.setProgram(null); | ||
| this.changeActiveStatus(false); | ||
| if (program == null) { | ||
| return; | ||
| } | ||
| this.removeCamerasFrom(program); | ||
| eventManager.removeListenersFrom(program.getOnscreenRenderTarget()); | ||
| program = null; | ||
| } | ||
|
|
||
| @Override | ||
|
|
@@ -192,41 +214,6 @@ public ProgramImp getProgram() { | |
| return this.program; | ||
| } | ||
|
|
||
| public void setProgram(ProgramImp program) { | ||
| if (this.program != program) { | ||
| if (this.program != null) { | ||
| this.eventManager.removeListenersFrom(this.program.getOnscreenRenderTarget()); | ||
| } | ||
| this.program = program; | ||
| if (program != null) { | ||
| this.eventManager.addListenersTo(program.getOnscreenRenderTarget()); | ||
| } | ||
| } | ||
| this.program = program; | ||
| } | ||
|
|
||
| //todo | ||
| // private static class Capsule { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh, no! My favorite class is going away! |
||
| // private final TransformableImp transformable; | ||
| // private EntityImp vehicle; | ||
| // private edu.cmu.cs.dennisc.math.AffineMatrix4x4 localTransformation; | ||
| // | ||
| // public Capsule( TransformableImp transformable ) { | ||
| // this.transformable = transformable; | ||
| // } | ||
| // | ||
| // public void preserve() { | ||
| // this.vehicle = this.transformable.getVehicle(); | ||
| // this.localTransformation = this.transformable.getSgComposite().getLocalTransformation(); | ||
| // } | ||
| // | ||
| // public void restore() { | ||
| // this.transformable.setVehicle( this.vehicle ); | ||
| // this.transformable.getSgComposite().setLocalTransformation( this.localTransformation ); | ||
| // } | ||
| // } | ||
| // private final java.util.List<Capsule> capsules = edu.cmu.cs.dennisc.java.util.Lists.newCopyOnWriteArrayList(); | ||
|
|
||
| public void preserveStateAndEventListeners() { | ||
| this.eventManager.silenceAllListeners(); | ||
| //todo: preserve state | ||
|
|
@@ -237,7 +224,7 @@ public void restoreStateAndEventListeners() { | |
| this.eventManager.restoreAllListeners(); | ||
| } | ||
|
|
||
| public void addCamerasTo(ProgramImp program) { | ||
| private void addCamerasTo(ProgramImp program) { | ||
| for (AbstractCamera sgCamera : VisitUtilities.getAll(this.sgScene, AbstractCamera.class)) { | ||
| EntityImp entityImp = EntityImp.getInstance(sgCamera); | ||
| if (entityImp instanceof CameraImp cameraImp) { | ||
|
|
@@ -246,7 +233,7 @@ public void addCamerasTo(ProgramImp program) { | |
| } | ||
| } | ||
|
|
||
| public void removeCamerasFrom(ProgramImp program) { | ||
| private void removeCamerasFrom(ProgramImp program) { | ||
| for (AbstractCamera sgCamera : VisitUtilities.getAll(this.sgScene, AbstractCamera.class)) { | ||
| EntityImp entityImp = EntityImp.getInstance(sgCamera); | ||
| if (entityImp instanceof CameraImp cameraImp) { | ||
|
|
@@ -260,11 +247,11 @@ public CameraImp findFirstCamera() { | |
| return (CameraImp) EntityImp.getInstance(sgCamera); | ||
| } | ||
|
|
||
| public void setGlobalBrightness(float globalBrightness) { | ||
| private void setGlobalBrightness(float globalBrightness) { | ||
| this.sgScene.globalBrightness.setValue(globalBrightness); | ||
| } | ||
|
|
||
| public void animateGlobalBrightness(float globalBrightness, double duration, Style style) { | ||
| private void animateGlobalBrightness(float globalBrightness, double duration, Style style) { | ||
| duration = adjustDurationIfNecessary(duration); | ||
| if (EpsilonUtilities.isWithinReasonableEpsilon(duration, RIGHT_NOW)) { | ||
| this.setGlobalBrightness(globalBrightness); | ||
|
|
@@ -296,7 +283,7 @@ public EventManager getEventManager() { | |
| private int activeCount; | ||
| private int deactiveCount; | ||
|
|
||
| private boolean isGlobalLightBrightnessAnimationDesired = true; | ||
| private final boolean isGlobalLightBrightnessAnimationDesired = true; | ||
|
|
||
| private final Scene sgScene = new Scene(); | ||
| private final Background sgBackground = new Background(); | ||
|
|
@@ -346,17 +333,6 @@ protected void handleSetValue(Color value) { | |
| SceneImp.this.sgFromBelowDirectionalLight.color.setValue(value.toColor4f()); | ||
| } | ||
| }; | ||
| public final FloatProperty globalLightBrightness = new FloatProperty(SceneImp.this) { | ||
| @Override | ||
| public Float getValue() { | ||
| return SceneImp.this.sgScene.globalBrightness.getValue(); | ||
| } | ||
|
|
||
| @Override | ||
| protected void handleSetValue(Float value) { | ||
| SceneImp.this.sgScene.globalBrightness.setValue(value); | ||
| } | ||
| }; | ||
|
|
||
| private static class FogDensityProperty extends FloatProperty { | ||
| public FogDensityProperty(SceneImp owner) { | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Was the removal of final here intentional? Just wondering since I don't see the method being overridden anywhere in the PR.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes. It is static, so final adds nothing.