Permalink
Browse files

Add Fisica library.

  • Loading branch information...
jdf committed Aug 2, 2013
1 parent 687bdf4 commit 3dbb99bab1b79b6691080c57ce26a2cb7acfe89e
View
@@ -7,5 +7,7 @@
<classpathentry kind="con" path="org.eclipse.jdt.junit.JUNIT_CONTAINER/4"/>
<classpathentry kind="lib" path="buildtime/lib/jython/jython.jar" sourcepath="buildtime/lib/jython/jython-2.5.3-sources.jar"/>
<classpathentry kind="lib" path="externals/processing/core/library/core.jar"/>
+ <classpathentry kind="lib" path="libraries/fisica/fisica.jar"/>
+ <classpathentry kind="lib" path="libraries/fisica/JBox2D-2.0.1-b250-Library.jar"/>
<classpathentry kind="output" path="bin"/>
</classpath>
View
@@ -62,9 +62,16 @@
<target name="build" depends="generate-driver,build-processing">
<mkdir dir="bin"/>
- <javac classpath="${jython}:${corejar}" destdir="bin" includeantruntime="false">
+ <javac destdir="bin" includeantruntime="false">
<src path="runtime/src"/>
<src path="runtime/generated"/>
+ <classpath>
+ <pathelement location="${jython}"/>
+ <pathelement location="${corejar}"/>
+ <fileset dir="libraries/fisica">
+ <include name="*.jar"/>
+ </fileset>
+ </classpath>
</javac>
<copy todir="bin">
<fileset dir="runtime/src" excludes="**/*.java"/>
View
@@ -10,15 +10,9 @@
import shutil
import sys
-(_, sketch) = sys.argv
-
-tld = 'C:/helios/workspace/zamples'
-
-src = '%s/examples/%s' % (tld, sketch)
+src, dest = sys.argv[1:]
if not (os.path.exists(src) and os.path.isdir(src)):
raise Exception("I expect the first argument to be the source directory.")
-
-dest = '%s/py/%s' % (tld, sketch)
if os.path.exists(dest):
shutil.rmtree(dest)
os.makedirs(dest)
@@ -58,6 +52,8 @@ def xform_py(d, text):
text = re.sub(r'(?m)^(\s*)else\s*$', r'\1else:', text)
text = re.sub(r'/\*+|\*+/', '"""', text)
text = text.replace('new ', '')
+ text = text.replace('true', 'True')
+ text = text.replace('false', 'False')
text=text.replace('this.', 'self.')
return (d, text)
Binary file not shown.
View
@@ -0,0 +1,25 @@
+COPYRIGHT
+---------------
+Copyright 2009-2010 Ricard Marxer <email@ricardmarxer.com>
+This software is licensed as GNU LGPL v3 or later. See COPYING and COPYING.LESSER
+for the details of the license.
+This product includes the software JBox2D. (http://www.jbox2d.org/).
+
+INSTALL
+---------------
+Unzip the fisica-XX.zip in the Processing libraries directory.
+The result shoul look like this:
+/path/to/processing/libraries/fisica/library/fisica.jar
+
+USAGE
+---------------
+In the Processing IDE Sketch > Import Library > fisica
+
+DOCUMENTATION
+---------------
+The documentation is in the documentation folder. Just open the index.html with any web browser.
+
+AUTHOR
+---------------
+You may contact the author of this library at:
+email at ricardmarxer dot com
View
Binary file not shown.
@@ -28,6 +28,9 @@
import org.python.core.PyUnicode;
import org.python.util.InteractiveConsole;
+import fisica.FContact;
+import fisica.FContactResult;
+
import processing.core.PApplet;
import processing.core.PConstants;
import processing.core.PFont;
@@ -87,6 +90,10 @@
mouseReleasedMeth, mouseDraggedMeth, keyPressedMeth, keyReleasedMeth, keyTypedMeth, initMeth,
stopMeth, sketchFullScreenMeth, sketchWidthMeth, sketchHeightMeth, sketchRendererMeth;
+ // Callbacks from the Fisica library.
+ private final PyObject contactStartedMeth, contactPersistedMeth, contactEndedMeth,
+ contactResultMeth;
+
// Adapted from Jython's PythonInterpreter.java exec(String s) to preserve
// the source file name, so that errors have the file name instead of
// "<string>"
@@ -178,6 +185,11 @@ public PyObject __call__(final PyObject[] args, final String[] kws) {
sketchRendererMeth = interp.get("sketchRenderer");
initMeth = interp.get("init");
stopMeth = interp.get("stop");
+ contactEndedMeth = interp.get("contactEnded");
+ contactPersistedMeth = interp.get("contactPersisted");
+ contactResultMeth = interp.get("contactResult");
+ contactStartedMeth = interp.get("contactStarted");
+
addComponentListener(new ComponentAdapter() {
@Override
public void componentHidden(final ComponentEvent e) {
@@ -211,7 +223,7 @@ public void init() {
}
}
- public void blockUntilFinished() throws InterruptedException {
+ public void await() throws InterruptedException {
finishedLatch.await();
}
@@ -480,4 +492,31 @@ public void stop() {
super.stop();
}
}
+
+ /*
+ * Fisica-related callbacks.
+ */
+ public void contactStarted(final FContact c) {
+ if (contactStartedMeth != null) {
+ contactStartedMeth.__call__(Py.java2py(c));
+ }
+ }
+
+ public void contactPersisted(final FContact c) {
+ if (contactPersistedMeth != null) {
+ contactPersistedMeth.__call__(Py.java2py(c));
+ }
+ }
+
+ public void contactEnded(final FContact c) {
+ if (contactEndedMeth != null) {
+ contactEndedMeth.__call__(Py.java2py(c));
+ }
+ }
+
+ public void contactResult(final FContactResult c) {
+ if (contactResultMeth != null) {
+ contactResultMeth.__call__(Py.java2py(c));
+ }
+ }
}
@@ -319,7 +319,7 @@ public static void runFromCommandLineArguments(final String[] args) throws Excep
*/
@PythonUsage(methodName = "getLibrariesDir")
public static File getLibrariesDir() {
- String propsResource;
+ final String propsResource;
try {
propsResource =
URLDecoder.decode(Runner.class.getResource("buildnumber.properties").toString(), "UTF-8");
@@ -350,13 +350,7 @@ public static void runSketch(final String[] args, final String sketchPath,
// Recursively search the "libraries" directory for jar files and
// directories containing dynamic libraries, adding them to the
// classpath and the library path respectively.
-
- // jar:file:/opt/feinberg/processing.py/processing-py.jar
- // or
- // file:/opt/feinberg/processing.py/bin/jycessing/buildnumber.properties
-
final File libraries = getLibrariesDir();
-
searchForExtraStuff(libraries);
// Where is the sketch located?
@@ -401,7 +395,7 @@ public static void runSketch(final String[] args, final String sketchPath,
try {
PApplet.runSketch(args, applet);
- applet.blockUntilFinished();
+ applet.await();
log("Applet is finished. Disposing window.");
((Window)SwingUtilities.getRoot(applet)).dispose();
} catch (final Throwable t) {

0 comments on commit 3dbb99b

Please sign in to comment.