Skip to content

Commit 43b30dd

Browse files
bob0bobstephengold
andauthored
Test post water 1699 (jMonkeyEngine#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 jMonkeyEngine#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 jMonkeyEngine#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 jMonkeyEngine#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 jMonkeyEngine#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]>
1 parent a8a7080 commit 43b30dd

1 file changed

Lines changed: 51 additions & 16 deletions

File tree

jme3-examples/src/main/java/jme3test/water/TestPostWater.java

Lines changed: 51 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,9 @@
3434
import com.jme3.app.SimpleApplication;
3535
import com.jme3.audio.AudioData.DataType;
3636
import com.jme3.audio.AudioNode;
37+
import com.jme3.audio.Filter;
3738
import com.jme3.audio.LowPassFilter;
39+
import com.jme3.font.BitmapText;
3840
import com.jme3.input.KeyInput;
3941
import com.jme3.input.controls.ActionListener;
4042
import com.jme3.input.controls.KeyTrigger;
@@ -74,6 +76,8 @@ public class TestPostWater extends SimpleApplication {
7476
private WaterFilter water;
7577
private AudioNode waves;
7678
final private LowPassFilter aboveWaterAudioFilter = new LowPassFilter(1, 1);
79+
final private Filter underWaterAudioFilter = new LowPassFilter(0.5f, 0.1f);
80+
private boolean useDryFilter = true;
7781

7882
public static void main(String[] args) {
7983
TestPostWater app = new TestPostWater();
@@ -173,16 +177,18 @@ public void simpleInitApp() {
173177
waves = new AudioNode(assetManager, "Sound/Environment/Ocean Waves.ogg",
174178
DataType.Buffer);
175179
waves.setLooping(true);
176-
waves.setReverbEnabled(true);
177-
if (uw) {
178-
waves.setDryFilter(new LowPassFilter(0.5f, 0.1f));
179-
} else {
180-
waves.setDryFilter(aboveWaterAudioFilter);
181-
}
180+
updateAudio();
182181
audioRenderer.playSource(waves);
183182
//
184183
viewPort.addProcessor(fpp);
185184

185+
setText(0, 50, "1 - Set Foam Texture to Foam.jpg");
186+
setText(0, 80, "2 - Set Foam Texture to Foam2.jpg");
187+
setText(0, 110, "3 - Set Foam Texture to Foam3.jpg");
188+
setText(0, 140, "4 - Turn Dry Filter under water On/Off");
189+
setText(0, 240, "PgUp - Larger Reflection Map");
190+
setText(0, 270, "PgDn - Smaller Reflection Map");
191+
186192
inputManager.addListener(new ActionListener() {
187193
@Override
188194
public void onAction(String name, boolean isPressed, float tpf) {
@@ -205,12 +211,16 @@ public void onAction(String name, boolean isPressed, float tpf) {
205211
water.setReflectionMapSize(Math.max(water.getReflectionMapSize() / 2, 32));
206212
System.out.println("Reflection map size : " + water.getReflectionMapSize());
207213
}
214+
if (name.equals("dryFilter")) {
215+
useDryFilter = !useDryFilter;
216+
}
208217
}
209218
}
210-
}, "foam1", "foam2", "foam3", "upRM", "downRM");
219+
}, "foam1", "foam2", "foam3", "upRM", "downRM", "dryFilter");
211220
inputManager.addMapping("foam1", new KeyTrigger(KeyInput.KEY_1));
212221
inputManager.addMapping("foam2", new KeyTrigger(KeyInput.KEY_2));
213222
inputManager.addMapping("foam3", new KeyTrigger(KeyInput.KEY_3));
223+
inputManager.addMapping("dryFilter", new KeyTrigger(KeyInput.KEY_4));
214224
inputManager.addMapping("upRM", new KeyTrigger(KeyInput.KEY_PGUP));
215225
inputManager.addMapping("downRM", new KeyTrigger(KeyInput.KEY_PGDN));
216226
}
@@ -275,17 +285,42 @@ public void simpleUpdate(float tpf) {
275285
time += tpf;
276286
waterHeight = (float) Math.cos(((time * 0.6f) % FastMath.TWO_PI)) * 1.5f;
277287
water.setWaterHeight(initialWaterHeight + waterHeight);
278-
if (water.isUnderWater() && !uw) {
288+
uw = water.isUnderWater();
289+
updateAudio();
290+
}
291+
292+
protected void setText(int x, int y, String text) {
293+
BitmapText txt2 = new BitmapText(guiFont, false);
294+
txt2.setText(text);
295+
txt2.setLocalTranslation(x, cam.getHeight() - y, 0);
296+
txt2.setColor(ColorRGBA.Red);
297+
guiNode.attachChild(txt2);
298+
}
279299

280-
waves.setDryFilter(new LowPassFilter(0.5f, 0.1f));
281-
uw = true;
300+
/**
301+
* Update the audio settings (dry filter and reverb)
302+
* based on boolean fields ({@code uw} and {@code useDryFilter}).
303+
*/
304+
protected void updateAudio() {
305+
Filter newDryFilter;
306+
if (!useDryFilter) {
307+
newDryFilter = null;
308+
} else if (uw) {
309+
newDryFilter = underWaterAudioFilter;
310+
} else {
311+
newDryFilter = aboveWaterAudioFilter;
312+
}
313+
Filter oldDryFilter = waves.getDryFilter();
314+
if (oldDryFilter != newDryFilter) {
315+
System.out.println("dry filter : " + newDryFilter);
316+
waves.setDryFilter(newDryFilter);
282317
}
283-
if (!water.isUnderWater() && uw) {
284-
uw = false;
285-
//waves.setReverbEnabled(false);
286-
waves.setDryFilter(new LowPassFilter(1, 1f));
287-
//waves.setDryFilter(new LowPassFilter(1,1f));
288318

319+
boolean newReverbEnabled = !uw;
320+
boolean oldReverbEnabled = waves.isReverbEnabled();
321+
if (oldReverbEnabled != newReverbEnabled) {
322+
System.out.println("reverb enabled : " + newReverbEnabled);
323+
waves.setReverbEnabled(newReverbEnabled);
289324
}
290325
}
291-
}
326+
}

0 commit comments

Comments
 (0)