Revision e3a72781
Added by Leszek Koltunski about 5 years ago
src/main/java/org/distorted/examples/rubik/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 |
|
Also available in: Unified diff
Fixes for memory leak problems uncovered by the 'Rubik' app. (mainly: new method DistortedNode.markForDeletion)