Project

General

Profile

« Previous | Next » 

Revision 1eafa9c6

Added by Leszek Koltunski about 2 months ago

Fix the detection of the solved state.

View differences:

src/main/java/org/distorted/objectlib/effects/objectchange/ObjectChangeEffect.java
130 130

  
131 131
    if( mPre!=null )
132 132
      {
133
      int numFaces = mObject[1].getNumFaces();
133
      int numFaces = mObject[1].getNumPuzzleFaces();
134 134
      mPre.setDefaultRotation(numFaces);
135 135
      }
136 136

  
src/main/java/org/distorted/objectlib/json/JsonWriter.java
436 436
    metadata.put("scrambles"  , meta.numScrambles() );
437 437
    metadata.put("shortname"  , object.getShortName() );
438 438
    metadata.put("resetmaps"  , object.shouldResetTextureMaps() );
439
    metadata.put("num_faces"  , object.getNumFaces() );
439
    metadata.put("num_faces"  , object.getNumPuzzleFaces() );
440 440
    metadata.put("price"      , meta.price() );
441 441
    metadata.put("category"   , meta.getCategory() );
442 442

  
src/main/java/org/distorted/objectlib/main/TwistyJson.java
404 404

  
405 405
///////////////////////////////////////////////////////////////////////////////////////////////////
406 406

  
407
  public int getNumFaces()
407
  public int getNumPuzzleFaces()
408 408
    {
409 409
    return mReader.getNumFaces();
410 410
    }
src/main/java/org/distorted/objectlib/main/TwistyObject.java
216 216
    mObjectQuats = getQuats();
217 217
    mNumQuats = mObjectQuats.length;
218 218
    mOrigPos = getCubitPositions(mNumLayers);
219
    mNumPuzzleFaces = getNumFaces();
219
    mNumPuzzleFaces = getNumPuzzleFaces();
220 220
    mRowOffsets = new float[mNumPuzzleFaces][3];
221 221
    mTmp = new float[4];
222 222
    mNumAxis = mAxis.length;
......
283 283
    int index = getSolvedFunctionIndex();
284 284
    mSolved = new TwistyObjectSolved(this,mOrigPos,index);
285 285
    mSolved.setupSolvedQuats(getSolvedQuats());
286
    mSolved.setPuzzleFaceColor(mColorTable);
286 287

  
287 288
    mEffects.apply(quatEffect);
288 289
    mEffects.apply(scaleEffect);
......
1278 1279
    }
1279 1280

  
1280 1281
///////////////////////////////////////////////////////////////////////////////////////////////////
1282
// this doesn't have to return the real, displayed color - but the default one (from Shape classes).
1283
// The real displayed color can be different because of the sticker color overrides in 'Config'.
1281 1284

  
1282 1285
  int getCubitFaceColor(int cubit, int face)
1283 1286
    {
......
1478 1481
      {
1479 1482
      createTexture(mTextureBorderMultiplier,mTextureCornerMultiplier);
1480 1483
      setTexture();
1484
      mSolved.setPuzzleFaceColor(mColorTable);
1481 1485
      }
1482 1486
    }
1483 1487

  
......
2177 2181
  // not only for JSON
2178 2182
  public abstract Static3D[] getRotationAxis();
2179 2183
  public abstract int[][] getBasicAngles();
2180
  public abstract int getNumFaces();
2184
  public abstract int getNumPuzzleFaces();
2181 2185
  public abstract int getFOV();
2182 2186
  public abstract String[][] getTutorials();
2183 2187
  }
src/main/java/org/distorted/objectlib/main/TwistyObjectSolved.java
44 44
    };
45 45

  
46 46
  private int[][] mSurfaceTable;
47
  private int[][] mFaceColorTable;
47
  private int[][] mTmpFaceColorTable;
48 48
  private int[][] mCubitFaceToSurfaceMap;
49
  private int[][] mCubitFaceColor;
49
  private int[][] mCubitFaceToPuzzleFaceMap;
50
  private int[] mPuzzleFaceColor;
50 51

  
51 52
///////////////////////////////////////////////////////////////////////////////////////////////////
52 53
// remember about the double cover or unit quaternions!
......
324 325
    int numVariants = mParent.getNumCubitVariants(numLayers);
325 326
    ObjectShape[] shapes = new ObjectShape[numVariants];
326 327
    mCubitFaceToSurfaceMap = new int[numCubits][];
327
    mCubitFaceColor = new int[numCubits][];
328
    mCubitFaceToPuzzleFaceMap = new int[numCubits][];
328 329

  
329 330
    for(int v=0; v<numVariants; v++) shapes[v] = mParent.getObjectShape(v);
330 331

  
......
335 336
      int variant = mParent.getCubitVariant(c,numLayers);
336 337
      ObjectShape s = shapes[variant];
337 338
      int numFaces = s.getNumFaces();
338
      mCubitFaceColor[c] = new int[numFaces];
339
      mCubitFaceToPuzzleFaceMap[c] = new int[numFaces];
339 340
      mCubitFaceToSurfaceMap[c] = new int[numFaces];
340 341
      for(int f=0; f<numFaces; f++) mCubitFaceToSurfaceMap[c][f] = -1;
341 342

  
......
358 359

  
359 360
      for(int f=0; f<numFaces; f++)
360 361
        {
361
        mCubitFaceColor[c][f] = mParent.getCubitFaceColor(c,f);
362
        mCubitFaceToPuzzleFaceMap[c][f] = mParent.getCubitFaceColor(c,f);
362 363

  
363
        if( !mParent.faceIsOuter(c,f) ) continue;
364
        //android.util.Log.e("D", "cubit "+c+" face "+f+" puzzle face: "+ mCubitFaceToPuzzleFaceMap[c][f]);
364 365

  
365
        //android.util.Log.e("D", "cubit "+c+" face "+f);
366
        if( !mParent.faceIsOuter(c,f) ) continue;
366 367

  
367 368
        float[] surface  = new float[4];
368 369
        float[] rotPoint = new float[4];
......
400 401
            {
401 402
            float[] ts = multiplySurface(surface, mObjectQuats[q]);
402 403
            int ind = adjoinNewSurface(tmpSurfaces,ts);
403
/*
404
            if( ind==6 || ind==5 )
405
              {
406
              android.util.Log.e("D","SURFACE "+ind+": "+ts[0]+" "+ts[1]+" "+ts[2]+" "+ts[3] );
407
              }
408
*/
409 404
            indices[q] = ind;
410 405
            }
411 406

  
......
572 567
  private int surfaceColor(int filled, int surface)
573 568
    {
574 569
    for(int s=0; s<filled; s++)
575
      if( mFaceColorTable[s][0] == surface ) return mFaceColorTable[s][1];
570
      if( mTmpFaceColorTable[s][0] == surface ) return mTmpFaceColorTable[s][1];
576 571

  
577
    return -1;
572
    return 0;
578 573
    }
579 574

  
580 575
///////////////////////////////////////////////////////////////////////////////////////////////////
......
582 577
  private boolean isSolved2(TwistyObjectCubit[] cubits)
583 578
    {
584 579
    int filled = 0;
585
    int max = mFaceColorTable.length;
580
    int max = mTmpFaceColorTable.length;
586 581

  
587 582
    for(int c=0; c<mNumCubits; c++)
588 583
      {
......
595 590

  
596 591
        if( initSurface>=0 )
597 592
          {
598
          int currSurface = mSurfaceTable[initSurface][quat];
599
          int currColor = mCubitFaceColor[c][f];
600
          int prevColor = surfaceColor(filled,currSurface);
593
          int puzzleFace = mCubitFaceToPuzzleFaceMap[c][f];
594
          int currSurface= mSurfaceTable[initSurface][quat];
595
          int currColor  = puzzleFace>=0 ? mPuzzleFaceColor[puzzleFace] : 0;
596
          int prevColor  = surfaceColor(filled,currSurface);
601 597

  
602
          if( prevColor<0 )
598
//android.util.Log.e("D", "cubit "+c+" face "+f+" puzzleFace: "+puzzleFace+" currColor: "+currColor+" prevColor: "+prevColor);
599

  
600
          if( prevColor==0 )
603 601
            {
604
            if( filled>=max ) return false;
605
            mFaceColorTable[filled][0] = currSurface;
606
            mFaceColorTable[filled][1] = currColor;
602
            if( filled>=max )
603
              {
604
              //android.util.Log.e("D", "false1");
605
              return false;
606
              }
607
            mTmpFaceColorTable[filled][0] = currSurface;
608
            mTmpFaceColorTable[filled][1] = currColor;
607 609
            prevColor = currColor;
608 610
            filled++;
609 611
            }
610 612

  
611
          if( prevColor!=currColor ) return false;
613
          if( prevColor!=currColor )
614
            {
615
            //android.util.Log.e("D", "false2");
616
            return false;
617
            }
612 618
          }
613 619
        }
614 620
      }
615 621

  
622
    // android.util.Log.e("D", "true");
616 623
    return true;
617 624
    }
618 625

  
......
697 704
    if( mFunctionIndex==2 )
698 705
      {
699 706
      computeSurfaceTable();
700
      int numFaces = parent.getNumFaces();
701
      mFaceColorTable = new int[numFaces][2];
707
      int numFaces = parent.getNumPuzzleFaces();
708
      mTmpFaceColorTable = new int[numFaces][2];
702 709
      }
703 710
    }
704 711

  
712
///////////////////////////////////////////////////////////////////////////////////////////////////
713

  
714
  void setPuzzleFaceColor(int[] color)
715
    {
716
    mPuzzleFaceColor = color;
717
    }
718

  
705 719
///////////////////////////////////////////////////////////////////////////////////////////////////
706 720

  
707 721
  boolean isSolved(TwistyObjectCubit[] cubits)
src/main/java/org/distorted/objectlib/shape/ShapeDiamond.java
55 55

  
56 56
///////////////////////////////////////////////////////////////////////////////////////////////////
57 57

  
58
  public final int getNumFaces()
58
  public final int getNumPuzzleFaces()
59 59
    {
60 60
    return NUM_FACES;
61 61
    }
src/main/java/org/distorted/objectlib/shape/ShapeDodecahedron.java
54 54

  
55 55
///////////////////////////////////////////////////////////////////////////////////////////////////
56 56

  
57
  public final int getNumFaces()
57
  public final int getNumPuzzleFaces()
58 58
    {
59 59
    return NUM_FACES;
60 60
    }
src/main/java/org/distorted/objectlib/shape/ShapeHexahedron.java
41 41

  
42 42
///////////////////////////////////////////////////////////////////////////////////////////////////
43 43

  
44
  public final int getNumFaces()
44
  public final int getNumPuzzleFaces()
45 45
    {
46 46
    return NUM_FACES;
47 47
    }
src/main/java/org/distorted/objectlib/shape/ShapeIcosahedron.java
63 63

  
64 64
///////////////////////////////////////////////////////////////////////////////////////////////////
65 65

  
66
  public final int getNumFaces()
66
  public final int getNumPuzzleFaces()
67 67
    {
68 68
    return NUM_FACES;
69 69
    }
src/main/java/org/distorted/objectlib/shape/ShapeOctahedron.java
42 42

  
43 43
///////////////////////////////////////////////////////////////////////////////////////////////////
44 44

  
45
  public final int getNumFaces()
45
  public final int getNumPuzzleFaces()
46 46
    {
47 47
    return NUM_FACES;
48 48
    }
src/main/java/org/distorted/objectlib/shape/ShapeTetrahedron.java
40 40

  
41 41
///////////////////////////////////////////////////////////////////////////////////////////////////
42 42

  
43
  public final int getNumFaces()
43
  public final int getNumPuzzleFaces()
44 44
    {
45 45
    return NUM_FACES;
46 46
    }
src/main/java/org/distorted/objectlib/touchcontrol/TouchControlSquare.java
35 35
    {
36 36
    super(object);
37 37

  
38
    mNumFaces = object.getNumFaces();
38
    mNumFaces = object.getNumPuzzleFaces();
39 39
    mFaceAxis = TouchControlHexahedron.FACE_AXIS;
40 40
    mTmp4  = new float[mNumFaces][4];
41 41
    mTmp2  = new float[mNumFaces][2];

Also available in: Unified diff