Project

General

Profile

« Previous | Next » 

Revision c9f953c2

Added by Leszek Koltunski over 7 years ago

Node: Sort children IDs when generating their list for the Map of (List<Children IDs>,NodeData).
This makes two internal nodes with the same children always isomorphic, no matter what is their order.

View differences:

src/main/java/org/distorted/library/DistortedNode.java
20 20
package org.distorted.library;
21 21

  
22 22
import java.util.ArrayList;
23
import java.util.Collections;
23 24
import java.util.HashMap;
24 25

  
25 26
///////////////////////////////////////////////////////////////////////////////////////////////////
......
120 121
  private ArrayList<Long> generateIDList()
121 122
    {
122 123
    ArrayList<Long> ret = new ArrayList<>();
123
     
124
    ret.add( mSurface.getID() );
125 124

  
126 125
    if( mNumChildren[0]==0 )
127 126
      {
127
      // add a negative number so this leaf never gets confused with a internal node
128
      // with a single child that happens to have ID identical to some leaf's Effects ID.
128 129
      ret.add(-mEffects.getID());
129 130
      }
130

  
131
    DistortedNode node;
132
   
133
    for(int i=0; i<mNumChildren[0]; i++)
131
    else
134 132
      {
135
      node = mChildren.get(i);
136
      ret.add(node.mData.ID);
137
      }
133
      DistortedNode node;
138 134
   
135
      for(int i=0; i<mNumChildren[0]; i++)
136
        {
137
        node = mChildren.get(i);
138
        ret.add(node.mData.ID);
139
        }
140

  
141
      // A bit questionable decision here - we are sorting the children IDs, which means
142
      // that order in which we draw the children is going to be undefined (well, this is not
143
      // strictly speaking true - when rendering, if no postprocessing and isomorphism are
144
      // involved, we *DO* render the children in order they were added; if however there
145
      // are two internal nodes with the same list of identical children, just added in a
146
      // different order each time, then we consider them isomorphic, i.e. identical and only
147
      // render the first one. If then two children of such 'pseudo-isomorphic' nodes are at
148
      // exactly the same Z-height this might result in some unexpected sights).
149
      //
150
      // Reason: with the children being sorted by postprocessing buckets, the order is
151
      // undefined anyway (although only when postprocessing is applied).
152
      //
153
      // See the consequences in the 'Olympic' app - remove a few leaves and add them back in
154
      // different order. You will see the number of renders go back to the original 14.
155
      Collections.sort(ret);
156
      }
157

  
158
    ret.add( 0, mSurface.getID() );
159

  
139 160
    return ret;
140 161
    }
141 162

  

Also available in: Unified diff