Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 18 additions & 30 deletions jme3-core/src/main/java/com/jme3/audio/AudioNode.java
Original file line number Diff line number Diff line change
Expand Up @@ -116,13 +116,13 @@ public enum Status {
*/
Stopped,
}

/**
* Creates a new <code>AudioNode</code> without any audio data set.
*/
public AudioNode() {
public AudioNode() {
}

/**
* Creates a new <code>AudioNode</code> with the given data and key.
*
Expand Down Expand Up @@ -161,7 +161,7 @@ public AudioNode(AssetManager assetManager, String name, DataType type) {
public AudioNode(AssetManager assetManager, String name, boolean stream, boolean streamCache) {
this.audioKey = new AudioKey(name, stream, streamCache);
this.data = (AudioData) assetManager.loadAsset(audioKey);
}
}

/**
* Creates a new <code>AudioNode</code> with the given audio file.
Expand Down Expand Up @@ -713,7 +713,7 @@ public void setVelocityFromTranslation(boolean velocityFromTranslation) {
this.velocityFromTranslation = velocityFromTranslation;
}

@Override
@Override
public void updateLogicalState(float tpf) {
super.updateLogicalState(tpf);
lastTpf = tpf;
Expand All @@ -722,48 +722,36 @@ public void updateLogicalState(float tpf) {
@Override
public void updateGeometricState() {
super.updateGeometricState();

if (channel < 0) {
if(channel<0||this.getParent()==null||!velocityFromTranslation) return;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you please follow the formatting scheme of the rest of the engine? This line should be
if (channel < 0 || this.getParent() == null || !velocityFromTranslation) return;

Vector3f currentWorldTranslation=worldTransform.getTranslation();
if(Float.isNaN(previousWorldTranslation.x)){
previousWorldTranslation.set(currentWorldTranslation);
return;
}

Vector3f currentWorldTranslation = worldTransform.getTranslation();

if (Float.isNaN(previousWorldTranslation.x)
|| !previousWorldTranslation.equals(currentWorldTranslation)) {

getRenderer().updateSourceParam(this, AudioParam.Position);

if (velocityFromTranslation) {
velocity.set(currentWorldTranslation).subtractLocal(previousWorldTranslation);
velocity.multLocal(1f / lastTpf);

getRenderer().updateSourceParam(this, AudioParam.Velocity);
}

if(!previousWorldTranslation.equals(currentWorldTranslation)){
getRenderer().updateSourceParam(this,AudioParam.Position);
velocity.set(currentWorldTranslation).subtractLocal(previousWorldTranslation).multLocal(1f/lastTpf);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about the velocityFromTranslation flag?
If it's not here it's now completely useless.

getRenderer().updateSourceParam(this,AudioParam.Velocity);
previousWorldTranslation.set(currentWorldTranslation);
}
}

@Override
public AudioNode clone(){
AudioNode clone = (AudioNode) super.clone();

clone.direction = direction.clone();
clone.velocity = velocity.clone();

return clone;
}

/**
* Called internally by com.jme3.util.clone.Cloner. Do not call directly.
*/
@Override
public void cloneFields( Cloner cloner, Object original ) {
super.cloneFields(cloner, original);
super.cloneFields(cloner, original);

this.direction = cloner.clone(direction);
this.velocity = cloner.clone(velocity);
this.direction=cloner.clone(direction);
this.velocity=velocityFromTranslation?new Vector3f():cloner.clone(velocity);
this.previousWorldTranslation=Vector3f.NAN.clone();

// Change in behavior: the filters were not cloned before meaning
// that two cloned audio nodes would share the same filter instance.
Expand Down