Package pthreading
Class PThread
- java.lang.Object
-
- pthreading.PThread
-
public abstract class PThread extends java.lang.ObjectExtend this class, overriding thecalc()anddraw()methods with your own code, then use aPThreadManagerto run the thread.Prefix every call to a Processing draw method with g -- for example: g.rect(10,10,10,10);
Refer to any PApplet variable by prefixing it with p -- for example: p.mousePressed.
- Author:
- micycle1
-
-
Constructor Summary
Constructors Constructor Description PThread(processing.core.PApplet p)Constructs a thread.
-
Method Summary
Modifier and Type Method Description protected voidcalc()An optional override (you can do calculation-related code indraw(), but putting it here may make more sense).voiddisableTiming()Disables the collection of timing information (draw and calc time).protected abstract voiddraw()The heart of a PThread.voidenableTiming()Enables the collection of timing information (draw and calc time).floatgetCalcFPS()Returns time taken for the thread's calc() loop to execute.floatgetDrawFPS()Returns time taken for the thread's draw() loop to execute.protected voidsetup()An optional override.
-
-
-
Constructor Detail
-
PThread
public PThread(processing.core.PApplet p)
Constructs a thread.NOTE: Merely instantiating a thread will not run it. Add it to a
PThreadManagerfor it to execute.- Parameters:
p- Parent PApplet
-
-
Method Detail
-
setup
protected void setup()
An optional override. Called at instantiation. Use this method set PGraphics' settings (e.g. g.colorMode(PApplet.HSB, 360, 100, 100); ), etc.
-
calc
protected void calc()
An optional override (you can do calculation-related code indraw(), but putting it here may make more sense). This code will be executed in a thread.Putting calculation-related code here, rather than in draw(), is useful when the 'unthread drawing' flag is true, so that draw time and calc time can be compared.
Internally, this method is called before
draw().- See Also:
draw()
-
draw
protected abstract void draw()
The heart of a PThread. Override this method with code that should be executed in a thread. Prefix calls to processing draw functions with g. (eg. g.ellipse(50, 50, 50, 50).Internally, this method is called after
calc().- See Also:
calc()
-
getDrawFPS
public final float getDrawFPS()
Returns time taken for the thread's draw() loop to execute. Can be used withgetCalcFPS()to determine if a thread is calculation bound or draw-call bound.- Returns:
- draw() execution time (milliseconds)
-
getCalcFPS
public final float getCalcFPS()
Returns time taken for the thread's calc() loop to execute. Can be used withgetDrawFPS()to determine if a thread is calculation bound or draw-call bound.- Returns:
- calc() execution time (milliseconds)
-
enableTiming
public final void enableTiming()
Enables the collection of timing information (draw and calc time). May incur a slight overhead. By default, timing information is not enabled.- See Also:
disableTiming(),getDrawFPS(),getCalcFPS()
-
disableTiming
public final void disableTiming()
Disables the collection of timing information (draw and calc time). By default, timing information is not enabled.- See Also:
enableTiming()
-
-