Project

General

Profile

« Previous | Next » 

Revision 8bfefd68

Added by Leszek Koltunski over 5 years ago

Split the DistortedNode class into two - DistortedNode and DistortedNodeData

View differences:

src/main/java/org/distorted/library/main/Distorted.java
231 231
  public static void onDestroy()
232 232
    {
233 233
    DistortedObject.onDestroy();
234
    DistortedNode.onDestroy();
234
    DistortedNodeData.onDestroy();
235 235
    DistortedEffects.onDestroy();
236 236
    DistortedMaster.onDestroy();
237 237
    DistortedOutputSurface.onDestroy();
src/main/java/org/distorted/library/main/DistortedEffects.java
854 854
 */
855 855
  public int abortAllEffects()
856 856
    {
857
    return mM.abortAll(true) + mV.abortAll(true) + mF.abortAll(true);
857
    return mM.abortAll(true) + mV.abortAll(true) + mF.abortAll(true) + mP.abortAll(true);
858 858
    }
859 859

  
860 860
///////////////////////////////////////////////////////////////////////////////////////////////////
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

  
src/main/java/org/distorted/library/main/DistortedNodeData.java
1
///////////////////////////////////////////////////////////////////////////////////////////////////
2
// Copyright 2019 Leszek Koltunski                                                               //
3
//                                                                                               //
4
// This file is part of Distorted.                                                               //
5
//                                                                                               //
6
// Distorted is free software: you can redistribute it and/or modify                             //
7
// it under the terms of the GNU General Public License as published by                          //
8
// the Free Software Foundation, either version 2 of the License, or                             //
9
// (at your option) any later version.                                                           //
10
//                                                                                               //
11
// Distorted is distributed in the hope that it will be useful,                                  //
12
// but WITHOUT ANY WARRANTY; without even the implied warranty of                                //
13
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the                                 //
14
// GNU General Public License for more details.                                                  //
15
//                                                                                               //
16
// You should have received a copy of the GNU General Public License                             //
17
// along with Distorted.  If not, see <http://www.gnu.org/licenses/>.                            //
18
///////////////////////////////////////////////////////////////////////////////////////////////////
19

  
20
package org.distorted.library.main;
21

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

  
25
///////////////////////////////////////////////////////////////////////////////////////////////////
26
/**
27
 * This is a member of DistortedNode. Makes sure two isomorphic Nodes only get rendered once.
28
 */
29
class DistortedNodeData
30
  {
31
  private static HashMap<ArrayList<Long>, DistortedNodeData> mMapNodeID = new HashMap<>();
32
  private static long mNextNodeID =0;
33

  
34
  private final ArrayList<Long> key;
35
  private int numPointingNodes;
36
  private long currTime;
37

  
38
  final long ID;
39
  DistortedFramebuffer mFBO;
40

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

  
43
  private DistortedNodeData(long id, ArrayList<Long> k)
44
    {
45
    ID              = id;
46
    key             = k;
47
    numPointingNodes= 1;
48
    currTime        =-1;
49
    mFBO            = null;
50
    }
51

  
52
///////////////////////////////////////////////////////////////////////////////////////////////////
53

  
54
  static synchronized void onDestroy()
55
    {
56
    mNextNodeID = 0;
57
    mMapNodeID.clear();
58
    }
59

  
60
///////////////////////////////////////////////////////////////////////////////////////////////////
61

  
62
  @SuppressWarnings("unused")
63
  static void debugMap()
64
    {
65
    DistortedNodeData tmp;
66

  
67
    for(ArrayList<Long> key: mMapNodeID.keySet())
68
      {
69
      tmp = mMapNodeID.get(key);
70
      android.util.Log.e("NodeData", "NodeID: "+tmp.ID+" <-- "+key);
71
      }
72
    }
73

  
74
///////////////////////////////////////////////////////////////////////////////////////////////////
75

  
76
  static DistortedNodeData returnData(ArrayList<Long> list)
77
    {
78
    DistortedNodeData newData = mMapNodeID.get(list);
79

  
80
    if( newData!=null )
81
      {
82
      newData.numPointingNodes++;
83
      }
84
    else
85
      {
86
      newData = new DistortedNodeData(++mNextNodeID,list);
87
      mMapNodeID.put(list,newData);
88
      }
89

  
90
    return newData;
91
    }
92

  
93
///////////////////////////////////////////////////////////////////////////////////////////////////
94

  
95
  boolean removeData()
96
    {
97
    if( --numPointingNodes==0 )
98
      {
99
      mMapNodeID.remove(key);
100

  
101
      if( mFBO!=null ) return true;
102
      }
103

  
104
    return false;
105
    }
106

  
107
///////////////////////////////////////////////////////////////////////////////////////////////////
108

  
109
  boolean notRenderedYetAtThisTime(long time)
110
    {
111
    if( currTime!=time )
112
      {
113
      currTime = time;
114
      return true;
115
      }
116

  
117
    return false;
118
    }
119
  }
src/main/java/org/distorted/library/main/EffectQueue.java
38 38
  private static final int DETACH = 2;
39 39
  private static final int DETALL = 3;
40 40

  
41
  int mNumEffects;      // 'ToBe' will be more than mNumEffects if doWork() hasn't
42
  int mNumEffectsToBe;  // added them yet (or less if it hasn't removed some yet)
41
  int mNumEffects;              // 'ToBe' will be more than mNumEffects if doWork() hasn't
42
  private int mNumEffectsToBe;  // added them yet (or less if it hasn't removed some yet)
43 43
  float[] mUniforms;
44 44
  long[] mCurrentDuration;
45 45
  Effect[] mEffects;
......
101 101
// (this is a speedup: then both queues can be applied once, which seriously speeds up stuff -
102 102
// especially important in case of postprocessing)
103 103

  
104
  void regenerateIDandSort()
104
  private void regenerateIDandSort()
105 105
    {
106 106
    if( mNumEffects>0 )
107 107
      {

Also available in: Unified diff