Revision ccf9fec5
Added by Leszek Koltunski over 5 years ago
| src/main/java/org/distorted/main/RubikPreRender.java | ||
|---|---|---|
| 19 | 19 |
|
| 20 | 20 |
package org.distorted.main; |
| 21 | 21 |
|
| 22 |
import android.content.Context; |
|
| 22 | 23 |
import android.content.SharedPreferences; |
| 24 |
import android.content.res.Resources; |
|
| 23 | 25 |
import android.os.Bundle; |
| 24 | 26 |
|
| 25 | 27 |
import org.distorted.dialogs.RubikDialogNewRecord; |
| ... | ... | |
| 102 | 104 |
if( mOldObject!=null ) mOldObject.releaseResources(); |
| 103 | 105 |
mOldObject = mNewObject; |
| 104 | 106 |
|
| 105 |
mNewObject = object.create(size, mView.getQuatCurrent(), mView.getQuatAccumulated(), moves); |
|
| 107 |
Context con = mView.getContext(); |
|
| 108 |
Resources res = con.getResources(); |
|
| 109 |
|
|
| 110 |
mNewObject = object.create(size, mView.getQuatCurrent(), mView.getQuatAccumulated(), moves, res); |
|
| 106 | 111 |
|
| 107 | 112 |
if( mNewObject!=null ) |
| 108 | 113 |
{
|
| src/main/java/org/distorted/objects/RubikCube.java | ||
|---|---|---|
| 19 | 19 |
|
| 20 | 20 |
package org.distorted.objects; |
| 21 | 21 |
|
| 22 |
import android.content.res.Resources; |
|
| 22 | 23 |
import android.graphics.Canvas; |
| 23 | 24 |
import android.graphics.Paint; |
| 24 | 25 |
|
| ... | ... | |
| 98 | 99 |
|
| 99 | 100 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 100 | 101 |
|
| 101 |
RubikCube(int size, Static4D quatCur, Static4D quatAcc, DistortedTexture texture, MeshRectangles mesh, DistortedEffects effects, int[][] moves) |
|
| 102 |
RubikCube(int size, Static4D quatCur, Static4D quatAcc, DistortedTexture texture, |
|
| 103 |
MeshRectangles mesh, DistortedEffects effects, int[][] moves, Resources res) |
|
| 102 | 104 |
{
|
| 103 |
super(size, 60, quatCur,quatAcc,texture,mesh,effects,moves, RubikObjectList.CUBE); |
|
| 105 |
super(size, 60, quatCur,quatAcc,texture,mesh,effects,moves, RubikObjectList.CUBE, res);
|
|
| 104 | 106 |
} |
| 105 | 107 |
|
| 106 | 108 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| src/main/java/org/distorted/objects/RubikObject.java | ||
|---|---|---|
| 20 | 20 |
package org.distorted.objects; |
| 21 | 21 |
|
| 22 | 22 |
import android.content.SharedPreferences; |
| 23 |
import android.content.res.Resources; |
|
| 23 | 24 |
import android.graphics.Bitmap; |
| 24 | 25 |
import android.graphics.Canvas; |
| 25 | 26 |
import android.graphics.Paint; |
| ... | ... | |
| 27 | 28 |
import com.google.firebase.crashlytics.FirebaseCrashlytics; |
| 28 | 29 |
|
| 29 | 30 |
import org.distorted.library.effect.Effect; |
| 30 |
import org.distorted.library.effect.MatrixEffectMove; |
|
| 31 | 31 |
import org.distorted.library.effect.MatrixEffectQuaternion; |
| 32 | 32 |
import org.distorted.library.effect.MatrixEffectScale; |
| 33 | 33 |
import org.distorted.library.effect.VertexEffectQuaternion; |
| ... | ... | |
| 36 | 36 |
import org.distorted.library.main.DistortedNode; |
| 37 | 37 |
import org.distorted.library.main.DistortedTexture; |
| 38 | 38 |
import org.distorted.library.mesh.MeshBase; |
| 39 |
import org.distorted.library.mesh.MeshJoined;
|
|
| 39 |
import org.distorted.library.mesh.MeshFile;
|
|
| 40 | 40 |
import org.distorted.library.mesh.MeshRectangles; |
| 41 | 41 |
import org.distorted.library.message.EffectListener; |
| 42 | 42 |
import org.distorted.library.type.Dynamic1D; |
| ... | ... | |
| 44 | 44 |
import org.distorted.library.type.Static3D; |
| 45 | 45 |
import org.distorted.library.type.Static4D; |
| 46 | 46 |
|
| 47 |
import java.io.DataInputStream; |
|
| 48 |
import java.io.IOException; |
|
| 49 |
import java.io.InputStream; |
|
| 50 |
|
|
| 47 | 51 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 48 | 52 |
|
| 49 | 53 |
public abstract class RubikObject extends DistortedNode |
| ... | ... | |
| 87 | 91 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 88 | 92 |
|
| 89 | 93 |
RubikObject(int size, int fov, Static4D quatCur, Static4D quatAcc, DistortedTexture nodeTexture, |
| 90 |
MeshRectangles nodeMesh, DistortedEffects nodeEffects, int[][] moves, RubikObjectList list) |
|
| 94 |
MeshRectangles nodeMesh, DistortedEffects nodeEffects, int[][] moves, RubikObjectList list, Resources res)
|
|
| 91 | 95 |
{
|
| 92 | 96 |
super(nodeTexture,nodeEffects,nodeMesh); |
| 93 | 97 |
|
| ... | ... | |
| 125 | 129 |
|
| 126 | 130 |
mCubits = new Cubit[NUM_CUBITS]; |
| 127 | 131 |
mTexture = new DistortedTexture(); |
| 128 |
MeshBase[] cubitMesh = new MeshBase[NUM_CUBITS]; |
|
| 132 |
|
|
| 133 |
int sizeIndex = RubikObjectList.getSizeIndex(list.ordinal(),mSize); |
|
| 134 |
int resourceID= list.getResourceIDs()[sizeIndex]; |
|
| 135 |
|
|
| 136 |
InputStream is = res.openRawResource(resourceID); |
|
| 137 |
DataInputStream dos = new DataInputStream(is); |
|
| 138 |
mMesh = new MeshFile(dos); |
|
| 139 |
|
|
| 140 |
try |
|
| 141 |
{
|
|
| 142 |
is.close(); |
|
| 143 |
} |
|
| 144 |
catch(IOException e) |
|
| 145 |
{
|
|
| 146 |
android.util.Log.e("meshFile", "Error closing InputStream: "+e.toString());
|
|
| 147 |
} |
|
| 129 | 148 |
|
| 130 | 149 |
for(int i=0; i<NUM_CUBITS; i++) |
| 131 | 150 |
{
|
| 132 | 151 |
mCubits[i] = new Cubit(this,mOrigPos[i]); |
| 133 |
cubitMesh[i] = createCubitMesh(i); |
|
| 134 |
cubitMesh[i].apply(new MatrixEffectMove(mOrigPos[i]),1,0); |
|
| 135 |
cubitMesh[i].setEffectAssociation(0, mCubits[i].computeAssociation(), 0); |
|
| 152 |
mMesh.setEffectAssociation(i, mCubits[i].computeAssociation(), 0); |
|
| 136 | 153 |
} |
| 137 | 154 |
|
| 138 |
mMesh = new MeshJoined(cubitMesh); |
|
| 139 |
|
|
| 140 |
resetAllTextureMaps(); |
|
| 141 |
|
|
| 142 | 155 |
mEffects = new DistortedEffects(); |
| 143 | 156 |
|
| 144 | 157 |
int num_quats = QUATS.length; |
| src/main/java/org/distorted/objects/RubikObjectList.java | ||
|---|---|---|
| 19 | 19 |
|
| 20 | 20 |
package org.distorted.objects; |
| 21 | 21 |
|
| 22 |
import android.content.res.Resources; |
|
| 23 |
|
|
| 22 | 24 |
import org.distorted.library.main.DistortedEffects; |
| 23 | 25 |
import org.distorted.library.main.DistortedTexture; |
| 24 | 26 |
import org.distorted.library.mesh.MeshRectangles; |
| ... | ... | |
| 33 | 35 |
{
|
| 34 | 36 |
CUBE ( |
| 35 | 37 |
new int[][] {
|
| 36 |
{2 , 12, R.drawable.cube2} ,
|
|
| 37 |
{3 , 16, R.drawable.cube3} ,
|
|
| 38 |
{4 , 20, R.drawable.cube4} ,
|
|
| 39 |
{5 , 24, R.drawable.cube5}
|
|
| 38 |
{2 , 12, R.drawable.cube2, R.raw.cube2} ,
|
|
| 39 |
{3 , 16, R.drawable.cube3, R.raw.cube3} ,
|
|
| 40 |
{4 , 20, R.drawable.cube4, R.raw.cube4} ,
|
|
| 41 |
{5 , 24, R.drawable.cube5, R.raw.cube5}
|
|
| 40 | 42 |
}, |
| 41 | 43 |
RubikCube.class, |
| 42 | 44 |
new RubikCubeMovement() |
| ... | ... | |
| 44 | 46 |
|
| 45 | 47 |
PYRA ( |
| 46 | 48 |
new int[][] {
|
| 47 |
{3 , 10, R.drawable.pyra3} ,
|
|
| 48 |
{4 , 15, R.drawable.pyra4} ,
|
|
| 49 |
{5 , 20, R.drawable.pyra5}
|
|
| 49 |
{3 , 10, R.drawable.pyra3, R.raw.pyra3} ,
|
|
| 50 |
{4 , 15, R.drawable.pyra4, R.raw.pyra4} ,
|
|
| 51 |
{5 , 20, R.drawable.pyra5, R.raw.pyra5}
|
|
| 50 | 52 |
}, |
| 51 | 53 |
RubikPyraminx.class, |
| 52 | 54 |
new RubikPyraminxMovement() |
| ... | ... | |
| 58 | 60 |
public static final int MAX_LEVEL; |
| 59 | 61 |
public static final int MAX_OBJECT_SIZE; |
| 60 | 62 |
|
| 61 |
private final int[] mObjectSizes, mMaxLevels, mIconIDs; |
|
| 63 |
private final int[] mObjectSizes, mMaxLevels, mIconIDs, mResourceIDs;
|
|
| 62 | 64 |
private final Class<? extends RubikObject> mObjectClass; |
| 63 | 65 |
private final RubikObjectMovement mObjectMovementClass; |
| 64 | 66 |
private static final RubikObjectList[] objects; |
| ... | ... | |
| 276 | 278 |
mObjectSizes= new int[length]; |
| 277 | 279 |
mMaxLevels = new int[length]; |
| 278 | 280 |
mIconIDs = new int[length]; |
| 281 |
mResourceIDs= new int[length]; |
|
| 279 | 282 |
|
| 280 | 283 |
for(int i=0; i<length; i++) |
| 281 | 284 |
{
|
| 282 | 285 |
mObjectSizes[i] = info[i][0]; |
| 283 | 286 |
mMaxLevels[i] = info[i][1]; |
| 284 | 287 |
mIconIDs[i] = info[i][2]; |
| 288 |
mResourceIDs[i] = info[i][3]; |
|
| 285 | 289 |
} |
| 286 | 290 |
|
| 287 | 291 |
mObjectClass = object; |
| ... | ... | |
| 311 | 315 |
|
| 312 | 316 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 313 | 317 |
|
| 314 |
public RubikObject create(int size, Static4D quatCur, Static4D quatAcc, int[][] moves) |
|
| 318 |
public int[] getResourceIDs() |
|
| 319 |
{
|
|
| 320 |
return mResourceIDs; |
|
| 321 |
} |
|
| 322 |
|
|
| 323 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 324 |
|
|
| 325 |
public RubikObject create(int size, Static4D quatCur, Static4D quatAcc, int[][] moves, Resources res) |
|
| 315 | 326 |
{
|
| 316 | 327 |
DistortedTexture texture = new DistortedTexture(); |
| 317 | 328 |
DistortedEffects effects = new DistortedEffects(); |
| ... | ... | |
| 319 | 330 |
|
| 320 | 331 |
switch(ordinal()) |
| 321 | 332 |
{
|
| 322 |
case 0: return new RubikCube (size, quatCur, quatAcc, texture, mesh, effects, moves); |
|
| 323 |
case 1: return new RubikPyraminx(size, quatCur, quatAcc, texture, mesh, effects, moves); |
|
| 333 |
case 0: return new RubikCube (size, quatCur, quatAcc, texture, mesh, effects, moves, res);
|
|
| 334 |
case 1: return new RubikPyraminx(size, quatCur, quatAcc, texture, mesh, effects, moves, res);
|
|
| 324 | 335 |
} |
| 325 | 336 |
|
| 326 | 337 |
return null; |
| src/main/java/org/distorted/objects/RubikPyraminx.java | ||
|---|---|---|
| 19 | 19 |
|
| 20 | 20 |
package org.distorted.objects; |
| 21 | 21 |
|
| 22 |
import android.content.res.Resources; |
|
| 22 | 23 |
import android.graphics.Canvas; |
| 23 | 24 |
import android.graphics.Paint; |
| 24 | 25 |
|
| ... | ... | |
| 98 | 99 |
|
| 99 | 100 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 100 | 101 |
|
| 101 |
RubikPyraminx(int size, Static4D quatCur, Static4D quatAcc, DistortedTexture texture, MeshRectangles mesh, DistortedEffects effects, int[][] moves) |
|
| 102 |
RubikPyraminx(int size, Static4D quatCur, Static4D quatAcc, DistortedTexture texture, |
|
| 103 |
MeshRectangles mesh, DistortedEffects effects, int[][] moves, Resources res) |
|
| 102 | 104 |
{
|
| 103 |
super(size, 30, quatCur,quatAcc,texture,mesh,effects,moves, RubikObjectList.PYRA); |
|
| 105 |
super(size, 30, quatCur,quatAcc,texture,mesh,effects,moves, RubikObjectList.PYRA, res);
|
|
| 104 | 106 |
} |
| 105 | 107 |
|
| 106 | 108 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
Also available in: Unified diff
Read the meshes from .dmesh files (rather than compute them dynamically).
This (along with single-mesh mode) hopefully makes the rendering much faster, while keeping the time needed for Object Change low.
The only downside: this increases the size of the release APK from 6 MB to 9.6 MB.