Project

General

Profile

« Previous | Next » 

Revision bee1d997

Added by Leszek Koltunski almost 5 years ago

RubikCube: add new WinEffectGlow

View differences:

src/main/java/org/distorted/effect/BaseEffect.java
252 252
      }
253 253

  
254 254
  ////////////////////////////////////////////////////////////////////////////////
255
  // map the (0..100) range of the SeekBar into (0..5000) milliseconds, in 100ms
256
  // increments.
255 257

  
256 258
    public static int translatePos(int pos)
257 259
      {
src/main/java/org/distorted/effect/scramble/ScrambleEffectNone.java
19 19

  
20 20
package org.distorted.effect.scramble;
21 21

  
22
///////////////////////////////////////////////////////////////////////////////////////////////////
23

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

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

  
29 29
public class ScrambleEffectNone extends ScrambleEffect
30 30
  {
31 31
  public void createEffects(int duration)
src/main/java/org/distorted/effect/solve/SolveEffectNone.java
19 19

  
20 20
package org.distorted.effect.solve;
21 21

  
22
///////////////////////////////////////////////////////////////////////////////////////////////////
23

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

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

  
29 29
public class SolveEffectNone extends SolveEffect
30 30
  {
31 31
  public void createEffectsPhase0(int duration)
src/main/java/org/distorted/effect/solve/SolveEffectSpin.java
19 19

  
20 20
package org.distorted.effect.solve;
21 21

  
22
///////////////////////////////////////////////////////////////////////////////////////////////////
23

  
24 22
import org.distorted.library.effect.Effect;
25 23
import org.distorted.library.effect.MatrixEffectRotate;
26 24
import org.distorted.library.type.Dynamic;
......
28 26
import org.distorted.library.type.Static1D;
29 27
import org.distorted.library.type.Static3D;
30 28

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

  
31 31
public class SolveEffectSpin extends SolveEffect
32 32
  {
33 33
  public void createEffectsPhase0(int duration)
src/main/java/org/distorted/effect/win/WinEffect.java
37 37
    {
38 38
    NONE   (WinEffectNone.class),
39 39
    SPIN   (WinEffectSpin.class),
40
    GLOW   (WinEffectGlow.class),
40 41
    ;
41 42

  
42 43
    final Class<? extends WinEffect> effect;
......
48 49
    }
49 50

  
50 51
  private static final int NUM_EFFECTS = Type.values().length;
51
  private static final int NUM_PHASES  = 2;
52 52
  private static final int FAKE_EFFECT_ID = -2;
53 53
  private static final Type[] types;
54 54

  
......
66 66
  private EffectListener mListener;
67 67
  private int mDuration;
68 68
  private int mEffectReturned;
69
  private int[] mCubeEffectNumber, mNodeEffectNumber;
70
  private int mPhase;
69
  private int mCubeEffectNumber, mNodeEffectNumber;
71 70

  
72 71
  RubikCube mCube;
73 72
  DistortedScreen mScreen;
74
  Effect[][] mCubeEffects;
75
  int[][] mCubeEffectPosition;
76
  Effect[][] mNodeEffects;
77
  int[][] mNodeEffectPosition;
78

  
79
///////////////////////////////////////////////////////////////////////////////////////////////////
80

  
81
  WinEffect()
82
    {
83
    mPhase        =  0;
84

  
85
    mCubeEffectNumber   = new int[NUM_PHASES];
86
    mNodeEffectNumber   = new int[NUM_PHASES];
87
    mCubeEffectPosition = new int[NUM_PHASES][];
88
    mNodeEffectPosition = new int[NUM_PHASES][];
89
    mCubeEffects        = new Effect[NUM_PHASES][];
90
    mNodeEffects        = new Effect[NUM_PHASES][];
91
    }
73
  Effect[] mCubeEffects;
74
  int[] mCubeEffectPosition;
75
  Effect[] mNodeEffects;
76
  int[] mNodeEffectPosition;
92 77

  
93 78
///////////////////////////////////////////////////////////////////////////////////////////////////
94 79

  
......
113 98

  
114 99
///////////////////////////////////////////////////////////////////////////////////////////////////
115 100

  
116
  abstract void createEffectsPhase0(int duration);
117
  abstract void createEffectsPhase1(int duration);
101
  abstract void createEffects(int duration);
118 102

  
119 103
///////////////////////////////////////////////////////////////////////////////////////////////////
120 104

  
121 105
  public void effectFinished(final long effectID)
122 106
    {
123
    int total = mCubeEffectNumber[mPhase]+mNodeEffectNumber[mPhase];
107
    int total = mCubeEffectNumber+mNodeEffectNumber;
124 108

  
125
    for(int i=0; i<mCubeEffectNumber[mPhase]; i++)
109
    for(int i=0; i<mCubeEffectNumber; i++)
126 110
      {
127
      long id = mCubeEffects[mPhase][i].getID();
111
      long id = mCubeEffects[i].getID();
128 112

  
129 113
      if( effectID == id )
130 114
        {
131
        if( ++mEffectReturned == total ) effectAction(mPhase);
115
        if( ++mEffectReturned == total ) mListener.effectFinished(FAKE_EFFECT_ID);
132 116
        mCube.remove(id);
133 117
        return;
134 118
        }
135 119
      }
136
    for(int i=0; i<mNodeEffectNumber[mPhase]; i++)
120
    for(int i=0; i<mNodeEffectNumber; i++)
137 121
      {
138
      long id = mNodeEffects[mPhase][i].getID();
122
      long id = mNodeEffects[i].getID();
139 123

  
140 124
      if( effectID == id )
141 125
        {
142
        if( ++mEffectReturned == total ) effectAction(mPhase);
126
        if( ++mEffectReturned == total ) mListener.effectFinished(FAKE_EFFECT_ID);
143 127
        mCube.getEffects().abortById(id);
144 128
        return;
145 129
        }
146 130
      }
147 131
    }
148 132

  
149
///////////////////////////////////////////////////////////////////////////////////////////////////
150

  
151
  private void effectAction(int phase)
152
    {
153
    switch(phase)
154
      {
155
      case 0: mEffectReturned = 0;
156
              mPhase          = 1;
157
              mCube.solve();
158
              createEffectsPhase1(mDuration);
159
              assignEffects(mPhase);
160
              break;
161
      case 1: mListener.effectFinished(FAKE_EFFECT_ID);
162
              break;
163
      }
164
    }
165

  
166 133
///////////////////////////////////////////////////////////////////////////////////////////////////
167 134

  
168 135
  public long start(int duration, RubikRenderer renderer)
......
172 139
    mListener = renderer;
173 140
    mDuration = duration;
174 141

  
175
    createEffectsPhase0(mDuration);
176
    assignEffects(mPhase);
142
    createEffects(mDuration);
143
    assignEffects();
177 144

  
178 145
    return FAKE_EFFECT_ID;
179 146
    }
180 147

  
181 148
///////////////////////////////////////////////////////////////////////////////////////////////////
182 149

  
183
  private void assignEffects(int phase)
150
  private void assignEffects()
184 151
    {
185
    mCubeEffectNumber[phase] = ( mCubeEffects[phase]!=null ) ? mCubeEffects[phase].length : 0;
186
    mNodeEffectNumber[phase] = ( mNodeEffects[phase]!=null ) ? mNodeEffects[phase].length : 0;
152
    mCubeEffectNumber = ( mCubeEffects!=null ) ? mCubeEffects.length : 0;
153
    mNodeEffectNumber = ( mNodeEffects!=null ) ? mNodeEffects.length : 0;
187 154

  
188
    if( mCubeEffectNumber[phase]==0 && mNodeEffectNumber[phase]==0 )
155
    if( mCubeEffectNumber==0 && mNodeEffectNumber==0 )
189 156
      {
190
      throw new RuntimeException("Cube and Node Effects ("+phase+" phase) both not created!");
157
      throw new RuntimeException("Cube and Node Effects both not created!");
191 158
      }
192 159

  
193
    for(int i=0; i<mCubeEffectNumber[phase]; i++)
160
    for(int i=0; i<mCubeEffectNumber; i++)
194 161
      {
195
      mCube.apply(mCubeEffects[phase][i],mCubeEffectPosition[phase][i]);
196
      mCubeEffects[phase][i].notifyWhenFinished(this);
162
      mCube.apply(mCubeEffects[i],mCubeEffectPosition[i]);
163
      mCubeEffects[i].notifyWhenFinished(this);
197 164
      }
198 165

  
199 166
    DistortedEffects nodeEffects = mCube.getEffects();
200 167

  
201
    for(int i=0; i<mNodeEffectNumber[phase]; i++)
168
    for(int i=0; i<mNodeEffectNumber; i++)
202 169
      {
203
      nodeEffects.apply(mNodeEffects[phase][i],mNodeEffectPosition[phase][i]);
204
      mNodeEffects[phase][i].notifyWhenFinished(this);
170
      nodeEffects.apply(mNodeEffects[i],mNodeEffectPosition[i]);
171
      mNodeEffects[i].notifyWhenFinished(this);
205 172
      }
206 173
    }
207 174

  
......
220 187
        }
221 188
      catch(NoSuchMethodException ex)
222 189
        {
223
        android.util.Log.e("SolveEffect", type.effect.getSimpleName()+": exception getting method: "+ex.getMessage());
190
        android.util.Log.e("WinEffect", type.effect.getSimpleName()+": exception getting method: "+ex.getMessage());
224 191
        method = null;
225 192
        }
226 193

  
......
230 197
        }
231 198
      catch(Exception ex)
232 199
        {
233
        android.util.Log.e("SolveEffect", type.effect.getSimpleName()+": exception invoking method: "+ex.getMessage());
200
        android.util.Log.e("WinEffect", type.effect.getSimpleName()+": exception invoking method: "+ex.getMessage());
234 201
        }
235 202
      }
236 203
    }
src/main/java/org/distorted/effect/win/WinEffectGlow.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.win;
21

  
22
import org.distorted.library.effect.Effect;
23
import org.distorted.library.effect.PostprocessEffectGlow;
24
import org.distorted.library.effect.VertexEffectSink;
25
import org.distorted.library.type.Dynamic1D;
26
import org.distorted.library.type.Dynamic4D;
27
import org.distorted.library.type.Static1D;
28
import org.distorted.library.type.Static3D;
29
import org.distorted.library.type.Static4D;
30

  
31
import static org.distorted.magic.RubikRenderer.TEXTURE_SIZE;
32

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

  
35
public class WinEffectGlow extends WinEffect
36
  {
37
  private static final int[] colors = new int[] {0,0,1,  1,0,1,  1,0,0,  1,1,0,  0,1,0,  1,1,1}; // blue, pink, red, yellow, green, white
38
  private static final int INDEX = 5;
39

  
40
///////////////////////////////////////////////////////////////////////////////////////////////////
41

  
42
  public void createEffects(int duration)
43
    {
44
    mNodeEffectPosition = new int[] {-1, -1};
45
    mNodeEffects        = new Effect[mNodeEffectPosition.length];
46

  
47
    Dynamic1D radiusDyn = new Dynamic1D(duration,1.0f);
48
    radiusDyn.add(new Static1D( 0));
49
    radiusDyn.add(new Static1D(50));
50
    radiusDyn.add(new Static1D( 0));
51

  
52
    Dynamic4D color= new Dynamic4D(duration,1.0f);
53
    Static4D P1    = new Static4D(colors[3*INDEX],colors[3*INDEX+1], colors[3*INDEX+2], 0.0f);
54
    Static4D P2    = new Static4D(colors[3*INDEX],colors[3*INDEX+1], colors[3*INDEX+2], 0.5f);
55
    color.add(P1);
56
    color.add(P2);
57
    color.add(P1);
58

  
59
    mNodeEffects[0] = new PostprocessEffectGlow(radiusDyn,color);
60

  
61
    Dynamic1D degreeDyn= new Dynamic1D(duration,1.0f);
62
    degreeDyn.add(new Static1D(1.0f));
63
    degreeDyn.add(new Static1D(2.5f));
64
    degreeDyn.add(new Static1D(1.0f));
65

  
66
    float centerPoint = TEXTURE_SIZE*0.5f;
67
    Static3D center = new Static3D(centerPoint,centerPoint,centerPoint);
68

  
69
    mNodeEffects[1] = new VertexEffectSink(degreeDyn,center);
70
    }
71

  
72
///////////////////////////////////////////////////////////////////////////////////////////////////
73
// Enable all effects used in this Effect. Called by reflection from the parent class.
74

  
75
  @SuppressWarnings("unused")
76
  static void enable()
77
    {
78
    PostprocessEffectGlow.enable();
79
    VertexEffectSink.enable();
80
    }
81
  }
src/main/java/org/distorted/effect/win/WinEffectNone.java
19 19

  
20 20
package org.distorted.effect.win;
21 21

  
22
///////////////////////////////////////////////////////////////////////////////////////////////////
23

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

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

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

  
41 27
///////////////////////////////////////////////////////////////////////////////////////////////////
42 28

  
43
  public void createEffectsPhase1(int duration)
29
public class WinEffectNone extends WinEffect
30
  {
31
  public void createEffects(int duration)
44 32
    {
45 33
    Dynamic3D d0 = new Dynamic3D(1,0.5f);
46 34
    d0.add(new Static3D(0,0,0));
47 35

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

  
53 41
///////////////////////////////////////////////////////////////////////////////////////////////////
src/main/java/org/distorted/effect/win/WinEffectSpin.java
19 19

  
20 20
package org.distorted.effect.win;
21 21

  
22
///////////////////////////////////////////////////////////////////////////////////////////////////
23

  
24 22
import org.distorted.library.effect.Effect;
25 23
import org.distorted.library.effect.MatrixEffectRotate;
26 24
import org.distorted.library.type.Dynamic;
......
28 26
import org.distorted.library.type.Static1D;
29 27
import org.distorted.library.type.Static3D;
30 28

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

  
31 31
public class WinEffectSpin extends WinEffect
32 32
  {
33
  public void createEffectsPhase0(int duration)
33
  public void createEffects(int duration)
34 34
    {
35
    mCubeEffectPosition[0] = new int[] {3};
36
    mCubeEffects[0]        = new Effect[mCubeEffectPosition[0].length];
35
    mCubeEffectPosition = new int[] {3};
36
    mCubeEffects        = new Effect[mCubeEffectPosition.length];
37 37

  
38 38
    Static3D axis  = new Static3D(1,0,0);
39 39
    Static3D center= new Static3D(0,0,0);
......
46 46
    d0.add(new Static1D( 3*36));
47 47
    d0.add(new Static1D( 6*36));
48 48
    d0.add(new Static1D(10*36));
49
    mCubeEffects[0][0] = new MatrixEffectRotate(d0,axis,center);
50
    }
51

  
52
///////////////////////////////////////////////////////////////////////////////////////////////////
53

  
54
  public void createEffectsPhase1(int duration)
55
    {
56
    mCubeEffectPosition[1] = new int[] {3};
57
    mCubeEffects[1]        = new Effect[mCubeEffectPosition[1].length];
58

  
59
    Static3D axis  = new Static3D(1,0,0);
60
    Static3D center= new Static3D(0,0,0);
49
    d0.add(new Static1D(14*36));
50
    d0.add(new Static1D(17*36));
51
    d0.add(new Static1D(19*36));
52
    d0.add(new Static1D(20*36));
61 53

  
62
    Dynamic1D d1 = new Dynamic1D(duration/2, 1.0f);
63
    d1.setMode(Dynamic.MODE_JUMP);
64
    d1.setConvexity(0.0f);
65
    d1.add(new Static1D( 0*36));
66
    d1.add(new Static1D( 4*36));
67
    d1.add(new Static1D( 7*36));
68
    d1.add(new Static1D( 9*36));
69
    d1.add(new Static1D(10*36));
70
    mCubeEffects[1][0] = new MatrixEffectRotate(d1,axis,center);
54
    mCubeEffects[0] = new MatrixEffectRotate(d0,axis,center);
71 55
    }
72 56

  
73 57
///////////////////////////////////////////////////////////////////////////////////////////////////
src/main/java/org/distorted/magic/RubikRenderer.java
316 316

  
317 317
     mEffectID[index] = type.startEffect(this);
318 318

  
319
     if( mEffectID[index] == -1 )
319
     if( mEffectID[index] < 0 )
320 320
       {
321 321
       mCanUI     = true;
322 322
       mCanRotate = true;

Also available in: Unified diff