1
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
2
|
// Copyright 2016 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
|
|
24
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
25
|
/**
|
26
|
* This static class handles assigning jobs to other classes. It does it once, at the beginning of
|
27
|
* each frame.
|
28
|
*/
|
29
|
class DistortedMaster
|
30
|
{
|
31
|
private static ArrayList<DistortedSlave> mSlaves = new ArrayList<>();
|
32
|
|
33
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
34
|
|
35
|
private DistortedMaster()
|
36
|
{
|
37
|
|
38
|
}
|
39
|
|
40
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
41
|
|
42
|
static boolean toDo()
|
43
|
{
|
44
|
DistortedSlave slave;
|
45
|
int num = mSlaves.size();
|
46
|
|
47
|
for(int i=0; i<num; i++)
|
48
|
{
|
49
|
slave = mSlaves.remove(0);
|
50
|
slave.doWork();
|
51
|
}
|
52
|
|
53
|
return ( num>0 );
|
54
|
}
|
55
|
|
56
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
57
|
|
58
|
static void newSlave(DistortedSlave s)
|
59
|
{
|
60
|
int num = mSlaves.size();
|
61
|
boolean found = false;
|
62
|
DistortedSlave tmp;
|
63
|
|
64
|
for(int i=0; i<num; i++)
|
65
|
{
|
66
|
tmp = mSlaves.get(i);
|
67
|
|
68
|
if( tmp==s )
|
69
|
{
|
70
|
found = true;
|
71
|
break;
|
72
|
}
|
73
|
}
|
74
|
|
75
|
if( !found ) mSlaves.add(s);
|
76
|
}
|
77
|
|
78
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
79
|
// can make this logarithmic but the typical number of children is very small anyway
|
80
|
|
81
|
static void addSorted(ArrayList<DistortedNode> mChildren, DistortedNode newChild)
|
82
|
{
|
83
|
DistortedNode child;
|
84
|
DistortedEffects effects;
|
85
|
int i,num = mChildren.size();
|
86
|
long bucket, newBucket;
|
87
|
|
88
|
effects = newChild.getEffects();
|
89
|
newBucket = effects.getBucket();
|
90
|
|
91
|
for(i=0; i<num; i++)
|
92
|
{
|
93
|
child = mChildren.get(i);
|
94
|
effects= child.getEffects();
|
95
|
bucket = effects.getBucket();
|
96
|
|
97
|
if( bucket>newBucket ) break;
|
98
|
}
|
99
|
|
100
|
mChildren.add(i,newChild);
|
101
|
|
102
|
//android.util.Log.e("newChild", "newBucket="+newBucket+" new child at "+i+" total num ="+num);
|
103
|
}
|
104
|
|
105
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
106
|
|
107
|
static void onDestroy()
|
108
|
{
|
109
|
mSlaves.clear();
|
110
|
}
|
111
|
}
|