From f3307e9ccda28d525083ba7c02bdfeb70f9a6ffd Mon Sep 17 00:00:00 2001 From: Wyatt Gillette Date: Tue, 17 Jun 2025 15:00:11 +0200 Subject: [PATCH 1/3] Update Listener.java --- .../main/java/com/jme3/audio/Listener.java | 30 +++++++++---------- 1 file changed, 14 insertions(+), 16 deletions(-) diff --git a/jme3-core/src/main/java/com/jme3/audio/Listener.java b/jme3-core/src/main/java/com/jme3/audio/Listener.java index d582df33cd..d5130bd57d 100644 --- a/jme3-core/src/main/java/com/jme3/audio/Listener.java +++ b/jme3-core/src/main/java/com/jme3/audio/Listener.java @@ -41,19 +41,20 @@ */ public class Listener { - private final Vector3f location; - private final Vector3f velocity; - private final Quaternion rotation; - private float volume = 1; + private final Vector3f location = new Vector3f(); + private final Vector3f velocity = new Vector3f(); + private final Quaternion rotation = new Quaternion(); + private float volume = 1f; private AudioRenderer renderer; + private final Vector3f left = new Vector3f(); + private final Vector3f up = new Vector3f(); + private final Vector3f direction = new Vector3f(); + /** * Constructs a new {@code Listener} with default parameters. */ public Listener() { - location = new Vector3f(); - velocity = new Vector3f(); - rotation = new Quaternion(); } /** @@ -62,9 +63,9 @@ public Listener() { * @param source The {@code Listener} to copy the properties from. */ public Listener(Listener source) { - this.location = source.location.clone(); - this.velocity = source.velocity.clone(); - this.rotation = source.rotation.clone(); + this.location.set(source.location); + this.velocity.set(source.velocity); + this.rotation.set(source.rotation); this.volume = source.volume; this.renderer = source.renderer; // Note: Renderer is also copied } @@ -130,32 +131,29 @@ public Vector3f getVelocity() { /** * Gets the left direction vector of the listener. - * This vector is derived from the listener's rotation. * * @return The listener's left direction as a {@link Vector3f}. */ public Vector3f getLeft() { - return rotation.getRotationColumn(0); + return rotation.getRotationColumn(0, left); } /** * Gets the up direction vector of the listener. - * This vector is derived from the listener's rotation. * * @return The listener's up direction as a {@link Vector3f}. */ public Vector3f getUp() { - return rotation.getRotationColumn(1); + return rotation.getRotationColumn(1, up); } /** * Gets the forward direction vector of the listener. - * This vector is derived from the listener's rotation. * * @return The listener's forward direction. */ public Vector3f getDirection() { - return rotation.getRotationColumn(2); + return rotation.getRotationColumn(2, direction); } /** From efb97a8569c905cac3853b10deae5c166a4f144e Mon Sep 17 00:00:00 2001 From: Riccardo Balbo Date: Tue, 13 Jan 2026 22:44:15 +0100 Subject: [PATCH 2/3] preserve backward compatibility --- .../main/java/com/jme3/audio/Listener.java | 81 +++++++++++++++++-- 1 file changed, 75 insertions(+), 6 deletions(-) diff --git a/jme3-core/src/main/java/com/jme3/audio/Listener.java b/jme3-core/src/main/java/com/jme3/audio/Listener.java index d5130bd57d..1dbd286105 100644 --- a/jme3-core/src/main/java/com/jme3/audio/Listener.java +++ b/jme3-core/src/main/java/com/jme3/audio/Listener.java @@ -47,9 +47,6 @@ public class Listener { private float volume = 1f; private AudioRenderer renderer; - private final Vector3f left = new Vector3f(); - private final Vector3f up = new Vector3f(); - private final Vector3f direction = new Vector3f(); /** * Constructs a new {@code Listener} with default parameters. @@ -110,6 +107,17 @@ public Vector3f getLocation() { return location; } + /** + * Gets the current location of the listener in world space. + * + * @param store The vector to store the result in. + * @return The listener's location as a {@link Vector3f}. + */ + public Vector3f getLocation(Vector3f store) { + if (store == null) store = new Vector3f(); + return store.set(location); + } + /** * Gets the current rotation of the listener in world space. * @@ -119,6 +127,17 @@ public Quaternion getRotation() { return rotation; } + /** + * Gets the current rotation of the listener in world space. + * + * @param store The quaternion to store the result in. + * @return The listener's rotation as a {@link Quaternion}. + */ + public Quaternion getRotation(Quaternion store) { + if (store == null) store = new Quaternion(); + return store.set(rotation); + } + /** * Gets the current velocity of the listener. * This is used for Doppler effect calculations. @@ -129,31 +148,81 @@ public Vector3f getVelocity() { return velocity; } + /** + * Gets the current velocity of the listener. + * + * @param store The vector to store the result in. + * @return The listener's velocity as a {@link Vector3f}. + */ + public Vector3f getVelocity(Vector3f store) { + if (store == null) store = new Vector3f(); + return store.set(velocity); + } + /** * Gets the left direction vector of the listener. + * This vector is derived from the listener's rotation. * * @return The listener's left direction as a {@link Vector3f}. */ public Vector3f getLeft() { - return rotation.getRotationColumn(0, left); + return rotation.getRotationColumn(0); + } + + + /** + * Gets the left direction vector of the listener. This vector is derived from the listener's rotation. + * + * @param store The vector to store the result in. + * @return The listener's left direction as a {@link Vector3f}. + */ + public Vector3f getLeft(Vector3f store) { + if (store == null) store = new Vector3f(); + return rotation.getRotationColumn(0, store); } /** * Gets the up direction vector of the listener. + * This vector is derived from the listener's rotation. * * @return The listener's up direction as a {@link Vector3f}. */ public Vector3f getUp() { - return rotation.getRotationColumn(1, up); + return rotation.getRotationColumn(1); + } + + /** + * Gets the up direction vector of the listener. + * This vector is derived from the listener's rotation. + * + * @param store The vector to store the result in. + * @return The listener's up direction as a {@link Vector3f}. + */ + public Vector3f getUp(Vector3f store) { + if (store == null) store = new Vector3f(); + return rotation.getRotationColumn(1, store); } /** * Gets the forward direction vector of the listener. + * This vector is derived from the listener's rotation. * * @return The listener's forward direction. */ public Vector3f getDirection() { - return rotation.getRotationColumn(2, direction); + return rotation.getRotationColumn(2); + } + + /** + * Gets the forward direction vector of the listener. + * This vector is derived from the listener's rotation. + * + * @param store The vector to store the result in. + * @return The listener's forward direction. + */ + public Vector3f getDirection(Vector3f store) { + if (store == null) store = new Vector3f(); + return rotation.getRotationColumn(2, store); } /** From fda703131ab15d7c741300dbf106e16ab764dc65 Mon Sep 17 00:00:00 2001 From: Riccardo Balbo Date: Tue, 13 Jan 2026 22:51:49 +0100 Subject: [PATCH 3/3] reduce allocations in ALAudioRenderer --- .../main/java/com/jme3/audio/openal/ALAudioRenderer.java | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/jme3-core/src/main/java/com/jme3/audio/openal/ALAudioRenderer.java b/jme3-core/src/main/java/com/jme3/audio/openal/ALAudioRenderer.java index ec89b9df06..9de16b5842 100644 --- a/jme3-core/src/main/java/com/jme3/audio/openal/ALAudioRenderer.java +++ b/jme3-core/src/main/java/com/jme3/audio/openal/ALAudioRenderer.java @@ -50,6 +50,8 @@ import com.jme3.math.Vector3f; import com.jme3.util.BufferUtils; import com.jme3.util.NativeObjectManager; +import com.jme3.util.TempVars; + import java.nio.ByteBuffer; import java.nio.FloatBuffer; import java.nio.IntBuffer; @@ -766,14 +768,16 @@ private void applyListenerPosition(Listener listener) { } private void applyListenerRotation(Listener listener) { - Vector3f dir = listener.getDirection(); - Vector3f up = listener.getUp(); + TempVars vars = TempVars.get(); + Vector3f dir = listener.getDirection(vars.vect1); + Vector3f up = listener.getUp(vars.vect2); // Use the shared FloatBuffer fb fb.rewind(); fb.put(dir.x).put(dir.y).put(dir.z); fb.put(up.x).put(up.y).put(up.z); fb.flip(); al.alListener(AL_ORIENTATION, fb); + vars.release(); } private void applyListenerVelocity(Listener listener) {