Revision 3bbe4d67
Added by Leszek Koltunski about 4 years ago
src/main/java/org/distorted/library/effectqueue/EffectQueue.java | ||
---|---|---|
53 | 53 |
float[] mFloatUniforms; |
54 | 54 |
int[] mIntUniforms; |
55 | 55 |
|
56 |
private static long mNextID = 1; |
|
57 |
private static HashMap<ArrayList<Long>,Long> mMapID = new HashMap<>(); // maps lists of Effect IDs (longs) to a |
|
58 |
// single long - the queue ID. |
|
59 | 56 |
private long mID; |
60 | 57 |
private int mIndex; |
61 | 58 |
private boolean mCreated; |
... | ... | |
203 | 200 |
{ |
204 | 201 |
if( mNumEffects>0 ) |
205 | 202 |
{ |
203 |
HashMap<ArrayList<Long>,Long> map = InternalStackFrameList.getMap(); |
|
206 | 204 |
ArrayList<Long> list = new ArrayList<>(); |
207 |
for (int i = 0; i < mNumEffects; i++) list.add(mEffects[i].getID());
|
|
208 |
Long id = mMapID.get(list);
|
|
205 |
for (int i=0; i<mNumEffects; i++) list.add(mEffects[i].getID());
|
|
206 |
Long id = map.get(list);
|
|
209 | 207 |
|
210 | 208 |
if( id!=null ) |
211 | 209 |
{ |
... | ... | |
213 | 211 |
} |
214 | 212 |
else |
215 | 213 |
{ |
216 |
mMapID.put(list,mNextID);
|
|
217 |
mID = mNextID++;
|
|
214 |
mID = InternalStackFrameList.getNextQueueID();
|
|
215 |
map.put(list,mID);
|
|
218 | 216 |
} |
219 | 217 |
} |
220 | 218 |
else |
... | ... | |
244 | 242 |
return InternalStackFrameList.getMax(index); |
245 | 243 |
} |
246 | 244 |
|
247 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
248 |
|
|
249 |
public static void onDestroy() |
|
250 |
{ |
|
251 |
mNextID = 1; |
|
252 |
mMapID.clear(); |
|
253 |
} |
|
254 |
|
|
255 | 245 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
256 | 246 |
// this assumes 0<=effect |
257 | 247 |
|
src/main/java/org/distorted/library/main/DistortedLibrary.java | ||
---|---|---|
1133 | 1133 |
if( InternalStackFrameList.isInitialized() ) |
1134 | 1134 |
{ |
1135 | 1135 |
InternalStackFrameList.onDestroy(id); |
1136 |
InternalMaster.onDestroy(); |
|
1137 |
InternalOutputSurface.onDestroy(); |
|
1138 |
EffectQueue.onDestroy(); |
|
1139 |
Effect.onDestroy(); |
|
1140 |
DeferredJobs.onDestroy(); |
|
1136 |
|
|
1137 |
InternalOutputSurface.onDestroy(); // those three really destroy |
|
1138 |
Effect.onDestroy(); // static data that does not |
|
1139 |
DeferredJobs.onDestroy(); // need to be part of a frame |
|
1141 | 1140 |
|
1142 | 1141 |
mOITCompilationAttempted = false; |
1143 | 1142 |
} |
src/main/java/org/distorted/library/main/InternalMaster.java | ||
---|---|---|
19 | 19 |
|
20 | 20 |
package org.distorted.library.main; |
21 | 21 |
|
22 |
import java.util.ArrayList;
|
|
22 |
import java.util.Set;
|
|
23 | 23 |
|
24 | 24 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
25 | 25 |
/** |
... | ... | |
32 | 32 |
*/ |
33 | 33 |
public class InternalMaster |
34 | 34 |
{ |
35 |
private static ArrayList<Slave> mSlaves = new ArrayList<>(); |
|
36 |
|
|
37 | 35 |
public interface Slave |
38 | 36 |
{ |
39 | 37 |
void doWork(); |
... | ... | |
50 | 48 |
|
51 | 49 |
static boolean toDo() |
52 | 50 |
{ |
53 |
Slave slave;
|
|
54 |
int num = mSlaves.size();
|
|
51 |
Set<Slave> set = InternalStackFrameList.getSet();
|
|
52 |
int numSlaves = set.size();
|
|
55 | 53 |
|
56 |
try
|
|
54 |
if( numSlaves>0 )
|
|
57 | 55 |
{ |
58 |
for(int i=0; i<num; i++)
|
|
56 |
for(Slave slave: set)
|
|
59 | 57 |
{ |
60 |
slave = mSlaves.remove(0); |
|
61 |
|
|
62 |
if( slave!=null ) slave.doWork(); |
|
63 |
} |
|
64 |
} |
|
65 |
catch(IndexOutOfBoundsException ie) |
|
66 |
{ |
|
67 |
// onDestroy must have been called, ignore |
|
58 |
if( slave!=null ) slave.doWork(); |
|
59 |
} |
|
60 |
return true; |
|
68 | 61 |
} |
69 | 62 |
|
70 |
return ( num>0 );
|
|
63 |
return false;
|
|
71 | 64 |
} |
72 | 65 |
|
73 | 66 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
74 | 67 |
|
75 | 68 |
public static void newSlave(Slave s) |
76 | 69 |
{ |
77 |
int num = mSlaves.size(); |
|
78 |
boolean found = false; |
|
79 |
Slave tmp; |
|
80 |
|
|
81 |
try |
|
82 |
{ |
|
83 |
for(int i=0; i<num; i++) |
|
84 |
{ |
|
85 |
tmp = mSlaves.get(i); |
|
86 |
|
|
87 |
if( tmp==s ) |
|
88 |
{ |
|
89 |
found = true; |
|
90 |
break; |
|
91 |
} |
|
92 |
} |
|
93 |
} |
|
94 |
catch(IndexOutOfBoundsException ie) |
|
95 |
{ |
|
96 |
// onDestroy must have been called, ignore |
|
97 |
} |
|
98 |
|
|
99 |
if( !found ) mSlaves.add(s); |
|
100 |
} |
|
101 |
|
|
102 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
103 |
|
|
104 |
static void onDestroy() |
|
105 |
{ |
|
106 |
mSlaves.clear(); |
|
70 |
InternalStackFrameList.getSet().add(s); |
|
107 | 71 |
} |
108 | 72 |
} |
src/main/java/org/distorted/library/main/InternalStackFrame.java | ||
---|---|---|
23 | 23 |
|
24 | 24 |
import java.util.ArrayList; |
25 | 25 |
import java.util.HashMap; |
26 |
import java.util.HashSet; |
|
26 | 27 |
import java.util.LinkedList; |
28 |
import java.util.Set; |
|
27 | 29 |
|
28 | 30 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
29 | 31 |
|
... | ... | |
69 | 71 |
private HashMap<ArrayList<Long>, InternalNodeData> mMapNodeID; // InternalNodeData |
70 | 72 |
private long mNextNodeID; |
71 | 73 |
|
74 |
////////////////////////////////////////////////////////////////// |
|
75 |
private Set<InternalMaster.Slave> mSlaves; // InternalMaster |
|
76 |
|
|
77 |
////////////////////////////////////////////////////////////////// EffectQueue |
|
78 |
private long mNextQueueID; // |
|
79 |
private HashMap<ArrayList<Long>,Long> mMapID; // maps lists of Effect IDs (longs) |
|
80 |
// to a single long - the queue ID. |
|
81 |
|
|
72 | 82 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
73 | 83 |
|
74 | 84 |
InternalStackFrame(long taskID) |
... | ... | |
76 | 86 |
mDoneList = new LinkedList<>(); |
77 | 87 |
mToDoMap = new HashMap<>(); |
78 | 88 |
mMapNodeID = new HashMap<>(); |
89 |
mSlaves = new HashSet<>(); |
|
90 |
mMapID = new HashMap<>(); |
|
79 | 91 |
mNextEffectsID= 0; |
80 | 92 |
mNextClientID = 0; |
81 | 93 |
mNextSystemID = 0; |
82 | 94 |
mNextNodeID = 0; |
95 |
mNextQueueID = 1; |
|
83 | 96 |
mTaskId = taskID; |
84 | 97 |
mMax = new int[EffectType.LENGTH]; |
85 | 98 |
|
... | ... | |
285 | 298 |
return false; |
286 | 299 |
} |
287 | 300 |
|
301 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
302 |
|
|
303 |
public HashMap<ArrayList<Long>,Long> getMap() |
|
304 |
{ |
|
305 |
return mMapID; |
|
306 |
} |
|
307 |
|
|
308 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
309 |
|
|
310 |
public long getNextQueueID() |
|
311 |
{ |
|
312 |
mNextQueueID++; |
|
313 |
|
|
314 |
return mNextQueueID-1; |
|
315 |
} |
|
316 |
|
|
288 | 317 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
289 | 318 |
|
290 | 319 |
InternalNodeData getMapID(ArrayList<Long> key) |
... | ... | |
308 | 337 |
mMapNodeID.remove(key); |
309 | 338 |
} |
310 | 339 |
|
340 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
341 |
|
|
342 |
Set<InternalMaster.Slave> getSet() |
|
343 |
{ |
|
344 |
return mSlaves; |
|
345 |
} |
|
346 |
|
|
311 | 347 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
312 | 348 |
|
313 | 349 |
void debugLists(String frameMarker) |
src/main/java/org/distorted/library/main/InternalStackFrameList.java | ||
---|---|---|
22 | 22 |
import org.distorted.library.message.EffectMessageSender; |
23 | 23 |
|
24 | 24 |
import java.util.ArrayList; |
25 |
import java.util.HashMap; |
|
26 |
import java.util.Set; |
|
25 | 27 |
|
26 | 28 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
27 | 29 |
|
... | ... | |
250 | 252 |
mCurrentFrame.removeKeyFromMap(key); |
251 | 253 |
} |
252 | 254 |
|
255 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
256 |
|
|
257 |
static Set<InternalMaster.Slave> getSet() |
|
258 |
{ |
|
259 |
return mCurrentFrame.getSet(); |
|
260 |
} |
|
261 |
|
|
253 | 262 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
254 | 263 |
// PUBLIC API |
255 | 264 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
... | ... | |
279 | 288 |
{ |
280 | 289 |
return mCurrentFrame.setMax(index,max); |
281 | 290 |
} |
291 |
|
|
292 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
293 |
|
|
294 |
public static HashMap<ArrayList<Long>,Long> getMap() |
|
295 |
{ |
|
296 |
return mCurrentFrame.getMap(); |
|
297 |
} |
|
298 |
|
|
299 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
300 |
|
|
301 |
public static long getNextQueueID() |
|
302 |
{ |
|
303 |
return mCurrentFrame.getNextQueueID(); |
|
304 |
} |
|
305 |
|
|
306 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
307 |
|
|
282 | 308 |
} |
Also available in: Unified diff
Put new things to the StackFrame.