Project

General

Profile

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

library / src / main / java / org / distorted / library / main / InternalStackFrameList.java @ b36227cd

1 9ec374e8 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
2
// Copyright 2020 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 30094332 Leszek Koltunski
import org.distorted.library.message.EffectMessageSender;
23
24 9ec374e8 Leszek Koltunski
import java.util.ArrayList;
25 3bbe4d67 Leszek Koltunski
import java.util.HashMap;
26 9ec374e8 Leszek Koltunski
27
///////////////////////////////////////////////////////////////////////////////////////////////////
28 11c187c0 Leszek Koltunski
/**
29
 * Implements a List of Frames (see InternalStackFrame)
30
 * <p>
31
 * Not part of public API, do not document
32
 *
33
 * @y.exclude
34
 */
35 9ec374e8 Leszek Koltunski
public class InternalStackFrameList
36
{
37
  private final static Object mLock = new Object();
38
  private static boolean mToDo = false;
39
  private static InternalStackFrame mCurrentFrame = null;
40 ddd46f8b Leszek Koltunski
  private static final ArrayList<InternalStackFrame> mFrameList = new ArrayList<>();
41 9ec374e8 Leszek Koltunski
42
///////////////////////////////////////////////////////////////////////////////////////////////////
43
44
  static void onCreate(long taskId)
45
    {
46
    int num = mFrameList.size();
47
    InternalStackFrame frame;
48
    boolean found = false;
49
50
    for(int i=0; i<num; i++)
51
      {
52
      frame = mFrameList.get(i);
53
54
      if( frame.getTaskId() == taskId )
55
        {
56
        mCurrentFrame = frame;
57
        found = true;
58
        break;
59
        }
60
      }
61
62
    if( !found )
63
      {
64
      synchronized(mLock)
65
        {
66
        mCurrentFrame = new InternalStackFrame(taskId);
67
        mFrameList.add(mCurrentFrame);
68
        }
69
      }
70
71
    mCurrentFrame.setInitialized(false);
72
    }
73
74
///////////////////////////////////////////////////////////////////////////////////////////////////
75
76
  static void onResume(long taskId)
77
    {
78
    int num = mFrameList.size();
79
    InternalStackFrame frame;
80
81
    for(int i=0; i<num; i++)
82
      {
83
      frame = mFrameList.get(i);
84
85
      if( frame.getTaskId() == taskId )
86
        {
87
        mCurrentFrame = frame;
88
        break;
89
        }
90
      }
91
92
    mCurrentFrame.setInitialized(false);
93
    }
94
95
///////////////////////////////////////////////////////////////////////////////////////////////////
96
97
  static void onPause(long taskId)
98
    {
99
    int num = mFrameList.size();
100
101
    for(int i=0; i<num; i++)
102
      {
103
      if( mFrameList.get(i).getTaskId() == taskId )
104
        {
105
        synchronized(mLock)
106
          {
107
          mCurrentFrame.onPause();
108
          InternalStackFrame.onPauseCommon();
109
          mToDo = true;
110
          }
111
112
        break;
113
        }
114
      }
115
    }
116
117
///////////////////////////////////////////////////////////////////////////////////////////////////
118
119
  static void onDestroy(long taskId)
120
    {
121
    int num = mFrameList.size();
122
123
    for(int i=0; i<num; i++)
124
      {
125
      if( mFrameList.get(i).getTaskId() == taskId )
126
        {
127
        synchronized(mLock)
128
          {
129
          mFrameList.remove(i);
130
          if( num==1 ) InternalStackFrame.cleanCommon();
131
          }
132
133
        break;
134
        }
135
      }
136 30094332 Leszek Koltunski
137
    setInitialized(false);
138
139
    if( num<2 )
140
      {
141
      EffectMessageSender.stopSending();
142
      }
143 9ec374e8 Leszek Koltunski
    }
144
145
///////////////////////////////////////////////////////////////////////////////////////////////////
146
147
  @SuppressWarnings("unused")
148
  static void debugLists()
149
    {
150
    int num = mFrameList.size();
151
    InternalStackFrame frame;
152
153
    InternalStackFrame.debugCommonList();
154
155
    for(int i=0; i<num; i++)
156
      {
157
      frame = mFrameList.get(i);
158
      frame.debugLists("frame "+i);
159
      }
160
    }
161
162 3543a3cf Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
163
164
  @SuppressWarnings("unused")
165
  static void debugMap()
166
    {
167
    int num = mFrameList.size();
168
    InternalStackFrame frame;
169
170
    for(int i=0; i<num; i++)
171
      {
172
      frame = mFrameList.get(i);
173
      frame.debugMap("frame "+i);
174
      }
175
    }
176
177 9ec374e8 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
178
// must be called from a thread holding OpenGL Context
179
180
  static boolean toDo()
181
    {
182
    if( mToDo )
183
      {
184
      mToDo = false;
185
186
      synchronized(mLock)
187
        {
188
        mCurrentFrame.toDo();
189
        InternalStackFrame.toDoCommon();
190
        }
191
      return true;
192
      }
193
194
    return false;
195
    }
196
197
///////////////////////////////////////////////////////////////////////////////////////////////////
198
199
  static void markFor(InternalObject obj, long id, int storage, int job)
200
    {
201
    synchronized(mLock)
202
      {
203
      mCurrentFrame.markFor(obj,id,storage,job);
204
      mToDo = true;
205
      }
206
    }
207
208
///////////////////////////////////////////////////////////////////////////////////////////////////
209
210
  static void removeFromDone(InternalObject obj, int storage)
211
    {
212
    synchronized(mLock)
213
      {
214
      mCurrentFrame.removeFromDoneList(obj,storage);
215
      }
216
    }
217
218
///////////////////////////////////////////////////////////////////////////////////////////////////
219
220
  static InternalStackFrame getCurrentFrame()
221
    {
222
    return mCurrentFrame;
223
    }
224
225 3543a3cf Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
226
227
  static long getNextEffectsID()
228
    {
229
    return mCurrentFrame.getNextEffectsID();
230
    }
231
232 9ec374e8 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
233
234
  static void setInitialized(boolean init)
235
    {
236
    mCurrentFrame.setInitialized(init);
237
    }
238
239 3543a3cf Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
240
241
  static InternalNodeData getMapID(ArrayList<Long> key)
242
    {
243
    return mCurrentFrame.getMapID(key);
244
    }
245
246
///////////////////////////////////////////////////////////////////////////////////////////////////
247
248
  static InternalNodeData putNewDataToMap(ArrayList<Long> key)
249
    {
250
    return mCurrentFrame.putNewDataToMap(key);
251
    }
252
253
///////////////////////////////////////////////////////////////////////////////////////////////////
254
255
  static void removeKeyFromMap(ArrayList<Long> key)
256
    {
257
    mCurrentFrame.removeKeyFromMap(key);
258
    }
259
260 3bbe4d67 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
261
262 fb001aff Leszek Koltunski
  static ArrayList<InternalMaster.Slave> getSet()
263 3bbe4d67 Leszek Koltunski
    {
264
    return mCurrentFrame.getSet();
265
    }
266
267 9ec374e8 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
268
// PUBLIC API
269 3543a3cf Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
270
271
  public static long getNextEffectID()
272
    {
273
    return mCurrentFrame.getNextEffectID();
274
    }
275
276 9ec374e8 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
277
278
  public static boolean isInitialized()
279
    {
280
    return mCurrentFrame.isInitialized();
281
    }
282
283 30094332 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
284
285
  public static int getMax(int index)
286
    {
287
    return mCurrentFrame.getMax(index);
288
    }
289
290
///////////////////////////////////////////////////////////////////////////////////////////////////
291
292
  public static boolean setMax(int index,int max)
293
    {
294
    return mCurrentFrame.setMax(index,max);
295
    }
296 3bbe4d67 Leszek Koltunski
297
///////////////////////////////////////////////////////////////////////////////////////////////////
298
299
  public static HashMap<ArrayList<Long>,Long> getMap()
300
    {
301
    return mCurrentFrame.getMap();
302
    }
303
304
///////////////////////////////////////////////////////////////////////////////////////////////////
305
306
  public static long getNextQueueID()
307
    {
308
    return mCurrentFrame.getNextQueueID();
309
    }
310
311
///////////////////////////////////////////////////////////////////////////////////////////////////
312
313 9ec374e8 Leszek Koltunski
}