Kaynağa Gözat

Add files via upload

Ryan McDonough 21 saat önce
ebeveyn
işleme
ab4c1f8852

+ 105 - 0
jme3-effects/src/main/java/com/jme3/vectoreffect/AbstractVectorEffect.java

@@ -0,0 +1,105 @@
+/*
+ * Copyright (c) 2009-2026 jMonkeyEngine
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ *   notice, this list of conditions and the following disclaimer.
+ *
+ * * Redistributions in binary form must reproduce the above copyright
+ *   notice, this list of conditions and the following disclaimer in the
+ *   documentation and/or other materials provided with the distribution.
+ *
+ * * Neither the name of 'jMonkeyEngine' nor the names of its contributors
+ *   may be used to endorse or promote products derived from this software
+ *   without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
+ * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+ * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+package com.jme3.vectoreffect;
+
+import com.jme3.app.state.AppStateManager;
+import java.util.ArrayList;
+
+/**
+ * @author yaRnMcDonuts
+ */
+
+public abstract class AbstractVectorEffect implements VectorEffect {
+    
+    protected VectorGroup vectorsToModify;    
+    private final ArrayList<Runnable> onFinishedCallbacks = new ArrayList<>();    
+    protected boolean isFinished = false;       
+   
+    public AbstractVectorEffect(){
+        
+    }
+    
+    public AbstractVectorEffect(VectorGroup vectorsToModify) {
+        this.vectorsToModify = vectorsToModify;
+    }        
+    
+    @Override
+    public void setIsFinished(boolean isFinished) {        
+        this.isFinished = isFinished;
+        if (isFinished) {
+            for(Runnable r : onFinishedCallbacks) {
+                r.run();
+            }
+            onFinishedCallbacks.clear();
+        }
+    }
+    
+    @Override
+    public VectorGroup getVectorsToModify(){
+        return vectorsToModify;
+    }
+    
+    @Override
+    public boolean isFinished() {        
+        return isFinished;  
+    }    
+    
+
+    @Override
+    public void reset() {
+        isFinished = false;
+    }
+    
+    
+    public void registerRunnableOnFinish(Runnable runnable) {
+        onFinishedCallbacks.add(runnable);
+    }  
+    
+    @Override
+    public void update(float tpf){
+       
+    }    
+        
+    // convenience registration method so users can avoid repeatedly writing this AppState fetching code
+    public void convenienceRegister(AppStateManager stateManager) {
+        if(stateManager != null){
+            VectorEffectManagerState vectorEffectManagerState = stateManager.getState(VectorEffectManagerState.class);
+            if(vectorEffectManagerState != null){
+                vectorEffectManagerState.registerVectorEffect(this);
+            }
+        }
+    }
+
+
+}
+

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

@@ -40,7 +40,7 @@ import com.jme3.math.Vector4f;
  *
  * @author yaRnMcDonuts
  */
-public final class EaseVectorEffect extends VectorEffect {
+public final class EaseVectorEffect extends AbstractVectorEffect {
 
     private VectorGroup targetVectors;
     private VectorGroup startVectors;    

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

@@ -39,7 +39,7 @@ import com.jme3.math.FastNoiseLite.NoiseType;
  *
  * @author yaRnMcDonuts
  */
-public class NoiseVectorEffect extends VectorEffect {
+public class NoiseVectorEffect extends AbstractVectorEffect {
     
     private FastNoiseLite noiseGenerator;        
 
@@ -85,7 +85,7 @@ public class NoiseVectorEffect extends VectorEffect {
             tempNoiseVariationVec.multLocal(noiseReturnVal);        
             originalVectorValues.getAsVector4(v, tempOriginalVec);
         
-            vectorsToModify.updateVectorObject(tempOriginalVec.add(tempNoiseVariationVec), v);
+            vectorsToModify.updateVectorObject(tempOriginalVec.addLocal(tempNoiseVariationVec), v);
         }             
     }    
     

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

@@ -39,8 +39,8 @@ import java.util.Collections;
  *
  * @author yaRnMcDonuts
  */
-public class SequencedVectorEffect extends VectorEffect {
-    private final ArrayList<VectorEffect> effects = new ArrayList<>();
+public class SequencedVectorEffect extends AbstractVectorEffect {
+    private final ArrayList<AbstractVectorEffect> effects = new ArrayList<>();
     private int currentIndex = 0;
     private boolean isRepeatingInfinitely = false;
     private float numTimesToRepeat = -1;
@@ -48,9 +48,9 @@ public class SequencedVectorEffect extends VectorEffect {
 
     public void setLooping(boolean repeat) {        this.isRepeatingInfinitely = repeat;    }
     public void setRepeatNumberOfTimes(float repititionCount){ this.numTimesToRepeat = repititionCount; }
-    public void addEffect(VectorEffect effect) {        effects.add(effect);    }
+    public void addEffect(AbstractVectorEffect effect) {        effects.add(effect);    }
 
-    public SequencedVectorEffect(VectorEffect... effects) {
+    public SequencedVectorEffect(AbstractVectorEffect... effects) {
         super();
         Collections.addAll(this.effects, effects);
     }
@@ -63,7 +63,7 @@ public class SequencedVectorEffect extends VectorEffect {
             return;
         }
 
-        VectorEffect current = effects.get(currentIndex);
+        AbstractVectorEffect current = effects.get(currentIndex);
         current.update(tpf);
 
         if (current.isFinished()) {
@@ -86,7 +86,7 @@ public class SequencedVectorEffect extends VectorEffect {
         super.reset(); 
         isFinished = false;
         currentIndex = 0;
-        for (VectorEffect e : effects) {
+        for (AbstractVectorEffect e : effects) {
             e.reset();
         }
     }

+ 7 - 56
jme3-effects/src/main/java/com/jme3/vectoreffect/VectorEffect.java

@@ -29,68 +29,19 @@
  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
-
 package com.jme3.vectoreffect;
 
-import com.jme3.app.state.AppStateManager;
-import java.util.ArrayList;
-
 /**
+ *
  * @author yaRnMcDonuts
  */
+public interface VectorEffect {
 
-public abstract class VectorEffect {
-    
-    protected VectorGroup vectorsToModify;    
-    private final ArrayList<Runnable> onFinishedCallbacks = new ArrayList<>();    
-    protected boolean isFinished = false;       
-   
-    public VectorEffect(){
+    public boolean isFinished();
+    public void update(float tpf);
+    public void setIsFinished(boolean b);
+    public VectorGroup getVectorsToModify();
+    public void reset();
         
-    }
     
-    public VectorEffect(VectorGroup vectorsToModify) {
-        this.vectorsToModify = vectorsToModify;
-    }        
-    
-    public void setIsFinished(boolean isFinished) {        
-        this.isFinished = isFinished;
-        if (isFinished) {
-            for(Runnable r : onFinishedCallbacks) {
-                r.run();
-            }
-            onFinishedCallbacks.clear();
-        }
-    }
-    
-    public boolean isFinished() {        
-        return isFinished;  
-    }    
-    
-
-    public void reset() {
-        isFinished = false;
-    }
-    
-    
-    public void registerRunnableOnFinish(Runnable runnable) {
-        onFinishedCallbacks.add(runnable);
-    }  
-    
-    public void update(float tpf){
-       
-    }    
-        
-    // convenience registration method so users can avoid repeatedly writing this AppState fetching code
-    public void convenienceRegister(AppStateManager stateManager) {
-        if(stateManager != null){
-            VectorEffectManagerState vectorEffectManagerState = stateManager.getState(VectorEffectManagerState.class);
-            if(vectorEffectManagerState != null){
-                vectorEffectManagerState.registerVectorEffect(this);
-            }
-        }
-    }
-
-
 }
-

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

@@ -85,9 +85,9 @@ public class VectorEffectManagerState extends BaseAppState {
         }
     }
 
-    public void cancelEffects(Object vectorObject) {
+    public void cancelEffects(VectorGroup vectorObject) {
         for(VectorEffect vectorEffect : activeVectorEffects){
-            if(vectorEffect.vectorsToModify.equals(vectorObject)){
+            if(vectorEffect.getVectorsToModify().equals(vectorObject)){
                 vectorEffect.setIsFinished(true);
             }
         }

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

@@ -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(VectorSupplier.of(supplier.get().clone()));
+            clonedGroup.vectorSupplier.add(supplier.clone());
         }
         return clonedGroup;
     }

+ 32 - 0
jme3-effects/src/main/java/com/jme3/vectoreffect/VectorSupplier.java

@@ -1,3 +1,34 @@
+/*
+ * Copyright (c) 2009-2021 jMonkeyEngine
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ *   notice, this list of conditions and the following disclaimer.
+ *
+ * * Redistributions in binary form must reproduce the above copyright
+ *   notice, this list of conditions and the following disclaimer in the
+ *   documentation and/or other materials provided with the distribution.
+ *
+ * * Neither the name of 'jMonkeyEngine' nor the names of its contributors
+ *   may be used to endorse or promote products derived from this software
+ *   without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
+ * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+ * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
 package com.jme3.vectoreffect;
 
 import com.jme3.math.ColorRGBA;
@@ -8,6 +39,7 @@ import com.jme3.math.Vector4f;
 public interface VectorSupplier extends Cloneable {
     Vector4f get();
     void set(Vector4f newVal);
+    VectorSupplier clone();
 
     static class Vector4fSupplier implements VectorSupplier {
         private final Vector4f vector;