From bcf8097271c7d59b75874775fe08e7d76e66454e Mon Sep 17 00:00:00 2001 From: benfry Date: Sun, 19 Sep 2004 17:43:46 +0000 Subject: [PATCH] loop/noLoop stuff --- processing/core/PApplet.java | 104 +++++++++++++++++++++++------------ processing/core/todo.txt | 10 ++++ 2 files changed, 79 insertions(+), 35 deletions(-) diff --git a/processing/core/PApplet.java b/processing/core/PApplet.java index 3dcc9bcd4..466b31aaa 100644 --- a/processing/core/PApplet.java +++ b/processing/core/PApplet.java @@ -89,11 +89,12 @@ public class PApplet extends Applet protected long fpsLastDelayTime = 0; protected float fpsTarget = 0; - boolean drawMethod; - boolean loopMethod; + //boolean drawMethod; + //boolean loopMethod; + boolean looping; // true if inside the loop method - boolean insideLoop; + //boolean insideLoop; // used for mouse tracking so that pmouseX doesn't get // updated too many times while still inside the loop @@ -168,8 +169,9 @@ public class PApplet extends Applet firstFrame = true; // this will be cleared by loop() if it is not overridden - drawMethod = true; - loopMethod = true; + //drawMethod = true; + //loopMethod = true; + looping = true; firstMouseEvent = true; /* @@ -285,12 +287,26 @@ public class PApplet extends Applet public void draw() { - drawMethod = false; + //drawMethod = false; } public void loop() { - loopMethod = false; + if (!looping) { + looping = true; + if (thread != null) { + thread.interrupt(); // wake from sleep + } + } + } + + public void noLoop() { + if (looping) { + looping = false; + if (thread != null) { + thread.interrupt(); // wake from sleep + } + } } @@ -373,7 +389,7 @@ public class PApplet extends Applet updated = false; if (PApplet.THREAD_DEBUG) println("nextFrame()"); - nextFrame(); + if (looping) nextFrame(); // moving this to update() (for 0069+) for linux sync problems //if (firstFrame) firstFrame = false; @@ -388,7 +404,9 @@ public class PApplet extends Applet // windows doesn't like 'yield', so have to sleep at least // for some small amount of time. if (PApplet.THREAD_DEBUG) System.out.println("gonna sleep"); - Thread.sleep(1); // sleep to make OS happy + // can't remember when/why i changed that to '1'.. + // i have a feeling that some applets aren't gonna like that + Thread.sleep(looping ? 1 : 10000); // sleep to make OS happy if (PApplet.THREAD_DEBUG) System.out.println("outta sleep"); } catch (InterruptedException e) { } } @@ -422,6 +440,7 @@ public class PApplet extends Applet if (fpsTarget != 0) framerate_delay(); + /* // attempt to draw a static image using draw() if (!drawn) { //synchronized (g.image) { @@ -438,37 +457,38 @@ public class PApplet extends Applet drawn = true; } // end synch } + */ // if not a static app, run the loop - if (!drawMethod) { - synchronized (g) { - g.beginFrame(); - //mouseUpdated = false; - insideLoop = true; - loop(); - insideLoop = false; + //if (!drawMethod) { + synchronized (g) { + g.beginFrame(); + //mouseUpdated = false; + //insideLoop = true; + draw(); + //insideLoop = false; - // these are called *after* loop so that valid - // drawing commands can be run inside them. it can't - // be before, since a call to background() would wipe - // out anything that had been drawn so far. - if (qmouseMoved) { - mouseMoved(); - qmouseMoved = false; - } - if (qmouseDragged) { - mouseDragged(); - qmouseDragged = false; - } - g.endFrame(); - } // end synch - update(); - } + // these are called *after* loop so that valid + // drawing commands can be run inside them. it can't + // be before, since a call to background() would wipe + // out anything that had been drawn so far. + if (qmouseMoved) { + mouseMoved(); + qmouseMoved = false; + } + if (qmouseDragged) { + mouseDragged(); + qmouseDragged = false; + } + g.endFrame(); + } // end synch + update(); + //} // takedown - if (!loopMethod) { - finished = true; - } + //if (!loopMethod) { + //finished = true; + //} pmouseX = mouseX; pmouseY = mouseY; @@ -792,6 +812,20 @@ public class PApplet extends Applet } + // ------------------------------------------------------------ + + + /** + * Explicitly exit the applet. Inserted as a call for static + * mode apps, but is generally necessary because apps no longer + * have draw/loop separation. + */ + public void exit() { + stop(); + // TODO if not running as an applet, do a System.exit() here + } + + /** * Function for an applet/application to kill itself and * display an error. Mostly this is here to be improved later. diff --git a/processing/core/todo.txt b/processing/core/todo.txt index abc44e4f8..52e38b1db 100644 --- a/processing/core/todo.txt +++ b/processing/core/todo.txt @@ -160,6 +160,16 @@ X printarr instead of print/println for arrays X println(Object o) conflicts with println(int a[]) X but println(Object o) is very needed +040919 +X loop/noLoop setup +_ add redraw() function +_ call redraw() on the first time through (to force initial draw) +_ otherwise noLoop() in setup means no drawing happens at all +_ defaults for PApplet and PGraphics are different +_ PGraphics has none.. PApplet has fill/stroke +_ set PImage.format as RGB by default? +_ this was problem with rendering an image from PGraphics on board + _ massive graphics engine changes _ explicitly state depth()/nodepth() _ move to new graphics engine