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 |
|
|
|
26 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
27 |
|
|
|
28 |
|
|
public class InternalStackFrameList
|
29 |
|
|
{
|
30 |
|
|
private final static Object mLock = new Object();
|
31 |
|
|
private static boolean mToDo = false;
|
32 |
|
|
private static InternalStackFrame mCurrentFrame = null;
|
33 |
|
|
private static ArrayList<InternalStackFrame> mFrameList = new ArrayList<>();
|
34 |
|
|
|
35 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
36 |
|
|
|
37 |
|
|
static void onCreate(long taskId)
|
38 |
|
|
{
|
39 |
|
|
int num = mFrameList.size();
|
40 |
|
|
InternalStackFrame frame;
|
41 |
|
|
boolean found = false;
|
42 |
|
|
|
43 |
|
|
for(int i=0; i<num; i++)
|
44 |
|
|
{
|
45 |
|
|
frame = mFrameList.get(i);
|
46 |
|
|
|
47 |
|
|
if( frame.getTaskId() == taskId )
|
48 |
|
|
{
|
49 |
|
|
mCurrentFrame = frame;
|
50 |
|
|
found = true;
|
51 |
|
|
break;
|
52 |
|
|
}
|
53 |
|
|
}
|
54 |
|
|
|
55 |
|
|
if( !found )
|
56 |
|
|
{
|
57 |
|
|
synchronized(mLock)
|
58 |
|
|
{
|
59 |
|
|
mCurrentFrame = new InternalStackFrame(taskId);
|
60 |
|
|
mFrameList.add(mCurrentFrame);
|
61 |
|
|
}
|
62 |
|
|
}
|
63 |
|
|
|
64 |
|
|
mCurrentFrame.setInitialized(false);
|
65 |
|
|
}
|
66 |
|
|
|
67 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
68 |
|
|
|
69 |
|
|
static void onResume(long taskId)
|
70 |
|
|
{
|
71 |
|
|
int num = mFrameList.size();
|
72 |
|
|
InternalStackFrame frame;
|
73 |
|
|
|
74 |
|
|
for(int i=0; i<num; i++)
|
75 |
|
|
{
|
76 |
|
|
frame = mFrameList.get(i);
|
77 |
|
|
|
78 |
|
|
if( frame.getTaskId() == taskId )
|
79 |
|
|
{
|
80 |
|
|
mCurrentFrame = frame;
|
81 |
|
|
break;
|
82 |
|
|
}
|
83 |
|
|
}
|
84 |
|
|
|
85 |
|
|
mCurrentFrame.setInitialized(false);
|
86 |
|
|
}
|
87 |
|
|
|
88 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
89 |
|
|
|
90 |
|
|
static void onPause(long taskId)
|
91 |
|
|
{
|
92 |
|
|
int num = mFrameList.size();
|
93 |
|
|
|
94 |
|
|
for(int i=0; i<num; i++)
|
95 |
|
|
{
|
96 |
|
|
if( mFrameList.get(i).getTaskId() == taskId )
|
97 |
|
|
{
|
98 |
|
|
synchronized(mLock)
|
99 |
|
|
{
|
100 |
|
|
mCurrentFrame.onPause();
|
101 |
|
|
InternalStackFrame.onPauseCommon();
|
102 |
|
|
mToDo = true;
|
103 |
|
|
}
|
104 |
|
|
|
105 |
|
|
break;
|
106 |
|
|
}
|
107 |
|
|
}
|
108 |
|
|
}
|
109 |
|
|
|
110 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
111 |
|
|
|
112 |
|
|
static void onDestroy(long taskId)
|
113 |
|
|
{
|
114 |
|
|
int num = mFrameList.size();
|
115 |
|
|
|
116 |
|
|
for(int i=0; i<num; i++)
|
117 |
|
|
{
|
118 |
|
|
if( mFrameList.get(i).getTaskId() == taskId )
|
119 |
|
|
{
|
120 |
|
|
synchronized(mLock)
|
121 |
|
|
{
|
122 |
|
|
mFrameList.remove(i);
|
123 |
|
|
if( num==1 ) InternalStackFrame.cleanCommon();
|
124 |
|
|
}
|
125 |
|
|
|
126 |
|
|
break;
|
127 |
|
|
}
|
128 |
|
|
}
|
129 |
30094332
|
Leszek Koltunski
|
|
130 |
|
|
setInitialized(false);
|
131 |
|
|
|
132 |
|
|
if( num<2 )
|
133 |
|
|
{
|
134 |
|
|
EffectMessageSender.stopSending();
|
135 |
|
|
}
|
136 |
9ec374e8
|
Leszek Koltunski
|
}
|
137 |
|
|
|
138 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
139 |
|
|
|
140 |
|
|
@SuppressWarnings("unused")
|
141 |
|
|
static void debugLists()
|
142 |
|
|
{
|
143 |
|
|
int num = mFrameList.size();
|
144 |
|
|
InternalStackFrame frame;
|
145 |
|
|
|
146 |
|
|
InternalStackFrame.debugCommonList();
|
147 |
|
|
|
148 |
|
|
for(int i=0; i<num; i++)
|
149 |
|
|
{
|
150 |
|
|
frame = mFrameList.get(i);
|
151 |
|
|
frame.debugLists("frame "+i);
|
152 |
|
|
}
|
153 |
|
|
}
|
154 |
|
|
|
155 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
156 |
|
|
// must be called from a thread holding OpenGL Context
|
157 |
|
|
|
158 |
|
|
static boolean toDo()
|
159 |
|
|
{
|
160 |
|
|
if( mToDo )
|
161 |
|
|
{
|
162 |
|
|
mToDo = false;
|
163 |
|
|
|
164 |
|
|
synchronized(mLock)
|
165 |
|
|
{
|
166 |
|
|
mCurrentFrame.toDo();
|
167 |
|
|
InternalStackFrame.toDoCommon();
|
168 |
|
|
}
|
169 |
|
|
return true;
|
170 |
|
|
}
|
171 |
|
|
|
172 |
|
|
return false;
|
173 |
|
|
}
|
174 |
|
|
|
175 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
176 |
|
|
|
177 |
|
|
static void markFor(InternalObject obj, long id, int storage, int job)
|
178 |
|
|
{
|
179 |
|
|
synchronized(mLock)
|
180 |
|
|
{
|
181 |
|
|
mCurrentFrame.markFor(obj,id,storage,job);
|
182 |
|
|
mToDo = true;
|
183 |
|
|
}
|
184 |
|
|
}
|
185 |
|
|
|
186 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
187 |
|
|
|
188 |
|
|
static void removeFromDone(InternalObject obj, int storage)
|
189 |
|
|
{
|
190 |
|
|
synchronized(mLock)
|
191 |
|
|
{
|
192 |
|
|
mCurrentFrame.removeFromDoneList(obj,storage);
|
193 |
|
|
}
|
194 |
|
|
}
|
195 |
|
|
|
196 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
197 |
|
|
|
198 |
|
|
static InternalStackFrame getCurrentFrame()
|
199 |
|
|
{
|
200 |
|
|
return mCurrentFrame;
|
201 |
|
|
}
|
202 |
|
|
|
203 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
204 |
|
|
|
205 |
|
|
static void setInitialized(boolean init)
|
206 |
|
|
{
|
207 |
|
|
mCurrentFrame.setInitialized(init);
|
208 |
|
|
}
|
209 |
|
|
|
210 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
211 |
|
|
// PUBLIC API
|
212 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
213 |
|
|
|
214 |
|
|
public static boolean isInitialized()
|
215 |
|
|
{
|
216 |
|
|
return mCurrentFrame.isInitialized();
|
217 |
|
|
}
|
218 |
|
|
|
219 |
30094332
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
220 |
|
|
|
221 |
|
|
public static int getMax(int index)
|
222 |
|
|
{
|
223 |
|
|
return mCurrentFrame.getMax(index);
|
224 |
|
|
}
|
225 |
|
|
|
226 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
227 |
|
|
|
228 |
|
|
public static boolean setMax(int index,int max)
|
229 |
|
|
{
|
230 |
|
|
return mCurrentFrame.setMax(index,max);
|
231 |
|
|
}
|
232 |
9ec374e8
|
Leszek Koltunski
|
}
|