You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardexpand all lines: README.md
+8-8
Original file line number
Diff line number
Diff line change
@@ -1,9 +1,9 @@
1
1
# PThreading
2
-
PThreading: A simple multithreaded framework for Processing.
2
+
PThreading: A framework for multithreaded drawing in [Processing](https://processing.org/).
3
3
4
4
---
5
5
6
-
The framework consists of two classes: `PThread` and `PThreadManager`. Override the `PThread` class with your code and then add instances of your new class to a PThreadManager to run the instances as threads that draw into your Processing sketch in a multithreaded manner.
6
+
The framework consists of two classes: `PThread` and `PThreadManager`. Override the `PThread` class with Processing code and then add instances of your new class to a PThreadManager; this will run the instances as threads that draw into your Processing sketch in a multithreaded manner.
7
7
8
8
## Motivation
9
9
@@ -15,7 +15,7 @@ Processing does indeed provide a quick and dirty way to implement a simple threa
15
15
16
16
... leaving *thread()* suitable only for CPU-bound sketches, at best.
17
17
18
-
In contrast, PThreading provides a way to do multithreaded drawing -- not just calculation -- and does so in an easy-to-use and well-synchronized manner. It exploits the fact that PGraphics objects can be drawn into safely from other threads.
18
+
In contrast, PThreading provides a way to do **multithreaded drawing** -- not just calculation -- and does so in an easy-to-use and well-synchronized manner. It exploits the fact that *PGraphics* objects can be drawn into safely from other threads.
19
19
20
20
## Setup
21
21
@@ -34,7 +34,7 @@ Download *pthreading.jar* from [releases](https://github.com/micycle1/PThreading
34
34
35
35
### 1. Extending PThread
36
36
37
-
Create a new class that extends PThread. You have to override the PThread's *draw()* method; overriding *calc()* is optional. In *draw()*, put Processing drawing code that you wish to be executed as a thread. A very simple example is shown below:
37
+
Create a new class that extends PThread. You have to override the PThread's *draw()* method; overriding *calc()*and *setup()*is optional. In *draw()*, put Processing drawing code that you wish to be executed as a thread. A very simple example is shown below:
38
38
39
39
#### PDE Example:
40
40
@@ -77,8 +77,9 @@ class myThread extends PThread {
77
77
```
78
78
79
79
**Important**:
80
-
* Prefix every call to a Processing draw method with g -- for example: *g.rect(10,10,10,10)* (relevant in all environments).
81
-
* Prefix every call to a Processing variable with p -- for example: *p.mousePressed* (relevant in non-PDE environments only).
80
+
* Prefix every call to a Processing **draw method** with **g** -- for example: *g.rect(10,10,10,10)* (relevant in all environments).
81
+
* Prefix every call to a Processing **variable** with **p** -- for example: *p.mousePressed* (relevant in non-PDE environments only).
82
+
* By default, *smooth()* is enabled for threads. Put *g.noSmooth();* in the thread consructor to disable anti-aliasing and thereby improve draw FPS.
82
83
83
84
### 2. Creating a PThreadManager
84
85
Create a thread manager and add threads to it. A [variety](micycle1.github.io/PThreading/pthreading/PThreadManager.html) of constructors are available. In this example the most simple constructor has been chosen. You can add multiple types of threads to a single thread manager.
@@ -104,8 +105,7 @@ Alternatively, you can call `threadManager.bindDraw()` once -- in `setup` for ex
104
105
105
106
---
106
107
107
-
That's it: now `a` and `b` will run as threads, drawing into the sketch. See /examples for more sophisticated behaviour.
108
+
That's it: now `a` and `b` will run as threads, drawing into the sketch. See the repo [examples](https://github.com/micycle1/PThreading/tree/master/examples) for the framework in action and more sophisticated behaviour.
108
109
109
110
## Limitations
110
111
Each thread uses the `Java2D` renderer, since this is the only renderer that allows PGraphics objects to be instantiated and drawn into from other threads. As a consequence you cannot **thread**`OPENGL` drawing, or any 3D draw functions -- note that you can still use the framework with a 3D sketch but any drawing with the PThreads is limited to 2D.
<dt><spanclass="memberNameLink"><ahref="../pthreading/PThread.html#setup()">setup()</a></span> - Method in class pthreading.<ahref="../pthreading/PThread.html" title="class in pthreading">PThread</a></dt>
85
+
<dd>
86
+
<divclass="block">An optional override.</div>
87
+
</dd>
84
88
<dt><spanclass="memberNameLink"><ahref="../pthreading/PThreadManager.html#stopThread(pthreading.PThread...)">stopThread(PThread...)</a></span> - Method in class pthreading.<ahref="../pthreading/PThreadManager.html" title="class in pthreading">PThreadManager</a></dt>
85
89
<dd>
86
90
<divclass="block">Stops a given thread or threads (varargs) and removes it from the thread
<dt><spanclass="memberNameLink"><ahref="../pthreading/PThread.html#calc()">calc()</a></span> - Method in class pthreading.<ahref="../pthreading/PThread.html" title="class in pthreading">PThread</a></dt>
85
85
<dd>
86
86
<divclass="block">An optional override (you <i>can</i> do calculation-related code in
0 commit comments