Revision ada90d33
Added by Leszek Koltunski over 8 years ago
src/main/java/org/distorted/library/DistortedBitmap.java | ||
---|---|---|
81 | 81 |
|
82 | 82 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
83 | 83 |
/** |
84 |
* Copy constructor used to create a DistortedBitmap based on various parts of another object. |
|
85 |
* <p> |
|
86 |
* Whatever we do not clone gets created just like in the default constructor. |
|
87 |
* |
|
88 |
* @param db Source object to create our object from |
|
89 |
* @param flags A bitmask of values specifying what to copy. |
|
90 |
* For example, CLONE_BITMAP | CLONE_MATRIX. |
|
84 |
* {@see DistortedObject#DistortedObject(DistortedObject,flags)} |
|
91 | 85 |
*/ |
92 | 86 |
public DistortedBitmap(DistortedBitmap db, int flags) |
93 | 87 |
{ |
94 | 88 |
super(db,flags); |
95 | 89 |
} |
96 | 90 |
|
91 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
92 |
|
|
93 |
protected DistortedObject deepCopy(int flags) |
|
94 |
{ |
|
95 |
return new DistortedBitmap(this,flags); |
|
96 |
} |
|
97 |
|
|
97 | 98 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
98 | 99 |
} |
99 | 100 |
|
src/main/java/org/distorted/library/DistortedCubes.java | ||
---|---|---|
67 | 67 |
for(int i=reallen; i<len; i++) desc += "0"; |
68 | 68 |
} |
69 | 69 |
|
70 |
if( desc.indexOf("1")>=0 )
|
|
70 |
if( desc.contains("1") )
|
|
71 | 71 |
{ |
72 | 72 |
Cs = cols; |
73 | 73 |
Rs = len/cols; |
... | ... | |
92 | 92 |
|
93 | 93 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
94 | 94 |
/** |
95 |
* Copy constructor used to create a DistortedCubes based on various parts of another object. |
|
96 |
* <p> |
|
97 |
* Whatever we do not clone gets created just like in the default constructor. |
|
98 |
* |
|
99 |
* @param dc Source object to create our object from |
|
100 |
* @param flags A bitmask of values specifying what to copy. |
|
101 |
* For example, CLONE_BITMAP | CLONE_MATRIX. |
|
95 |
* {@see DistortedObject#DistortedObject(DistortedObject,flags)} |
|
102 | 96 |
*/ |
103 | 97 |
public DistortedCubes(DistortedCubes dc, int flags) |
104 | 98 |
{ |
105 | 99 |
super(dc,flags); |
106 | 100 |
} |
107 | 101 |
|
102 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
103 |
|
|
104 |
protected DistortedObject deepCopy(int flags) |
|
105 |
{ |
|
106 |
return new DistortedCubes(this,flags); |
|
107 |
} |
|
108 |
|
|
108 | 109 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
109 | 110 |
} |
src/main/java/org/distorted/library/DistortedNode.java | ||
---|---|---|
299 | 299 |
public DistortedNode(DistortedNode node, int flags) |
300 | 300 |
{ |
301 | 301 |
mParent = null; |
302 |
|
|
303 |
if( node.mObject instanceof DistortedBitmap) |
|
304 |
mObject = new DistortedBitmap( (DistortedBitmap)node.mObject, flags); |
|
305 |
else if( node.mObject instanceof DistortedCubes) |
|
306 |
mObject = new DistortedCubes( (DistortedCubes)node.mObject, flags); |
|
307 |
else |
|
308 |
throw new RuntimeException("unsupported type of object!"); |
|
302 |
mObject = node.mObject.deepCopy(flags); |
|
309 | 303 |
|
310 | 304 |
if( (flags & Distorted.CLONE_CHILDREN) != 0 ) |
311 | 305 |
{ |
src/main/java/org/distorted/library/DistortedObject.java | ||
---|---|---|
30 | 30 |
|
31 | 31 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
32 | 32 |
|
33 |
/** |
|
34 |
* Default empty constructor so that derived classes can call it |
|
35 |
*/ |
|
36 |
public DistortedObject() |
|
37 |
{ |
|
38 |
|
|
39 |
} |
|
40 |
|
|
41 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
42 |
/** |
|
43 |
* Copy constructor used to create a DistortedObject based on various parts of another object. |
|
44 |
* <p> |
|
45 |
* Whatever we do not clone gets created just like in the default constructor. |
|
46 |
* |
|
47 |
* @param dc Source object to create our object from |
|
48 |
* @param flags A bitmask of values specifying what to copy. |
|
49 |
* For example, CLONE_BITMAP | CLONE_MATRIX. |
|
50 |
*/ |
|
51 |
public DistortedObject(DistortedObject dc, int flags) |
|
52 |
{ |
|
53 |
initializeEffectLists(dc,flags); |
|
54 |
|
|
55 |
mID = DistortedObjectList.add(this); |
|
56 |
|
|
57 |
mSizeX = dc.mSizeX; |
|
58 |
mSizeY = dc.mSizeY; |
|
59 |
mSizeZ = dc.mSizeZ; |
|
60 |
mSize = dc.mSize; |
|
61 |
mGrid = dc.mGrid; |
|
62 |
|
|
63 |
if( (flags & Distorted.CLONE_BITMAP) != 0 ) |
|
64 |
{ |
|
65 |
mTextureDataH = dc.mTextureDataH; |
|
66 |
mBmp = dc.mBmp; |
|
67 |
mBitmapSet = dc.mBitmapSet; |
|
68 |
} |
|
69 |
else |
|
70 |
{ |
|
71 |
mTextureDataH = new int[1]; |
|
72 |
mTextureDataH[0]= 0; |
|
73 |
mBitmapSet = new boolean[1]; |
|
74 |
mBitmapSet[0] = false; |
|
75 |
mBmp = new Bitmap[1]; |
|
76 |
mBmp[0] = null; |
|
77 |
|
|
78 |
if( Distorted.isInitialized() ) resetTexture(); |
|
79 |
} |
|
80 |
} |
|
33 |
protected abstract DistortedObject deepCopy(int flags); |
|
81 | 34 |
|
82 | 35 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
83 | 36 |
|
... | ... | |
213 | 166 |
return mBmp==null ? 0 : mBmp.hashCode(); |
214 | 167 |
} |
215 | 168 |
|
169 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
170 |
|
|
171 |
/** |
|
172 |
* Default empty constructor so that derived classes can call it |
|
173 |
*/ |
|
174 |
public DistortedObject() |
|
175 |
{ |
|
176 |
|
|
177 |
} |
|
178 |
|
|
179 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
180 |
/** |
|
181 |
* Copy constructor used to create a DistortedObject based on various parts of another object. |
|
182 |
* <p> |
|
183 |
* Whatever we do not clone gets created just like in the default constructor. |
|
184 |
* |
|
185 |
* @param dc Source object to create our object from |
|
186 |
* @param flags A bitmask of values specifying what to copy. |
|
187 |
* For example, CLONE_BITMAP | CLONE_MATRIX. |
|
188 |
*/ |
|
189 |
public DistortedObject(DistortedObject dc, int flags) |
|
190 |
{ |
|
191 |
initializeEffectLists(dc,flags); |
|
192 |
|
|
193 |
mID = DistortedObjectList.add(this); |
|
194 |
|
|
195 |
mSizeX = dc.mSizeX; |
|
196 |
mSizeY = dc.mSizeY; |
|
197 |
mSizeZ = dc.mSizeZ; |
|
198 |
mSize = dc.mSize; |
|
199 |
mGrid = dc.mGrid; |
|
200 |
|
|
201 |
if( (flags & Distorted.CLONE_BITMAP) != 0 ) |
|
202 |
{ |
|
203 |
mTextureDataH = dc.mTextureDataH; |
|
204 |
mBmp = dc.mBmp; |
|
205 |
mBitmapSet = dc.mBitmapSet; |
|
206 |
} |
|
207 |
else |
|
208 |
{ |
|
209 |
mTextureDataH = new int[1]; |
|
210 |
mTextureDataH[0]= 0; |
|
211 |
mBitmapSet = new boolean[1]; |
|
212 |
mBitmapSet[0] = false; |
|
213 |
mBmp = new Bitmap[1]; |
|
214 |
mBmp[0] = null; |
|
215 |
|
|
216 |
if( Distorted.isInitialized() ) resetTexture(); |
|
217 |
} |
|
218 |
} |
|
219 |
|
|
216 | 220 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
217 | 221 |
/** |
218 | 222 |
* Draw the DistortedObject to the location specified by current Matrix effects. |
src/main/java/org/distorted/library/DistortedObjectList.java | ||
---|---|---|
10 | 10 |
final class DistortedObjectList |
11 | 11 |
{ |
12 | 12 |
private static long id =0; |
13 |
private static HashMap<Long,DistortedObject> mBitmaps = new HashMap<>();
|
|
13 |
private static HashMap<Long,DistortedObject> mObjects = new HashMap<>();
|
|
14 | 14 |
|
15 | 15 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
16 | 16 |
|
17 |
static synchronized long add(DistortedObject dBmp)
|
|
17 |
static synchronized long add(DistortedObject obj)
|
|
18 | 18 |
{ |
19 | 19 |
long ret = id++; |
20 |
mBitmaps.put(ret,dBmp);
|
|
20 |
mObjects.put(ret,obj);
|
|
21 | 21 |
return ret; |
22 | 22 |
} |
23 | 23 |
|
24 | 24 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
25 | 25 |
|
26 |
static synchronized void remove(DistortedObject dBmp)
|
|
26 |
static synchronized void remove(DistortedObject obj)
|
|
27 | 27 |
{ |
28 |
mBitmaps.remove(dBmp);
|
|
28 |
mObjects.remove(obj);
|
|
29 | 29 |
} |
30 | 30 |
|
31 | 31 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
32 | 32 |
|
33 | 33 |
static DistortedObject get(long id) |
34 | 34 |
{ |
35 |
return mBitmaps.get(id);
|
|
35 |
return mObjects.get(id);
|
|
36 | 36 |
} |
37 | 37 |
|
38 | 38 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
39 | 39 |
|
40 | 40 |
static synchronized void reset() |
41 | 41 |
{ |
42 |
for(long id: mBitmaps.keySet())
|
|
42 |
for(long id: mObjects.keySet())
|
|
43 | 43 |
{ |
44 | 44 |
get(id).resetTexture(); |
45 | 45 |
} |
... | ... | |
49 | 49 |
|
50 | 50 |
static synchronized void release() |
51 | 51 |
{ |
52 |
for(long id: mBitmaps.keySet())
|
|
52 |
for(long id: mObjects.keySet())
|
|
53 | 53 |
{ |
54 | 54 |
get(id).releasePriv(); |
55 | 55 |
} |
56 | 56 |
|
57 |
mBitmaps.clear();
|
|
57 |
mObjects.clear();
|
|
58 | 58 |
id = 0; |
59 | 59 |
} |
60 | 60 |
|
Also available in: Unified diff
Make deep copying DistortedObjects (needed in DistortedNode) standard.