Project

General

Profile

« Previous | Next » 

Revision a62aa9d7

Added by Leszek Koltunski about 5 years ago

Progress with ScrambleEffects

View differences:

src/main/java/org/distorted/effect/ScrambleEffect.java
34 34
  public enum Type
35 35
    {
36 36
    NONE         (ScrambleEffectNone.class        ),
37
    ROTATIONS    (ScrambleEffectRotations.class   ),
37 38
    ;
38 39

  
39 40
    final Class<? extends ScrambleEffect> effect;
......
45 46
    }
46 47

  
47 48
  private static int NUM_EFFECTS = Type.values().length;
48
  private static final int NUM_PHASES  = 2;
49 49
  private static final int FAKE_EFFECT_ID  = -3;
50 50
  private static final Type[] types;
51 51

  
......
62 62

  
63 63
  private EffectListener mListener;
64 64
  private int mDuration;
65
  private int mEffectReturned;
66
  private int[] mCubeEffectNumber, mNodeEffectNumber;
67
  private int mPhase;
65
  private int[] mEffectReturned;
68 66
  private RubikCube mCube;
69 67
  private DistortedScreen mScreen;
70 68

  
69
  static final int EFFECT_FLAVOUR_BASE  = 0;
70
  static final int EFFECT_FLAVOUR_PLUGIN= 1;
71
  static final int NUM_EFFECT_FLAVOURS  = 2;
72

  
71 73
  Effect[][] mNodeEffects;
72 74
  int[][] mNodeEffectPosition;
73 75
  Effect[][] mCubeEffects;
74 76
  int[][] mCubeEffectPosition;
77
  int[] mCubeEffectNumber, mNodeEffectNumber;
75 78

  
76 79
///////////////////////////////////////////////////////////////////////////////////////////////////
77 80

  
78 81
  ScrambleEffect()
79 82
    {
80
    mPhase = 0;
81

  
82
    mCubeEffectNumber   = new int[NUM_PHASES];
83
    mNodeEffectNumber   = new int[NUM_PHASES];
84
    mCubeEffectPosition = new int[NUM_PHASES][];
85
    mNodeEffectPosition = new int[NUM_PHASES][];
86
    mCubeEffects        = new Effect[NUM_PHASES][];
87
    mNodeEffects        = new Effect[NUM_PHASES][];
83
    mEffectReturned     = new int[NUM_EFFECT_FLAVOURS];
84
    mCubeEffectNumber   = new int[NUM_EFFECT_FLAVOURS];
85
    mNodeEffectNumber   = new int[NUM_EFFECT_FLAVOURS];
86
    mCubeEffectPosition = new int[NUM_EFFECT_FLAVOURS][];
87
    mNodeEffectPosition = new int[NUM_EFFECT_FLAVOURS][];
88
    mCubeEffects        = new Effect[NUM_EFFECT_FLAVOURS][];
89
    mNodeEffects        = new Effect[NUM_EFFECT_FLAVOURS][];
88 90
    }
89 91

  
90 92
///////////////////////////////////////////////////////////////////////////////////////////////////
......
117 119

  
118 120
///////////////////////////////////////////////////////////////////////////////////////////////////
119 121

  
120
  abstract void createEffectsPhase0(int duration);
121
  abstract void createEffectsPhase1(int duration);
122
  abstract void createEffects(int duration);
123
  abstract void effectFinishedPlugin(final long effectID);
122 124

  
123 125
///////////////////////////////////////////////////////////////////////////////////////////////////
124

  
125
  public void effectFinished(final long effectID)
126
// TODO
127
  private void createBaseEffects(int duration, int numScrambles)
126 128
    {
127
    int total = mCubeEffectNumber[mPhase]+mNodeEffectNumber[mPhase];
129
    mCubeEffectNumber[EFFECT_FLAVOUR_BASE] = 0;
130
    mNodeEffectNumber[EFFECT_FLAVOUR_BASE] = 0;
131
    }
128 132

  
129
    for(int i=0; i<mCubeEffectNumber[mPhase]; i++)
130
      {
131
      long id = mCubeEffects[mPhase][i].getID();
133
///////////////////////////////////////////////////////////////////////////////////////////////////
134
// TODO
132 135

  
133
      if( effectID == id )
134
        {
135
        if( ++mEffectReturned == total ) effectAction(mPhase);
136
        mCube.remove(id);
137
        return;
138
        }
139
      }
140
    for(int i=0; i<mNodeEffectNumber[mPhase]; i++)
141
      {
142
      long id = mNodeEffects[mPhase][i].getID();
136
  private void effectFinishedBase(final long effectID)
137
    {
143 138

  
144
      if( effectID == id )
145
        {
146
        if( ++mEffectReturned == total ) effectAction(mPhase);
147
        mCube.getEffects().abortById(id);
148
        return;
149
        }
150
      }
151 139
    }
152 140

  
153 141
///////////////////////////////////////////////////////////////////////////////////////////////////
154 142

  
155
  private void effectAction(int phase)
143
  public void effectFinished(final long effectID)
156 144
    {
157
    switch(phase)
145
    for(int flavour=0; flavour<NUM_EFFECT_FLAVOURS; flavour++)
158 146
      {
159
      case 0: mEffectReturned = 0;
160
              mPhase          = 1;
161
              mCube.unscramble();
162
              createEffectsPhase1(mDuration);
163
              assignEffects(mPhase);
164
              break;
165
      case 1: mListener.effectFinished(FAKE_EFFECT_ID);
166
              break;
147
      for(int i=0; i<mCubeEffectNumber[flavour]; i++)
148
        {
149
        long id = mCubeEffects[flavour][i].getID();
150

  
151
        if( effectID == id )
152
          {
153
          mEffectReturned[flavour]++;
154

  
155
          switch(flavour)
156
            {
157
            case EFFECT_FLAVOUR_BASE  : effectFinishedBase(  effectID); break;
158
            case EFFECT_FLAVOUR_PLUGIN: effectFinishedPlugin(effectID); break;
159
            }
160

  
161
          if( mEffectReturned[flavour] == mCubeEffectNumber[flavour]+mNodeEffectNumber[flavour] )
162
            {
163
            disassignEffects(flavour);
164
            }
165

  
166
          return;
167
          }
168
        }
169
      for(int i=0; i<mNodeEffectNumber[flavour]; i++)
170
        {
171
        long id = mNodeEffects[flavour][i].getID();
172

  
173
        if( effectID == id )
174
          {
175
          mEffectReturned[flavour]++;
176

  
177
          switch(flavour)
178
            {
179
            case EFFECT_FLAVOUR_BASE  : effectFinishedBase(  effectID); break;
180
            case EFFECT_FLAVOUR_PLUGIN: effectFinishedPlugin(effectID); break;
181
            }
182

  
183
          if( mEffectReturned[flavour] == mCubeEffectNumber[flavour]+mNodeEffectNumber[flavour] )
184
            {
185
            disassignEffects(flavour);
186
            }
187

  
188
          return;
189
          }
190
        }
167 191
      }
168 192
    }
169 193

  
......
176 200
    mListener = listener;
177 201
    mDuration = duration;
178 202

  
179
    createEffectsPhase0(mDuration);
180
    assignEffects(mPhase);
203
    createBaseEffects(mDuration, numScrambles);
204
    assignEffects(EFFECT_FLAVOUR_BASE);
205

  
206
    createEffects(mDuration);
207

  
208
    if( mCubeEffectNumber[EFFECT_FLAVOUR_PLUGIN]==0 && mNodeEffectNumber[EFFECT_FLAVOUR_PLUGIN]==0 )
209
      {
210
      throw new RuntimeException("Cube and Node Plugin Effects not created!");
211
      }
212

  
213
    assignEffects(EFFECT_FLAVOUR_PLUGIN);
181 214

  
182 215
    return FAKE_EFFECT_ID;
183 216
    }
184 217

  
185 218
///////////////////////////////////////////////////////////////////////////////////////////////////
186 219

  
187
  private void assignEffects(int phase)
220
  private void assignEffects(int flavour)
188 221
    {
189
    mCubeEffectNumber[phase] = ( mCubeEffects[phase]!=null ) ? mCubeEffects[phase].length : 0;
190
    mNodeEffectNumber[phase] = ( mNodeEffects[phase]!=null ) ? mNodeEffects[phase].length : 0;
222
    for(int i=0; i<mCubeEffectNumber[flavour]; i++)
223
      {
224
      android.util.Log.e("scramble", "applying cube effect "+mCubeEffects[flavour][i].getName());
225

  
226
      mCube.apply(mCubeEffects[flavour][i],mCubeEffectPosition[flavour][i]);
227
      mCubeEffects[flavour][i].notifyWhenFinished(this);
228
      }
229

  
230
    DistortedEffects nodeEffects = mCube.getEffects();
191 231

  
192
    if( mCubeEffectNumber[phase]==0 && mNodeEffectNumber[phase]==0 )
232
    for(int i=0; i<mNodeEffectNumber[flavour]; i++)
193 233
      {
194
      throw new RuntimeException("Cube and Node Effects ("+phase+" phase) both not created!");
234
      nodeEffects.apply(mNodeEffects[flavour][i],mNodeEffectPosition[flavour][i]);
235
      mNodeEffects[flavour][i].notifyWhenFinished(this);
195 236
      }
237
    }
238

  
239
///////////////////////////////////////////////////////////////////////////////////////////////////
196 240

  
197
    for(int i=0; i<mCubeEffectNumber[phase]; i++)
241
  private void disassignEffects(int flavour)
242
    {
243
    for(int i=0; i<mCubeEffectNumber[flavour]; i++)
198 244
      {
199
      mCube.apply(mCubeEffects[phase][i],mCubeEffectPosition[phase][i]);
200
      mCubeEffects[phase][i].notifyWhenFinished(this);
245
      android.util.Log.e("scramble", "removing cube effect "+mCubeEffects[flavour][i].getName());
246

  
247
      mCube.remove(mCubeEffects[flavour][i].getID());
201 248
      }
202 249

  
203 250
    DistortedEffects nodeEffects = mCube.getEffects();
204 251

  
205
    for(int i=0; i<mNodeEffectNumber[phase]; i++)
252
    for(int i=0; i<mNodeEffectNumber[flavour]; i++)
253
      {
254
      nodeEffects.abortById(mNodeEffects[flavour][i].getID());
255
      }
256

  
257
    if( flavour==EFFECT_FLAVOUR_PLUGIN )
206 258
      {
207
      nodeEffects.apply(mNodeEffects[phase][i],mNodeEffectPosition[phase][i]);
208
      mNodeEffects[phase][i].notifyWhenFinished(this);
259
      mListener.effectFinished(FAKE_EFFECT_ID);
209 260
      }
210 261
    }
211 262

  
src/main/java/org/distorted/effect/ScrambleEffectNone.java
28 28

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

  
36
    mCubeEffectPosition[0] = new int[] {-1};
37
    mCubeEffects[0]        = new Effect[mCubeEffectPosition[0].length];
38
    mCubeEffects[0][0]     = new MatrixEffectMove(d0);
36
    mCubeEffectNumber[EFFECT_FLAVOUR_PLUGIN]   = 1;
37
    mNodeEffectNumber[EFFECT_FLAVOUR_PLUGIN]   = 0;
38

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

  
41 44
///////////////////////////////////////////////////////////////////////////////////////////////////
42 45

  
43
  public void createEffectsPhase1(int duration)
46
  public void effectFinishedPlugin(final long effectID)
44 47
    {
45
    Dynamic3D d0 = new Dynamic3D(1,0.5f);
46
    d0.add(new Static3D(0,0,0));
47 48

  
48
    mCubeEffectPosition[1]  = new int[] {-1};
49
    mCubeEffects[1]         = new Effect[mCubeEffectPosition[1].length];
50
    mCubeEffects[1][0]      = new MatrixEffectMove(d0);
51 49
    }
52 50

  
53 51
///////////////////////////////////////////////////////////////////////////////////////////////////
src/main/java/org/distorted/effect/ScrambleEffectRotations.java
1
///////////////////////////////////////////////////////////////////////////////////////////////////
2
// Copyright 2019 Leszek Koltunski                                                               //
3
//                                                                                               //
4
// This file is part of Distorted.                                                               //
5
//                                                                                               //
6
// Distorted 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
// Distorted 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 Distorted.  If not, see <http://www.gnu.org/licenses/>.                            //
18
///////////////////////////////////////////////////////////////////////////////////////////////////
19

  
20
package org.distorted.effect;
21

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

  
28
import static org.distorted.magic.RubikRenderer.TEXTURE_SIZE;
29

  
30
///////////////////////////////////////////////////////////////////////////////////////////////////
31

  
32
public class ScrambleEffectRotations extends ScrambleEffect
33
  {
34

  
35
///////////////////////////////////////////////////////////////////////////////////////////////////
36

  
37
  public void createEffects(int duration)
38
    {
39
    mCubeEffectNumber[EFFECT_FLAVOUR_PLUGIN]   = 1;
40
    mNodeEffectNumber[EFFECT_FLAVOUR_PLUGIN]   = 0;
41
    mCubeEffectPosition[EFFECT_FLAVOUR_PLUGIN] = new int[] {6};
42
    mCubeEffects[EFFECT_FLAVOUR_PLUGIN]        = new Effect[mCubeEffectPosition[EFFECT_FLAVOUR_PLUGIN].length];
43

  
44
    float Z = TEXTURE_SIZE/3;
45

  
46
    Dynamic3D d0 = new Dynamic3D(duration, 0.5f);
47
    d0.setMode(Dynamic.MODE_PATH);
48
    d0.add(new Static3D( 0, 0, 0));
49
    d0.add(new Static3D( 0, 0,-Z));
50
    d0.add(new Static3D( 0, 0, 0));
51
    mCubeEffects[EFFECT_FLAVOUR_PLUGIN][0] = new MatrixEffectMove(d0);
52
    }
53

  
54
///////////////////////////////////////////////////////////////////////////////////////////////////
55

  
56
  public void effectFinishedPlugin(final long effectID)
57
    {
58

  
59
    }
60

  
61
///////////////////////////////////////////////////////////////////////////////////////////////////
62
// Enable all effects used in this Effect. Called by reflection from the parent class.
63

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

  
68
    }
69
  }

Also available in: Unified diff