Revision ed06301f
Added by Leszek Koltunski about 7 years ago
| src/main/java/org/distorted/library/main/Distorted.java | ||
|---|---|---|
| 29 | 29 |
import org.distorted.library.effect.FragmentEffect; |
| 30 | 30 |
import org.distorted.library.effect.PostprocessEffect; |
| 31 | 31 |
import org.distorted.library.effect.VertexEffect; |
| 32 |
import org.distorted.library.message.EffectMessageSender; |
|
| 32 | 33 |
|
| 33 | 34 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 34 | 35 |
/** |
| src/main/java/org/distorted/library/main/EffectMessageSender.java | ||
|---|---|---|
| 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.main; |
|
| 21 |
|
|
| 22 |
import org.distorted.library.message.EffectListener; |
|
| 23 |
import org.distorted.library.message.EffectMessage; |
|
| 24 |
|
|
| 25 |
import java.util.Vector; |
|
| 26 |
|
|
| 27 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 28 |
|
|
| 29 |
final class EffectMessageSender extends Thread |
|
| 30 |
{
|
|
| 31 |
private class Message |
|
| 32 |
{
|
|
| 33 |
EffectListener mListener; |
|
| 34 |
EffectMessage mMessage; |
|
| 35 |
long mEffectID; |
|
| 36 |
long mObjectID; |
|
| 37 |
|
|
| 38 |
Message(EffectListener l, EffectMessage m, long effID, long objID) |
|
| 39 |
{
|
|
| 40 |
mListener = l; |
|
| 41 |
mMessage = m; |
|
| 42 |
mEffectID = effID; |
|
| 43 |
mObjectID = objID; |
|
| 44 |
} |
|
| 45 |
} |
|
| 46 |
|
|
| 47 |
private static Vector<Message> mList =null; |
|
| 48 |
private static EffectMessageSender mThis=null; |
|
| 49 |
private static volatile boolean mNotify = false; |
|
| 50 |
private static volatile boolean mRunning = false; |
|
| 51 |
|
|
| 52 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 53 |
|
|
| 54 |
private EffectMessageSender() |
|
| 55 |
{
|
|
| 56 |
} |
|
| 57 |
|
|
| 58 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 59 |
|
|
| 60 |
static void startSending() |
|
| 61 |
{
|
|
| 62 |
mRunning = true; |
|
| 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 |
mRunning = false; |
|
| 84 |
|
|
| 85 |
if( mThis!=null ) |
|
| 86 |
{
|
|
| 87 |
synchronized(mThis) |
|
| 88 |
{
|
|
| 89 |
mThis.notify(); |
|
| 90 |
} |
|
| 91 |
} |
|
| 92 |
} |
|
| 93 |
|
|
| 94 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 95 |
|
|
| 96 |
public void run() |
|
| 97 |
{
|
|
| 98 |
Message tmp; |
|
| 99 |
|
|
| 100 |
while(mRunning) |
|
| 101 |
{
|
|
| 102 |
//android.util.Log.i("SENDER", "sender thread running...");
|
|
| 103 |
|
|
| 104 |
while( mList.size()>0 ) |
|
| 105 |
{
|
|
| 106 |
tmp = mList.remove(0); |
|
| 107 |
tmp.mListener.effectMessage(tmp.mMessage, tmp.mEffectID, tmp.mObjectID); |
|
| 108 |
} |
|
| 109 |
|
|
| 110 |
synchronized(mThis) |
|
| 111 |
{
|
|
| 112 |
if (!mNotify) |
|
| 113 |
{
|
|
| 114 |
try { mThis.wait(); }
|
|
| 115 |
catch(InterruptedException ex) { }
|
|
| 116 |
} |
|
| 117 |
mNotify = false; |
|
| 118 |
} |
|
| 119 |
} |
|
| 120 |
|
|
| 121 |
mThis = null; |
|
| 122 |
mList.clear(); |
|
| 123 |
|
|
| 124 |
//android.util.Log.i("SENDER", "sender thread finished...");
|
|
| 125 |
} |
|
| 126 |
|
|
| 127 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 128 |
|
|
| 129 |
static void newMessage(EffectListener l, EffectMessage m, long effID, long objID) |
|
| 130 |
{
|
|
| 131 |
Message msg = mThis.new Message(l,m,effID,objID); |
|
| 132 |
mList.add(msg); |
|
| 133 |
|
|
| 134 |
synchronized(mThis) |
|
| 135 |
{
|
|
| 136 |
mNotify = true; |
|
| 137 |
mThis.notify(); |
|
| 138 |
} |
|
| 139 |
} |
|
| 140 |
} |
|
| src/main/java/org/distorted/library/main/EffectQueue.java | ||
|---|---|---|
| 24 | 24 |
import org.distorted.library.effect.EffectType; |
| 25 | 25 |
import org.distorted.library.message.EffectListener; |
| 26 | 26 |
import org.distorted.library.message.EffectMessage; |
| 27 |
import org.distorted.library.message.EffectMessageSender; |
|
| 27 | 28 |
|
| 28 | 29 |
import java.util.ArrayList; |
| 29 | 30 |
import java.util.HashMap; |
| src/main/java/org/distorted/library/main/EffectQueueFragment.java | ||
|---|---|---|
| 24 | 24 |
import org.distorted.library.effect.EffectType; |
| 25 | 25 |
import org.distorted.library.effect.FragmentEffect; |
| 26 | 26 |
import org.distorted.library.message.EffectMessage; |
| 27 |
import org.distorted.library.message.EffectMessageSender; |
|
| 27 | 28 |
|
| 28 | 29 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 29 | 30 |
|
| src/main/java/org/distorted/library/main/EffectQueueMatrix.java | ||
|---|---|---|
| 25 | 25 |
import org.distorted.library.effect.EffectType; |
| 26 | 26 |
import org.distorted.library.effect.MatrixEffect; |
| 27 | 27 |
import org.distorted.library.message.EffectMessage; |
| 28 |
import org.distorted.library.message.EffectMessageSender; |
|
| 28 | 29 |
|
| 29 | 30 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 30 | 31 |
|
| src/main/java/org/distorted/library/main/EffectQueuePostprocess.java | ||
|---|---|---|
| 29 | 29 |
import org.distorted.library.effect.VertexEffect; |
| 30 | 30 |
import org.distorted.library.mesh.MeshBase; |
| 31 | 31 |
import org.distorted.library.message.EffectMessage; |
| 32 |
import org.distorted.library.message.EffectMessageSender; |
|
| 32 | 33 |
import org.distorted.library.program.DistortedProgram; |
| 33 | 34 |
|
| 34 | 35 |
import java.io.InputStream; |
| src/main/java/org/distorted/library/main/EffectQueueVertex.java | ||
|---|---|---|
| 24 | 24 |
import org.distorted.library.effect.EffectType; |
| 25 | 25 |
import org.distorted.library.effect.VertexEffect; |
| 26 | 26 |
import org.distorted.library.message.EffectMessage; |
| 27 |
import org.distorted.library.message.EffectMessageSender; |
|
| 27 | 28 |
|
| 28 | 29 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 29 | 30 |
|
| src/main/java/org/distorted/library/message/EffectMessageSender.java | ||
|---|---|---|
| 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.message; |
|
| 21 |
|
|
| 22 |
import java.util.Vector; |
|
| 23 |
|
|
| 24 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 25 |
/** |
|
| 26 |
* Not part of public API, do not document (public only because has to be used in Meshes) |
|
| 27 |
* |
|
| 28 |
* @y.exclude |
|
| 29 |
*/ |
|
| 30 |
public final class EffectMessageSender extends Thread |
|
| 31 |
{
|
|
| 32 |
private class Message |
|
| 33 |
{
|
|
| 34 |
EffectListener mListener; |
|
| 35 |
EffectMessage mMessage; |
|
| 36 |
long mEffectID; |
|
| 37 |
long mObjectID; |
|
| 38 |
|
|
| 39 |
Message(EffectListener l, EffectMessage m, long effID, long objID) |
|
| 40 |
{
|
|
| 41 |
mListener = l; |
|
| 42 |
mMessage = m; |
|
| 43 |
mEffectID = effID; |
|
| 44 |
mObjectID = objID; |
|
| 45 |
} |
|
| 46 |
} |
|
| 47 |
|
|
| 48 |
private static Vector<Message> mList =null; |
|
| 49 |
private static EffectMessageSender mThis=null; |
|
| 50 |
private static volatile boolean mNotify = false; |
|
| 51 |
private static volatile boolean mRunning = false; |
|
| 52 |
|
|
| 53 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 54 |
|
|
| 55 |
private EffectMessageSender() |
|
| 56 |
{
|
|
| 57 |
} |
|
| 58 |
|
|
| 59 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 60 |
|
|
| 61 |
public static void startSending() |
|
| 62 |
{
|
|
| 63 |
mRunning = true; |
|
| 64 |
|
|
| 65 |
if( mThis==null ) |
|
| 66 |
{
|
|
| 67 |
mList = new Vector<>(); |
|
| 68 |
mThis = new EffectMessageSender(); |
|
| 69 |
mThis.start(); |
|
| 70 |
} |
|
| 71 |
else |
|
| 72 |
{
|
|
| 73 |
synchronized(mThis) |
|
| 74 |
{
|
|
| 75 |
mThis.notify(); |
|
| 76 |
} |
|
| 77 |
} |
|
| 78 |
} |
|
| 79 |
|
|
| 80 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 81 |
|
|
| 82 |
public static void stopSending() |
|
| 83 |
{
|
|
| 84 |
mRunning = false; |
|
| 85 |
|
|
| 86 |
if( mThis!=null ) |
|
| 87 |
{
|
|
| 88 |
synchronized(mThis) |
|
| 89 |
{
|
|
| 90 |
mThis.notify(); |
|
| 91 |
} |
|
| 92 |
} |
|
| 93 |
} |
|
| 94 |
|
|
| 95 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 96 |
|
|
| 97 |
public void run() |
|
| 98 |
{
|
|
| 99 |
Message tmp; |
|
| 100 |
|
|
| 101 |
while(mRunning) |
|
| 102 |
{
|
|
| 103 |
//android.util.Log.i("SENDER", "sender thread running...");
|
|
| 104 |
|
|
| 105 |
while( mList.size()>0 ) |
|
| 106 |
{
|
|
| 107 |
tmp = mList.remove(0); |
|
| 108 |
tmp.mListener.effectMessage(tmp.mMessage, tmp.mEffectID, tmp.mObjectID); |
|
| 109 |
} |
|
| 110 |
|
|
| 111 |
synchronized(mThis) |
|
| 112 |
{
|
|
| 113 |
if (!mNotify) |
|
| 114 |
{
|
|
| 115 |
try { mThis.wait(); }
|
|
| 116 |
catch(InterruptedException ex) { }
|
|
| 117 |
} |
|
| 118 |
mNotify = false; |
|
| 119 |
} |
|
| 120 |
} |
|
| 121 |
|
|
| 122 |
mThis = null; |
|
| 123 |
mList.clear(); |
|
| 124 |
|
|
| 125 |
//android.util.Log.i("SENDER", "sender thread finished...");
|
|
| 126 |
} |
|
| 127 |
|
|
| 128 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 129 |
|
|
| 130 |
public static void newMessage(EffectListener l, EffectMessage m, long effID, long objID) |
|
| 131 |
{
|
|
| 132 |
Message msg = mThis.new Message(l,m,effID,objID); |
|
| 133 |
mList.add(msg); |
|
| 134 |
|
|
| 135 |
synchronized(mThis) |
|
| 136 |
{
|
|
| 137 |
mNotify = true; |
|
| 138 |
mThis.notify(); |
|
| 139 |
} |
|
| 140 |
} |
|
| 141 |
} |
|
Also available in: Unified diff
Move EffectMessageSender to the 'message' package (duh!)