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.Vector;
|
23
|
|
24
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
25
|
|
26
|
final class EffectMessageSender extends Thread
|
27
|
{
|
28
|
private class Message
|
29
|
{
|
30
|
EffectListener mListener;
|
31
|
EffectMessage mMessage;
|
32
|
long mEffectID;
|
33
|
int mEffectName;
|
34
|
long mBitmapID;
|
35
|
String mStr;
|
36
|
|
37
|
Message(EffectListener l, EffectMessage m, long id, int name, long bmpID, String str)
|
38
|
{
|
39
|
mListener = l;
|
40
|
mMessage = m;
|
41
|
mEffectID = id;
|
42
|
mEffectName = name;
|
43
|
mBitmapID = bmpID;
|
44
|
mStr = str;
|
45
|
}
|
46
|
}
|
47
|
|
48
|
private static Vector<Message> mList =null;
|
49
|
private static EffectMessageSender mThis=null;
|
50
|
private static volatile boolean mPaused;
|
51
|
|
52
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
53
|
|
54
|
private EffectMessageSender()
|
55
|
{
|
56
|
}
|
57
|
|
58
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
59
|
|
60
|
static void startSending()
|
61
|
{
|
62
|
mPaused = false;
|
63
|
|
64
|
if( mThis==null )
|
65
|
{
|
66
|
mList = new Vector<>();
|
67
|
mThis = new EffectMessageSender();
|
68
|
mThis.start();
|
69
|
}
|
70
|
else
|
71
|
{
|
72
|
synchronized(mThis)
|
73
|
{
|
74
|
mThis.notify();
|
75
|
}
|
76
|
}
|
77
|
}
|
78
|
|
79
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
80
|
|
81
|
static void stopSending()
|
82
|
{
|
83
|
mPaused = true;
|
84
|
}
|
85
|
|
86
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
87
|
|
88
|
public void run()
|
89
|
{
|
90
|
Message tmp;
|
91
|
|
92
|
while(true)
|
93
|
{
|
94
|
if( mList.size()>0 )
|
95
|
{
|
96
|
tmp = mList.get(0);
|
97
|
tmp.mListener.effectMessage(tmp.mMessage, tmp.mEffectID, tmp.mEffectName, tmp.mBitmapID, tmp.mStr);
|
98
|
mList.remove(0);
|
99
|
}
|
100
|
|
101
|
if( mPaused )
|
102
|
{
|
103
|
synchronized(mThis)
|
104
|
{
|
105
|
try { mThis.wait(); }
|
106
|
catch(InterruptedException ex) { }
|
107
|
}
|
108
|
}
|
109
|
}
|
110
|
}
|
111
|
|
112
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
113
|
|
114
|
static void newMessage(EffectListener l, EffectMessage m, long id, int name, long bmpID, String str)
|
115
|
{
|
116
|
Message msg = mThis.new Message(l,m,id,name,bmpID,str);
|
117
|
mList.add(msg);
|
118
|
}
|
119
|
}
|
120
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|