Project

General

Profile

« Previous | Next » 

Revision d2556e79

Added by Leszek Koltunski about 3 years ago

Move yet more code to objectlib.

View differences:

src/main/java/org/distorted/dialogs/RubikDialogEffects.java
34 34
import android.view.View;
35 35
import android.view.ViewGroup;
36 36
import android.view.Window;
37
import android.view.WindowManager;
38 37
import android.widget.AdapterView;
39 38
import android.widget.ArrayAdapter;
40 39
import android.widget.Button;
......
43 42
import android.widget.Spinner;
44 43
import android.widget.TextView;
45 44

  
46
import org.distorted.effects.BaseEffect;
45
import org.distorted.objectlib.effects.BaseEffect;
47 46
import org.distorted.main.R;
48 47
import org.distorted.main.RubikActivity;
49 48

  
src/main/java/org/distorted/effects/BaseEffect.java
1
///////////////////////////////////////////////////////////////////////////////////////////////////
2
// Copyright 2020 Leszek Koltunski                                                               //
3
//                                                                                               //
4
// This file is part of Magic Cube.                                                              //
5
//                                                                                               //
6
// Magic Cube is free software: you can redistribute it and/or modify                            //
7
// it under the terms of the GNU General Public License as published by                          //
8
// the Free Software Foundation, either version 2 of the License, or                             //
9
// (at your option) any later version.                                                           //
10
//                                                                                               //
11
// Magic Cube is distributed in the hope that it will be useful,                                 //
12
// but WITHOUT ANY WARRANTY; without even the implied warranty of                                //
13
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the                                 //
14
// GNU General Public License for more details.                                                  //
15
//                                                                                               //
16
// You should have received a copy of the GNU General Public License                             //
17
// along with Magic Cube.  If not, see <http://www.gnu.org/licenses/>.                           //
18
///////////////////////////////////////////////////////////////////////////////////////////////////
19

  
20
package org.distorted.effects;
21

  
22
import java.lang.reflect.InvocationTargetException;
23
import java.lang.reflect.Method;
24
import android.content.SharedPreferences;
25

  
26
import org.distorted.library.main.DistortedScreen;
27

  
28
import org.distorted.effects.scramble.ScrambleEffect;
29
import org.distorted.effects.objectchange.ObjectChangeEffect;
30
import org.distorted.effects.solve.SolveEffect;
31
import org.distorted.effects.win.WinEffect;
32
import org.distorted.main.R;
33

  
34
///////////////////////////////////////////////////////////////////////////////////////////////////
35

  
36
public class BaseEffect
37
  {
38
  public enum Type
39
    {
40
    SIZECHANGE  ( 20, 1, R.string.objectchange_effect, ObjectChangeEffect.class),
41
    SOLVE       ( 20, 1, R.string.solve_effect      , SolveEffect.class     ),
42
    SCRAMBLE    ( 60, 1, R.string.scramble_effect   , ScrambleEffect.class  ),
43
    WIN         ( 20, 1, R.string.win_effect        , WinEffect.class       ),
44
    ;
45

  
46
    private final int mDefaultPos, mDefaultType;
47
    private final Class<? extends BaseEffect> mClass;
48
    private int mCurrentPos, mCurrentType;
49
    private int mText;
50

  
51
    Type(int dPos, int dType, int text, Class<? extends BaseEffect> clazz )
52
      {
53
      mDefaultPos  = mCurrentPos = dPos;
54
      mDefaultType = mCurrentType= dType;
55
      mText        = text;
56
      mClass       = clazz;
57
      }
58

  
59
    public static final int LENGTH = Type.values().length;
60
    private static final Type[] types;  // copy the values() to a local variable so that we
61
                                        // don't have to keep recreating the array every time
62
    static
63
      {
64
      int i=0;
65

  
66
      types= new Type[LENGTH];
67

  
68
      for(Type type: Type.values())
69
        {
70
        types[i] = type;
71
        i++;
72
        }
73
      }
74

  
75
  ////////////////////////////////////////////////////////////////////////////////
76

  
77
    public int getText()
78
      {
79
      return mText;
80
      }
81

  
82
  ////////////////////////////////////////////////////////////////////////////////
83

  
84
    public int getCurrentPos()
85
      {
86
      return mCurrentPos;
87
      }
88

  
89
  ////////////////////////////////////////////////////////////////////////////////
90

  
91
    public int getCurrentType()
92
      {
93
      return mCurrentType;
94
      }
95

  
96
  ////////////////////////////////////////////////////////////////////////////////
97

  
98
    public void setCurrentPos(int pos)
99
      {
100
      mCurrentPos = pos;
101
      }
102

  
103
  ////////////////////////////////////////////////////////////////////////////////
104

  
105
    public void setCurrentType(int type)
106
      {
107
      mCurrentType = type;
108
      }
109

  
110
  ////////////////////////////////////////////////////////////////////////////////
111

  
112
    public void savePreferences(SharedPreferences.Editor editor)
113
      {
114
      String name = name();
115

  
116
      editor.putInt(name+"_Pos" , mCurrentPos );
117
      editor.putInt(name+"_Type", mCurrentType);
118
      }
119

  
120
  ////////////////////////////////////////////////////////////////////////////////
121

  
122
    public void restorePreferences(SharedPreferences preferences)
123
      {
124
      String name = name();
125

  
126
      mCurrentPos  = preferences.getInt(name+"_Pos" , mDefaultPos );
127
      mCurrentType = preferences.getInt(name+"_Type", mDefaultType);
128
      }
129

  
130
  ////////////////////////////////////////////////////////////////////////////////
131

  
132
    public String[] getNames()
133
      {
134
      Method method;
135

  
136
      try
137
        {
138
        method = mClass.getDeclaredMethod("getNames");
139
        }
140
      catch(NoSuchMethodException ex)
141
        {
142
        android.util.Log.e("BaseEffect", mClass.getSimpleName()+": exception getting method: "+ex.getMessage());
143
        method = null;
144
        }
145

  
146
      try
147
        {
148
        if( method!=null )
149
          {
150
          Object value = method.invoke(null);
151
          return (String[]) value;
152
          }
153
        }
154
      catch(Exception ex)
155
        {
156
        android.util.Log.e("BaseEffect", mClass.getSimpleName()+": exception invoking method: "+ex.getMessage());
157
        }
158

  
159
      return null;
160
      }
161

  
162
  ////////////////////////////////////////////////////////////////////////////////
163

  
164
    public static Type getType(int ordinal)
165
      {
166
      return types[ordinal];
167
      }
168

  
169
  ////////////////////////////////////////////////////////////////////////////////
170

  
171
    public static void enableEffects()
172
      {
173
      Method method;
174

  
175
      for(Type type: values())
176
        {
177
        try
178
          {
179
          method = type.mClass.getDeclaredMethod("enableEffects");
180
          }
181
        catch(NoSuchMethodException ex)
182
          {
183
          android.util.Log.e("BaseEffect", type.mClass.getSimpleName()+": exception getting method: "+ex.getMessage());
184
          method = null;
185
          }
186

  
187
        try
188
          {
189
          if( method!=null ) method.invoke(null);
190
          }
191
        catch(Exception ex)
192
          {
193
          android.util.Log.e("BaseEffect", type.mClass.getSimpleName()+": exception invoking method: "+ex.getMessage());
194
          }
195
        }
196
      }
197

  
198
  ////////////////////////////////////////////////////////////////////////////////
199

  
200
    public long startEffect(DistortedScreen screen, EffectController cont) throws NoSuchMethodException, IllegalAccessException, InvocationTargetException
201
      {
202
      Method method1 = mClass.getDeclaredMethod("create", int.class);
203

  
204
      Object value1 = method1.invoke(null,mCurrentType);
205
      BaseEffect baseEffect = (BaseEffect)value1;
206

  
207
      Method method2 = mClass.getDeclaredMethod("start", int.class, DistortedScreen.class, EffectController.class);
208

  
209
      Integer translated = translatePos(mCurrentPos)+1;
210
      Object value2 = method2.invoke(baseEffect,translated,screen,cont);
211
      return (Long)value2;
212
      }
213

  
214
  ////////////////////////////////////////////////////////////////////////////////
215
  // map the (0..100) range of the SeekBar into (0..5000) milliseconds, in 100ms
216
  // increments.
217

  
218
    public static int translatePos(int pos)
219
      {
220
      return (pos/2)*100;
221
      }
222
    }
223

  
224
  // END ENUM ////////////////////////////////////////////////////////////////////
225
  }
src/main/java/org/distorted/effects/EffectController.java
1
///////////////////////////////////////////////////////////////////////////////////////////////////
2
// Copyright 2020 Leszek Koltunski                                                               //
3
//                                                                                               //
4
// This file is part of Magic Cube.                                                              //
5
//                                                                                               //
6
// Magic Cube is free software: you can redistribute it and/or modify                            //
7
// it under the terms of the GNU General Public License as published by                          //
8
// the Free Software Foundation, either version 2 of the License, or                             //
9
// (at your option) any later version.                                                           //
10
//                                                                                               //
11
// Magic Cube is distributed in the hope that it will be useful,                                 //
12
// but WITHOUT ANY WARRANTY; without even the implied warranty of                                //
13
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the                                 //
14
// GNU General Public License for more details.                                                  //
15
//                                                                                               //
16
// You should have received a copy of the GNU General Public License                             //
17
// along with Magic Cube.  If not, see <http://www.gnu.org/licenses/>.                           //
18
///////////////////////////////////////////////////////////////////////////////////////////////////
19

  
20
package org.distorted.effects;
21

  
22
import org.distorted.library.message.EffectListener;
23
import org.distorted.objectlib.main.TwistyObject;
24
import org.distorted.objectlib.helpers.MovesFinished;
25

  
26
///////////////////////////////////////////////////////////////////////////////////////////////////
27

  
28
public interface EffectController extends EffectListener
29
  {
30
  void addRotation(MovesFinished listener, int axis, int rowBitmap, int angle, long duration);
31
  TwistyObject getOldObject();
32
  TwistyObject getObject();
33
  int getNumScrambles();
34
  void solve();
35
  }
src/main/java/org/distorted/effects/objectchange/ObjectChangeEffect.java
1
///////////////////////////////////////////////////////////////////////////////////////////////////
2
// Copyright 2019 Leszek Koltunski                                                               //
3
//                                                                                               //
4
// This file is part of Magic Cube.                                                              //
5
//                                                                                               //
6
// Magic Cube is free software: you can redistribute it and/or modify                            //
7
// it under the terms of the GNU General Public License as published by                          //
8
// the Free Software Foundation, either version 2 of the License, or                             //
9
// (at your option) any later version.                                                           //
10
//                                                                                               //
11
// Magic Cube is distributed in the hope that it will be useful,                                 //
12
// but WITHOUT ANY WARRANTY; without even the implied warranty of                                //
13
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the                                 //
14
// GNU General Public License for more details.                                                  //
15
//                                                                                               //
16
// You should have received a copy of the GNU General Public License                             //
17
// along with Magic Cube.  If not, see <http://www.gnu.org/licenses/>.                           //
18
///////////////////////////////////////////////////////////////////////////////////////////////////
19

  
20
package org.distorted.effects.objectchange;
21

  
22
import java.lang.reflect.Method;
23

  
24
import org.distorted.library.effect.Effect;
25
import org.distorted.library.main.DistortedEffects;
26
import org.distorted.library.main.DistortedScreen;
27
import org.distorted.library.message.EffectListener;
28

  
29
import org.distorted.objectlib.main.TwistyObject;
30

  
31
import org.distorted.effects.BaseEffect;
32
import org.distorted.effects.EffectController;
33

  
34
///////////////////////////////////////////////////////////////////////////////////////////////////
35

  
36
public abstract class ObjectChangeEffect extends BaseEffect implements EffectListener
37
{
38
  public enum Type
39
    {
40
    NONE         (ObjectChangeEffectNone.class        ),
41
    TRANSPARENCY (ObjectChangeEffectTransparency.class),
42
    MOVE         (ObjectChangeEffectMove.class        ),
43
    ROUND        (ObjectChangeEffectRound.class       ),
44
    SCALE        (ObjectChangeEffectScale.class       ),
45
    ;
46

  
47
    final Class<? extends ObjectChangeEffect> effect;
48

  
49
    Type(Class<? extends ObjectChangeEffect> effect)
50
      {
51
      this.effect= effect;
52
      }
53
    }
54

  
55
  private static final int NUM_EFFECTS = Type.values().length;
56
  private static final int NUM_PHASES  = 2;
57
  private static final int FAKE_EFFECT_ID  = -1;
58
  private static final Type[] types;
59

  
60
  static
61
    {
62
    int i=0;
63
    types = new Type[NUM_EFFECTS];
64

  
65
    for(Type type: Type.values())
66
      {
67
      types[i++] = type;
68
      }
69
    }
70

  
71
  private EffectController mController;
72
  private int mDuration;
73
  private final int[] mEffectReturned;
74
  private final int[] mCubeEffectNumber, mNodeEffectNumber;
75
  private final int[] mEffectFinished;
76
  private final boolean[] mPhaseActive;
77

  
78
  TwistyObject[] mObject;
79
  DistortedScreen mScreen;
80
  Effect[][] mCubeEffects;
81
  int[][] mCubeEffectPosition;
82
  Effect[][] mNodeEffects;
83
  int[][] mNodeEffectPosition;
84

  
85
///////////////////////////////////////////////////////////////////////////////////////////////////
86

  
87
  ObjectChangeEffect()
88
    {
89
    mPhaseActive        = new boolean[NUM_PHASES];
90
    mEffectReturned     = new int[NUM_PHASES];
91
    mCubeEffectNumber   = new int[NUM_PHASES];
92
    mNodeEffectNumber   = new int[NUM_PHASES];
93
    mEffectFinished     = new int[NUM_PHASES];
94
    mCubeEffectPosition = new int[NUM_PHASES][];
95
    mNodeEffectPosition = new int[NUM_PHASES][];
96
    mCubeEffects        = new Effect[NUM_PHASES][];
97
    mNodeEffects        = new Effect[NUM_PHASES][];
98
    mObject             = new TwistyObject[NUM_PHASES];
99
    }
100

  
101
///////////////////////////////////////////////////////////////////////////////////////////////////
102

  
103
  abstract int createEffectsPhase0(int duration);
104
  abstract int createEffectsPhase1(int duration);
105

  
106
///////////////////////////////////////////////////////////////////////////////////////////////////
107

  
108
  private void effectFinishedPhase(final long effectID, int phase)
109
    {
110
    for(int i=0; i<mCubeEffectNumber[phase]; i++)
111
      {
112
      long id = mCubeEffects[phase][i].getID();
113

  
114
      if( effectID == id )
115
        {
116
        effectReturned(phase);
117
        mObject[phase].remove(id);
118
        return;
119
        }
120
      }
121
    for(int i=0; i<mNodeEffectNumber[phase]; i++)
122
      {
123
      long id = mNodeEffects[phase][i].getID();
124

  
125
      if( effectID == id )
126
        {
127
        effectReturned(phase);
128
        mObject[phase].getEffects().abortById(id);
129
        return;
130
        }
131
      }
132
    }
133

  
134
///////////////////////////////////////////////////////////////////////////////////////////////////
135

  
136
  private void effectReturned(int phase)
137
    {
138
    mEffectReturned[phase]++;
139

  
140
    if( mEffectReturned[phase] == mEffectFinished[phase] )
141
      {
142
      switch(phase)
143
        {
144
        case 0: mPhaseActive[1] = true;
145
                mEffectFinished[1] = createEffectsPhase1(mDuration);
146
                assignEffects(1);
147
                mScreen.attach(mObject[1]);
148
                break;
149
        case 1: mController.effectFinished(FAKE_EFFECT_ID);
150
                break;
151
        }
152
      }
153
    if( mEffectReturned[phase] == mCubeEffectNumber[phase]+mNodeEffectNumber[phase] )
154
      {
155
      switch(phase)
156
        {
157
        case 0: mPhaseActive[0] = false;
158
                mScreen.detach(mObject[0]);
159
                break;
160
        case 1: mPhaseActive[1] = false;
161
                break;
162
        }
163
      }
164
    }
165

  
166
///////////////////////////////////////////////////////////////////////////////////////////////////
167

  
168
  private void assignEffects(int phase)
169
    {
170
    mCubeEffectNumber[phase] = ( mCubeEffects[phase]!=null ) ? mCubeEffects[phase].length : 0;
171
    mNodeEffectNumber[phase] = ( mNodeEffects[phase]!=null ) ? mNodeEffects[phase].length : 0;
172

  
173
    if( mCubeEffectNumber[phase]==0 && mNodeEffectNumber[phase]==0 )
174
      {
175
      throw new RuntimeException("Cube and Node Effects ("+phase+" phase) both not created!");
176
      }
177

  
178
    for(int i=0; i<mCubeEffectNumber[phase]; i++)
179
      {
180
      mObject[phase].apply(mCubeEffects[phase][i],mCubeEffectPosition[phase][i]);
181
      mCubeEffects[phase][i].notifyWhenFinished(this);
182
      }
183

  
184
    DistortedEffects nodeEffects = mObject[phase].getEffects();
185

  
186
    for(int i=0; i<mNodeEffectNumber[phase]; i++)
187
      {
188
      nodeEffects.apply(mNodeEffects[phase][i],mNodeEffectPosition[phase][i]);
189
      mNodeEffects[phase][i].notifyWhenFinished(this);
190
      }
191
    }
192

  
193
///////////////////////////////////////////////////////////////////////////////////////////////////
194
// PUBLIC API
195
///////////////////////////////////////////////////////////////////////////////////////////////////
196

  
197
  public void effectFinished(final long effectID)
198
    {
199
    if( mPhaseActive[0] ) effectFinishedPhase(effectID,0);
200
    if( mPhaseActive[1] ) effectFinishedPhase(effectID,1);
201
    }
202

  
203
///////////////////////////////////////////////////////////////////////////////////////////////////
204

  
205
  @SuppressWarnings("unused")
206
  public static String[] getNames()
207
    {
208
    String[] names = new String[NUM_EFFECTS];
209

  
210
    for( int i=0; i<NUM_EFFECTS; i++)
211
      {
212
      names[i] = types[i].name();
213
      }
214

  
215
    return names;
216
    }
217

  
218
///////////////////////////////////////////////////////////////////////////////////////////////////
219

  
220
  @SuppressWarnings("unused")
221
  public static ObjectChangeEffect create(int ordinal) throws InstantiationException, IllegalAccessException
222
    {
223
    return types[ordinal].effect.newInstance();
224
    }
225

  
226
///////////////////////////////////////////////////////////////////////////////////////////////////
227

  
228
  @SuppressWarnings("unused")
229
  public long start(int duration, DistortedScreen screen, EffectController cont)
230
    {
231
    mScreen    = screen;
232
    mObject[0] = cont.getOldObject();
233
    mObject[1] = cont.getObject();
234
    mController= cont;
235
    mDuration  = duration;
236

  
237
    if( mObject[0]!=null )
238
      {
239
      mPhaseActive[0] = true;
240
      mEffectFinished[0] = createEffectsPhase0(mDuration);
241
      assignEffects(0);
242
      }
243
    else
244
      {
245
      mPhaseActive[1] = true;
246
      mEffectFinished[1] = createEffectsPhase1(mDuration);
247
      assignEffects(1);
248
      mScreen.attach(mObject[1]);
249
      }
250

  
251
    return FAKE_EFFECT_ID;
252
    }
253

  
254
///////////////////////////////////////////////////////////////////////////////////////////////////
255

  
256
  @SuppressWarnings("unused")
257
  public static void enableEffects()
258
    {
259
    Method method;
260

  
261
    for(Type type: Type.values())
262
      {
263
      try
264
        {
265
        method = type.effect.getDeclaredMethod("enable");  // enable not public, thus getDeclaredMethod
266
        }
267
      catch(NoSuchMethodException ex)
268
        {
269
        android.util.Log.e("SizeChangeEffect", type.effect.getSimpleName()+": exception getting method: "+ex.getMessage());
270
        method = null;
271
        }
272

  
273
      try
274
        {
275
        if( method!=null ) method.invoke(null);
276
        }
277
      catch(Exception ex)
278
        {
279
        android.util.Log.e("SizeChangeEffect", type.effect.getSimpleName()+": exception invoking method: "+ex.getMessage());
280
        }
281
      }
282
    }
283
}
src/main/java/org/distorted/effects/objectchange/ObjectChangeEffectMove.java
1
///////////////////////////////////////////////////////////////////////////////////////////////////
2
// Copyright 2019 Leszek Koltunski                                                               //
3
//                                                                                               //
4
// This file is part of Magic Cube.                                                              //
5
//                                                                                               //
6
// Magic Cube is free software: you can redistribute it and/or modify                            //
7
// it under the terms of the GNU General Public License as published by                          //
8
// the Free Software Foundation, either version 2 of the License, or                             //
9
// (at your option) any later version.                                                           //
10
//                                                                                               //
11
// Magic Cube is distributed in the hope that it will be useful,                                 //
12
// but WITHOUT ANY WARRANTY; without even the implied warranty of                                //
13
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the                                 //
14
// GNU General Public License for more details.                                                  //
15
//                                                                                               //
16
// You should have received a copy of the GNU General Public License                             //
17
// along with Magic Cube.  If not, see <http://www.gnu.org/licenses/>.                           //
18
///////////////////////////////////////////////////////////////////////////////////////////////////
19

  
20
package org.distorted.effects.objectchange;
21

  
22
import org.distorted.library.effect.Effect;
23
import org.distorted.library.effect.MatrixEffectMove;
24
import org.distorted.library.type.Dynamic3D;
25
import org.distorted.library.type.Static3D;
26

  
27
///////////////////////////////////////////////////////////////////////////////////////////////////
28

  
29
class ObjectChangeEffectMove extends ObjectChangeEffect
30
  {
31
  public int createEffectsPhase0(int duration)
32
    {
33
    int w = mScreen.getWidth();
34
    int h = mScreen.getHeight();
35
    int xmove = w/2 + (w<h?w:h)/2;
36

  
37
    mNodeEffectPosition[0] = new int[] {1};
38
    mNodeEffects[0]        = new Effect[mNodeEffectPosition[0].length];
39

  
40
    Dynamic3D d0 = new Dynamic3D(duration/2, 0.5f);
41
    d0.add(new Static3D(    0,0,0));
42
    d0.add(new Static3D(xmove,0,0));
43
    mNodeEffects[0][0] = new MatrixEffectMove(d0);
44

  
45
    return 1;
46
    }
47

  
48
///////////////////////////////////////////////////////////////////////////////////////////////////
49

  
50
  public int createEffectsPhase1(int duration)
51
    {
52
    int w = mScreen.getWidth();
53
    int h = mScreen.getHeight();
54
    int xmove = w/2 + (w<h?w:h)/2;
55

  
56
    mNodeEffectPosition[1] = new int[] {1};
57
    mNodeEffects[1]        = new Effect[mNodeEffectPosition[1].length];
58

  
59
    Dynamic3D d0 = new Dynamic3D(duration/2, 0.5f);
60
    d0.add(new Static3D(-xmove,0,0));
61
    d0.add(new Static3D(     0,0,0));
62
    mNodeEffects[1][0] = new MatrixEffectMove(d0);
63

  
64
    return 1;
65
    }
66

  
67
///////////////////////////////////////////////////////////////////////////////////////////////////
68
// Enable all effects used in this Effect. Called by reflection from the parent class.
69
// Matrix Effects do not have to be enabled.
70

  
71
  @SuppressWarnings("unused")
72
  static void enable()
73
    {
74

  
75
    }
76
  }
77

  
src/main/java/org/distorted/effects/objectchange/ObjectChangeEffectNone.java
1
///////////////////////////////////////////////////////////////////////////////////////////////////
2
// Copyright 2019 Leszek Koltunski                                                               //
3
//                                                                                               //
4
// This file is part of Magic Cube.                                                              //
5
//                                                                                               //
6
// Magic Cube is free software: you can redistribute it and/or modify                            //
7
// it under the terms of the GNU General Public License as published by                          //
8
// the Free Software Foundation, either version 2 of the License, or                             //
9
// (at your option) any later version.                                                           //
10
//                                                                                               //
11
// Magic Cube is distributed in the hope that it will be useful,                                 //
12
// but WITHOUT ANY WARRANTY; without even the implied warranty of                                //
13
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the                                 //
14
// GNU General Public License for more details.                                                  //
15
//                                                                                               //
16
// You should have received a copy of the GNU General Public License                             //
17
// along with Magic Cube.  If not, see <http://www.gnu.org/licenses/>.                           //
18
///////////////////////////////////////////////////////////////////////////////////////////////////
19

  
20
package org.distorted.effects.objectchange;
21

  
22
import org.distorted.library.effect.Effect;
23
import org.distorted.library.effect.MatrixEffectMove;
24
import org.distorted.library.type.Dynamic3D;
25
import org.distorted.library.type.Static3D;
26

  
27
///////////////////////////////////////////////////////////////////////////////////////////////////
28

  
29
class ObjectChangeEffectNone extends ObjectChangeEffect
30
  {
31
  public int createEffectsPhase0(int duration)
32
    {
33
    mCubeEffectPosition[0] = new int[] {-1};
34
    mCubeEffects[0]        = new Effect[mCubeEffectPosition[0].length];
35

  
36
    Dynamic3D d0 = new Dynamic3D(1,0.5f);
37
    d0.add(new Static3D(0,0,0));
38
    mCubeEffects[0][0] = new MatrixEffectMove(d0);
39

  
40
    return 1;
41
    }
42

  
43
///////////////////////////////////////////////////////////////////////////////////////////////////
44

  
45
  public int createEffectsPhase1(int duration)
46
    {
47
    mCubeEffectPosition[1] = new int[] {-1};
48
    mCubeEffects[1]        = new Effect[mCubeEffectPosition[1].length];
49

  
50
    Dynamic3D d0 = new Dynamic3D(1,0.5f);
51
    d0.add(new Static3D(0,0,0));
52
    mCubeEffects[1][0] = new MatrixEffectMove(d0);
53

  
54
    return 1;
55
    }
56

  
57
///////////////////////////////////////////////////////////////////////////////////////////////////
58
// enable all effects used in this Effect (here: none).  Called by reflection from the parent class.
59

  
60
  @SuppressWarnings("unused")
61
  static void enable()
62
    {
63

  
64
    }
65
  }
src/main/java/org/distorted/effects/objectchange/ObjectChangeEffectRound.java
1
///////////////////////////////////////////////////////////////////////////////////////////////////
2
// Copyright 2019 Leszek Koltunski                                                               //
3
//                                                                                               //
4
// This file is part of Magic Cube.                                                              //
5
//                                                                                               //
6
// Magic Cube is free software: you can redistribute it and/or modify                            //
7
// it under the terms of the GNU General Public License as published by                          //
8
// the Free Software Foundation, either version 2 of the License, or                             //
9
// (at your option) any later version.                                                           //
10
//                                                                                               //
11
// Magic Cube is distributed in the hope that it will be useful,                                 //
12
// but WITHOUT ANY WARRANTY; without even the implied warranty of                                //
13
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the                                 //
14
// GNU General Public License for more details.                                                  //
15
//                                                                                               //
16
// You should have received a copy of the GNU General Public License                             //
17
// along with Magic Cube.  If not, see <http://www.gnu.org/licenses/>.                           //
18
///////////////////////////////////////////////////////////////////////////////////////////////////
19

  
20
package org.distorted.effects.objectchange;
21

  
22
import org.distorted.library.effect.Effect;
23
import org.distorted.library.effect.MatrixEffectMove;
24
import org.distorted.library.effect.MatrixEffectScale;
25
import org.distorted.library.type.Dynamic;
26
import org.distorted.library.type.Dynamic3D;
27
import org.distorted.library.type.Static3D;
28

  
29
///////////////////////////////////////////////////////////////////////////////////////////////////
30

  
31
class ObjectChangeEffectRound extends ObjectChangeEffect
32
  {
33
  public int createEffectsPhase0(int duration)
34
    {
35
    float X = mObject[0].getNodeSize()/3.0f;
36

  
37
    mCubeEffectPosition[0] = new int[] {2,3};
38
    mCubeEffects[0]        = new Effect[mCubeEffectPosition[0].length];
39

  
40
    Dynamic3D d0 = new Dynamic3D(duration/2, 0.5f);
41
    d0.add(new Static3D( 1.00f, 1.00f, 1.00f));
42
    d0.add(new Static3D( 0.01f, 0.01f, 0.01f));
43
    mCubeEffects[0][0] = new MatrixEffectScale(d0);
44

  
45
    Dynamic3D d1 = new Dynamic3D(duration/2, 0.5f);
46
    d1.setMode(Dynamic.MODE_PATH);
47
    d1.add(new Static3D( 0, 0, 0));
48
    d1.add(new Static3D(+X, 0, 0));
49
    d1.add(new Static3D( 0, 0, 0));
50
    mCubeEffects[0][1] = new MatrixEffectMove(d1);
51

  
52
    return 2;
53
    }
54

  
55
///////////////////////////////////////////////////////////////////////////////////////////////////
56

  
57
  public int createEffectsPhase1(int duration)
58
    {
59
    float X = mObject[0].getNodeSize()/3.0f;
60

  
61
    mCubeEffectPosition[1] = new int[] {2,3};
62
    mCubeEffects[1]        = new Effect[mCubeEffectPosition[1].length];
63

  
64
    Dynamic3D d0 = new Dynamic3D(duration/2, 0.5f);
65
    d0.add(new Static3D( 0.01f, 0.01f, 0.01f));
66
    d0.add(new Static3D( 1.00f, 1.00f, 1.00f));
67
    mCubeEffects[1][0] = new MatrixEffectScale(d0);
68

  
69
    Dynamic3D d1 = new Dynamic3D(duration/2, 0.5f);
70
    d1.setMode(Dynamic.MODE_PATH);
71
    d1.add(new Static3D( 0, 0, 0));
72
    d1.add(new Static3D(-X, 0, 0));
73
    d1.add(new Static3D( 0, 0, 0));
74
    mCubeEffects[1][1] = new MatrixEffectMove(d1);
75

  
76
    return 2;
77
    }
78

  
79
///////////////////////////////////////////////////////////////////////////////////////////////////
80
// Enable all effects used in this Effect. Called by reflection from the parent class.
81
// Matrix Effects do not have to be enabled.
82

  
83
  @SuppressWarnings("unused")
84
  static void enable()
85
    {
86

  
87
    }
88
  }
89

  
src/main/java/org/distorted/effects/objectchange/ObjectChangeEffectScale.java
1
///////////////////////////////////////////////////////////////////////////////////////////////////
2
// Copyright 2019 Leszek Koltunski                                                               //
3
//                                                                                               //
4
// This file is part of Magic Cube.                                                              //
5
//                                                                                               //
6
// Magic Cube is free software: you can redistribute it and/or modify                            //
7
// it under the terms of the GNU General Public License as published by                          //
8
// the Free Software Foundation, either version 2 of the License, or                             //
9
// (at your option) any later version.                                                           //
10
//                                                                                               //
11
// Magic Cube is distributed in the hope that it will be useful,                                 //
12
// but WITHOUT ANY WARRANTY; without even the implied warranty of                                //
13
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the                                 //
14
// GNU General Public License for more details.                                                  //
15
//                                                                                               //
16
// You should have received a copy of the GNU General Public License                             //
17
// along with Magic Cube.  If not, see <http://www.gnu.org/licenses/>.                           //
18
///////////////////////////////////////////////////////////////////////////////////////////////////
19

  
20
package org.distorted.effects.objectchange;
21

  
22
import org.distorted.library.effect.Effect;
23
import org.distorted.library.effect.MatrixEffectScale;
24
import org.distorted.library.type.Dynamic3D;
25
import org.distorted.library.type.Static3D;
26

  
27
///////////////////////////////////////////////////////////////////////////////////////////////////
28

  
29
class ObjectChangeEffectScale extends ObjectChangeEffect
30
  {
31
  public int createEffectsPhase0(int duration)
32
    {
33
    mCubeEffectPosition[0] = new int[] {2};
34
    mCubeEffects[0]        = new Effect[mCubeEffectPosition[0].length];
35

  
36
    Dynamic3D d0 = new Dynamic3D(duration/2, 0.5f);
37
    d0.add(new Static3D(1.00f, 1.00f, 1.00f));
38
    d0.add(new Static3D(0.01f, 0.01f, 0.01f));
39
    mCubeEffects[0][0] = new MatrixEffectScale(d0);
40

  
41
    return 1;
42
    }
43

  
44
///////////////////////////////////////////////////////////////////////////////////////////////////
45

  
46
  public int createEffectsPhase1(int duration)
47
    {
48
    mCubeEffectPosition[1] = new int[] {2};
49
    mCubeEffects[1]        = new Effect[mCubeEffectPosition[1].length];
50

  
51
    Dynamic3D d0 = new Dynamic3D(duration/2, 0.5f);
52
    d0.add(new Static3D(0.01f, 0.01f, 0.01f));
53
    d0.add(new Static3D(1.00f, 1.00f, 1.00f));
54
    mCubeEffects[1][0] = new MatrixEffectScale(d0);
55

  
56
    return 1;
57
    }
58

  
59
///////////////////////////////////////////////////////////////////////////////////////////////////
60
// Enable all effects used in this Effect. Called by reflection from the parent class.
61
// Matrix Effects do not have to be enabled.
62

  
63
  @SuppressWarnings("unused")
64
  static void enable()
65
    {
66

  
67
    }
68
  }
69

  
src/main/java/org/distorted/effects/objectchange/ObjectChangeEffectTransparency.java
1
///////////////////////////////////////////////////////////////////////////////////////////////////
2
// Copyright 2019 Leszek Koltunski                                                               //
3
//                                                                                               //
4
// This file is part of Magic Cube.                                                              //
5
//                                                                                               //
6
// Magic Cube is free software: you can redistribute it and/or modify                            //
7
// it under the terms of the GNU General Public License as published by                          //
8
// the Free Software Foundation, either version 2 of the License, or                             //
9
// (at your option) any later version.                                                           //
10
//                                                                                               //
11
// Magic Cube is distributed in the hope that it will be useful,                                 //
12
// but WITHOUT ANY WARRANTY; without even the implied warranty of                                //
13
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the                                 //
14
// GNU General Public License for more details.                                                  //
15
//                                                                                               //
16
// You should have received a copy of the GNU General Public License                             //
17
// along with Magic Cube.  If not, see <http://www.gnu.org/licenses/>.                           //
18
///////////////////////////////////////////////////////////////////////////////////////////////////
19

  
20
package org.distorted.effects.objectchange;
21

  
22
import org.distorted.library.effect.Effect;
23
import org.distorted.library.effect.FragmentEffectAlpha;
24
import org.distorted.library.effect.VertexEffectWave;
25
import org.distorted.library.type.Dynamic1D;
26
import org.distorted.library.type.Dynamic5D;
27
import org.distorted.library.type.Static1D;
28
import org.distorted.library.type.Static3D;
29
import org.distorted.library.type.Static5D;
30

  
31
///////////////////////////////////////////////////////////////////////////////////////////////////
32

  
33
class ObjectChangeEffectTransparency extends ObjectChangeEffect
34
  {
35
  public int createEffectsPhase0(int duration)
36
    {
37
    mNodeEffectPosition[0] = new int[] {-1,-1};
38
    mNodeEffects[0]        = new Effect[mNodeEffectPosition[0].length];
39

  
40
    float init_amplitude = 0.0f;
41
    float end_amplitude  = 1/8.0f;
42
    float length         = 1/8.0f;
43
    float init_phase     = 360.0f;
44
    float end_phase      = 0.0f;
45
    float alpha          = 30.0f;
46
    float beta           = 90.0f;
47

  
48
    Dynamic5D d1 = new Dynamic5D(duration/2, 0.5f);
49
    d1.add(new Static5D( init_amplitude, length, init_phase, alpha, beta) );
50
    d1.add(new Static5D( end_amplitude , length, end_phase , alpha, beta) );
51
    Static3D center = new Static3D(0,0,0);
52
    mNodeEffects[0][0] = new VertexEffectWave(d1, center, null);
53

  
54
    Dynamic1D d0 = new Dynamic1D(duration/2, 0.5f);
55
    d0.add(new Static1D(1.0f));
56
    d0.add(new Static1D(0.0f));
57
    mNodeEffects[0][1] = new FragmentEffectAlpha(d0);
58

  
59
    return 2;
60
    }
61

  
62
///////////////////////////////////////////////////////////////////////////////////////////////////
63

  
64
  public int createEffectsPhase1(int duration)
65
    {
66
    mNodeEffectPosition[1] = new int[] {-1,-1};
67
    mNodeEffects[1]        = new Effect[mNodeEffectPosition[1].length];
68

  
69
    float init_amplitude = 1/8.0f;
70
    float end_amplitude  = 0.0f;
71
    float length         = 1/8.0f;
72
    float init_phase     = 0.0f;
73
    float end_phase      = 360.0f;
74
    float alpha          = 30.0f;
75
    float beta           = 90.0f;
76

  
77
    Dynamic5D d1 = new Dynamic5D(duration/2, 0.5f);
78
    d1.add(new Static5D( init_amplitude, length, init_phase, alpha, beta) );
79
    d1.add(new Static5D( end_amplitude , length, end_phase , alpha, beta) );
80
    Static3D center = new Static3D(0,0,0);
81
    mNodeEffects[1][0] = new VertexEffectWave(d1, center, null);
82

  
83
    Dynamic1D d0 = new Dynamic1D(duration/2, 0.5f);
84
    d0.add(new Static1D(0.0f));
85
    d0.add(new Static1D(1.0f));
86
    mNodeEffects[1][1] = new FragmentEffectAlpha(d0);
87

  
88
    return 2;
89
    }
90

  
91
///////////////////////////////////////////////////////////////////////////////////////////////////
92
// Enable all effects used in this Effect. Called by reflection from the parent class.
93

  
94
  @SuppressWarnings("unused")
95
  static void enable()
96
    {
97
    FragmentEffectAlpha.enable();
98
    VertexEffectWave.enable();
99
    }
100
  }
src/main/java/org/distorted/effects/scramble/ScrambleEffect.java
1
///////////////////////////////////////////////////////////////////////////////////////////////////
2
// Copyright 2019 Leszek Koltunski                                                               //
3
//                                                                                               //
4
// This file is part of Magic Cube.                                                              //
5
//                                                                                               //
6
// Magic Cube is free software: you can redistribute it and/or modify                            //
7
// it under the terms of the GNU General Public License as published by                          //
8
// the Free Software Foundation, either version 2 of the License, or                             //
9
// (at your option) any later version.                                                           //
10
//                                                                                               //
11
// Magic Cube is distributed in the hope that it will be useful,                                 //
12
// but WITHOUT ANY WARRANTY; without even the implied warranty of                                //
13
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the                                 //
14
// GNU General Public License for more details.                                                  //
15
//                                                                                               //
16
// You should have received a copy of the GNU General Public License                             //
17
// along with Magic Cube.  If not, see <http://www.gnu.org/licenses/>.                           //
18
///////////////////////////////////////////////////////////////////////////////////////////////////
19

  
20
package org.distorted.effects.scramble;
21

  
22
import java.lang.reflect.Method;
23
import java.util.Random;
24

  
25
import org.distorted.library.effect.Effect;
26
import org.distorted.library.main.DistortedEffects;
27
import org.distorted.library.main.DistortedScreen;
28
import org.distorted.library.message.EffectListener;
29

  
30
import org.distorted.objectlib.main.ObjectType;
31
import org.distorted.objectlib.main.TwistyObject;
32

  
33
import org.distorted.effects.BaseEffect;
34
import org.distorted.effects.EffectController;
35
import org.distorted.objectlib.helpers.MovesFinished;
36

  
37
///////////////////////////////////////////////////////////////////////////////////////////////////
38

  
39
public abstract class ScrambleEffect extends BaseEffect implements EffectListener, MovesFinished
40
{
41
  public enum Type
42
    {
43
    NONE         (ScrambleEffectNone.class        ),
44
    ROTATIONS    (ScrambleEffectRotations.class   ),
45
    ;
46

  
47
    final Class<? extends ScrambleEffect> effect;
48

  
49
    Type(Class<? extends ScrambleEffect> effect)
50
      {
51
      this.effect= effect;
52
      }
53
    }
54

  
55
  private static final int NUM_EFFECTS = Type.values().length;
56
  private static final int FAKE_EFFECT_ID  = -3;
57
  private static final Type[] types;
58

  
59
  static
60
    {
61
    int i=0;
62
    types = new Type[NUM_EFFECTS];
63

  
64
    for(Type type: Type.values())
65
      {
66
      types[i++] = type;
67
      }
68
    }
69

  
70
  private EffectController mController;
71
  private int mEffectReturned;
72
  private int mNumScramblesLeft;
73
  private long mDurationPerDegree;
74
  private final Random mRnd;
75
  private int[] mBasicAngle;
76
  private boolean mRotReady, mPluginReady;
77

  
78
  TwistyObject mObject;
79
  Effect[] mNodeEffects;
80
  int[] mNodeEffectPosition;
81
  Effect[] mCubeEffects;
82
  int[] mCubeEffectPosition;
83
  int mCubeEffectNumber, mNodeEffectNumber;
84
  int mNumScrambles;
85
  int[][] mScrambles;
86

  
87
///////////////////////////////////////////////////////////////////////////////////////////////////
88

  
89
  ScrambleEffect()
90
    {
91
    mRnd = new Random( System.currentTimeMillis() );
92
    mScrambles = new int[ObjectType.MAX_SCRAMBLE][3];
93
    }
94

  
95
///////////////////////////////////////////////////////////////////////////////////////////////////
96

  
97
  abstract void createEffects(int duration, int numScrambles);
98
  abstract void effectFinishedPlugin(final long effectID);
99

  
100
///////////////////////////////////////////////////////////////////////////////////////////////////
101

  
102
  private void createBaseEffects(int duration, int numScrambles)
103
    {
104
    mNumScramblesLeft = numScrambles;
105
    int absAngle, angle, axis, basicDegrees, totalDegrees = 0;
106

  
107
    for(int scramble=0; scramble<mNumScramblesLeft; scramble++)
108
      {
109
      mObject.randomizeNewScramble(mScrambles, mRnd, scramble, numScrambles);
110
      axis  = mScrambles[scramble][0];
111
      angle = mScrambles[scramble][2];
112
      absAngle = (angle<0 ? -angle : angle);
113
      basicDegrees = 360/mBasicAngle[axis];
114
      totalDegrees += absAngle*basicDegrees;
115
      }
116

  
117
    mDurationPerDegree = duration/totalDegrees;
118
    mNumScrambles = 0;
119

  
120
    mRotReady    = false;
121
    mPluginReady = false;
122

  
123
    addNewScramble();
124
    }
125

  
126
///////////////////////////////////////////////////////////////////////////////////////////////////
127

  
128
  private void addNewScramble()
129
    {
130
    if( mNumScramblesLeft>0 )
131
      {
132
      int axis = mScrambles[mNumScrambles][0];
133
      int row  = mScrambles[mNumScrambles][1];
134
      int angle= mScrambles[mNumScrambles][2];
135

  
136
      int rowBitmap= (1<<row);
137
      int absAngle = (angle<0 ? -angle : angle);
138
      int basicDegrees  = 360/mBasicAngle[axis];
139
      long durationMillis = absAngle*basicDegrees*mDurationPerDegree;
140

  
141
      mNumScramblesLeft--;
142
      mController.addRotation(this, axis, rowBitmap, angle*basicDegrees, durationMillis);
143
      mNumScrambles++;
144
      }
145
    else
146
      {
147
      mRotReady = true;
148
      if( mPluginReady ) mController.effectFinished(FAKE_EFFECT_ID);
149
      }
150
    }
151

  
152
///////////////////////////////////////////////////////////////////////////////////////////////////
153

  
154
  private void assignEffects()
155
    {
156
    for(int i=0; i<mCubeEffectNumber; i++)
157
      {
158
      mObject.apply(mCubeEffects[i],mCubeEffectPosition[i]);
159
      mCubeEffects[i].notifyWhenFinished(this);
160
      }
161

  
162
    DistortedEffects nodeEffects = mObject.getEffects();
163

  
164
    for(int i=0; i<mNodeEffectNumber; i++)
165
      {
166
      nodeEffects.apply(mNodeEffects[i],mNodeEffectPosition[i]);
167
      mNodeEffects[i].notifyWhenFinished(this);
168
      }
169
    }
170

  
171
///////////////////////////////////////////////////////////////////////////////////////////////////
172

  
173
  private void disassignEffects()
174
    {
175
    for(int i=0; i<mCubeEffectNumber; i++)
176
      {
177
      mObject.remove(mCubeEffects[i].getID());
178
      }
179

  
180
    DistortedEffects nodeEffects = mObject.getEffects();
181

  
182
    for(int i=0; i<mNodeEffectNumber; i++)
183
      {
184
      nodeEffects.abortById(mNodeEffects[i].getID());
185
      }
186
    }
187

  
188
///////////////////////////////////////////////////////////////////////////////////////////////////
189
// PUBLIC API
190
///////////////////////////////////////////////////////////////////////////////////////////////////
191

  
192
  @SuppressWarnings("unused")
193
  public static String[] getNames()
194
    {
195
    String[] names = new String[NUM_EFFECTS];
196

  
197
    for( int i=0; i<NUM_EFFECTS; i++)
198
      {
199
      names[i] = types[i].name();
200
      }
201

  
202
    return names;
203
    }
204

  
205
///////////////////////////////////////////////////////////////////////////////////////////////////
206

  
207
  @SuppressWarnings("unused")
208
  public static ScrambleEffect create(int ordinal) throws InstantiationException, IllegalAccessException
209
    {
210
    return types[ordinal].effect.newInstance();
211
    }
212

  
213
///////////////////////////////////////////////////////////////////////////////////////////////////
214

  
215
  public void onActionFinished(final long effectID)
216
    {
217
    addNewScramble();
218
    }
219

  
220
///////////////////////////////////////////////////////////////////////////////////////////////////
221

  
222
  private void effectFinishedAction(final long effectID, final long id)
223
    {
224
    mEffectReturned++;
225
    effectFinishedPlugin(effectID);
226

  
227
    if( mEffectReturned == mCubeEffectNumber+mNodeEffectNumber )
228
      {
229
      disassignEffects();
230

  
231
      mPluginReady = true;
232
      if( mRotReady ) mController.effectFinished(FAKE_EFFECT_ID);
233
      }
234
    }
235

  
236
///////////////////////////////////////////////////////////////////////////////////////////////////
237

  
238
  public void effectFinished(final long effectID)
239
    {
240
    for(int i=0; i<mCubeEffectNumber; i++)
241
      {
242
      long id = mCubeEffects[i].getID();
243

  
244
      if( effectID == id )
245
        {
246
        effectFinishedAction(effectID,id);
247
        return;
248
        }
249
      }
250

  
251
    for(int i=0; i<mNodeEffectNumber; i++)
252
      {
253
      long id = mNodeEffects[i].getID();
254

  
255
      if( effectID == id )
256
        {
257
        effectFinishedAction(effectID,id);
258
        return;
259
        }
260
      }
261
    }
262

  
263
///////////////////////////////////////////////////////////////////////////////////////////////////
264

  
265
  @SuppressWarnings("unused")
266
  public long start(int duration, DistortedScreen screen, EffectController cont)
267
    {
268
    mObject    = cont.getObject();
269
    mController= cont;
270

  
271
    // NOT mController.solve() !! This would be a very subtle bug. We need to do this immediately,
272
    // because here we are already inside the mController.preRender() function (doing 'scrambleObjectNow')
273
    // and doing a delayed 'solve()' here would mean we'd be sometimes first doing the first rotation,
274
    // and only after it - the solve.
275
    mObject.solve();
276

  
277
    mBasicAngle = mObject.getBasicAngle();
278

  
279
    int numScrambles = cont.getNumScrambles();
280
    int dura = (int)(duration*Math.pow(numScrambles,0.66f));
281
    createBaseEffects(dura,numScrambles);
282
    createEffects    (dura,numScrambles);
283

  
284
    if( mCubeEffectNumber==0 && mNodeEffectNumber==0 )
285
      {
286
      throw new RuntimeException("Cube and Node Plugin Effects not created!");
287
      }
288

  
289
    assignEffects();
290

  
291
    return FAKE_EFFECT_ID;
292
    }
293

  
294
///////////////////////////////////////////////////////////////////////////////////////////////////
295

  
296
  @SuppressWarnings("unused")
297
  public static void enableEffects()
298
    {
299
    Method method;
300

  
301
    for(Type type: Type.values())
302
      {
303
      try
304
        {
305
        method = type.effect.getDeclaredMethod("enable"); // enable not public, thus getDeclaredMethod
306
        }
307
      catch(NoSuchMethodException ex)
308
        {
309
        android.util.Log.e("ScrambleEffect", type.effect.getSimpleName()+": exception getting method: "+ex.getMessage());
310
        method = null;
311
        }
312

  
313
      try
314
        {
315
        if( method!=null ) method.invoke(null);
316
        }
317
      catch(Exception ex)
318
        {
319
        android.util.Log.e("ScrambleEffect", type.effect.getSimpleName()+": exception invoking method: "+ex.getMessage());
320
        }
321
      }
322
    }
323
}
src/main/java/org/distorted/effects/scramble/ScrambleEffectNone.java
1
///////////////////////////////////////////////////////////////////////////////////////////////////
2
// Copyright 2019 Leszek Koltunski                                                               //
3
//                                                                                               //
4
// This file is part of Magic Cube.                                                              //
5
//                                                                                               //
6
// Magic Cube is free software: you can redistribute it and/or modify                            //
7
// it under the terms of the GNU General Public License as published by                          //
8
// the Free Software Foundation, either version 2 of the License, or                             //
9
// (at your option) any later version.                                                           //
10
//                                                                                               //
11
// Magic Cube is distributed in the hope that it will be useful,                                 //
12
// but WITHOUT ANY WARRANTY; without even the implied warranty of                                //
13
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the                                 //
14
// GNU General Public License for more details.                                                  //
15
//                                                                                               //
16
// You should have received a copy of the GNU General Public License                             //
17
// along with Magic Cube.  If not, see <http://www.gnu.org/licenses/>.                           //
18
///////////////////////////////////////////////////////////////////////////////////////////////////
19

  
20
package org.distorted.effects.scramble;
21

  
22
import org.distorted.library.effect.Effect;
23
import org.distorted.library.effect.MatrixEffectMove;
24
import org.distorted.library.type.Dynamic3D;
25
import org.distorted.library.type.Static3D;
26

  
27
///////////////////////////////////////////////////////////////////////////////////////////////////
28

  
29
public class ScrambleEffectNone extends ScrambleEffect
30
  {
31
  public void createEffects(int duration, int numScrambles)
32
    {
33
    Dynamic3D d0 = new Dynamic3D(1,0.5f);
34
    d0.add(new Static3D(0,0,0));
35

  
36
    mCubeEffectNumber   = 1;
37
    mNodeEffectNumber   = 0;
38

  
39
    mCubeEffectPosition = new int[] {-1};
40
    mCubeEffects        = new Effect[mCubeEffectPosition.length];
41
    mCubeEffects[0]     = new MatrixEffectMove(d0);
42
    }
43

  
44
///////////////////////////////////////////////////////////////////////////////////////////////////
45

  
46
  public void effectFinishedPlugin(final long effectID)
47
    {
48

  
49
    }
50

  
51
///////////////////////////////////////////////////////////////////////////////////////////////////
52
// Enable all effects used in this Effect. Called by reflection from the parent class.
53

  
54
  @SuppressWarnings("unused")
55
  static void enable()
56
    {
57

  
58
    }
59
  }
src/main/java/org/distorted/effects/scramble/ScrambleEffectRotations.java
1
///////////////////////////////////////////////////////////////////////////////////////////////////
2
// Copyright 2019 Leszek Koltunski                                                               //
3
//                                                                                               //
4
// This file is part of Magic Cube.                                                              //
5
//                                                                                               //
6
// Magic Cube is free software: you can redistribute it and/or modify                            //
7
// it under the terms of the GNU General Public License as published by                          //
8
// the Free Software Foundation, either version 2 of the License, or                             //
9
// (at your option) any later version.                                                           //
10
//                                                                                               //
11
// Magic Cube is distributed in the hope that it will be useful,                                 //
12
// but WITHOUT ANY WARRANTY; without even the implied warranty of                                //
13
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the                                 //
14
// GNU General Public License for more details.                                                  //
15
//                                                                                               //
16
// You should have received a copy of the GNU General Public License                             //
17
// along with Magic Cube.  If not, see <http://www.gnu.org/licenses/>.                           //
18
///////////////////////////////////////////////////////////////////////////////////////////////////
19

  
20
package org.distorted.effects.scramble;
21

  
22
import java.util.Random;
23

  
24
import org.distorted.library.effect.Effect;
25
import org.distorted.library.effect.MatrixEffectMove;
26
import org.distorted.library.effect.MatrixEffectQuaternion;
27
import org.distorted.library.type.Dynamic;
28
import org.distorted.library.type.Dynamic3D;
29
import org.distorted.library.type.DynamicQuat;
30
import org.distorted.library.type.Static3D;
31
import org.distorted.library.type.Static4D;
32

  
33
///////////////////////////////////////////////////////////////////////////////////////////////////
34

  
35
public class ScrambleEffectRotations extends ScrambleEffect
36
  {
37
  private final Random mRndGen = new Random(0);
38

  
39
///////////////////////////////////////////////////////////////////////////////////////////////////
40

  
41
  private Static4D generateNewRandomPoint()
42
    {
43
    float x = mRndGen.nextFloat();
44
    float y = mRndGen.nextFloat();
45
    float z = mRndGen.nextFloat();
46
    float w = mRndGen.nextFloat();
47

  
48
    float len = (float)Math.sqrt(x*x + y*y + z*z + w*w);
49

  
50
    return new Static4D( x/len, y/len, z/len, w/len);
51
    }
52

  
53
///////////////////////////////////////////////////////////////////////////////////////////////////
54

  
55
  public void createEffects(int duration, int numScrambles)
56
    {
57
    mCubeEffectNumber   = 2;
58
    mNodeEffectNumber   = 0;
59
    mCubeEffectPosition = new int[] {2,3};
60
    mCubeEffects        = new Effect[mCubeEffectPosition.length];
61

  
62
    mRndGen.setSeed(System.currentTimeMillis());
63

  
64
    int numRandomPoints = (int)(Math.pow(numScrambles,0.7f));
65

  
66
    DynamicQuat dq = new DynamicQuat(duration, 0.5f);
67
    dq.setMode(Dynamic.MODE_PATH);
68
    dq.add(new Static4D(0,0,0,1));
69

  
70
    for(int point=0; point<numRandomPoints; point++)
71
      {
72
      dq.add(generateNewRandomPoint());
73
      }
74

  
75
    dq.add(new Static4D(0,0,0,1));
76

  
77
    mCubeEffects[0] = new MatrixEffectQuaternion(dq, new Static3D(0,0,0));
78

  
79
    float Z = mObject.getNodeSize()/3.0f;
80

  
81
    Dynamic3D d0 = new Dynamic3D(duration, 0.5f);
82
    d0.setMode(Dynamic.MODE_PATH);
... This diff was truncated because it exceeds the maximum size that can be displayed.

Also available in: Unified diff