Project

General

Profile

Download (3.74 KB) Statistics
| Branch: | Revision:

library / src / main / java / org / distorted / library / main / InternalMaster.java @ 178983f4

1 c204c69d leszek
///////////////////////////////////////////////////////////////////////////////////////////////////
2 2e569ff6 Leszek Koltunski
// Copyright 2016 Leszek Koltunski  leszek@koltunski.pl                                          //
3 c204c69d leszek
//                                                                                               //
4 46b572b5 Leszek Koltunski
// This file is part of Distorted.                                                               //
5 c204c69d leszek
//                                                                                               //
6 2e569ff6 Leszek Koltunski
// 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 c204c69d leszek
//                                                                                               //
11 2e569ff6 Leszek Koltunski
// This library is distributed in the hope that it will be useful,                               //
12 c204c69d leszek
// but WITHOUT ANY WARRANTY; without even the implied warranty of                                //
13 2e569ff6 Leszek Koltunski
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU                             //
14
// Lesser General Public License for more details.                                               //
15 c204c69d leszek
//                                                                                               //
16 2e569ff6 Leszek Koltunski
// 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 c204c69d leszek
///////////////////////////////////////////////////////////////////////////////////////////////////
20
21 fe82a979 Leszek Koltunski
package org.distorted.library.main;
22 c204c69d leszek
23 fb001aff Leszek Koltunski
import java.util.ArrayList;
24 efe3d8fe leszek
25 c204c69d leszek
///////////////////////////////////////////////////////////////////////////////////////////////////
26
/**
27 efe3d8fe leszek
 * This static class handles assigning jobs to other classes. It does it once, at the beginning of
28
 * each frame.
29 86d322b5 Leszek Koltunski
 * <p>
30
 * Not part of public API, do not document (public only because has to be used in PostprocessEffects)
31
 *
32
 * @y.exclude
33 c204c69d leszek
 */
34 7602a827 Leszek Koltunski
public class InternalMaster
35 c204c69d leszek
  {
36 11c187c0 Leszek Koltunski
  /**
37
   * Not part of public API, do not document (public only because has to be used in PostprocessEffects)
38
   *
39
   * @y.exclude
40
   */
41 86d322b5 Leszek Koltunski
  public interface Slave
42
    {
43
    void doWork();
44
    }
45 efe3d8fe leszek
46
///////////////////////////////////////////////////////////////////////////////////////////////////
47
48 7602a827 Leszek Koltunski
  private InternalMaster()
49 efe3d8fe leszek
    {
50
51
    }
52
53
///////////////////////////////////////////////////////////////////////////////////////////////////
54
55
  static boolean toDo()
56
    {
57 fb001aff Leszek Koltunski
    Slave slave;
58
    ArrayList<Slave> list = InternalStackFrameList.getSet();
59
    int numSlaves = list.size();
60 efe3d8fe leszek
61 fb001aff Leszek Koltunski
    try
62 efe3d8fe leszek
      {
63 fb001aff Leszek Koltunski
      for(int i=0; i<numSlaves; i++)
64 bd4b36be Leszek Koltunski
        {
65 fb001aff Leszek Koltunski
        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 efe3d8fe leszek
      }
73
74 fb001aff Leszek Koltunski
    return numSlaves>0;
75 efe3d8fe leszek
    }
76
77
///////////////////////////////////////////////////////////////////////////////////////////////////
78 13981586 Leszek Koltunski
79 86d322b5 Leszek Koltunski
  public static void newSlave(Slave s)
80 efe3d8fe leszek
    {
81 fb001aff Leszek Koltunski
    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 efe3d8fe leszek
    }
106 c204c69d leszek
  }