Project

General

Profile

« Previous | Next » 

Revision c8bc83d9

Added by Leszek Koltunski over 2 years ago

Simplify TwistyObject's API.

View differences:

src/main/java/org/distorted/objectlib/main/TwistyObject.java
354 354
      }
355 355
    }
356 356

  
357
///////////////////////////////////////////////////////////////////////////////////////////////////
358

  
359
  private int getMultQuat(int index1, int index2)
360
    {
361
    if( mQuatMult==null )
362
      {
363
      mQuatMult = new int[NUM_QUATS][NUM_QUATS];
364

  
365
      for(int i=0; i<NUM_QUATS; i++)
366
        for(int j=0; j<NUM_QUATS; j++) mQuatMult[i][j] = -1;
367
      }
368

  
369
    if( mQuatMult[index1][index2]==-1 )
370
      {
371
      mQuatMult[index1][index2] = mulQuat(index1,index2);
372
      }
373

  
374
    return mQuatMult[index1][index2];
375
    }
376

  
357 377
///////////////////////////////////////////////////////////////////////////////////////////////////
358 378
// This is used to build internal data structures for the generic 'isSolved()'
359 379
//
......
362 382
// Color index, i.e. the index into the 'FACE_COLORS' table.
363 383
// else (edge or corner cubit, more than one non-black face): return -2.
364 384

  
365
  public int retCubitSolvedStatus(int cubit, int numLayers)
385
  protected int retCubitSolvedStatus(int cubit, int numLayers)
366 386
    {
367 387
    int numNonBlack=0, nonBlackIndex=-1, color;
368 388

  
......
385 405

  
386 406
///////////////////////////////////////////////////////////////////////////////////////////////////
387 407

  
388
  public boolean shouldResetTextureMaps()
408
  protected boolean shouldResetTextureMaps()
389 409
    {
390 410
    return false;
391 411
    }
392 412

  
393 413
///////////////////////////////////////////////////////////////////////////////////////////////////
394 414

  
395
  public int[] buildSolvedQuats(Static3D faceAx, Static4D[] quats)
415
  protected int[] buildSolvedQuats(Static3D faceAx, Static4D[] quats)
396 416
    {
397 417
    final float MAXD = 0.0001f;
398 418
    float x = faceAx.get0();
......
437 457

  
438 458
///////////////////////////////////////////////////////////////////////////////////////////////////
439 459

  
440
  private int getMultQuat(int index1, int index2)
441
    {
442
    if( mQuatMult==null )
443
      {
444
      mQuatMult = new int[NUM_QUATS][NUM_QUATS];
445

  
446
      for(int i=0; i<NUM_QUATS; i++)
447
        for(int j=0; j<NUM_QUATS; j++) mQuatMult[i][j] = -1;
448
      }
449

  
450
    if( mQuatMult[index1][index2]==-1 )
451
      {
452
      mQuatMult[index1][index2] = mulQuat(index1,index2);
453
      }
454

  
455
    return mQuatMult[index1][index2];
456
    }
457

  
458
///////////////////////////////////////////////////////////////////////////////////////////////////
459

  
460
  public boolean isSolved()
461
    {
462
    if( mSolvedFunctionIndex==0 ) return isSolved0();
463
    if( mSolvedFunctionIndex==1 ) return isSolved1();
464
    if( mSolvedFunctionIndex==2 ) return isSolved2();
465
    if( mSolvedFunctionIndex==3 ) return isSolved3();
466

  
467
    return false;
468
    }
469

  
470
///////////////////////////////////////////////////////////////////////////////////////////////////
471

  
472
  public boolean isSolved0()
460
  private boolean isSolved0()
473 461
    {
474 462
    int len, q1,q = CUBITS[0].mQuatIndex;
475 463
    int[] solved;
......
536 524
// (0,1,4), (2,3,6), (5,9,10), (7,8,11)
537 525
// are all the same color.
538 526

  
539
  public boolean isSolved1()
527
  private boolean isSolved1()
540 528
    {
541 529
    if( mScramble==null )
542 530
      {
......
587 575
// Y cubits: 1, 3, 9, 11
588 576
// Z cubits: 4, 5, 6, 7
589 577

  
590
  public boolean isSolved2()
578
  private boolean isSolved2()
591 579
    {
592 580
    int qX = CUBITS[0].mQuatIndex;
593 581
    int qY = CUBITS[1].mQuatIndex;
......
611 599
// and all the 12 left and right edges and corners also with the same quat multiplied by
612 600
// QUATS[12] - i.e. also upside down.
613 601

  
614
  public boolean isSolved3()
602
  private boolean isSolved3()
615 603
    {
616 604
    int index = CUBITS[0].mQuatIndex;
617 605

  
......
641 629
    return true;
642 630
    }
643 631

  
644
///////////////////////////////////////////////////////////////////////////////////////////////////
645

  
646
  public void setObjectRatio(float sizeChange)
647
    {
648
    mObjectScreenRatio *= (1.0f+sizeChange)/2;
649

  
650
    if( mObjectScreenRatio>MAX_SIZE_CHANGE) mObjectScreenRatio = MAX_SIZE_CHANGE;
651
    if( mObjectScreenRatio<MIN_SIZE_CHANGE) mObjectScreenRatio = MIN_SIZE_CHANGE;
652

  
653
    float scale = mObjectScreenRatio*mInitScreenRatio*mNodeSize/mRealSize;
654
    mObjectScale.set(scale,scale,scale);
655
    }
656

  
657
///////////////////////////////////////////////////////////////////////////////////////////////////
658

  
659
  public float getObjectRatio()
660
    {
661
    return mObjectScreenRatio*mInitScreenRatio;
662
    }
663

  
664 632
///////////////////////////////////////////////////////////////////////////////////////////////////
665 633

  
666 634
  int computeRow(float[] pos, int axisIndex)
......
870 838
    return -1;
871 839
    }
872 840

  
873
///////////////////////////////////////////////////////////////////////////////////////////////////
874

  
875
  public int getCubitFaceColorIndex(int cubit, int face)
876
    {
877
    Static4D texMap = mMesh.getTextureMap(NUM_FACE_COLORS*cubit + face);
878

  
879
    int x = (int)(texMap.get0()/texMap.get2());
880
    int y = (int)(texMap.get1()/texMap.get3());
881

  
882
    return (mNumTexRows-1-y)*NUM_STICKERS_IN_ROW + x;
883
    }
884

  
885 841
///////////////////////////////////////////////////////////////////////////////////////////////////
886 842
// the getFaceColors + final black in a grid (so that we do not exceed the maximum texture size)
887 843

  
......
920 876
      }
921 877
    }
922 878

  
879
///////////////////////////////////////////////////////////////////////////////////////////////////
880

  
881
  private float getAngle()
882
    {
883
    int pointNum = mRotationAngle.getNumPoints();
884

  
885
    if( pointNum>=1 )
886
      {
887
      return mRotationAngle.getPoint(pointNum-1).get0();
888
      }
889
    else
890
      {
891
      FirebaseCrashlytics crashlytics = FirebaseCrashlytics.getInstance();
892
      crashlytics.log("points in RotationAngle: "+pointNum);
893
      return 0;
894
      }
895
    }
896

  
897
///////////////////////////////////////////////////////////////////////////////////////////////////
898

  
899
  private void recordQuatsState(String message)
900
    {
901
    StringBuilder quats = new StringBuilder();
902

  
903
    for(int j=0; j<NUM_CUBITS; j++)
904
      {
905
      quats.append(mQuatDebug[j]);
906
      quats.append(" ");
907
      }
908

  
909
    String name = intGetObjectType(mNumLayers).name();
910

  
911
    if( BuildConfig.DEBUG )
912
      {
913
      android.util.Log.e("quats" , quats.toString());
914
      android.util.Log.e("object", name);
915
      }
916
    else
917
      {
918
      Exception ex = new Exception(message);
919
      FirebaseCrashlytics crashlytics = FirebaseCrashlytics.getInstance();
920
      crashlytics.setCustomKey("quats" , quats.toString());
921
      crashlytics.setCustomKey("object", name);
922
      crashlytics.recordException(ex);
923
      }
924
    }
925

  
926
///////////////////////////////////////////////////////////////////////////////////////////////////
927
// PUBLIC API
928
///////////////////////////////////////////////////////////////////////////////////////////////////
929

  
930
  public boolean isSolved()
931
    {
932
    if( mSolvedFunctionIndex==0 ) return isSolved0();
933
    if( mSolvedFunctionIndex==1 ) return isSolved1();
934
    if( mSolvedFunctionIndex==2 ) return isSolved2();
935
    if( mSolvedFunctionIndex==3 ) return isSolved3();
936

  
937
    return false;
938
    }
939

  
940
///////////////////////////////////////////////////////////////////////////////////////////////////
941

  
942
  public void setObjectRatio(float sizeChange)
943
    {
944
    mObjectScreenRatio *= (1.0f+sizeChange)/2;
945

  
946
    if( mObjectScreenRatio>MAX_SIZE_CHANGE) mObjectScreenRatio = MAX_SIZE_CHANGE;
947
    if( mObjectScreenRatio<MIN_SIZE_CHANGE) mObjectScreenRatio = MIN_SIZE_CHANGE;
948

  
949
    float scale = mObjectScreenRatio*mInitScreenRatio*mNodeSize/mRealSize;
950
    mObjectScale.set(scale,scale,scale);
951
    }
952

  
953
///////////////////////////////////////////////////////////////////////////////////////////////////
954

  
955
  public float getObjectRatio()
956
    {
957
    return mObjectScreenRatio*mInitScreenRatio;
958
    }
959

  
960
///////////////////////////////////////////////////////////////////////////////////////////////////
961

  
962
  public int getCubitFaceColorIndex(int cubit, int face)
963
    {
964
    Static4D texMap = mMesh.getTextureMap(NUM_FACE_COLORS*cubit + face);
965

  
966
    int x = (int)(texMap.get0()/texMap.get2());
967
    int y = (int)(texMap.get1()/texMap.get3());
968

  
969
    return (mNumTexRows-1-y)*NUM_STICKERS_IN_ROW + x;
970
    }
971

  
923 972
///////////////////////////////////////////////////////////////////////////////////////////////////
924 973

  
925 974
  public int getNumLayers()
......
987 1036
      }
988 1037
    }
989 1038

  
990
///////////////////////////////////////////////////////////////////////////////////////////////////
991

  
992
  public void recordQuatsState(String message)
993
    {
994
    StringBuilder quats = new StringBuilder();
995

  
996
    for(int j=0; j<NUM_CUBITS; j++)
997
      {
998
      quats.append(mQuatDebug[j]);
999
      quats.append(" ");
1000
      }
1001

  
1002
    String name = intGetObjectList(mNumLayers).name();
1003

  
1004
    if( BuildConfig.DEBUG )
1005
      {
1006
      android.util.Log.e("quats" , quats.toString());
1007
      android.util.Log.e("object", name);
1008
      }
1009
    else
1010
      {
1011
      Exception ex = new Exception(message);
1012
      FirebaseCrashlytics crashlytics = FirebaseCrashlytics.getInstance();
1013
      crashlytics.setCustomKey("quats" , quats.toString());
1014
      crashlytics.setCustomKey("object", name);
1015
      crashlytics.recordException(ex);
1016
      }
1017
    }
1018

  
1019 1039
///////////////////////////////////////////////////////////////////////////////////////////////////
1020 1040

  
1021 1041
  public void releaseResources()
......
1165 1185
    return 0;
1166 1186
    }
1167 1187

  
1168
///////////////////////////////////////////////////////////////////////////////////////////////////
1169

  
1170
  private float getAngle()
1171
    {
1172
    int pointNum = mRotationAngle.getNumPoints();
1173

  
1174
    if( pointNum>=1 )
1175
      {
1176
      return mRotationAngle.getPoint(pointNum-1).get0();
1177
      }
1178
    else
1179
      {
1180
      FirebaseCrashlytics crashlytics = FirebaseCrashlytics.getInstance();
1181
      crashlytics.log("points in RotationAngle: "+pointNum);
1182
      return 0;
1183
      }
1184
    }
1185

  
1186 1188
///////////////////////////////////////////////////////////////////////////////////////////////////
1187 1189

  
1188 1190
  public synchronized void removeRotationNow()
......
1272 1274

  
1273 1275
///////////////////////////////////////////////////////////////////////////////////////////////////
1274 1276

  
1275
  public ObjectType getObjectList()
1277
  public ObjectType getObjectType()
1276 1278
    {
1277
    return intGetObjectList(mNumLayers);
1279
    return intGetObjectType(mNumLayers);
1278 1280
    }
1279 1281

  
1280 1282
///////////////////////////////////////////////////////////////////////////////////////////////////
......
1306 1308
  protected abstract ObjectSticker retSticker(int face);
1307 1309
  protected abstract int getFaceColor(int cubit, int cubitface, int numLayers);
1308 1310
  protected abstract int getResource(int mNumLayers);
1309
  protected abstract ObjectType intGetObjectList(int numLayers);
1311
  protected abstract ObjectType intGetObjectType(int numLayers);
1310 1312

  
1311 1313
  public abstract Movement getMovement();
1312 1314
  public abstract Static3D[] getRotationAxis();

Also available in: Unified diff