Ver Fonte

Test post water 1699 (#1707)

* This is a very simple addition. It allows a person to set 3 variables in AppSettings. ‘CenterWindow’, ‘WindowXPosition’ and ‘WindowYPosition’ variables. This way these variable will be saved in the profile when the profile is saved, and be reloaded. I added ‘CenterWindow’ to be added with a ‘true’ value for the default value so it will run just like it did before.

But if you set ‘CenterWindow’ to ‘false’ then inside LwjglWindow.java (lwjgl3 code) it will look at these new values, it will determine to center the window or use the position values to place the window back at the location the user last moved it to.

Of course, these values are only updated if the “program” updates this value. So if you want to save screen position, you can save them on closing to and on restart put the window back into the same location.

* formatting and comments changes.

* jme3test.app.TestApplication hangs with LWJGL3 #1193
LWJGL3-JME library would block the current thread when executing LWJGL3.    Instead of calling run() that is blocking,  made it work like LWJGL2-JME library when they start it as a thread so run gets called. I commented out the run() function and replaced it with Thread.start().

* removing unwanted changes, since you can't do multiple pull requests at once.

* formatting issues.

* changed parameter naming to be more consistency with other items.

* jme3test.app.TestApplication hangs with LWJGL3 #1193

LWJGL3-JME projects was doing a call that is blocking the current thread.  I changed it to match how LWJGL2-JME project launches the Context Window.

* jme3test.app.TestApplication hangs with LWJGL3 #1193 (#3)

LWJGL3-JME projects was doing a call that is blocking the current thread.  I changed it to match how LWJGL2-JME project launches the Context Window.

* removing unwanted changes.

* AppSettings:  enhance the new javadoc

* AppSettings:  capitalize Window{X/Y}Position consistent w/other settings

* LwjglWindow:  convert tabs to spaces

* AppSettings:  re-arrange @see tags in javadoc

* TestPostWater issue #1699

Changed it so when you go under water to turn off reverb.   I turned off the Low Filter because it is not needed with Reverb is turned off.

* Added a feature to leave dry filter on/off.  Also put on the screen other hot keys this demo supports.

* type preventing input to work correctly.

* more formattings changes.

* TestPostWater:  standardize key names

* TestPostWater:  correct key assignements that were swapped

* TestPostWater:  organize imports per the style guide

* TestPostWater:  whitespace

* TestPostWater:  change useDryFilter logic so the 4 key has prompt effect

Co-authored-by: Stephen Gold <[email protected]>
bob0bob há 3 anos atrás
pai
commit
4799f4fe1d
1 ficheiros alterados com 51 adições e 16 exclusões
  1. 51 16
      jme3-examples/src/main/java/jme3test/water/TestPostWater.java

+ 51 - 16
jme3-examples/src/main/java/jme3test/water/TestPostWater.java

@@ -34,7 +34,9 @@ package jme3test.water;
 import com.jme3.app.SimpleApplication;
 import com.jme3.audio.AudioData.DataType;
 import com.jme3.audio.AudioNode;
+import com.jme3.audio.Filter;
 import com.jme3.audio.LowPassFilter;
+import com.jme3.font.BitmapText;
 import com.jme3.input.KeyInput;
 import com.jme3.input.controls.ActionListener;
 import com.jme3.input.controls.KeyTrigger;
@@ -74,6 +76,8 @@ public class TestPostWater extends SimpleApplication {
     private WaterFilter water;
     private AudioNode waves;
     final private LowPassFilter aboveWaterAudioFilter = new LowPassFilter(1, 1);
+    final private Filter underWaterAudioFilter = new LowPassFilter(0.5f, 0.1f);
+    private boolean useDryFilter = true;
 
     public static void main(String[] args) {
         TestPostWater app = new TestPostWater();
@@ -173,16 +177,18 @@ public class TestPostWater extends SimpleApplication {
         waves = new AudioNode(assetManager, "Sound/Environment/Ocean Waves.ogg",
                 DataType.Buffer);
         waves.setLooping(true);
-        waves.setReverbEnabled(true);
-        if (uw) {
-            waves.setDryFilter(new LowPassFilter(0.5f, 0.1f));
-        } else {
-            waves.setDryFilter(aboveWaterAudioFilter);
-        }
+        updateAudio();
         audioRenderer.playSource(waves);
         //  
         viewPort.addProcessor(fpp);
 
+        setText(0, 50, "1 - Set Foam Texture to Foam.jpg");
+        setText(0, 80, "2 - Set Foam Texture to Foam2.jpg");
+        setText(0, 110, "3 - Set Foam Texture to Foam3.jpg");
+        setText(0, 140, "4 - Turn Dry Filter under water On/Off");
+        setText(0, 240, "PgUp - Larger Reflection Map");
+        setText(0, 270, "PgDn - Smaller Reflection Map");
+
         inputManager.addListener(new ActionListener() {
             @Override
             public void onAction(String name, boolean isPressed, float tpf) {
@@ -205,12 +211,16 @@ public class TestPostWater extends SimpleApplication {
                         water.setReflectionMapSize(Math.max(water.getReflectionMapSize() / 2, 32));
                         System.out.println("Reflection map size : " + water.getReflectionMapSize());
                     }
+                    if (name.equals("dryFilter")) {
+                        useDryFilter = !useDryFilter; 
+                    }
                 }
             }
-        }, "foam1", "foam2", "foam3", "upRM", "downRM");
+        }, "foam1", "foam2", "foam3", "upRM", "downRM", "dryFilter");
         inputManager.addMapping("foam1", new KeyTrigger(KeyInput.KEY_1));
         inputManager.addMapping("foam2", new KeyTrigger(KeyInput.KEY_2));
         inputManager.addMapping("foam3", new KeyTrigger(KeyInput.KEY_3));
+        inputManager.addMapping("dryFilter", new KeyTrigger(KeyInput.KEY_4));
         inputManager.addMapping("upRM", new KeyTrigger(KeyInput.KEY_PGUP));
         inputManager.addMapping("downRM", new KeyTrigger(KeyInput.KEY_PGDN));
     }
@@ -275,17 +285,42 @@ public class TestPostWater extends SimpleApplication {
         time += tpf;
         waterHeight = (float) Math.cos(((time * 0.6f) % FastMath.TWO_PI)) * 1.5f;
         water.setWaterHeight(initialWaterHeight + waterHeight);
-        if (water.isUnderWater() && !uw) {
+        uw = water.isUnderWater();
+        updateAudio();
+    }
+    
+    protected void setText(int x, int y, String text) {
+        BitmapText txt2 = new BitmapText(guiFont, false);
+        txt2.setText(text);
+        txt2.setLocalTranslation(x, cam.getHeight() - y, 0);
+        txt2.setColor(ColorRGBA.Red);
+        guiNode.attachChild(txt2);
+    }
 
-            waves.setDryFilter(new LowPassFilter(0.5f, 0.1f));
-            uw = true;
+    /**
+     * Update the audio settings (dry filter and reverb)
+     * based on boolean fields ({@code uw} and {@code useDryFilter}).
+     */
+    protected void updateAudio() {
+        Filter newDryFilter;
+        if (!useDryFilter) {
+            newDryFilter = null;
+        } else if (uw) {
+            newDryFilter = underWaterAudioFilter;
+        } else {
+            newDryFilter = aboveWaterAudioFilter;
+        }
+        Filter oldDryFilter = waves.getDryFilter();
+        if (oldDryFilter != newDryFilter) {
+            System.out.println("dry filter : " + newDryFilter);
+            waves.setDryFilter(newDryFilter);
         }
-        if (!water.isUnderWater() && uw) {
-            uw = false;
-            //waves.setReverbEnabled(false);
-            waves.setDryFilter(new LowPassFilter(1, 1f));
-            //waves.setDryFilter(new LowPassFilter(1,1f));
 
+        boolean newReverbEnabled = !uw;
+        boolean oldReverbEnabled = waves.isReverbEnabled();
+        if (oldReverbEnabled != newReverbEnabled) {
+            System.out.println("reverb enabled : " + newReverbEnabled);
+            waves.setReverbEnabled(newReverbEnabled);
         }
     }
-}
+}