Project

General

Profile

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

library / src / main / java / org / distorted / library / DistortedMaster.java @ efe3d8fe

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;
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

    
80
  static void onDestroy()
81
    {
82
    mSlaves.clear();
83
    }
84
  }
(6-6/24)