Skip to content

Commit

Permalink
Various improvements [v.1.1.0]
Browse files Browse the repository at this point in the history
Add examples.
  • Loading branch information
micycle1 committed Oct 18, 2019
1 parent 742147e commit aafcc90
Show file tree
Hide file tree
Showing 41 changed files with 1,257 additions and 124 deletions.
16 changes: 8 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
# PThreading
PThreading: A simple multithreaded framework for Processing.
PThreading: A framework for multithreaded drawing in [Processing](https://processing.org/).

---

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.
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.

## Motivation

Expand All @@ -15,7 +15,7 @@ Processing does indeed provide a quick and dirty way to implement a simple threa
... leaving *thread()* suitable only for CPU-bound sketches, at best.

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.
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.

## Setup

Expand All @@ -34,7 +34,7 @@ Download *pthreading.jar* from [releases](https://github.com/micycle1/PThreading

### 1. Extending PThread

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:
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:

#### PDE Example:

Expand Down Expand Up @@ -77,8 +77,9 @@ class myThread extends PThread {
```

**Important**:
* Prefix every call to a Processing draw method with g -- for example: *g.rect(10,10,10,10)* (relevant in all environments).
* Prefix every call to a Processing variable with p -- for example: *p.mousePressed* (relevant in non-PDE environments only).
* Prefix every call to a Processing **draw method** with **g** -- for example: *g.rect(10,10,10,10)* (relevant in all environments).
* Prefix every call to a Processing **variable** with **p** -- for example: *p.mousePressed* (relevant in non-PDE environments only).
* By default, *smooth()* is enabled for threads. Put *g.noSmooth();* in the thread consructor to disable anti-aliasing and thereby improve draw FPS.

### 2. Creating a PThreadManager
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.
Expand All @@ -104,8 +105,7 @@ Alternatively, you can call `threadManager.bindDraw()` once -- in `setup` for ex

---

That's it: now `a` and `b` will run as threads, drawing into the sketch. See /examples for more sophisticated behaviour.
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.

## Limitations
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.
Not all sketches are suitable:
4 changes: 2 additions & 2 deletions docs/allclasses-index.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
<!-- NewPage -->
<html lang="en">
<head>
<!-- Generated by javadoc (12.0.1) on Sat Oct 12 16:13:46 BST 2019 -->
<!-- Generated by javadoc (12.0.1) on Fri Oct 18 19:01:01 BST 2019 -->
<title>All Classes</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta name="dc.created" content="2019-10-12">
<meta name="dc.created" content="2019-10-18">
<link rel="stylesheet" type="text/css" href="stylesheet.css" title="Style">
<link rel="stylesheet" type="text/css" href="jquery/jquery-ui.css" title="Style">
<script type="text/javascript" src="script.js"></script>
Expand Down
4 changes: 2 additions & 2 deletions docs/allpackages-index.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
<!-- NewPage -->
<html lang="en">
<head>
<!-- Generated by javadoc (12.0.1) on Sat Oct 12 16:13:46 BST 2019 -->
<!-- Generated by javadoc (12.0.1) on Fri Oct 18 19:01:01 BST 2019 -->
<title>All Packages</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta name="dc.created" content="2019-10-12">
<meta name="dc.created" content="2019-10-18">
<link rel="stylesheet" type="text/css" href="stylesheet.css" title="Style">
<link rel="stylesheet" type="text/css" href="jquery/jquery-ui.css" title="Style">
<script type="text/javascript" src="script.js"></script>
Expand Down
4 changes: 2 additions & 2 deletions docs/constant-values.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
<!-- NewPage -->
<html lang="en">
<head>
<!-- Generated by javadoc (12.0.1) on Sat Oct 12 16:13:46 BST 2019 -->
<!-- Generated by javadoc (12.0.1) on Fri Oct 18 19:01:01 BST 2019 -->
<title>Constant Field Values</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta name="dc.created" content="2019-10-12">
<meta name="dc.created" content="2019-10-18">
<link rel="stylesheet" type="text/css" href="stylesheet.css" title="Style">
<link rel="stylesheet" type="text/css" href="jquery/jquery-ui.css" title="Style">
<script type="text/javascript" src="script.js"></script>
Expand Down
4 changes: 2 additions & 2 deletions docs/deprecated-list.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
<!-- NewPage -->
<html lang="en">
<head>
<!-- Generated by javadoc (12.0.1) on Sat Oct 12 16:13:46 BST 2019 -->
<!-- Generated by javadoc (12.0.1) on Fri Oct 18 19:01:01 BST 2019 -->
<title>Deprecated List</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta name="dc.created" content="2019-10-12">
<meta name="dc.created" content="2019-10-18">
<link rel="stylesheet" type="text/css" href="stylesheet.css" title="Style">
<link rel="stylesheet" type="text/css" href="jquery/jquery-ui.css" title="Style">
<script type="text/javascript" src="script.js"></script>
Expand Down
4 changes: 2 additions & 2 deletions docs/help-doc.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
<!-- NewPage -->
<html lang="en">
<head>
<!-- Generated by javadoc (12.0.1) on Sat Oct 12 16:13:46 BST 2019 -->
<!-- Generated by javadoc (12.0.1) on Fri Oct 18 19:01:01 BST 2019 -->
<title>API Help</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta name="dc.created" content="2019-10-12">
<meta name="dc.created" content="2019-10-18">
<link rel="stylesheet" type="text/css" href="stylesheet.css" title="Style">
<link rel="stylesheet" type="text/css" href="jquery/jquery-ui.css" title="Style">
<script type="text/javascript" src="script.js"></script>
Expand Down
4 changes: 2 additions & 2 deletions docs/index-files/index-1.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
<!-- NewPage -->
<html lang="en">
<head>
<!-- Generated by javadoc (12.0.1) on Sat Oct 12 16:13:46 BST 2019 -->
<!-- Generated by javadoc (12.0.1) on Fri Oct 18 19:01:01 BST 2019 -->
<title>A-Index</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta name="dc.created" content="2019-10-12">
<meta name="dc.created" content="2019-10-18">
<link rel="stylesheet" type="text/css" href="../stylesheet.css" title="Style">
<link rel="stylesheet" type="text/css" href="../jquery/jquery-ui.css" title="Style">
<script type="text/javascript" src="../script.js"></script>
Expand Down
8 changes: 6 additions & 2 deletions docs/index-files/index-10.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
<!-- NewPage -->
<html lang="en">
<head>
<!-- Generated by javadoc (12.0.1) on Sat Oct 12 16:13:46 BST 2019 -->
<!-- Generated by javadoc (12.0.1) on Fri Oct 18 19:01:01 BST 2019 -->
<title>S-Index</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta name="dc.created" content="2019-10-12">
<meta name="dc.created" content="2019-10-18">
<link rel="stylesheet" type="text/css" href="../stylesheet.css" title="Style">
<link rel="stylesheet" type="text/css" href="../jquery/jquery-ui.css" title="Style">
<script type="text/javascript" src="../script.js"></script>
Expand Down Expand Up @@ -81,6 +81,10 @@
</a>
<h2 class="title">S</h2>
<dl>
<dt><span class="memberNameLink"><a href="../pthreading/PThread.html#setup()">setup()</a></span> - Method in class pthreading.<a href="../pthreading/PThread.html" title="class in pthreading">PThread</a></dt>
<dd>
<div class="block">An optional override.</div>
</dd>
<dt><span class="memberNameLink"><a href="../pthreading/PThreadManager.html#stopThread(pthreading.PThread...)">stopThread(PThread...)</a></span> - Method in class pthreading.<a href="../pthreading/PThreadManager.html" title="class in pthreading">PThreadManager</a></dt>
<dd>
<div class="block">Stops a given thread or threads (varargs) and removes it from the thread
Expand Down
4 changes: 2 additions & 2 deletions docs/index-files/index-11.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
<!-- NewPage -->
<html lang="en">
<head>
<!-- Generated by javadoc (12.0.1) on Sat Oct 12 16:13:46 BST 2019 -->
<!-- Generated by javadoc (12.0.1) on Fri Oct 18 19:01:01 BST 2019 -->
<title>U-Index</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta name="dc.created" content="2019-10-12">
<meta name="dc.created" content="2019-10-18">
<link rel="stylesheet" type="text/css" href="../stylesheet.css" title="Style">
<link rel="stylesheet" type="text/css" href="../jquery/jquery-ui.css" title="Style">
<script type="text/javascript" src="../script.js"></script>
Expand Down
4 changes: 2 additions & 2 deletions docs/index-files/index-2.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
<!-- NewPage -->
<html lang="en">
<head>
<!-- Generated by javadoc (12.0.1) on Sat Oct 12 16:13:46 BST 2019 -->
<!-- Generated by javadoc (12.0.1) on Fri Oct 18 19:01:01 BST 2019 -->
<title>B-Index</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta name="dc.created" content="2019-10-12">
<meta name="dc.created" content="2019-10-18">
<link rel="stylesheet" type="text/css" href="../stylesheet.css" title="Style">
<link rel="stylesheet" type="text/css" href="../jquery/jquery-ui.css" title="Style">
<script type="text/javascript" src="../script.js"></script>
Expand Down
6 changes: 3 additions & 3 deletions docs/index-files/index-3.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
<!-- NewPage -->
<html lang="en">
<head>
<!-- Generated by javadoc (12.0.1) on Sat Oct 12 16:13:46 BST 2019 -->
<!-- Generated by javadoc (12.0.1) on Fri Oct 18 19:01:01 BST 2019 -->
<title>C-Index</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta name="dc.created" content="2019-10-12">
<meta name="dc.created" content="2019-10-18">
<link rel="stylesheet" type="text/css" href="../stylesheet.css" title="Style">
<link rel="stylesheet" type="text/css" href="../jquery/jquery-ui.css" title="Style">
<script type="text/javascript" src="../script.js"></script>
Expand Down Expand Up @@ -84,7 +84,7 @@ <h2 class="title">C</h2>
<dt><span class="memberNameLink"><a href="../pthreading/PThread.html#calc()">calc()</a></span> - Method in class pthreading.<a href="../pthreading/PThread.html" title="class in pthreading">PThread</a></dt>
<dd>
<div class="block">An optional override (you <i>can</i> do calculation-related code in
<a href="../pthreading/PThread.html#draw()"><code>PThread.draw()</code></a>.</div>
<a href="../pthreading/PThread.html#draw()"><code>PThread.draw()</code></a>, but putting it here may make more sense).</div>
</dd>
</dl>
<a href="index-1.html">A</a>&nbsp;<a href="index-2.html">B</a>&nbsp;<a href="index-3.html">C</a>&nbsp;<a href="index-4.html">D</a>&nbsp;<a href="index-5.html">E</a>&nbsp;<a href="index-6.html">G</a>&nbsp;<a href="index-7.html">I</a>&nbsp;<a href="index-8.html">P</a>&nbsp;<a href="index-9.html">R</a>&nbsp;<a href="index-10.html">S</a>&nbsp;<a href="index-11.html">U</a>&nbsp;<br><a href="../allclasses-index.html">All&nbsp;Classes</a>&nbsp;<a href="../allpackages-index.html">All&nbsp;Packages</a></div>
Expand Down
4 changes: 2 additions & 2 deletions docs/index-files/index-4.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
<!-- NewPage -->
<html lang="en">
<head>
<!-- Generated by javadoc (12.0.1) on Sat Oct 12 16:13:46 BST 2019 -->
<!-- Generated by javadoc (12.0.1) on Fri Oct 18 19:01:01 BST 2019 -->
<title>D-Index</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta name="dc.created" content="2019-10-12">
<meta name="dc.created" content="2019-10-18">
<link rel="stylesheet" type="text/css" href="../stylesheet.css" title="Style">
<link rel="stylesheet" type="text/css" href="../jquery/jquery-ui.css" title="Style">
<script type="text/javascript" src="../script.js"></script>
Expand Down
4 changes: 2 additions & 2 deletions docs/index-files/index-5.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
<!-- NewPage -->
<html lang="en">
<head>
<!-- Generated by javadoc (12.0.1) on Sat Oct 12 16:13:46 BST 2019 -->
<!-- Generated by javadoc (12.0.1) on Fri Oct 18 19:01:01 BST 2019 -->
<title>E-Index</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta name="dc.created" content="2019-10-12">
<meta name="dc.created" content="2019-10-18">
<link rel="stylesheet" type="text/css" href="../stylesheet.css" title="Style">
<link rel="stylesheet" type="text/css" href="../jquery/jquery-ui.css" title="Style">
<script type="text/javascript" src="../script.js"></script>
Expand Down
4 changes: 2 additions & 2 deletions docs/index-files/index-6.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
<!-- NewPage -->
<html lang="en">
<head>
<!-- Generated by javadoc (12.0.1) on Sat Oct 12 16:13:46 BST 2019 -->
<!-- Generated by javadoc (12.0.1) on Fri Oct 18 19:01:01 BST 2019 -->
<title>G-Index</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta name="dc.created" content="2019-10-12">
<meta name="dc.created" content="2019-10-18">
<link rel="stylesheet" type="text/css" href="../stylesheet.css" title="Style">
<link rel="stylesheet" type="text/css" href="../jquery/jquery-ui.css" title="Style">
<script type="text/javascript" src="../script.js"></script>
Expand Down
4 changes: 2 additions & 2 deletions docs/index-files/index-7.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
<!-- NewPage -->
<html lang="en">
<head>
<!-- Generated by javadoc (12.0.1) on Sat Oct 12 16:13:46 BST 2019 -->
<!-- Generated by javadoc (12.0.1) on Fri Oct 18 19:01:01 BST 2019 -->
<title>I-Index</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta name="dc.created" content="2019-10-12">
<meta name="dc.created" content="2019-10-18">
<link rel="stylesheet" type="text/css" href="../stylesheet.css" title="Style">
<link rel="stylesheet" type="text/css" href="../jquery/jquery-ui.css" title="Style">
<script type="text/javascript" src="../script.js"></script>
Expand Down
4 changes: 2 additions & 2 deletions docs/index-files/index-8.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
<!-- NewPage -->
<html lang="en">
<head>
<!-- Generated by javadoc (12.0.1) on Sat Oct 12 16:13:46 BST 2019 -->
<!-- Generated by javadoc (12.0.1) on Fri Oct 18 19:01:01 BST 2019 -->
<title>P-Index</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta name="dc.created" content="2019-10-12">
<meta name="dc.created" content="2019-10-18">
<link rel="stylesheet" type="text/css" href="../stylesheet.css" title="Style">
<link rel="stylesheet" type="text/css" href="../jquery/jquery-ui.css" title="Style">
<script type="text/javascript" src="../script.js"></script>
Expand Down
4 changes: 2 additions & 2 deletions docs/index-files/index-9.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
<!-- NewPage -->
<html lang="en">
<head>
<!-- Generated by javadoc (12.0.1) on Sat Oct 12 16:13:46 BST 2019 -->
<!-- Generated by javadoc (12.0.1) on Fri Oct 18 19:01:01 BST 2019 -->
<title>R-Index</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta name="dc.created" content="2019-10-12">
<meta name="dc.created" content="2019-10-18">
<link rel="stylesheet" type="text/css" href="../stylesheet.css" title="Style">
<link rel="stylesheet" type="text/css" href="../jquery/jquery-ui.css" title="Style">
<script type="text/javascript" src="../script.js"></script>
Expand Down
4 changes: 2 additions & 2 deletions docs/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
<!-- NewPage -->
<html lang="en">
<head>
<!-- Generated by javadoc (12.0.1) on Sat Oct 12 16:13:46 BST 2019 -->
<!-- Generated by javadoc (12.0.1) on Fri Oct 18 19:01:01 BST 2019 -->
<title>Generated Documentation (Untitled)</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta name="dc.created" content="2019-10-12">
<meta name="dc.created" content="2019-10-18">
<script type="text/javascript">window.location.replace('pthreading/package-summary.html')</script>
<noscript>
<meta http-equiv="Refresh" content="0;pthreading/package-summary.html">
Expand Down
Loading

0 comments on commit aafcc90

Please sign in to comment.