Revision 34998c9d
Added by Leszek Koltunski over 5 years ago
distorted-cube.iml | ||
---|---|---|
105 | 105 |
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/instant_run_merged_manifests" /> |
106 | 106 |
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/instant_run_split_apk_resources" /> |
107 | 107 |
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/javac" /> |
108 |
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/jniLibs" /> |
|
109 |
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/lint_jar" /> |
|
110 | 108 |
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/manifest-checker" /> |
111 | 109 |
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/merged_assets" /> |
112 | 110 |
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/merged_jni_libs" /> |
... | ... | |
118 | 116 |
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/reload-dex" /> |
119 | 117 |
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/res" /> |
120 | 118 |
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/resources" /> |
121 |
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/rs" /> |
|
122 | 119 |
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/shader_assets" /> |
123 |
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/shaders" /> |
|
124 | 120 |
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/signing_config" /> |
125 | 121 |
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/split-apk" /> |
126 | 122 |
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/symbols" /> |
127 |
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/tmp" /> |
|
128 | 123 |
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/transforms" /> |
129 | 124 |
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/validate_signing_config" /> |
130 | 125 |
<excludeFolder url="file://$MODULE_DIR$/build/outputs" /> |
... | ... | |
148 | 143 |
<orderEntry type="library" name="Gradle: android.arch.core:common:1.1.0@jar" level="project" /> |
149 | 144 |
<orderEntry type="module" module-name="distorted-library" /> |
150 | 145 |
<orderEntry type="module" module-name="distorted-library" /> |
146 |
<orderEntry type="module" module-name="distorted-library" /> |
|
147 |
<orderEntry type="module" module-name="distorted-library" /> |
|
148 |
<orderEntry type="module" module-name="distorted-library" /> |
|
151 | 149 |
</component> |
152 | 150 |
</module> |
src/main/java/org/distorted/magic/RubikActivity.java | ||
---|---|---|
34 | 34 |
public class RubikActivity extends Activity |
35 | 35 |
{ |
36 | 36 |
static final int DEFAULT_SIZE = 3; |
37 |
private static final int STARTING_SIZE = 2;
|
|
37 |
private static final int SMALLEST_SIZE = 2;
|
|
38 | 38 |
private static final int[] button_ids = {R.id.rubikSize2, R.id.rubikSize3, R.id.rubikSize4}; |
39 | 39 |
|
40 | 40 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
... | ... | |
102 | 102 |
for(int b=0; b<button_ids.length; b++) |
103 | 103 |
if( button_ids[b] == id ) |
104 | 104 |
{ |
105 |
size = b+STARTING_SIZE;
|
|
105 |
size = b+SMALLEST_SIZE;
|
|
106 | 106 |
break; |
107 | 107 |
} |
108 | 108 |
|
... | ... | |
120 | 120 |
{ |
121 | 121 |
Drawable d = findViewById(button_ids[b]).getBackground(); |
122 | 122 |
|
123 |
if( size == b+STARTING_SIZE )
|
|
123 |
if( size == b+SMALLEST_SIZE )
|
|
124 | 124 |
{ |
125 | 125 |
d.setColorFilter(ContextCompat.getColor(this,R.color.red), PorterDuff.Mode.MULTIPLY); |
126 | 126 |
} |
src/main/java/org/distorted/magic/RubikCube.java | ||
---|---|---|
29 | 29 |
import org.distorted.library.effect.MatrixEffectScale; |
30 | 30 |
import org.distorted.library.effect.VertexEffectSink; |
31 | 31 |
import org.distorted.library.main.DistortedEffects; |
32 |
import org.distorted.library.main.DistortedNode; |
|
32 | 33 |
import org.distorted.library.main.DistortedScreen; |
33 | 34 |
import org.distorted.library.main.DistortedTexture; |
34 | 35 |
import org.distorted.library.mesh.MeshCubes; |
... | ... | |
49 | 50 |
private static final Static3D VectY = new Static3D(0,1,0); |
50 | 51 |
private static final Static3D VectZ = new Static3D(0,0,1); |
51 | 52 |
|
53 |
private DistortedNode[][][] mNodes; |
|
52 | 54 |
private MeshCubes[][][] mCubes; |
53 | 55 |
private DistortedEffects[][][] mEffects; |
54 | 56 |
private Static4D[][][] mQuatScramble; |
... | ... | |
75 | 77 |
mRotAxis= RubikSurfaceView.VECTX; |
76 | 78 |
mTexture = new DistortedTexture(TEXTURE_SIZE,TEXTURE_SIZE); |
77 | 79 |
|
80 |
mNodes = new DistortedNode[mSize][mSize][mSize]; |
|
78 | 81 |
mCubes = new MeshCubes[mSize][mSize][mSize]; |
79 | 82 |
mEffects = new DistortedEffects[mSize][mSize][mSize]; |
80 | 83 |
mQuatScramble = new Static4D[mSize][mSize][mSize]; |
... | ... | |
160 | 163 |
{ |
161 | 164 |
if( x==0 || x==mSize-1 || y==0 || y==mSize-1 || z==0 || z==mSize-1 ) |
162 | 165 |
{ |
163 |
screen.attach(mTexture,mEffects[x][y][z],mCubes[x][y][z]); |
|
166 |
mNodes[x][y][z] = new DistortedNode(mTexture,mEffects[x][y][z],mCubes[x][y][z]); |
|
167 |
screen.attach(mNodes[x][y][z]); |
|
168 |
} |
|
169 |
} |
|
170 |
} |
|
171 |
|
|
172 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
173 |
// all DistortedTextures, DistortedNodes, DistortedFramebuffers, DistortedScreens and all types of |
|
174 |
// Meshes HAVE TO be markedForDeletion when they are no longer needed- otherwise we have a major |
|
175 |
// memory leak. |
|
176 |
|
|
177 |
void releaseResources() |
|
178 |
{ |
|
179 |
mTexture.markForDeletion(); |
|
180 |
|
|
181 |
for(int x=0; x<mSize; x++) |
|
182 |
for(int y=0; y<mSize; y++) |
|
183 |
for(int z=0; z<mSize; z++) |
|
184 |
{ |
|
185 |
if( x==0 || x==mSize-1 || y==0 || y==mSize-1 || z==0 || z==mSize-1 ) |
|
186 |
{ |
|
187 |
mCubes[x][y][z].markForDeletion(); |
|
188 |
mNodes[x][y][z].markForDeletion(); |
|
164 | 189 |
} |
165 | 190 |
} |
166 | 191 |
} |
... | ... | |
217 | 242 |
|
218 | 243 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
219 | 244 |
|
220 |
void finishRotationCalledOnNextRender(EffectListener listener)
|
|
245 |
void finishRotationNow(EffectListener listener)
|
|
221 | 246 |
{ |
222 | 247 |
boolean first = true; |
223 | 248 |
float startingAngle = mRotationAngleStatic.get1(); |
... | ... | |
249 | 274 |
|
250 | 275 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
251 | 276 |
|
252 |
void removeRotationCalledOnNextRender(EffectListener listener)
|
|
277 |
void removeRotationNow(EffectListener listener)
|
|
253 | 278 |
{ |
254 | 279 |
mEffectsListeningForNow.deregisterForMessages(listener); |
255 | 280 |
|
src/main/java/org/distorted/magic/RubikRenderer.java | ||
---|---|---|
45 | 45 |
private Static4D mQuatCurrent, mQuatAccumulated; |
46 | 46 |
private Static4D mTempCurrent, mTempAccumulated; |
47 | 47 |
private float mCubeSizeInScreenSpace; |
48 |
private int mNextCubeSize; |
|
48 | 49 |
private boolean mFinishRotation, mRemoveRotation, mFinishDragCurrent, mFinishDragAccumulated; |
49 | 50 |
private boolean mCanRotate; |
50 | 51 |
private RubikCube mCube; |
... | ... | |
74 | 75 |
mFinishDragCurrent = false; |
75 | 76 |
mFinishDragAccumulated = false; |
76 | 77 |
|
78 |
mNextCubeSize= 0; |
|
79 |
|
|
77 | 80 |
mCanRotate = true; |
78 | 81 |
} |
79 | 82 |
|
... | ... | |
101 | 104 |
{ |
102 | 105 |
mCanRotate = false; |
103 | 106 |
mFinishRotation=false; |
104 |
mCube.finishRotationCalledOnNextRender(this);
|
|
107 |
mCube.finishRotationNow(this);
|
|
105 | 108 |
} |
106 | 109 |
|
107 | 110 |
if( mRemoveRotation ) |
108 | 111 |
{ |
109 | 112 |
mRemoveRotation=false; |
110 |
mCube.removeRotationCalledOnNextRender(this);
|
|
113 |
mCube.removeRotationNow(this);
|
|
111 | 114 |
mCanRotate = true; |
112 | 115 |
} |
116 |
|
|
117 |
if( mNextCubeSize!=0 ) |
|
118 |
{ |
|
119 |
createCubeNow(mNextCubeSize); |
|
120 |
mScreen.detachAll(); |
|
121 |
mCube.attachToScreen(mScreen); |
|
122 |
mNextCubeSize = 0; |
|
123 |
} |
|
113 | 124 |
} |
114 | 125 |
|
115 | 126 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
... | ... | |
180 | 191 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
181 | 192 |
|
182 | 193 |
void createCube(int newSize) |
194 |
{ |
|
195 |
mNextCubeSize = newSize; |
|
196 |
} |
|
197 |
|
|
198 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
199 |
|
|
200 |
void createCubeNow(int newSize) |
|
183 | 201 |
{ |
184 | 202 |
int oldSize = mCube==null ? 0 : mCube.getSize(); |
185 | 203 |
|
186 | 204 |
if( oldSize!=newSize ) |
187 | 205 |
{ |
206 |
if( mCube!=null ) mCube.releaseResources(); |
|
188 | 207 |
mCube = new RubikCube(newSize, mMove, mScale, mQuatCurrent, mQuatAccumulated); |
189 | 208 |
mCube.createTexture(); |
190 | 209 |
|
... | ... | |
192 | 211 |
{ |
193 | 212 |
recomputeScaleFactor(mScreenWidth,mScreenHeight); |
194 | 213 |
} |
195 |
|
|
196 |
mScreen.detachAll(); |
|
197 |
mCube.attachToScreen(mScreen); |
|
198 | 214 |
} |
199 | 215 |
} |
200 | 216 |
|
201 | 217 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
202 | 218 |
|
203 |
void recomputeScaleFactor(int screenWidth, int screenHeight) |
|
219 |
private void recomputeScaleFactor(int screenWidth, int screenHeight)
|
|
204 | 220 |
{ |
205 | 221 |
mCubeSizeInScreenSpace = CUBE_SCREEN_RATIO*(screenWidth>screenHeight ? screenHeight:screenWidth); |
206 | 222 |
float texSize = mCube.getTextureSize(); |
src/main/java/org/distorted/magic/RubikSurfaceView.java | ||
---|---|---|
80 | 80 |
mScreenWidth = mScreenHeight = mScreenMin = 0; |
81 | 81 |
|
82 | 82 |
mRenderer = new RubikRenderer(this); |
83 |
mRenderer.createCube(RubikActivity.DEFAULT_SIZE); |
|
83 |
mRenderer.createCubeNow(RubikActivity.DEFAULT_SIZE);
|
|
84 | 84 |
|
85 | 85 |
mQuatCurrent = new Static4D(0,0,0,1); |
86 | 86 |
mQuatAccumulated = mRenderer.initializeQuat(); |
Also available in: Unified diff
Port fixes for the memory leak problems from distorted-examples.