diff --git a/processing/build/windows/make.sh b/processing/build/windows/make.sh index 16453bb0e..bba21cfce 100755 --- a/processing/build/windows/make.sh +++ b/processing/build/windows/make.sh @@ -5,8 +5,7 @@ if test -d work then -# BUILD_PREPROC=false - BUILD_PREPROC=true + BUILD_PREPROC=false else echo Setting up directories to build P5... BUILD_PREPROC=true diff --git a/processing/core/PApplet.java b/processing/core/PApplet.java index fc9fcda69..5c521d123 100644 --- a/processing/core/PApplet.java +++ b/processing/core/PApplet.java @@ -146,11 +146,15 @@ public class PApplet extends Applet static public final int DEFAULT_HEIGHT = 100; public int width, height; - protected int libraryCount; - protected PLibrary libraries[]; - protected boolean libraryCalls[][]; - //int registeredCount[]; - //PLibrary registered[][]; + protected RegisteredMethods sizeMethods; + protected RegisteredMethods preMethods, drawMethods, postMethods; + protected RegisteredMethods mouseEventMethods, keyEventMethods; + protected RegisteredMethods disposeMethods; + + //protected int libraryCount; + //protected PLibrary libraries[]; + //protected boolean libraryCalls[][]; + //int setupCount = 0; // this text isn't seen unless PApplet is used on its // own and someone takes advantage of leechErr.. not likely @@ -224,8 +228,15 @@ public class PApplet extends Applet */ // these need to be inited before setup - libraries = new PLibrary[10]; - libraryCalls = new boolean[10][PLibrary.CALL_COUNT]; + //libraries = new PLibrary[10]; + //libraryCalls = new boolean[10][PLibrary.CALL_COUNT]; + sizeMethods = new RegisteredMethods(); + preMethods = new RegisteredMethods(); + drawMethods = new RegisteredMethods(); + postMethods = new RegisteredMethods(); + mouseEventMethods = new RegisteredMethods(); + keyEventMethods = new RegisteredMethods(); + disposeMethods = new RegisteredMethods(); /* // call the applet's setup method @@ -282,15 +293,31 @@ public class PApplet extends Applet public void stop() { //finished = true; // why did i comment this out? - if (thread != null) { - thread = null; - } + // don't run stop and disposers twice + if (thread == null) return; + //if (thread != null) { + thread = null; + //} + + disposeMethods.handle(); + /* for (int i = 0; i < libraryCount; i++) { if (libraryCalls[i][PLibrary.DISPOSE]) { libraries[i].dispose(); // endNet/endSerial etc } } + + for (int i = 0; i < stopCount; i++) { + try { + System.err.println("stopping " + i); + stopMethods[i].invoke(stopObjects[i], new Object[] { }); + } catch (Exception e) { + System.err.println("Couldn't stop " + stopObjects[i]); + e.printStackTrace(); + } + } + */ } @@ -316,7 +343,7 @@ public class PApplet extends Applet // ------------------------------------------------------------ - + /* public void attach(PLibrary library) { if (libraryCount == libraries.length) { PLibrary temp[] = new PLibrary[libraryCount << 1]; @@ -365,6 +392,166 @@ public class PApplet extends Applet } } } + */ + + + public class RegisteredMethods { + int count; + Object objects[]; + Method methods[]; + + + // convenience version for no args + public void handle() { + handle(new Object[] { }); + } + + public void handle(Object args[]) { + for (int i = 0; i < count; i++) { + try { + //System.out.println(objects[i] + " " + args); + methods[i].invoke(objects[i], args); + } catch (Exception e) { + e.printStackTrace(); + } + } + } + + public void add(Object object, Method method) { + if (objects == null) { + objects = new Object[5]; + methods = new Method[5]; + } + if (count == objects.length) { + Object otemp[] = new Object[count << 1]; + System.arraycopy(objects, 0, otemp, 0, count); + objects = otemp; + Method mtemp[] = new Method[count << 1]; + System.arraycopy(methods, 0, mtemp, 0, count); + methods = mtemp; + } + objects[count] = object; + methods[count] = method; + count++; + } + } + + + //public void registerSetup(Object o) { + //System.err.println("registerSetup not yet implemented"); + //} + + public void registerSize(Object o) { + Class args[] = new Class[] { Integer.TYPE, Integer.TYPE }; + registerWithArgs(preMethods, "size", o, args); + } + + public void registerPre(Object o) { + registerNoArgs(preMethods, "pre", o); + } + + public void registerDraw(Object o) { + registerNoArgs(drawMethods, "draw", o); + } + + public void registerPost(Object o) { + registerNoArgs(postMethods, "post", o); + } + + public void registerMouseEvent(Object o) { + Class args[] = new Class[] { MouseEvent.class }; + registerWithArgs(mouseEventMethods, "mouseEvent", o, args); + } + + + public void registerKeyEvent(Object o) { + Class args[] = new Class[] { KeyEvent.class }; + registerWithArgs(keyEventMethods, "keyEvent", o, args); + } + + public void registerDispose(Object o) { + registerNoArgs(disposeMethods, "dispose", o); + } + + + protected void registerNoArgs(RegisteredMethods meth, + String name, Object o) { + Class c = o.getClass(); + try { + Method method = c.getMethod(name, new Class[] {}); + meth.add(o, method); + + } catch (Exception e) { + die("Could not register " + name + " + () for " + o, e); + } + } + + + protected void registerWithArgs(RegisteredMethods meth, + String name, Object o, Class args[]) { + Class c = o.getClass(); + try { + Method method = c.getMethod(name, args); + meth.add(o, method); + + } catch (Exception e) { + die("Could not register " + name + " + () for " + o, e); + } + } + + + /* + Class c = o.getClass(); + try { + Method method = c.getMethod("mouseEvent", + + mouseEventMethods.add(o, method); + + } catch (Exception e) { + die("Could not register mouseEvent() for " + o, e); + } + } + + public void registerSize(Object o) { + Class c = o.getClass(); + try { + Method method = c.getMethod("size", + new Class[] { Integer.TYPE, Integer.TYPE }); + sizeMethods.add(o, method); + + } catch (Exception e) { + die("Could not register size() for " + o, e); + } + } + + + public void registerKeyEvent(Object o) { + Class c = o.getClass(); + try { + Method method = c.getMethod("keyEvent", + new Class[] { KeyEvent.class }); + keyEventMethods.add(o, method); + + } catch (Exception e) { + die("Could not register mouseEvent() for " + o, e); + } + } + */ + + /* + protected void handleDispose() { + for (int i = 0; i < disposeMethods.count; i++) { + try { + //System.err.println("stopping " + i); + disposeMethods[i].handle(new Object[] { }); + //diposeMethods[i].invoke(stopObjects[i], new Object[] { }); + } catch (Exception e) { + System.err.println("Couldn't stop " + stopObjects[i]); + e.printStackTrace(); + } + } + } + */ // ------------------------------------------------------------ @@ -376,6 +563,8 @@ public class PApplet extends Applet public void draw() { //drawMethod = false; + finished = true; // if no draw method, then... + //println("all done"); } @@ -429,11 +618,15 @@ public class PApplet extends Applet this.width = g.width; this.height = g.height; + Object args[] = new Object[] { new Integer(width), new Integer(height) }; + sizeMethods.handle(args); + /* for (int i = 0; i < libraryCount; i++) { if (libraryCalls[i][PLibrary.SIZE]) { libraries[i].size(width, height); // endNet/endSerial etc } } + */ if (frame != null) { Insets insets = frame.getInsets(); @@ -581,9 +774,10 @@ public class PApplet extends Applet this.height = g.height; } else { - for (int i = 0; i < libraryCount; i++) { - if (libraryCalls[i][PLibrary.PRE]) libraries[i].pre(); - } + preMethods.handle(); + //for (int i = 0; i < libraryCount; i++) { + // if (libraryCalls[i][PLibrary.PRE]) libraries[i].pre(); + //} draw(); // these are called *after* loop so that valid @@ -595,9 +789,10 @@ public class PApplet extends Applet if (THREAD_DEBUG) println(Thread.currentThread().getName() + " 2b endFrame"); - for (int i = 0; i < libraryCount; i++) { - if (libraryCalls[i][PLibrary.DRAW]) libraries[i].draw(); - } + drawMethods.handle(); + //for (int i = 0; i < libraryCount; i++) { + //if (libraryCalls[i][PLibrary.DRAW]) libraries[i].draw(); + //} } g.endFrame(); @@ -621,9 +816,10 @@ public class PApplet extends Applet //if (THREAD_DEBUG) println(" 3d out of wait"); //frameCount++; - for (int i = 0; i < libraryCount; i++) { - if (libraryCalls[i][PLibrary.POST]) libraries[i].post(); - } + postMethods.handle(); + //for (int i = 0; i < libraryCount; i++) { + //if (libraryCalls[i][PLibrary.POST]) libraries[i].post(); + //} } } redraw = false; // unset 'redraw' flag in case it was set @@ -675,7 +871,7 @@ public class PApplet extends Applet } if (THREAD_DEBUG) println(Thread.currentThread().getName() + " thread finished"); - //stop(); // call to shutdown libs? + stop(); // call to shutdown libs? } @@ -722,11 +918,14 @@ public class PApplet extends Applet mouseY = event.getY(); mouseEvent = event; + mouseEventMethods.handle(new Object[] { event }); + /* for (int i = 0; i < libraryCount; i++) { if (libraryCalls[i][PLibrary.MOUSE]) { libraries[i].mouse(event); // endNet/endSerial etc } } + */ // this used to only be called on mouseMoved and mouseDragged // change it back if people run into trouble @@ -873,11 +1072,14 @@ public class PApplet extends Applet key = event.getKeyChar(); keyCode = event.getKeyCode(); + keyEventMethods.handle(new Object[] { event }); + /* for (int i = 0; i < libraryCount; i++) { if (libraryCalls[i][PLibrary.KEY]) { libraries[i].key(event); // endNet/endSerial etc } } + */ switch (event.getID()) { case KeyEvent.KEY_PRESSED: diff --git a/processing/core/PLibrary.java b/processing/core/PLibrary.java deleted file mode 100644 index daf8d5dfb..000000000 --- a/processing/core/PLibrary.java +++ /dev/null @@ -1,106 +0,0 @@ -/* -*- mode: jde; c-basic-offset: 2; indent-tabs-mode: nil -*- */ - -/* - PLibrary - interface for classes that plug into bagel - Part of the Processing project - http://processing.org - - Copyright (c) 2004 Ben Fry and the Processing project. - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General - Public License along with this library; if not, write to the - Free Software Foundation, Inc., 59 Temple Place, Suite 330, - Boston, MA 02111-1307 USA -*/ - -package processing.core; - -import java.awt.event.*; - - -/** - * A series of messages can be registered via PApplet.registerCall(). - * For instance parent.registerCall(PRE) inside of the setup method - * will make sure that this library is informed each time beginFrame - * has just been called yet no drawing has taken place (would you like - * to take over the camera, eh?) - * - * An assumption for library writers is that they're fairly - * technically savvy and familiar with Java. The primary target - * audience for Procesing is less technical, so libraries are - * designed to be simple to use but only slightly more complex - * to write. - */ -public interface PLibrary { - - static final int SIZE = 6; - static final int PRE = 0; - static final int DRAW = 1; - static final int POST = 2; - static final int MOUSE = 3; - static final int KEY = 4; - static final int DISPOSE = 5; - - static final int CALL_COUNT = 7; - - /** - * This is called after the constructor on "attach" - */ - public void setup(PApplet parent); - - /** - * Called when the applet is resized. - */ - public void size(int w, int h); - - /** - * Called just after beginFrame() but before anything is - * drawn in the user's draw() method. - */ - public void pre(); - - /** - * Called before endFrame() but after all other drawing. - */ - public void draw(); - - /** - * Called betwee endFrame() and the next beginFrame() - * so that things can be post-processed based on the final, - * fully rendered, image. - */ - public void post(); - - /** - * If registered, this will be called when a mouse event has occurred. - * Use event.getID() to see whether it's MouseEvent.MOUSE_CLICKED or - * something else exciting. - */ - public void mouse(MouseEvent event); - - /** - * A key event has occurred, use event.getID() to see whether it's - * KeyEvent.KEY_PRESSED or whatever. - */ - public void key(KeyEvent e); - - /** - * Called when the applet or application is stopped. - * Override this method to shut down your threads. - * - * Named dispose() instead of stop() since stop() is often - * a useful method name for library functions (i.e. PMovie.stop() - * which will stop a movie that is playing, but not kill off - * its thread and associated resources. - */ - public void dispose(); -} diff --git a/processing/core/todo.txt b/processing/core/todo.txt index 392e24ad2..091f35340 100644 --- a/processing/core/todo.txt +++ b/processing/core/todo.txt @@ -44,6 +44,11 @@ X problem was the threading issues X bring back renderer menu X reading/saving pref for opengl renderer +_ basic sample audio playback needed for p5 +_ make separate java 1.1 and java 1.3 classes +_ once debugged, merge these back together and use reflection +_ (unless it's a messy disaster) + X beginFrame() around setup() X draw mode stuff happens inside setup.. o or maybe need to get better at size() inside of draw() ? @@ -60,6 +65,9 @@ _ problem is in gl and in core, and is inconsistent _ move more logic for layout into PApplet.. maybe a static method? _ this way can avoid duplicating / breaking things +_ add prompt() method to Camera and Serial +_ allows user to select default input device + _ still threading issues with running opengl _ first run hangs until quit _ though doesn't seem to replicate when p5 is restarted diff --git a/processing/todo.txt b/processing/todo.txt index 9bc1d481b..23b9a476a 100644 --- a/processing/todo.txt +++ b/processing/todo.txt @@ -86,8 +86,6 @@ o if a data file is in the sketch (not data) folder export breaks o works fine in the editor, but on export gets a nullpointer ex X no way around this, because needs to be able to read from local dir -_ basic sample audio playback needed for p5 - //