1
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
2
|
// Copyright 2016 Leszek Koltunski leszek@koltunski.pl //
|
3
|
// //
|
4
|
// This file is part of Distorted. //
|
5
|
// //
|
6
|
// This library is free software; you can redistribute it and/or //
|
7
|
// modify it under the terms of the GNU Lesser General Public //
|
8
|
// License as published by the Free Software Foundation; either //
|
9
|
// version 2.1 of the License, or (at your option) any later version. //
|
10
|
// //
|
11
|
// This library 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 GNU //
|
14
|
// Lesser General Public License for more details. //
|
15
|
// //
|
16
|
// You should have received a copy of the GNU Lesser General Public //
|
17
|
// License along with this library; if not, write to the Free Software //
|
18
|
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA //
|
19
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
20
|
|
21
|
package org.distorted.library.main;
|
22
|
|
23
|
import java.util.ArrayList;
|
24
|
|
25
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
26
|
/**
|
27
|
* This static class handles assigning jobs to other classes. It does it once, at the beginning of
|
28
|
* each frame.
|
29
|
* <p>
|
30
|
* Not part of public API, do not document (public only because has to be used in PostprocessEffects)
|
31
|
*
|
32
|
* @y.exclude
|
33
|
*/
|
34
|
public class InternalMaster
|
35
|
{
|
36
|
/**
|
37
|
* Not part of public API, do not document (public only because has to be used in PostprocessEffects)
|
38
|
*
|
39
|
* @y.exclude
|
40
|
*/
|
41
|
public interface Slave
|
42
|
{
|
43
|
void doWork();
|
44
|
}
|
45
|
|
46
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
47
|
|
48
|
private InternalMaster()
|
49
|
{
|
50
|
|
51
|
}
|
52
|
|
53
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
54
|
|
55
|
static boolean toDo()
|
56
|
{
|
57
|
Slave slave;
|
58
|
ArrayList<Slave> list = InternalStackFrameList.getSet();
|
59
|
int numSlaves = list.size();
|
60
|
|
61
|
try
|
62
|
{
|
63
|
for(int i=0; i<numSlaves; i++)
|
64
|
{
|
65
|
slave = list.remove(0);
|
66
|
if( slave!=null ) slave.doWork();
|
67
|
}
|
68
|
}
|
69
|
catch(IndexOutOfBoundsException ie)
|
70
|
{
|
71
|
// onDestroy must have been called, ignore
|
72
|
}
|
73
|
|
74
|
return numSlaves>0;
|
75
|
}
|
76
|
|
77
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
78
|
|
79
|
public static void newSlave(Slave s)
|
80
|
{
|
81
|
ArrayList<Slave> list = InternalStackFrameList.getSet();
|
82
|
int num = list.size();
|
83
|
boolean found = false;
|
84
|
Slave tmp;
|
85
|
|
86
|
try
|
87
|
{
|
88
|
for(int i=0; i<num; i++)
|
89
|
{
|
90
|
tmp = list.get(i);
|
91
|
|
92
|
if( tmp==s )
|
93
|
{
|
94
|
found = true;
|
95
|
break;
|
96
|
}
|
97
|
}
|
98
|
}
|
99
|
catch(IndexOutOfBoundsException ie)
|
100
|
{
|
101
|
// onDestroy must have been called, ignore
|
102
|
}
|
103
|
|
104
|
if( !found ) list.add(s);
|
105
|
}
|
106
|
}
|