Przeglądaj źródła

Add files via upload

Ryan McDonough 16 godzin temu
rodzic
commit
f7c5fd0a0a

+ 18 - 12
jme3-effects/src/main/java/com/jme3/vectoreffect/EaseVectorEffect.java

@@ -43,14 +43,18 @@ import com.jme3.math.Vector4f;
 public final class EaseVectorEffect extends VectorEffect {
 
     private VectorGroup targetVectors;
-    private VectorGroup startVectors;
-
+    private VectorGroup startVectors;    
+  
     private float duration = 0f;
     private float easeTimer = 0f;
     private float delay = 0f;
     private float delayTimer = 0f;
 
     private EaseFunction easeFunction = Easing.linear; 
+    
+    private final Vector4f tempTargetVec = new Vector4f();
+    private final Vector4f tempStartVec = new Vector4f();
+
 
     public EaseVectorEffect(VectorGroup vectorToModify) {
         super(vectorToModify);
@@ -80,6 +84,7 @@ public final class EaseVectorEffect extends VectorEffect {
         setEaseFunction(easeFunction);
         setDelayTime(delay);
     }
+    
 
     @Override
     public void update(float tpf) {
@@ -89,11 +94,10 @@ public final class EaseVectorEffect extends VectorEffect {
             delayTimer += tpf;
             return;
         }
-
         
         if (startVectors == null) {
-            startVectors = vectorsToModify.clone();
-        }
+            startVectors = vectorsToModify.clone();    
+        }        
 
         easeTimer += tpf;
         float t = Math.min(easeTimer / duration, 1f);
@@ -102,12 +106,13 @@ public final class EaseVectorEffect extends VectorEffect {
 
         for(int v = 0; v < vectorsToModify.getSize(); v++){
             
-                Vector4f targetVector = targetVectors.getAsVector4(v);
-                Vector4f startVector = startVectors.getAsVector4(v);
-                Vector4f difference = targetVector.subtract(startVector);
-                
-                Vector4f currentValue = startVector.add(difference.mult(easedT));
-                vectorsToModify.updateVectorObject(currentValue, v);            
+            int targetIndex = Math.min(v, targetVectors.getSize() - 1); //allows multiple vectors to share a lesser number of targets if desired
+            targetVectors.getAsVector4(targetIndex, tempTargetVec);
+            startVectors.getAsVector4(v, tempStartVec);
+            tempTargetVec.subtractLocal(tempStartVec);
+            tempTargetVec.multLocal(easedT);
+
+            vectorsToModify.updateVectorObject(tempStartVec.addLocal(tempTargetVec), v);            
         }        
 
         if (t >= 1f) {
@@ -134,7 +139,8 @@ public final class EaseVectorEffect extends VectorEffect {
     public void reset() {
         delayTimer = 0;
         easeTimer = 0;
-        startVectors = null;
+        startVectors = null;           
         super.reset(); 
     }
+    
 }

+ 10 - 9
jme3-effects/src/main/java/com/jme3/vectoreffect/NoiseVectorEffect.java

@@ -46,6 +46,9 @@ public class NoiseVectorEffect extends VectorEffect {
     private VectorGroup noiseMagnitudes;    
     private VectorGroup originalVectorValues;
     
+    private final Vector4f tempNoiseVariationVec = new Vector4f();
+    private final Vector4f tempOriginalVec = new Vector4f();
+    
     public float speed = 1;
     private float timeAccrued = 0;
     
@@ -72,19 +75,17 @@ public class NoiseVectorEffect extends VectorEffect {
             originalVectorValues = vectorsToModify.clone();
         }
         
-        timeAccrued += tpf;                
-        
-        //to-do: add a togglable isUniform boolean that can be set false to allow each x/y/z/w component to be altered by a different noise value.
-        
+        timeAccrued += tpf;             
         float noiseReturnVal = noiseGenerator.GetNoise(timeAccrued * speed, 12.671f + timeAccrued * speed * 0.92173f, 19.54f + timeAccrued * speed * 0.68913f);
         
         for(int v = 0; v < vectorsToModify.getSize(); v++){
             int magnitudeIndex = Math.min(v, noiseMagnitudes.getSize() - 1); //allows multiple vectors to share the same magnitude if desired
-            Vector4f noiseVariation = noiseMagnitudes.getAsVector4(magnitudeIndex).mult(noiseReturnVal);
-        
-            noiseVariation.addLocal(originalVectorValues.getAsVector4(v));
+            noiseMagnitudes.getAsVector4(magnitudeIndex, tempNoiseVariationVec);
+
+            tempNoiseVariationVec.multLocal(noiseReturnVal);        
+            originalVectorValues.getAsVector4(v, tempOriginalVec);
         
-            vectorsToModify.updateVectorObject(noiseVariation, v);
+            vectorsToModify.updateVectorObject(tempOriginalVec.add(tempNoiseVariationVec), v);
         }             
     }    
     
@@ -99,6 +100,6 @@ public class NoiseVectorEffect extends VectorEffect {
     @Override
     public void reset() {
         super.reset(); 
-        originalVectorValues = null;
+        originalVectorValues = null;       
     }
 }

+ 1 - 3
jme3-effects/src/main/java/com/jme3/vectoreffect/SequencedVectorEffect.java

@@ -55,7 +55,6 @@ public class SequencedVectorEffect extends VectorEffect {
         Collections.addAll(this.effects, effects);
     }
 
-
     @Override
     public void update(float tpf) {
         super.update(tpf);
@@ -77,8 +76,7 @@ public class SequencedVectorEffect extends VectorEffect {
                 if (!isRepeatingInfinitely && currentCycle >= numTimesToRepeat) {
                     setIsFinished(true);
                     currentCycle = 0;
-                }
-               
+                }               
             }
         }
     }    

+ 0 - 3
jme3-effects/src/main/java/com/jme3/vectoreffect/VectorEffect.java

@@ -36,9 +36,6 @@ import com.jme3.app.state.AppStateManager;
 import java.util.ArrayList;
 
 /**
- * Base class for vector/color effects. * 
- * Supports Vector2f, Vector3f, Vector4f, and ColorRGBA.
- * 
  * @author yaRnMcDonuts
  */
 

+ 17 - 16
jme3-effects/src/main/java/com/jme3/vectoreffect/VectorEffectManagerState.java

@@ -35,6 +35,7 @@ package com.jme3.vectoreffect;
 import com.jme3.app.Application;
 import com.jme3.app.state.BaseAppState;
 import java.util.ArrayList;
+import java.util.Iterator;
 
 /**
  *
@@ -65,30 +66,30 @@ public class VectorEffectManagerState extends BaseAppState {
     }
     
     public void registerVectorEffect(VectorEffect vectorEffect){
-        if(activeVectorEffects != null){
-            if(!activeVectorEffects.contains(vectorEffect)){
-                activeVectorEffects.add(vectorEffect);
-            }       
-        }
+        if(!activeVectorEffects.contains(vectorEffect)){
+            activeVectorEffects.add(vectorEffect);
+        }     
     }
     
     @Override
     public void update(float tpf) {
         super.update(tpf);
-        
-        for(VectorEffect vectorEffect : activeVectorEffects){
-            
-            
+        for (Iterator<VectorEffect> it = activeVectorEffects.iterator(); it.hasNext(); ) {
+            VectorEffect vectorEffect = it.next();
 
-            if(vectorEffect.isFinished()){
-                getApplication().enqueue(() ->{
-                    activeVectorEffects.remove(vectorEffect);
-                });
-            }
-            else{
+            if (vectorEffect.isFinished()) {
+                it.remove(); 
+            } else {
                 vectorEffect.update(tpf);
             }
         }
+    }
 
-    } 
+    public void cancelEffects(Object vectorObject) {
+        for(VectorEffect vectorEffect : activeVectorEffects){
+            if(vectorEffect.vectorsToModify.equals(vectorObject)){
+                vectorEffect.setIsFinished(true);
+            }
+        }
+    }
 }

+ 3 - 3
jme3-effects/src/main/java/com/jme3/vectoreffect/VectorGroup.java

@@ -80,8 +80,8 @@ public class VectorGroup implements Cloneable {
         }
     }
 
-    protected Vector4f getAsVector4(int index) {
-        return vectorSupplier.get(index).get();
+    protected Vector4f getAsVector4(int index, Vector4f store) {
+        return store.set(vectorSupplier.get(index).get());
     }
 
     protected void updateVectorObject(Vector4f newVal, int index) {
@@ -93,7 +93,7 @@ public class VectorGroup implements Cloneable {
     public VectorGroup clone() {
         VectorGroup clonedGroup = new VectorGroup(new VectorSupplier[0]);
         for (VectorSupplier supplier : this.vectorSupplier) {
-            clonedGroup.vectorSupplier.add(supplier);
+            clonedGroup.vectorSupplier.add(VectorSupplier.of(supplier.get().clone()));
         }
         return clonedGroup;
     }

+ 10 - 6
jme3-effects/src/main/java/com/jme3/vectoreffect/VectorSupplier.java

@@ -9,8 +9,6 @@ public interface VectorSupplier extends Cloneable {
     Vector4f get();
     void set(Vector4f newVal);
 
-
-
     static class Vector4fSupplier implements VectorSupplier {
         private final Vector4f vector;
 
@@ -18,10 +16,12 @@ public interface VectorSupplier extends Cloneable {
             this.vector = vector;
         }
 
+        @Override
         public Vector4f get() {
             return vector;
         }
 
+        @Override
         public void set(Vector4f newVal) {
             this.vector.set(newVal);
         }
@@ -29,8 +29,7 @@ public interface VectorSupplier extends Cloneable {
         @Override
         public Vector4fSupplier clone() {
             return new Vector4fSupplier(vector.clone());
-        }
-      
+        }      
     }
 
     static class Vector3fSupplier implements VectorSupplier {
@@ -40,11 +39,13 @@ public interface VectorSupplier extends Cloneable {
             this.vector = vector;
         }
 
+        @Override
         public Vector4f get() {
             store.set(vector.x, vector.y, vector.z, 0);
             return store;
         }
 
+        @Override
         public void set(Vector4f newVal) {
             this.vector.set(newVal.x, newVal.y, newVal.z);
             get(); //update store
@@ -64,11 +65,13 @@ public interface VectorSupplier extends Cloneable {
             this.color = color;
         }
 
+        @Override
         public Vector4f get() {
             store.set(color.r, color.g, color.b, color.a);
             return store;
         }
 
+        @Override
         public void set(Vector4f newVal) {
             this.color.set(newVal.x, newVal.y, newVal.z, newVal.w);
             get(); //update store
@@ -88,11 +91,13 @@ public interface VectorSupplier extends Cloneable {
             this.vector = vector;
         }
 
+        @Override
         public Vector4f get() {
             store.set(vector.x, vector.y, 0, 0);
             return store;
         }
 
+        @Override
         public void set(Vector4f newVal) {
             this.vector.set(newVal.x, newVal.y);
             get(); //update store
@@ -102,8 +107,7 @@ public interface VectorSupplier extends Cloneable {
         public Vector2fSupplier clone() {
             return new Vector2fSupplier(vector.clone());
         }
-    }
-    
+    }   
 
 
     public static VectorSupplier of(Vector4f vector) {