Added Ex. 10

added client hosts a server
added javadoc comments
This commit is contained in:
Cedric Beck
2024-10-06 14:29:31 +02:00
parent 216bd60d84
commit 5edd4ebe0b
10 changed files with 392 additions and 46 deletions

View File

@@ -7,6 +7,14 @@
package pp.util;
import com.jme3.app.Application;
import com.jme3.asset.AssetLoadException;
import com.jme3.asset.AssetNotFoundException;
import com.jme3.audio.AudioData;
import com.jme3.audio.AudioNode;
import java.lang.System.Logger;
import java.lang.System.Logger.Level;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashSet;
@@ -17,6 +25,8 @@
* A class with auxiliary functions.
*/
public class Util {
private static final Logger LOGGER = System.getLogger(Util.class.getName());
private Util() { /* do not instantiate */ }
/**
@@ -87,4 +97,24 @@ public static <T, E extends T> Set<T> add(Set<T> set, E element) {
newSet.add(element);
return newSet;
}
/**
* Loads a sound from the specified file.
*
* @param app The application
* @param name The name of the sound file.
* @return The loaded AudioNode.
*/
public static AudioNode loadSound(Application app, String name) {
try {
final AudioNode sound = new AudioNode(app.getAssetManager(), name, AudioData.DataType.Buffer);
sound.setLooping(false);
sound.setPositional(false);
return sound;
}
catch (AssetLoadException | AssetNotFoundException ex) {
LOGGER.log(Level.ERROR, ex.getMessage(), ex);
}
return null;
}
}