Project

General

Profile

« Previous | Next » 

Revision 8e34674e

Added by Leszek Koltunski over 7 years ago

Move the *List classes into static members of DistortedFramebuffer and DistortedObject.

View differences:

src/main/java/org/distorted/library/DistortedObject.java
32 32
import org.distorted.library.type.Data5D;
33 33
import org.distorted.library.type.Static3D;
34 34

  
35
import java.util.HashMap;
36

  
35 37
///////////////////////////////////////////////////////////////////////////////////////////////////
36 38
/**
37 39
 * All Objects to which Distorted Graphics effects can be applied need to be extended from here.
40
 *
41
 * Just like in DistortedNode and DistortedFramebuffer, we need to have a static list of all
42
 * DistortedObjects currently created by the application so that we can implement the 'mark for
43
 * deletion now - actually delete on next render' thing.
44
 * We need to be able to quickly retrieve an Object by its ID, thus a HashMap.
38 45
 */
39 46
public abstract class DistortedObject 
40 47
  {
48
  private static long mNextID =0;
49
  private static HashMap<Long,DistortedObject> mObjects = new HashMap<>();
50

  
41 51
  private EffectQueueMatrix    mM;
42 52
  private EffectQueueFragment  mF;
43 53
  private EffectQueueVertex    mV;
......
82 92
    mSizeY= y;
83 93
    mSizeZ= z;
84 94

  
85
    mID             = DistortedObjectList.add(this);
95
    mID = mNextID++;
96
    mObjects.put(mID,this);
97

  
86 98
    mTextureDataH   = new int[1];
87 99
    mTextureDataH[0]= 0;
88 100
    mBmp            = new Bitmap[1];
......
137 149
// this will be called on startup and every time OpenGL context has been lost
138 150
// also call this from the constructor if the OpenGL context has been created already.
139 151
    
140
  void resetTexture()
152
  private void resetTexture()
141 153
    {
142 154
    if( mTextureDataH!=null )
143 155
      {
......
161 173
   
162 174
  void drawPriv(long currTime, DistortedFramebuffer df)
163 175
    {
164
    DistortedFramebufferList.deleteAllMarked();
176
    DistortedFramebuffer.deleteAllMarked();
165 177

  
166 178
    GLES20.glViewport(0, 0, df.mWidth, df.mHeight);
167 179
      
......
190 202
    
191 203
///////////////////////////////////////////////////////////////////////////////////////////////////
192 204
   
193
  void releasePriv()
205
  private void releasePriv()
194 206
    {
195
    if( matrixCloned  ==false) mM.abortAll(false);
196
    if( vertexCloned  ==false) mV.abortAll(false);
197
    if( fragmentCloned==false) mF.abortAll(false);
207
    if( !matrixCloned  ) mM.abortAll(false);
208
    if( !vertexCloned  ) mV.abortAll(false);
209
    if( !fragmentCloned) mF.abortAll(false);
198 210

  
199 211
    mBmp          = null;
200 212
    mGrid         = null;
......
207 219
///////////////////////////////////////////////////////////////////////////////////////////////////
208 220

  
209 221
  long getBitmapID()
222
    {
223
    return mBmp==null ? 0 : mBmp.hashCode();
224
    }
225

  
226
///////////////////////////////////////////////////////////////////////////////////////////////////
227

  
228
  static synchronized void reset()
229
    {
230
    for(long id: mObjects.keySet())
210 231
      {
211
      return mBmp==null ? 0 : mBmp.hashCode();
232
      mObjects.get(id).resetTexture();
233
      }
234
    }
235

  
236
///////////////////////////////////////////////////////////////////////////////////////////////////
237

  
238
  static synchronized void release()
239
    {
240
    for(long id: mObjects.keySet())
241
      {
242
      mObjects.get(id).releasePriv();
212 243
      }
213 244

  
245
    mObjects.clear();
246
    mNextID = 0;
247
    }
248

  
249
///////////////////////////////////////////////////////////////////////////////////////////////////
250
// PUBLIC API
214 251
///////////////////////////////////////////////////////////////////////////////////////////////////
215 252
/**
216 253
 * Default empty constructor so that derived classes can call it
......
236 273
    {
237 274
    initializeEffectLists(dc,flags);
238 275

  
239
    mID = DistortedObjectList.add(this);
276
    mID = mNextID++;
277
    mObjects.put(mID,this);
240 278

  
241 279
    mSizeX = dc.mSizeX;
242 280
    mSizeY = dc.mSizeY;
......
284 322
/**
285 323
 * Releases all resources.
286 324
 */
287
  public synchronized void release()
325
  public synchronized void delete()
288 326
    {
289 327
    releasePriv();
290
    DistortedObjectList.remove(this);
328
    mObjects.remove(this);
291 329
    }
292 330

  
293 331
///////////////////////////////////////////////////////////////////////////////////////////////////

Also available in: Unified diff