Project

General

Profile

Download (3.19 KB) Statistics
| Branch: | Tag: | Revision:

magiccube / src / main / java / org / distorted / objects / RubikObjectCategoriesDiff.java @ 988e3d33

1
///////////////////////////////////////////////////////////////////////////////////////////////////
2
// Copyright 2024 Leszek Koltunski                                                               //
3
//                                                                                               //
4
// This file is part of Magic Cube.                                                              //
5
//                                                                                               //
6
// Magic Cube is proprietary software licensed under an EULA which you should have received      //
7
// along with the code. If not, check https://distorted.org/magic/License-Magic-Cube.html        //
8
///////////////////////////////////////////////////////////////////////////////////////////////////
9

    
10
package org.distorted.objects;
11

    
12
import java.util.Arrays;
13

    
14
///////////////////////////////////////////////////////////////////////////////////////////////////
15

    
16
public class RubikObjectCategoriesDiff extends RubikObjectCategories
17
{
18
  private void buildSort(float[] data)
19
    {
20
    int numObjects = data.length;
21
    float[] sorted = new float[numObjects];
22
    System.arraycopy(data, 0, sorted, 0, numObjects);
23

    
24
    Arrays.sort(sorted);
25

    
26
    int[] categories = new int[numObjects];
27
    int numCategories = 0;
28

    
29
    for(int o=0; o<numObjects; o++)
30
      if( o==0 || (int)sorted[o-1] != (int)sorted[o] )
31
        {
32
        categories[numCategories] = (int)sorted[o];
33
        numCategories++;
34
        }
35

    
36
    int lastChange = -1;
37
    int curr = 0;
38
    int[] numInCategory = new int[numCategories];
39

    
40
    for(int o=0; o<numObjects; o++)
41
      if( o==numObjects-1 || (int)sorted[o] != (int)sorted[o+1] )
42
        {
43
        numInCategory[curr] = o-lastChange;
44
        curr++;
45
        lastChange = o;
46
        }
47

    
48
    mObjectIndices = new int[numCategories][];
49

    
50
    boolean[] taken = new boolean[numObjects];
51
    for(int i=0; i<numObjects; i++) taken[i] = false;
52

    
53
    for(int c=0; c<numCategories; c++)
54
      {
55
      mObjectIndices[c] = new int[numInCategory[c]];
56

    
57
      int cat = categories[c];
58
      int index = 0;
59

    
60
      for(int o=0; o<numObjects; o++)
61
        if( (int)sorted[o]==cat )
62
          for(int n=0; n<numObjects; n++)
63
            if( data[n]==sorted[o] && !taken[n] )
64
              {
65
              taken[n]=true;
66
              mObjectIndices[c][index++] = n;
67
              break;
68
              }
69
      }
70
    }
71

    
72
///////////////////////////////////////////////////////////////////////////////////////////////////
73

    
74
  void buildIndices()
75
    {
76
    int numObjects = RubikObjectList.getNumObjects();
77
    float[] diffs = new float[numObjects];
78

    
79
    for(int o=0; o<numObjects; o++)
80
      {
81
      RubikObject obj = RubikObjectList.getObject(o);
82
      diffs[o] = obj==null ? 0 : obj.getDifficulty();
83
      }
84

    
85
    buildSort(diffs);
86
    }
87

    
88
///////////////////////////////////////////////////////////////////////////////////////////////////
89

    
90
  void buildTitle()
91
    {
92
    mIconIDs = new int[mNumCategories];
93

    
94
    for(int t=0; t<mNumCategories; t++)
95
      {
96
      int obj = mObjectIndices[t][0];
97
      RubikObject object = RubikObjectList.getObject(obj);
98
      int difficulty = object==null ? 0 : (int)object.getDifficulty();
99
      mIconIDs[t] = DIFF_IMAGES[difficulty];
100
      }
101
    }
102
}
(4-4/7)