Project

General

Profile

« Previous | Next » 

Revision ccf9fec5

Added by Leszek Koltunski almost 4 years ago

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.

View differences:

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;

Also available in: Unified diff