Project

General

Profile

« Previous | Next » 

Revision 8bfefd68

Added by Leszek Koltunski about 5 years ago

Split the DistortedNode class into two - DistortedNode and DistortedNodeData

View differences:

src/main/java/org/distorted/library/main/DistortedNode.java
25 25

  
26 26
import java.util.ArrayList;
27 27
import java.util.Collections;
28
import java.util.HashMap;
29 28

  
30 29
///////////////////////////////////////////////////////////////////////////////////////////////////
31 30
/**
......
45 44
  private static final int DETALL = 2;
46 45
  private static final int SORT   = 3;
47 46

  
48
  private ArrayList<DistortedNode> mChildren;
49
  private int[] mNumChildren;  // ==mChildren.length(), but we only create mChildren if the first one gets added
50

  
51 47
  private class Job
52 48
    {
53 49
    int type;
......
62 58

  
63 59
  private ArrayList<Job> mJobs = new ArrayList<>();
64 60

  
65
  private static HashMap<ArrayList<Long>,NodeData> mMapNodeID = new HashMap<>();
66
  private static long mNextNodeID =0;
61
  private ArrayList<DistortedNode> mChildren;
62
  private int[] mNumChildren;  // ==mChildren.length(), but we only create mChildren if the first one gets added
67 63

  
68 64
  private boolean mRenderWayOIT;
69 65
  private DistortedNode mParent;
......
72 68
  private DistortedEffects mEffects;
73 69
  private DistortedSurface mSurface;
74 70
  private DistortedRenderState mState;
75
  private NodeData mData;
71
  private DistortedNodeData mData;
76 72
  private int mFboW, mFboH, mFboDepthStencil;
77 73

  
78
  private class NodeData
79
    {
80
    final long ID;
81
    final ArrayList<Long> key;
82

  
83
    int numPointingNodes;
84
    long currTime;
85
    DistortedFramebuffer mFBO;
86

  
87
    NodeData(long id, ArrayList<Long> k)
88
      {
89
      ID              = id;
90
      key             = k;
91
      numPointingNodes= 1;
92
      currTime        =-1;
93
      mFBO            = null;
94
      }
95
    }
96

  
97
///////////////////////////////////////////////////////////////////////////////////////////////////
98

  
99
  static synchronized void onDestroy()
100
    {
101
    mNextNodeID = 0;
102
    mMapNodeID.clear();
103
    }
104

  
105 74
///////////////////////////////////////////////////////////////////////////////////////////////////
106 75

  
107 76
  public void markForDeletion()
108 77
    {
109
    if( --mData.numPointingNodes==0 )
78
    if( mData.removeData() )
110 79
      {
111
      mMapNodeID.remove(mData.key);
112

  
113
      if( mData.mFBO!=null )
114
        {
115
        mData.mFBO.markForDeletion();
116
        mData.mFBO = null;
117
        }
80
      mData.mFBO.markForDeletion();
81
      mData.mFBO = null;
118 82
      }
119 83

  
120 84
    mEffects.removeNode(this);
......
164 128
    return ret;
165 129
    }
166 130

  
167
///////////////////////////////////////////////////////////////////////////////////////////////////
168
// Debug - print all the Node IDs
169

  
170
  @SuppressWarnings("unused")
171
  void debug(int depth)
172
    {
173
    String tmp="";
174
    int i;
175

  
176
    for(i=0; i<depth; i++) tmp +="   ";
177
    tmp += ("NodeID="+mData.ID+" nodes pointing: "+mData.numPointingNodes+" surfaceID="+
178
            mSurface.getID()+" FBO="+(mData.mFBO==null ? "null":mData.mFBO.getID()))+
179
            " parent sID="+(mParent==null ? "null": (mParent.mSurface.getID()));
180

  
181
    android.util.Log.e("NODE", tmp);
182

  
183
    for(i=0; i<mNumChildren[0]; i++)
184
      mChildren.get(i).debug(depth+1);
185
    }
186

  
187
///////////////////////////////////////////////////////////////////////////////////////////////////
188
// Debug - print contents of the HashMap
189

  
190
  @SuppressWarnings("unused")
191
  static void debugMap()
192
    {
193
    NodeData tmp;
194

  
195
    for(ArrayList<Long> key: mMapNodeID.keySet())
196
      {
197
      tmp = mMapNodeID.get(key);
198
      android.util.Log.e("NODE", "NodeID: "+tmp.ID+" <-- "+key);
199
      }
200
    }
201

  
202
///////////////////////////////////////////////////////////////////////////////////////////////////
203

  
204
  private NodeData retData()
205
    {
206
    ArrayList<Long> newList = generateIDList();
207
    NodeData newData = mMapNodeID.get(newList);
208

  
209
    if( newData!=null )
210
      {
211
      newData.numPointingNodes++;
212
      }
213
    else
214
      {
215
      newData = new NodeData(++mNextNodeID,newList);
216
      mMapNodeID.put(newList,newData);
217
      }
218

  
219
    return newData;
220
    }
221

  
222 131
///////////////////////////////////////////////////////////////////////////////////////////////////
223 132
// tree isomorphism algorithm
224 133

  
225 134
  private void adjustIsomorphism()
226 135
    {
227
    NodeData newData = retData();
228
    boolean deleteOldFBO = false;
229
    boolean createNewFBO = false;
230

  
231
    if( --mData.numPointingNodes==0 )
232
      {
233
      mMapNodeID.remove(mData.key);
234
      if( mData.mFBO!=null ) deleteOldFBO=true;
235
      }
236
    if( mNumChildren[0]>0 && newData.mFBO==null )
237
      {
238
      createNewFBO = true;
239
      }
240
    if( mNumChildren[0]==0 && newData.mFBO!=null )
241
      {
242
      newData.mFBO.markForDeletion();
243
      android.util.Log.e("NODE", "ERROR!! this NodeData cannot possibly contain a non-null FBO!! "+newData.mFBO.getID() );
244
      newData.mFBO = null;
245
      }
136
    DistortedNodeData newData = DistortedNodeData.returnData(generateIDList());
137
    boolean deleteOldFBO = mData.removeData();
138
    boolean createNewFBO = (mNumChildren[0]>0 && newData.mFBO==null);
246 139

  
247 140
    if( deleteOldFBO && createNewFBO )
248 141
      {
249
      newData.mFBO = mData.mFBO;  // just copy over
142
      newData.mFBO = mData.mFBO;
250 143
      }
251 144
    else if( deleteOldFBO )
252 145
      {
......
325 218
    {
326 219
    int numRenders = 0;
327 220

  
328
    if( mNumChildren[0]>0 && mData.currTime!=currTime )
221
    if( mNumChildren[0]>0 && mData.notRenderedYetAtThisTime(currTime) )
329 222
      {
330
      mData.currTime = currTime;
331

  
332 223
      for (int i=0; i<mNumChildren[0]; i++)
333 224
        {
334 225
        numRenders += mChildren.get(i).renderRecursive(currTime);
......
413 304
    mFboH            = 0;  // mSurface's dimensions
414 305
    mFboDepthStencil = DistortedFramebuffer.DEPTH_NO_STENCIL;
415 306

  
416
    mData = retData();
307
    mData = DistortedNodeData.returnData(generateIDList());
417 308
    mEffects.newNode(this);
418 309
    }
419 310

  
......
482 373
      mNumChildren = new int[1];
483 374
      }
484 375

  
485
    mData = retData();
376
    mData = DistortedNodeData.returnData(generateIDList());
486 377
    mEffects.newNode(this);
487 378
    }
488 379

  

Also available in: Unified diff