diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 00000000..6c84be07 --- /dev/null +++ b/.gitattributes @@ -0,0 +1,2 @@ +* text=auto eol=lf +*.bat text=auto eol=crlf diff --git a/.gitignore b/.gitignore index b465178c..32f0c537 100644 --- a/.gitignore +++ b/.gitignore @@ -1,12 +1,145 @@ -*.class - -# Package Files # -*.jar -*.war -*.ear -*.iml -.project -.classpath -.settings -/target -/.idea +## Gradle: +.gradle/ +gradle-app.setting +/build/ +/android/build/ +/core/build/ +/lwjgl2/build/ +/lwjgl3/build/ +/html/build/ +/ios/build/ +/ios-moe/build/ +/headless/build/ +/server/build/ +/shared/build/ + +## Java: +*.class +*.war +*.ear +hs_err_pid* +.attach_pid* + +## Android: +/android/libs/armeabi-v7a/ +/android/libs/arm64-v8a/ +/android/libs/x86/ +/android/libs/x86_64/ +/android/gen/ +/android/out/ +local.properties +com_crashlytics_export_strings.xml + +## Robovm: +/ios/robovm-build/ + +## iOS: +/ios/xcode/*.xcodeproj/* +!/ios/xcode/*.xcodeproj/xcshareddata +!/ios/xcode/*.xcodeproj/project.pbxproj +/ios/xcode/native/ +/ios/IOSLauncher.app +/ios/IOSLauncher.app.dSYM + +## GWT: +/html/war/ +/html/gwt-unitCache/ +.apt_generated/ +/html/war/WEB-INF/deploy/ +/html/war/WEB-INF/classes/ +.gwt/ +gwt-unitCache/ +www-test/ +.gwt-tmp/ + +## IntelliJ, Android Studio: +.idea/ +*.ipr +*.iws +*.iml + +## Eclipse: +.classpath +.project +.metadata/ +/android/bin/ +/core/bin/ +/lwjgl2/bin/ +/lwjgl3/bin/ +/html/bin/ +/ios/bin/ +/ios-moe/bin/ +/headless/bin/ +/server/bin/ +/shared/bin/ +*.tmp +*.bak +*.swp +*~.nib +.settings/ +.loadpath +.externalToolBuilders/ +*.launch + + +## NetBeans: + +/nbproject/private/ +/android/nbproject/private/ +/core/nbproject/private/ +/lwjgl2/nbproject/private/ +/lwjgl3/nbproject/private/ +/html/nbproject/private/ +/ios/nbproject/private/ +/ios-moe/nbproject/private/ +/headless/nbproject/private/ +/server/nbproject/private/ +/shared/nbproject/private/ + +/nbbuild/ +/android/nbbuild/ +/core/nbbuild/ +/lwjgl2/nbbuild/ +/lwjgl3/nbbuild/ +/html/nbbuild/ +/ios/nbbuild/ +/ios-moe/nbbuild/ +/headless/nbbuild/ +/server/nbbuild/ +/shared/nbbuild/ + +/dist/ +/android/dist/ +/core/dist/ +/lwjgl2/dist/ +/lwjgl3/dist/ +/html/dist/ +/ios/dist/ +/ios-moe/dist/ +/headless/dist/ +/server/dist/ +/shared/dist/ + +/nbdist/ +/android/nbdist/ +/core/nbdist/ +/lwjgl2/nbdist/ +/lwjgl3/nbdist/ +/html/nbdist/ +/ios/nbdist/ +/ios-moe/nbdist/ +/headless/nbdist/ +/server/nbdist/ +/shared/nbdist/ + +nbactions.xml +nb-configuration.xml + +## OS-Specific: +.DS_Store +Thumbs.db + +## Miscellaneous: +*~ +*.*# +*#*# diff --git a/README.md b/README.md index 185f042c..99fcd626 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,179 @@ +# libGDX Open Dynamics Engine (ODE4J) - physics engine LIBRARY + +![image](https://github.com/antzGames/gdx-ode4j/assets/10563814/c59c282d-9198-4066-81b7-0de4e5808f64) + +This is a ODE4J library compatible with all libGDX backends, including GWT. It is based on +version 0.4.2 of [Open Dynamics Engine for Java](https://github.com/tzaeschke/ode4j). + +If you want to use ODE4J only on libGDX Desktop/Android/iOS backends then I recommend you use [odej4](https://github.com/tzaeschke/ode4j) directly. +However if you want cross platform support (i.e include GWT support) then you need to use this library. + +Currently this is the only 3D physics engine option for GWT on libGDX. + +## How to use in your project + +Add the dependency in your core project: + +```gradle +project(":core") { + ... + + dependencies { + ... + api "com.github.antzGames:gdx-ode4j:master-SNAPSHOT" + } +} +``` + +If you are targeting HTML (GWT) you will also need the following: + +```gradle +project(":html") { + ... + dependencies { + ... + implementation "com.github.antzGames:gdx-ode4j:master-SNAPSHOT:sources" + implementation "com.github.tommyettinger:formic:0.1.4:sources" + } +} +``` + +and lastly add this to your `GdxDefinition.gwt.xml` file: + +```xml + + ... + + + ... + +``` + +## Runtime examples + +Some examples can be found in my [gdx-ode4j-examples](https://github.com/antzGames/gdx-ode4j-examples) repository. + +Or play with them on [itch.io](https://antzgames.itch.io/physics-in-a-browser). + +https://github.com/antzGames/gdx-ode4j/assets/10563814/bc46a9a9-f2e8-414b-bfde-8be6ea54e46b + +## Math classes + +Ode4j has its own math classes similar to libGDX's Vector3, Matrix3, Matrix4, and Quaternion. + +I added a math utility class called [Ode2GDXMathUtils](https://github.com/antzGames/gdx-ode4j/blob/master/src/main/java/com/github/antzGames/gdx/ode4j/Ode2GdxMathUtils.java). Use the following methods to create the libGDX Quaternion from ode4j's QuanternionC or DMatrix3C: + +```java + Quaternion q1 = Ode2GdxMathUtils.getGdxQuaternion(odeQuaternion); + Quaternion q2 = Ode2GdxMathUtils.getGdxQuaternion(odeMat3); +``` + +In addition ode4j uses double and not float like most of libGDX's math classes. + +## Limitations + +### Fixed timesteps + +ODE was made to work with fixed timesteps. Do not pass `Gdx.graphics.getDeltaTime()` to `world.quickStep()`. + +The following online [ODE HOWTO entry](https://ode.org/wiki/index.php/HOWTO_fixed_vs_variable_timestep) discusses how to incorporate this limitation into a game. + +Using `vsync=true` in your game launch configuration helps, but some people might run at 60hz, while others might run at 50Hz, 75Hz, 144Hz. +This means that objects will fall/interact at different speeds on these different refresh rates. + +Below is example code that you can use to force physics to only update at a fixed interval (timestep). + +```java +public static final float MIN_FRAME_LENGTH = 1f/60f; + ... + +@Override +public void render(float deltaTime){ + timeSinceLastRender += deltaTime; + + // Only compute 60Hz for physics + if (timeSinceLastRender >= MIN_FRAME_LENGTH) { + odePhysicsSystem.update(MIN_FRAME_LENGTH); // My custom class, which eventaully calls world.quickStep(MIN_FRAME_LENGTH) + timeSinceLastRender -= MIN_FRAME_LENGTH; + + if(timeSinceLastRender > MIN_FRAME_LENGTH) + timeSinceLastRender = 0; + } + + ... +} +``` + +### Performance + +I have tried jBullet, PhysX and ODE physics engines with libGDX. ODE is the slowest, and the reason being is that in ODE everything is using double precision. + +### Known Issues + +ODE4J 0.4.2 has some Triangle Mesh (TriMesh) collision detection issues. + +The owner of ODE4J has fixed them in ODE4J 0.5.0. + +I will have to update this library to use ODE4J 0.5.0 which is planned. + +## Where to get ODE/ode4j documentation and help + +ODE official manual: http://ode.org/wiki/index.php/Manual + +By far the most useful part is the [HOWTO](http://ode.org/wiki/index.php/HOWTO) section + +ode4j discord channel : https://discord.gg/UFXJcXv2P8 ode4j/Java + +ode4j contains also some features that are not present in ODE, such as a ragdoll and heightfields with holes. See ode4j's [Wiki](https://github.com/tzaeschke/ode4j/wiki/Functionality-beyond-ODE). + +The [ODE forum](https://groups.google.com/forum/#!forum/ode-users) is useful for questions around physics and general API usage. + +The [ode4j forum](https://groups.google.com/forum/?hl=en#!forum/ode4j) is for problems and functionality specific to ode4j/Java. + +There is also the [old website](https://tzaeschke.github.io/ode4j-old/), including some [screenshots](https://tzaeschke.github.io/ode4j-old/ode4j-features.html). + +Here is a [Youtube video](https://www.youtube.com/watch?v=ENlpu_Jjp3Q) of a list of games that used ODE from 2002-2015. You will be suprised how many of your favorite games used this physcis libary. + +## ODE, ode4j and other Licenses + +### Licensing & Copyright for ODE and ode4j + +This library is under copyright by Tilmann Zäschke (Java port), Russell L. Smith (copyright holder of the original ODE code), Francisco Leon (copyright holder of the original GIMPACT code) and Daniel Fiser (copyright holder of the original libccd). + +This library is free software; you can redistribute it and/or modify it under the terms of EITHER: +(1) 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. The text of the GNU Lesser General Public License is included with this library in the file LICENSE.TXT. +(2) The BSD-style license that is included with this library in the files ODE-LICENSE-BSD.TXT and ODE4j-LICENSE-BSD.TXT. + +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 files LICENSE.TXT, ODE-LICENSE-BSD.TXT, GIMPACT-LICENSE-BSD.TXT, GIMPACT-LICENSE-LGPL.TXT, ODE4J-LICENSE-BSD.TXT and LIBCCD_BSD-LICENSE for more details. + +The LICENSE.TXT, ODE-LICENSE-BSD.TXT, GIMPACT-LICENSE-BSD.TXT, GIMPACT-LICENSE-LGPL.TXT, LIBCCD_BSD-LICENSE and ODE4J-LICENSE-BSD.TXT files are available in the source code. + +## Legal + +ode4j: +Copyright (c) 2009-2017 Tilmann Zäschke ode4j@gmx.de. +All rights reserved. + +Like the original ODE, ode4j is licensed under LGPL v2.1 and BSD 3-clause. Choose whichever license suits your needs. + +### ode4j contains Java ports of the following software + +[ODE/OpenDE](http://www.ode.org/): +Copyright (c) 2001,2002 Russell L. Smith +All rights reserved. + +GIMPACT (part of ODE/OpenDE): +Copyright of GIMPACT (c) 2006 Francisco Leon. C.C. 80087371. +email: projectileman(AT)yahoo.com + +[LIBCCD](https://github.com/danfis/libccd): +Copyright (c) 2010 Daniel Fiser ; +3-clause BSD License + +[Turbulenz Engine](https://github.com/turbulenz/turbulenz_engine): +Copyright (c) 2009-2014 Turbulenz Limited; MIT License + + # ode4j ![Java 8](https://github.com/tzaeschke/ode4j/actions/workflows/build-java-8.yml/badge.svg) diff --git a/build.gradle b/build.gradle new file mode 100644 index 00000000..9bcea70a --- /dev/null +++ b/build.gradle @@ -0,0 +1,96 @@ +buildscript { + repositories { + mavenLocal() + mavenCentral() + maven { url "https://oss.sonatype.org/content/repositories/snapshots/" } + gradlePluginPortal() + } + dependencies { + classpath 'com.vanniktech:gradle-maven-publish-plugin:0.22.0' + } +} + +apply plugin: 'java-library' +apply plugin: 'com.vanniktech.maven.publish' + +// Changing this to 11 may be possible, but anything higher will restrict this library to being used on desktop only. +// It may be possible to downgrade this to 1.7, but then you need to avoid using LWJGL3 within this library/its tests. +sourceCompatibility = 1.8 + +//Obviously, change the next line to match your project name. +def projectName = 'gdx-ode4j' + +//Change this to whatever Maven Central group you might publish to, which is probably not this one if you aren't Tommy Ettinger. +group 'com.github.antzGames' + +version "$VERSION_NAME" // You can set the version in gradle.properties . + +[compileJava, compileTestJava, javadoc]*.options*.encoding = 'UTF-8' + +sourceSets { + main.java.srcDirs = ['core/src/main/java'] + main.java.exclude(['core/src/test', '**/cpp4j/Cstd*.java', '**/cpp4j/FILE.java']) + main.resources.srcDirs = ['core/src/main/resources'] +} + +// Disable JDK 8's doclint +// http://blog.joda.org/2014/02/turning-off-doclint-in-jdk-8-javadoc.html +if (JavaVersion.current().isJava8Compatible()) { + allprojects { + tasks.withType(Javadoc) { + // The -quiet is because of some sort of weird JDK JavaCompiler bug: + // https://discuss.gradle.org/t/passing-arguments-to-compiler-and-javadoc/1661 + options.addStringOption('Xdoclint:none,-missing', '-quiet') + } + } +} + +if(JavaVersion.current().isJava9Compatible()) { + allprojects { + tasks.withType(JavaCompile) { + options.release.set(8) // LWJGL3 needs Java 8 starting in libGDX 1.11.0, which forces tests + // to use Java 8 or higher. options.release enforces compatibility with Java 8, + // including how NIO Buffers behave (which broke compatibility in Java 9). + } + } +} + +// JavaDocs will be published inside the docs/ folder, which you can easily put on GitHub Pages in your repo settings. +// You may instead want to remove this line if frequent doc changes use up too much repo space. +javadoc.destinationDir = file('docs/apidocs') + +jar { + archiveBaseName.set(projectName) + manifest { + attributes 'Implementation-Title': projectName, 'Implementation-Version': archiveVersion + } +} + +repositories { + // You can uncomment mavenLocal() if you need self-built versions, but it can be a problem with GWT or other sources dependencies. + mavenLocal() + mavenCentral() + maven { url 'https://s01.oss.sonatype.org' } + google() + gradlePluginPortal() + maven { url 'https://oss.sonatype.org/content/repositories/snapshots/' } + maven { url 'https://s01.oss.sonatype.org/content/repositories/snapshots/' } + // JitPack is a good repo to have if you depend on commit versions. + // Having the below repo might cause problems if uploading to Maven Central. + maven { url 'https://jitpack.io' } +} + +dependencies { +// Change gdxVersion in gradle.properties to update or downgrade. +// Libraries that don't use libGDX directly can change the next line +// from `api` to `testImplementation` . + api "com.badlogicgames.gdx:gdx:$gdxVersion" + api "com.github.tommyettinger:formic:$formicVersion" + testImplementation "com.badlogicgames.gdx:gdx-backend-lwjgl3:$gdxVersion" + testImplementation "com.badlogicgames.gdx:gdx-platform:$gdxVersion:natives-desktop" + testImplementation "junit:junit:4.13.2" + api "org.slf4j:slf4j-api:2.0.7" + + // I don't know what conditions may require this to run tests. + //testRuntimeOnly "org.junit.vintage:junit-vintage-engine:5.9.0" +} diff --git a/core/src/main/java/org/ode4j/GWTAtomicIntegerArray.java b/core/src/main/java/org/ode4j/GWTAtomicIntegerArray.java new file mode 100644 index 00000000..0808dd2f --- /dev/null +++ b/core/src/main/java/org/ode4j/GWTAtomicIntegerArray.java @@ -0,0 +1,221 @@ +package org.ode4j; + +import java.io.Serializable; + +public class GWTAtomicIntegerArray implements Serializable { + private static final long serialVersionUID = 2862133569453604235L; + private final int[] array; + + public GWTAtomicIntegerArray(int length) { + this.array = new int[length]; + } + + public GWTAtomicIntegerArray(int[] array) { + this.array = array; + } + + public final int length() { + return this.array.length; + } + + public final int get(int i) { + return this.array[i]; + } + + public final void set(int i, int newValue) { + this.array[i] = newValue; + } +// +// public final void lazySet(int i, int newValue) { +// AA.setRelease(this.array, i, newValue); +// } +// +// public final int getAndSet(int i, int newValue) { +// return AA.getAndSet(this.array, i, newValue); +// } + + public final boolean compareAndSet(int i, int expectedValue, int newValue) { + if (this.array[i] == expectedValue) { + this.array[i] = newValue; + return true; + } + return false; + } + +// /** @deprecated */ +// @Deprecated( +// since = "9" +// ) +// public final boolean weakCompareAndSet(int i, int expectedValue, int newValue) { +// return AA.weakCompareAndSetPlain(this.array, i, expectedValue, newValue); +// } +// +// public final boolean weakCompareAndSetPlain(int i, int expectedValue, int newValue) { +// return AA.weakCompareAndSetPlain(this.array, i, expectedValue, newValue); +// } +// +// public final int getAndIncrement(int i) { +// return AA.getAndAdd(this.array, i, 1); +// } +// +// public final int getAndDecrement(int i) { +// return AA.getAndAdd(this.array, i, -1); +// } +// +// public final int getAndAdd(int i, int delta) { +// return AA.getAndAdd(this.array, i, delta); +// } +// +// public final int incrementAndGet(int i) { +// return AA.getAndAdd(this.array, i, 1) + 1; +// } +// +// public final int decrementAndGet(int i) { +// return AA.getAndAdd(this.array, i, -1) - 1; +// } +// +// public final int addAndGet(int i, int delta) { +// return AA.getAndAdd(this.array, i, delta) + delta; +// } +// +// public final int getAndUpdate(int i, IntUnaryOperator updateFunction) { +// int prev = this.get(i); +// int next = 0; +// boolean haveNext = false; +// +// while(true) { +// if (!haveNext) { +// next = updateFunction.applyAsInt(prev); +// } +// +// if (this.weakCompareAndSetVolatile(i, prev, next)) { +// return prev; +// } +// +// haveNext = prev == (prev = this.get(i)); +// } +// } +// +// public final int updateAndGet(int i, IntUnaryOperator updateFunction) { +// int prev = this.get(i); +// int next = 0; +// boolean haveNext = false; +// +// while(true) { +// if (!haveNext) { +// next = updateFunction.applyAsInt(prev); +// } +// +// if (this.weakCompareAndSetVolatile(i, prev, next)) { +// return next; +// } +// +// haveNext = prev == (prev = this.get(i)); +// } +// } +// +// public final int getAndAccumulate(int i, int x, IntBinaryOperator accumulatorFunction) { +// int prev = this.get(i); +// int next = 0; +// boolean haveNext = false; +// +// while(true) { +// if (!haveNext) { +// next = accumulatorFunction.applyAsInt(prev, x); +// } +// +// if (this.weakCompareAndSetVolatile(i, prev, next)) { +// return prev; +// } +// +// haveNext = prev == (prev = this.get(i)); +// } +// } +// +// public final int accumulateAndGet(int i, int x, IntBinaryOperator accumulatorFunction) { +// int prev = this.get(i); +// int next = 0; +// boolean haveNext = false; +// +// while(true) { +// if (!haveNext) { +// next = accumulatorFunction.applyAsInt(prev, x); +// } +// +// if (this.weakCompareAndSetVolatile(i, prev, next)) { +// return next; +// } +// +// haveNext = prev == (prev = this.get(i)); +// } +// } +// +// public String toString() { +// int iMax = this.array.length - 1; +// if (iMax == -1) { +// return "[]"; +// } else { +// StringBuilder b = new StringBuilder(); +// b.append('['); +// int i = 0; +// +// while(true) { +// b.append(this.get(i)); +// if (i == iMax) { +// return b.append(']').toString(); +// } +// +// b.append(',').append(' '); +// ++i; +// } +// } +// } +// +// public final int getPlain(int i) { +// return AA.get(this.array, i); +// } +// +// public final void setPlain(int i, int newValue) { +// AA.set(this.array, i, newValue); +// } +// +// public final int getOpaque(int i) { +// return AA.getOpaque(this.array, i); +// } +// +// public final void setOpaque(int i, int newValue) { +// AA.setOpaque(this.array, i, newValue); +// } +// +// public final int getAcquire(int i) { +// return AA.getAcquire(this.array, i); +// } +// +// public final void setRelease(int i, int newValue) { +// AA.setRelease(this.array, i, newValue); +// } +// +// public final int compareAndExchange(int i, int expectedValue, int newValue) { +// return AA.compareAndExchange(this.array, i, expectedValue, newValue); +// } +// +// public final int compareAndExchangeAcquire(int i, int expectedValue, int newValue) { +// return AA.compareAndExchangeAcquire(this.array, i, expectedValue, newValue); +// } +// +// public final int compareAndExchangeRelease(int i, int expectedValue, int newValue) { +// return AA.compareAndExchangeRelease(this.array, i, expectedValue, newValue); +// } +// +// public final boolean weakCompareAndSetVolatile(int i, int expectedValue, int newValue) { +// return AA.weakCompareAndSet(this.array, i, expectedValue, newValue); +// } +// +// public final boolean weakCompareAndSetAcquire(int i, int expectedValue, int newValue) { +// return AA.weakCompareAndSetAcquire(this.array, i, expectedValue, newValue); +// } +// +// public final boolean weakCompareAndSetRelease(int i, int expectedValue, int newValue) { +// return AA.weakCompareAndSetRelease(this.array, i, expectedValue, newValue); +// } +} diff --git a/core/src/main/java/org/ode4j/Ode2GdxMathUtils.java b/core/src/main/java/org/ode4j/Ode2GdxMathUtils.java new file mode 100644 index 00000000..3f2f8092 --- /dev/null +++ b/core/src/main/java/org/ode4j/Ode2GdxMathUtils.java @@ -0,0 +1,77 @@ +package org.ode4j; + +import com.badlogic.gdx.math.Quaternion; + +import org.ode4j.math.DMatrix3C; +import org.ode4j.math.DQuaternionC; + +public class Ode2GdxMathUtils { + + private static float m00; + private static float m01; + private static float m02; + private static float m10; + private static float m11; + private static float m12; + private static float m20; + private static float m21; + private static float m22; + + private static float qw, qx, qy, qz; + private static float tr; + private static float S; + + private static Quaternion q = new Quaternion(); + + // 0, 1, 2, 3 + // ODE w, x, y ,z + // libGDX x, y, z, w + public static Quaternion getGdxQuaternion(DQuaternionC odeQ){ + q.set((float)odeQ.get1(), (float)odeQ.get2(), (float)odeQ.get3(), (float) odeQ.get0()); + return q; + } + + // From https://www.euclideanspace.com/maths/geometry/rotations/conversions/matrixToQuaternion/ + public static Quaternion getGdxQuaternion(DMatrix3C odeMat3) { + + m00 = (float) odeMat3.get00(); + m01 = (float) odeMat3.get01(); + m02 = (float) odeMat3.get02(); + m10 = (float) odeMat3.get10(); + m11 = (float) odeMat3.get11(); + m12 = (float) odeMat3.get12(); + m20 = (float) odeMat3.get20(); + m21 = (float) odeMat3.get21(); + m22 = (float) odeMat3.get22(); + + tr = m00 + m11 + m22; + + if (tr > 0) { + S = (float)Math.sqrt(tr + 1.0) * 2; // S=4*qw + qw = 0.25f * S; + qx = (m21 - m12) / S; + qy = (m02 - m20) / S; + qz = (m10 - m01) / S; + } else if ((m00 > m11) & (m00 > m22)) { + S = (float)Math.sqrt(1.0 + m00 - m11 - m22) * 2; // S=4*qx + qw = (m21 - m12) / S; + qx = 0.25f * S; + qy = (m01 + m10) / S; + qz = (m02 + m20) / S; + } else if (m11 > m22) { + S = (float)Math.sqrt(1.0 + m11 - m00 - m22) * 2; // S=4*qy + qw = (m02 - m20) / S; + qx = (m01 + m10) / S; + qy = 0.25f * S; + qz = (m12 + m21) / S; + } else { + S = (float)Math.sqrt(1.0 + m22 - m00 - m11) * 2; // S=4*qz + qw = (m10 - m01) / S; + qx = (m02 + m20) / S; + qy = (m12 + m21) / S; + qz = 0.25f * S; + } + q.set(qx, qy, qz, qw); + return q; + } +} diff --git a/core/src/main/java/org/ode4j/math/DMatrix3.java b/core/src/main/java/org/ode4j/math/DMatrix3.java index 44058169..2ffef3f7 100644 --- a/core/src/main/java/org/ode4j/math/DMatrix3.java +++ b/core/src/main/java/org/ode4j/math/DMatrix3.java @@ -22,6 +22,8 @@ package org.ode4j.math; +import com.badlogic.gdx.utils.NumberUtils; + import java.util.Arrays; /** @@ -727,7 +729,7 @@ public final boolean equals(Object o) { public int hashCode() { int h = 0; for (double d: v) { - h |= Double.doubleToRawLongBits(d); + h |= NumberUtils.doubleToLongBits(d); h <<= 2; } return h; diff --git a/core/src/main/java/org/ode4j/math/DQuaternion.java b/core/src/main/java/org/ode4j/math/DQuaternion.java index 9577cfb0..82837589 100644 --- a/core/src/main/java/org/ode4j/math/DQuaternion.java +++ b/core/src/main/java/org/ode4j/math/DQuaternion.java @@ -22,6 +22,8 @@ package org.ode4j.math; +import com.badlogic.gdx.utils.NumberUtils; + import static org.ode4j.ode.internal.Common.M_PI; /** @@ -193,13 +195,13 @@ public boolean equals(Object obj) { @Deprecated // float is generally not comparable. To be removed in 0.6.0. TODO deprecated public int hashCode() { int h = 0; - h |= Double.doubleToRawLongBits(w); + h |= NumberUtils.doubleToLongBits(w); h <<= 6; - h |= Double.doubleToRawLongBits(x); + h |= NumberUtils.doubleToLongBits(x); h <<= 6; - h |= Double.doubleToRawLongBits(y); + h |= NumberUtils.doubleToLongBits(y); h <<= 6; - h |= Double.doubleToRawLongBits(z); + h |= NumberUtils.doubleToLongBits(z); h <<= 6; return h; } diff --git a/core/src/main/java/org/ode4j/math/DVector3.java b/core/src/main/java/org/ode4j/math/DVector3.java index 1e405b85..a252d309 100644 --- a/core/src/main/java/org/ode4j/math/DVector3.java +++ b/core/src/main/java/org/ode4j/math/DVector3.java @@ -21,6 +21,8 @@ *************************************************************************/ package org.ode4j.math; +import com.badlogic.gdx.utils.NumberUtils; + import org.ode4j.math.DMatrix3.DVector3ColView; import org.ode4j.ode.OdeMath; @@ -644,9 +646,9 @@ public boolean equals(Object obj) { @Override @Deprecated // float is generally not comparable. To be removed in 0.6.0. TODO deprecated public int hashCode() { - return (int) (Double.doubleToRawLongBits(get0()) * - Double.doubleToRawLongBits(get1()) * - Double.doubleToRawLongBits(get2())); + return (int) (NumberUtils.doubleToLongBits(get0()) * + NumberUtils.doubleToLongBits(get1()) * + NumberUtils.doubleToLongBits(get2())); } /** diff --git a/core/src/main/java/org/ode4j/math/DVector3View.java b/core/src/main/java/org/ode4j/math/DVector3View.java index 21e03433..d2e46b82 100644 --- a/core/src/main/java/org/ode4j/math/DVector3View.java +++ b/core/src/main/java/org/ode4j/math/DVector3View.java @@ -21,6 +21,8 @@ *************************************************************************/ package org.ode4j.math; +import com.badlogic.gdx.utils.NumberUtils; + public abstract class DVector3View implements DVector3I { @Override public abstract double get0(); @@ -100,8 +102,8 @@ public boolean equals(Object obj) { @Override @Deprecated // float is generally not comparable. To be removed in 0.6.0. TODO deprecated public int hashCode() { - return (int) (Double.doubleToRawLongBits(get0()) * - Double.doubleToRawLongBits(get1()) * - Double.doubleToRawLongBits(get2())); + return (int) (NumberUtils.doubleToLongBits(get0()) * + NumberUtils.doubleToLongBits(get1()) * + NumberUtils.doubleToLongBits(get2())); } } diff --git a/core/src/main/java/org/ode4j/math/DVector6.java b/core/src/main/java/org/ode4j/math/DVector6.java index 42fcb0f5..3d34a09a 100644 --- a/core/src/main/java/org/ode4j/math/DVector6.java +++ b/core/src/main/java/org/ode4j/math/DVector6.java @@ -21,6 +21,8 @@ *************************************************************************/ package org.ode4j.math; +import com.badlogic.gdx.utils.NumberUtils; + import java.util.Arrays; @@ -145,7 +147,7 @@ public boolean equals(Object obj) { public int hashCode() { int h = 0; for (double d: v) { - h |= Double.doubleToRawLongBits(d); + h |= NumberUtils.doubleToLongBits(d); h <<= 4; } return h; diff --git a/core/src/main/java/org/ode4j/math/DVectorN.java b/core/src/main/java/org/ode4j/math/DVectorN.java index 20ed9002..b629d55b 100644 --- a/core/src/main/java/org/ode4j/math/DVectorN.java +++ b/core/src/main/java/org/ode4j/math/DVectorN.java @@ -44,15 +44,15 @@ public DVectorN(double[] data) { System.arraycopy(data, 0, v, 0, v.length); } - /** - * Please use @see #copy() instead. This is deprecated because we don't implement Cloneable. - * @return A clone() of this object. - */ - @Override - @Deprecated // TODO deprecated. Should be removed. Please use copy() instead. To be removed in 0.6.0. - public DVectorN clone() { - return new DVectorN(this); - } +// /** +// * Please use @see #copy() instead. This is deprecated because we don't implement Cloneable. +// * @return A clone() of this object. +// */ +// @Override +// @Deprecated // TODO deprecated. Should be removed. Please use copy() instead. To be removed in 0.6.0. +// public DVectorN clone() { +// return new DVectorN(this); +// } /** * @return A copy of this object. diff --git a/core/src/main/java/org/ode4j/ode/DStopwatch.java b/core/src/main/java/org/ode4j/ode/DStopwatch.java index 5e640564..bad15a11 100644 --- a/core/src/main/java/org/ode4j/ode/DStopwatch.java +++ b/core/src/main/java/org/ode4j/ode/DStopwatch.java @@ -24,6 +24,8 @@ *************************************************************************/ package org.ode4j.ode; +import com.badlogic.gdx.utils.TimeUtils; + // @Deprecated // This will be removed in 0.6.0 public class DStopwatch { @@ -40,12 +42,12 @@ public void reset () { public void start () { - _cc = System.nanoTime(); + _cc = TimeUtils.nanoTime(); } public void stop () { - _time += System.nanoTime() - _cc; + _time += TimeUtils.nanoTime() - _cc; } diff --git a/core/src/main/java/org/ode4j/ode/internal/Common.java b/core/src/main/java/org/ode4j/ode/internal/Common.java index da8e6076..4548765c 100644 --- a/core/src/main/java/org/ode4j/ode/internal/Common.java +++ b/core/src/main/java/org/ode4j/ode/internal/Common.java @@ -24,6 +24,8 @@ *************************************************************************/ package org.ode4j.ode.internal; +import com.badlogic.gdx.utils.NumberUtils; + import org.ode4j.math.DVector3; import org.ode4j.ode.DGeom.DNearCallback; import org.ode4j.ode.DWorld; @@ -532,9 +534,27 @@ public static double dCopysign(double magnitude, double sign) { } //#define dNextAfter(x, y) nextafterf(x, y) /* next value after */ - public static double dNextAfter(double start, double direction) { - return Math.nextAfter(start, direction); - } +// public static double dNextAfter(double start, double direction) { +// return Math.nextAfter(start, direction); +// } + + public static final double dNextAfter(double start, double direction) { + + long transducer; + if (start > direction) { + if (start != 0.0D) { + transducer = NumberUtils.doubleToLongBits(start); + return NumberUtils.longBitsToDouble(transducer + (transducer > 0L ? -1L : 1L)); + } else { + return -4.9E-324D; + } + } else if (start < direction) { + transducer = NumberUtils.doubleToLongBits(start + 0.0D); + return NumberUtils.longBitsToDouble(transducer + (transducer >= 0L ? 1L : -1L)); + } else { + return start == direction ? direction : start + direction; + } + } //#ifdef HAVE___ISNAN diff --git a/core/src/main/java/org/ode4j/ode/internal/DLCP.java b/core/src/main/java/org/ode4j/ode/internal/DLCP.java index 670dbc09..8618f348 100644 --- a/core/src/main/java/org/ode4j/ode/internal/DLCP.java +++ b/core/src/main/java/org/ode4j/ode/internal/DLCP.java @@ -38,7 +38,7 @@ import static org.ode4j.ode.internal.Misc.dMakeRandomMatrix; import static org.ode4j.ode.internal.Misc.dMaxDifference; import static org.ode4j.ode.internal.Misc.dRandReal; -import static org.ode4j.ode.internal.cpp4j.Cstdio.printf; +//import static org.ode4j.ode.internal.cpp4j.Cstdio.printf; import static org.ode4j.ode.internal.cpp4j.Cstring.memcpy; import static org.ode4j.ode.internal.cpp4j.Cstring.memmove; @@ -1544,8 +1544,8 @@ else if (xi >= lo[i] && xi <= hi[i] && wi == 0) { // pacifier if (print) { - printf("passed: NL=%3d NH=%3d C=%3d ", n1, n2, n3); - printf("time=%10.3f ms avg=%10.4f\n", time * 1000.0, average); +// printf("passed: NL=%3d NH=%3d C=%3d ", n1, n2, n3); +// printf("time=%10.3f ms avg=%10.4f\n", time * 1000.0, average); } } arena.END_STATE_SAVE(saveInner); diff --git a/core/src/main/java/org/ode4j/ode/internal/DxBox.java b/core/src/main/java/org/ode4j/ode/internal/DxBox.java index 61769653..cdd423cc 100644 --- a/core/src/main/java/org/ode4j/ode/internal/DxBox.java +++ b/core/src/main/java/org/ode4j/ode/internal/DxBox.java @@ -35,6 +35,7 @@ import static org.ode4j.ode.OdeMath.*; import static org.ode4j.ode.internal.cpp4j.C_All.*; +import static org.ode4j.ode.internal.cpp4j.Cstring.memcpy; /** diff --git a/core/src/main/java/org/ode4j/ode/internal/DxConvex.java b/core/src/main/java/org/ode4j/ode/internal/DxConvex.java index 2d91bef0..acfeab09 100644 --- a/core/src/main/java/org/ode4j/ode/internal/DxConvex.java +++ b/core/src/main/java/org/ode4j/ode/internal/DxConvex.java @@ -29,8 +29,8 @@ import static org.ode4j.ode.OdeMath.*; import static org.ode4j.ode.internal.DxCollisionUtil.dVector3Copy; import static org.ode4j.ode.internal.cpp4j.Cmath.fabs; -import static org.ode4j.ode.internal.cpp4j.Cstdio.fprintf; -import static org.ode4j.ode.internal.cpp4j.Cstdio.stdout; +//import static org.ode4j.ode.internal.cpp4j.Cstdio.fprintf; +//import static org.ode4j.ode.internal.cpp4j.Cstdio.stdout; import org.ode4j.math.DVector3; import org.ode4j.math.DVector3C; @@ -247,13 +247,13 @@ private int SupportIndex(DVector3 dir) points[(index03)+1]*points[(index13)+0]*points[(index23)+2] - points[(index03)+0]*points[(index13)+2]*points[(index23)+1])<0) { - fprintf(stdout,"WARNING: Polygon %d is not defined counterclockwise\n",i); + //fprintf(stdout,"WARNING: Polygon %d is not defined counterclockwise\n",i); } //points_in_poly+=(*points_in_poly+1); points_in_polyPos+= polygons[points_in_polyPos]+1; indexPos=points_in_polyPos+1;//index=points_in_poly+1; //if(planes[(i*4)+3]<0) fprintf(stdout,"WARNING: Plane %d does not contain the origin\n",i); - if(planesD[i]<0) fprintf(stdout,"WARNING: Plane %d does not contain the origin\n",i); + //if(planesD[i]<0) fprintf(stdout,"WARNING: Plane %d does not contain the origin\n",i); } } //#endif dNODEBUG diff --git a/core/src/main/java/org/ode4j/ode/internal/DxGimpact.java b/core/src/main/java/org/ode4j/ode/internal/DxGimpact.java index 9e8dcdbd..ac2f5f9f 100644 --- a/core/src/main/java/org/ode4j/ode/internal/DxGimpact.java +++ b/core/src/main/java/org/ode4j/ode/internal/DxGimpact.java @@ -47,15 +47,15 @@ public class DxGimpact extends DxTriMesh { //GimTrimesh m_collision_trimesh; //void dGeomTriMeshSetLastTransform( DMatrix4 last_trans ) { //stub - void dGeomTriMeshSetLastTransform( Object last_trans ) { //stub - throw new UnsupportedAddressTypeException(); - } - - // DMatrix4 dGeomTriMeshGetLastTransform() { - Object dGeomTriMeshGetLastTransform() { - throw new UnsupportedAddressTypeException(); - // return null; // stub - } +// void dGeomTriMeshSetLastTransform( Object last_trans ) { //stub +// throw new UnsupportedAddressTypeException(); +// } +// +// // DMatrix4 dGeomTriMeshGetLastTransform() { +// Object dGeomTriMeshGetLastTransform() { +// throw new UnsupportedAddressTypeException(); +// // return null; // stub +// } // Trimesh diff --git a/core/src/main/java/org/ode4j/ode/internal/DxQuickStep.java b/core/src/main/java/org/ode4j/ode/internal/DxQuickStep.java index f3f821e9..0338460a 100644 --- a/core/src/main/java/org/ode4j/ode/internal/DxQuickStep.java +++ b/core/src/main/java/org/ode4j/ode/internal/DxQuickStep.java @@ -39,7 +39,7 @@ import static org.ode4j.ode.internal.CommonEnums.*; import static org.ode4j.ode.internal.QuickStepEnums.*; import static org.ode4j.ode.internal.Timer.*; -import static org.ode4j.ode.internal.Timer.dTimerReport; +//import static org.ode4j.ode.internal.Timer.dTimerReport; import static org.ode4j.ode.internal.cpp4j.Cstring.memcpy; import java.io.PrintStream; @@ -50,7 +50,7 @@ import org.ode4j.math.DVector3; import org.ode4j.ode.DJoint; import org.ode4j.ode.internal.Objects_H.dxQuickStepParameters; -import org.ode4j.ode.internal.cpp4j.FILE; +//import org.ode4j.ode.internal.cpp4j.FILE; import org.ode4j.ode.internal.joints.DxJoint; import org.ode4j.ode.internal.processmem.DxStepperProcessingCallContext; import org.ode4j.ode.internal.processmem.DxStepperProcessingCallContext.dmaxcallcountestimate_fn_t; @@ -111,7 +111,7 @@ private static void IFTIMING_dTimerEnd() { } private static void IFTIMING_dTimerReport (PrintStream fout, int average) { if (TIMING) { - dTimerReport(new FILE(fout), average); + //dTimerReport(new FILE(fout), average); } } diff --git a/core/src/main/java/org/ode4j/ode/internal/ErrorHdl.java b/core/src/main/java/org/ode4j/ode/internal/ErrorHdl.java index 3dc70596..fee01add 100644 --- a/core/src/main/java/org/ode4j/ode/internal/ErrorHdl.java +++ b/core/src/main/java/org/ode4j/ode/internal/ErrorHdl.java @@ -25,8 +25,8 @@ package org.ode4j.ode.internal; import org.ode4j.ode.internal.ErrorHandler.dMessageFunction; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; +//import org.slf4j.Logger; +//import org.slf4j.LoggerFactory; /** @@ -35,7 +35,7 @@ */ public class ErrorHdl { - public static Logger logger = LoggerFactory.getLogger(ErrorHdl.class); + //public static Logger logger = LoggerFactory.getLogger(ErrorHdl.class); // /** // * @author Tilmann Zaeschke @@ -120,7 +120,7 @@ public static void dError (int num, String msg, Object ... ap) { if (error_function != null) { error_function.call (num,msg,ap); } else { - logger.error("ODE Error " + num + ": " + msg, ap); + //logger.error("ODE Error " + num + ": " + msg, ap); } throw new RuntimeException("#"+num + ": " + msg); //exit (1); @@ -139,11 +139,12 @@ public static void dDebug (int num, String msg, Object ... ap) { if (debug_function != null) { debug_function.call (num,msg,ap); } else { - logger.debug("ODE INTERNAL ERROR " + " " + num + ": " + msg, ap); + //logger.debug("ODE INTERNAL ERROR " + " " + num + ": " + msg, ap); } // *((char *)0) = 0; ... commit SEGVicide //abort(); - throw new RuntimeException("#"+num + ": " + String.format(msg, ap)); + //throw new RuntimeException("#"+num + ": " + String.format(msg, ap)); + throw new RuntimeException("#"+num + ": " + msg); } @@ -160,7 +161,7 @@ public static void dMessage (int num, String msg, Object ... ap) { message_function.call (num,msg,ap); } else { //printMessage (num,"ODE Message",msg,ap); - logger.info("ODE Message " + num + ": " + msg, ap); + //logger.info("ODE Message " + num + ": " + msg, ap); } } diff --git a/core/src/main/java/org/ode4j/ode/internal/Misc.java b/core/src/main/java/org/ode4j/ode/internal/Misc.java index 2d0dcbcb..2a71f93c 100644 --- a/core/src/main/java/org/ode4j/ode/internal/Misc.java +++ b/core/src/main/java/org/ode4j/ode/internal/Misc.java @@ -32,11 +32,11 @@ import org.ode4j.math.DQuaternionC; import org.ode4j.math.DVector3; import org.ode4j.math.DVector3C; -import org.ode4j.ode.internal.cpp4j.FILE; +//import org.ode4j.ode.internal.cpp4j.FILE; import static org.ode4j.ode.internal.Common.dFabs; import static org.ode4j.ode.internal.Common.dPAD; -import static org.ode4j.ode.internal.cpp4j.Cstdio.*; +//import static org.ode4j.ode.internal.cpp4j.Cstdio.*; @@ -229,15 +229,15 @@ public static double dRandReal() /** print out a matrix */ // void dPrintMatrix (final double []A, int n, int m, char []fmt, FILE f) - void dPrintMatrix (final double []A, int n, int m, String fmt, FILE f) - { - int skip = dPAD(m); - int Arowp = 0;//A; - for (int i=0; i 0) { - IFTIMING_dTimerReport(stdout, 1); + //IFTIMING_dTimerReport(stdout, 1); } } else { throw new UnsupportedOperationException(); @@ -1660,8 +1660,8 @@ private static void dxStepIsland_Stage4(dxStepperStage4CallContext stage4CallCon double[] J = localContext.m_J; double[] pairsRhsLambda = localContext.m_pairsRhsCfm; final int[] mIndex = localContext.m_mindex; - AtomicIntegerArray bodyStartJoints = localContext.m_bodyStartJoints; - AtomicIntegerArray bodyJointLinks = localContext.m_bodyJointLinks; + GWTAtomicIntegerArray bodyStartJoints = localContext.m_bodyStartJoints; + GWTAtomicIntegerArray bodyJointLinks = localContext.m_bodyJointLinks; final int nb = callContext.m_islandBodiesCount(); int bi = 0; diff --git a/core/src/main/java/org/ode4j/ode/internal/Timer.java b/core/src/main/java/org/ode4j/ode/internal/Timer.java index 6a0f84d9..f176c4fa 100644 --- a/core/src/main/java/org/ode4j/ode/internal/Timer.java +++ b/core/src/main/java/org/ode4j/ode/internal/Timer.java @@ -25,10 +25,12 @@ package org.ode4j.ode.internal; -import static org.ode4j.ode.internal.cpp4j.Cstdio.*; +import com.badlogic.gdx.utils.TimeUtils; + +//import static org.ode4j.ode.internal.cpp4j.Cstdio.*; import org.ode4j.ode.DStopwatch; -import org.ode4j.ode.internal.cpp4j.FILE; +//import org.ode4j.ode.internal.cpp4j.FILE; /** * TODO @@ -45,13 +47,13 @@ public class Timer { // private static void getClockCount (long[] cc) // { - // long ms = System.nanoTime();//TimeMillis(); + // long ms = TimeUtils.nanoTime();//TimeMillis(); // // cc[1] = ms.lo / 1000000; // // cc[0] = ms.lo - ( cc[1] * 1000000 ); // } private static long getClockCount () { - return System.nanoTime();//TimeMillis(); + return TimeUtils.nanoTime();//TimeMillis(); } @@ -86,12 +88,12 @@ public static double dTimerResolution() // double t1 = loadClockCount (cc1); // double t2 = loadClockCount (cc2); long cc2; - long cc1 = System.nanoTime(); + long cc1 = TimeUtils.nanoTime(); do { - cc2 = System.nanoTime(); + cc2 = TimeUtils.nanoTime(); } while (cc1 == cc2); do { - cc1 = System.nanoTime(); + cc1 = TimeUtils.nanoTime(); } while (cc1 == cc2); return (cc1-cc2) / dTimerTicksPerSecond(); @@ -221,88 +223,88 @@ public static void dTimerEnd() // print report //static void fprintDoubleWithPrefix (FILE *f, double a, const char *fmt) - private static void fprintDoubleWithPrefix (FILE f, double a, final String fmt) - { - if (a >= 0.999999) { - fprintf (f,fmt,a); - return; - } - a *= 1000.0; - if (a >= 0.999999) { - fprintf (f,fmt,a); - fprintf (f,"m"); - return; - } - a *= 1000.0; - if (a >= 0.999999) { - fprintf (f,fmt,a); - fprintf (f,"u"); - return; - } - a *= 1000.0; - fprintf (f,fmt,a); - fprintf (f,"n"); - } - - - public static void dTimerReport (FILE fout, int average) - { - int i; - int maxl;//size_t maxl; - double ccunit = 1.0/dTimerTicksPerSecond(); - fprintf (fout,"\nTimer Report ("); - fprintDoubleWithPrefix (fout,ccunit,"%.2f "); - fprintf (fout,"s resolution)\n------------\n"); - if (num < 1) return; - - // get maximum description length - maxl = 0; - for (i=0; i maxl) maxl = l; - } - - // calculate total time - double tt1 = loadClockCount (event[0].cc); - double tt2 = loadClockCount (event[num-1].cc); - double total = tt2 - tt1; - if (total <= 0) total = 1; - - // compute time difference for all slots except the last one. update totals - double []times = new double[num];//(double*) ALLOCA (num * sizeof(double)); - for (i=0; i < (num-1); i++) { - double t1 = loadClockCount (event[i].cc); - double t2 = loadClockCount (event[i+1].cc); - times[i] = t2 - t1; - event[i].count++; - event[i].total_t += times[i]; - event[i].total_p += times[i]/total * 100.0; - } - - // print report (with optional averages) - for (i=0; i= 0.999999) { +// //fprintf (f,fmt,a); +// return; +// } +// a *= 1000.0; +// if (a >= 0.999999) { +// //fprintf (f,fmt,a); +// //fprintf (f,"m"); +// return; +// } +// a *= 1000.0; +// if (a >= 0.999999) { +// //fprintf (f,fmt,a); +// //fprintf (f,"u"); +// return; +// } +// a *= 1000.0; +// //fprintf (f,fmt,a); +// //fprintf (f,"n"); +// } + + +// public static void dTimerReport (FILE fout, int average) +// { +// int i; +// int maxl;//size_t maxl; +// double ccunit = 1.0/dTimerTicksPerSecond(); +// //fprintf (fout,"\nTimer Report ("); +// fprintDoubleWithPrefix (fout,ccunit,"%.2f "); +// //fprintf (fout,"s resolution)\n------------\n"); +// if (num < 1) return; +// +// // get maximum description length +// maxl = 0; +// for (i=0; i maxl) maxl = l; +// } +// +// // calculate total time +// double tt1 = loadClockCount (event[0].cc); +// double tt2 = loadClockCount (event[num-1].cc); +// double total = tt2 - tt1; +// if (total <= 0) total = 1; +// +// // compute time difference for all slots except the last one. update totals +// double []times = new double[num];//(double*) ALLOCA (num * sizeof(double)); +// for (i=0; i < (num-1); i++) { +// double t1 = loadClockCount (event[i].cc); +// double t2 = loadClockCount (event[i+1].cc); +// times[i] = t2 - t1; +// event[i].count++; +// event[i].total_t += times[i]; +// event[i].total_p += times[i]/total * 100.0; +// } +// +// // print report (with optional averages) +// for (i=0; i>52)-1022; - return Double.longBitsToDouble((0x800fffffffffffffL & bits)| 0x3fe0000000000000L); + return NumberUtils.longBitsToDouble((0x800fffffffffffffL & bits)| 0x3fe0000000000000L); } protected Cmath() {} diff --git a/core/src/main/java/org/ode4j/ode/internal/cpp4j/Csetjmp.java b/core/src/main/java/org/ode4j/ode/internal/cpp4j/Csetjmp.java index 7b12dbba..0901858d 100644 --- a/core/src/main/java/org/ode4j/ode/internal/cpp4j/Csetjmp.java +++ b/core/src/main/java/org/ode4j/ode/internal/cpp4j/Csetjmp.java @@ -28,7 +28,7 @@ * * @author Tilmann Zaeschke */ -public class Csetjmp extends Cstdio { +public class Csetjmp { /** * diff --git a/core/src/main/java/org/ode4j/ode/internal/cpp4j/java/FormattedStringBuilder.java b/core/src/main/java/org/ode4j/ode/internal/cpp4j/java/FormattedStringBuilder.java index b8ca5375..0e2ad150 100644 --- a/core/src/main/java/org/ode4j/ode/internal/cpp4j/java/FormattedStringBuilder.java +++ b/core/src/main/java/org/ode4j/ode/internal/cpp4j/java/FormattedStringBuilder.java @@ -47,7 +47,7 @@ public class FormattedStringBuilder { /** New Line. */ - public final static String NL = System.getProperty("line.separator"); + public final static String NL = "\n"; private StringBuilder _delegate; @@ -115,13 +115,13 @@ public FormattedStringBuilder append(int i) { * @param t Exception to print. * @return The updated instance of FormattedStringBuilder. */ - public FormattedStringBuilder append(Throwable t) { - ByteArrayOutputStream os = new ByteArrayOutputStream(); - PrintStream p = new PrintStream(os); - t.printStackTrace(p); - p.close(); - return append(os.toString()); - } +// public FormattedStringBuilder append(Throwable t) { +// ByteArrayOutputStream os = new ByteArrayOutputStream(); +// PrintStream p = new PrintStream(os); +// t.printStackTrace(p); +// p.close(); +// return append(os.toString()); +// } /** * Appends the stack trace of the Throwable argument to this sequence @@ -129,9 +129,9 @@ public FormattedStringBuilder append(Throwable t) { * @param t Exception to print. * @return The updated instance of FormattedStringBuilder. */ - public FormattedStringBuilder appendln(Throwable t) { - return append(t).appendln(); - } +// public FormattedStringBuilder appendln(Throwable t) { +// return append(t).appendln(); +// } /** * Appends to the line the white spaces and then the string s diff --git a/core/src/main/java/org/ode4j/ode/internal/gimpact/GimAABBSet.java b/core/src/main/java/org/ode4j/ode/internal/gimpact/GimAABBSet.java index 96c7e6b3..7d46c2c6 100644 --- a/core/src/main/java/org/ode4j/ode/internal/gimpact/GimAABBSet.java +++ b/core/src/main/java/org/ode4j/ode/internal/gimpact/GimAABBSet.java @@ -100,7 +100,8 @@ public aabb3f getGlobalBound() { /** Function for creating an overlapping pair set. */ //#define GIM_CREATE_PAIR_SET(dynarray) GIM_DYNARRAY_CREATE(GIM_PAIR,dynarray,G_ARRAY_GROW_SIZE) static GimDynArray GIM_CREATE_PAIR_SET() { - return GimDynArray.GIM_DYNARRAY_CREATE(GIM_PAIR.class, GimDynArray.G_ARRAY_GROW_SIZE); //GIM_PAIR !! TZ TODO ? + //return GimDynArray.GIM_DYNARRAY_CREATE(GIM_PAIR.class, GimDynArray.G_ARRAY_GROW_SIZE); //GIM_PAIR !! TZ TODO ? + return GimDynArray.GIM_DYNARRAY_CREATE(1, GimDynArray.G_ARRAY_GROW_SIZE); //GIM_PAIR !! TZ TODO ? } // /** diff --git a/core/src/main/java/org/ode4j/ode/internal/gimpact/GimContact.java b/core/src/main/java/org/ode4j/ode/internal/gimpact/GimContact.java index ded7fbff..0c140027 100644 --- a/core/src/main/java/org/ode4j/ode/internal/gimpact/GimContact.java +++ b/core/src/main/java/org/ode4j/ode/internal/gimpact/GimContact.java @@ -132,7 +132,8 @@ private static int GIM_CALC_KEY_CONTACT(vec3f pos) ///Creates a contact list for queries //#define GIM_CREATE_CONTACT_LIST(contact_array) GIM_DYNARRAY_CREATE(GIM_CONTACT,contact_array,100) public static GimDynArray GIM_CREATE_CONTACT_LIST() { - return GimDynArray.GIM_DYNARRAY_CREATE(GimContact.class, 100);//GIM_CONTACT,contact_array,100); + //return GimDynArray.GIM_DYNARRAY_CREATE(GimContact.class, 100);//GIM_CONTACT,contact_array,100); + return GimDynArray.GIM_DYNARRAY_CREATE(0, 100);//GIM_CONTACT,contact_array,100); } //#define GIM_PUSH_CONTACT(contact_array, point, normal, deep,handle1, handle2, feat1, feat2)\ diff --git a/core/src/main/java/org/ode4j/ode/internal/gimpact/GimDynArray.java b/core/src/main/java/org/ode4j/ode/internal/gimpact/GimDynArray.java index 48843d50..31090cad 100644 --- a/core/src/main/java/org/ode4j/ode/internal/gimpact/GimDynArray.java +++ b/core/src/main/java/org/ode4j/ode/internal/gimpact/GimDynArray.java @@ -73,15 +73,27 @@ private GimDynArray() { //! Creates a dynamic array zero sized //#define GIM_DYNARRAY_CREATE(type, array_data, reserve_size) \ @SuppressWarnings("unchecked") - static GimDynArray GIM_DYNARRAY_CREATE(Class clazz, int reserve_size) + //static GimDynArray GIM_DYNARRAY_CREATE(Class clazz, int reserve_size) + static GimDynArray GIM_DYNARRAY_CREATE(int type, int reserve_size) { GimDynArray a = new GimDynArray(); //(array_data).m_pdata = (char *)gim_alloc((reserve_size) * sizeof(type)); - a.m_pdata = (T[]) Array.newInstance(clazz, reserve_size); //gim_alloc((reserve_size));// * sizeof(type)); - a.m_size = 0; + //a.m_pdata = (T[]) Array.newInstance(clazz, reserve_size); //gim_alloc((reserve_size));// * sizeof(type)); + //a.m_pdata = (T[]) new Object[reserve_size]; // doesnt work + + if (type == 0) + a.m_pdata = (T[]) new GimContact[reserve_size]; + else if (type == 1) + a.m_pdata = (T[]) new GimAABBSet.GIM_PAIR[reserve_size]; + else + a.m_pdata = (T[]) new GimGeometry.vec4f[reserve_size]; + + a.m_size = 0; a.m_reserve_size = reserve_size; return a; - } + } + + /** * Creates a dynamic array with n = size elements. diff --git a/core/src/main/java/org/ode4j/ode/internal/gimpact/GimTrimesh.java b/core/src/main/java/org/ode4j/ode/internal/gimpact/GimTrimesh.java index 49302004..19e4ce0f 100644 --- a/core/src/main/java/org/ode4j/ode/internal/gimpact/GimTrimesh.java +++ b/core/src/main/java/org/ode4j/ode/internal/gimpact/GimTrimesh.java @@ -358,7 +358,8 @@ public void gim_trimesh_capsule_collision(GIM_CAPSULE_DATA capsule, GimDynArray< ///Function for create Trimesh Plane collision result //#define GIM_CREATE_TRIMESHPLANE_CONTACTS(dynarray) GIM_DYNARRAY_CREATE(vec4f,dynarray,G_ARRAY_GROW_SIZE) public static GimDynArray GIM_CREATE_TRIMESHPLANE_CONTACTS() { - return GimDynArray.GIM_DYNARRAY_CREATE(vec4f.class, GimDynArray.G_ARRAY_GROW_SIZE);//vec4f,dynarray,G_ARRAY_GROW_SIZE); + //return GimDynArray.GIM_DYNARRAY_CREATE(vec4f.class, GimDynArray.G_ARRAY_GROW_SIZE);//vec4f,dynarray,G_ARRAY_GROW_SIZE); + return GimDynArray.GIM_DYNARRAY_CREATE(2, GimDynArray.G_ARRAY_GROW_SIZE);//vec4f,dynarray,G_ARRAY_GROW_SIZE); } //! Trimesh Plane Collisions diff --git a/core/src/main/java/org/ode4j/ode/internal/processmem/DxWorldProcessMemArena.java b/core/src/main/java/org/ode4j/ode/internal/processmem/DxWorldProcessMemArena.java index 85705262..21a883d4 100644 --- a/core/src/main/java/org/ode4j/ode/internal/processmem/DxWorldProcessMemArena.java +++ b/core/src/main/java/org/ode4j/ode/internal/processmem/DxWorldProcessMemArena.java @@ -24,12 +24,13 @@ *************************************************************************/ package org.ode4j.ode.internal.processmem; +import org.ode4j.GWTAtomicIntegerArray; import org.ode4j.ode.internal.Common; import org.ode4j.ode.internal.DxBody; import org.ode4j.ode.internal.joints.DxJoint; import org.ode4j.ode.internal.processmem.DxUtil.BlockPointer; -import java.util.concurrent.atomic.AtomicIntegerArray; +//import java.util.concurrent.atomic.AtomicIntegerArray; public final class DxWorldProcessMemArena { @@ -216,8 +217,8 @@ public double[] AllocateOveralignedArrayDReal(int count, int alignment) return new double[count]; } - public final AtomicIntegerArray AllocateArrayAtomicord32(int size) { - return new AtomicIntegerArray(size); + public final GWTAtomicIntegerArray AllocateArrayAtomicord32(int size) { + return new GWTAtomicIntegerArray(size); } /** diff --git a/core/src/main/java/org/ode4j/ode/threading/Atomics.java b/core/src/main/java/org/ode4j/ode/threading/Atomics.java index 40121c44..c01f789d 100644 --- a/core/src/main/java/org/ode4j/ode/threading/Atomics.java +++ b/core/src/main/java/org/ode4j/ode/threading/Atomics.java @@ -21,6 +21,8 @@ *************************************************************************/ package org.ode4j.ode.threading; +import org.ode4j.GWTAtomicIntegerArray; + import java.util.concurrent.atomic.AtomicInteger; import java.util.concurrent.atomic.AtomicIntegerArray; import java.util.concurrent.atomic.AtomicReference; @@ -32,7 +34,7 @@ public static boolean ThrsafeCompareExchange(AtomicInteger paoDestination, int a return paoDestination.compareAndSet(aoComparand, aoExchange); } - public static boolean ThrsafeCompareExchange(AtomicIntegerArray paoDestination, int arrayOffset, int aoComparand, int aoExchange) + public static boolean ThrsafeCompareExchange(GWTAtomicIntegerArray paoDestination, int arrayOffset, int aoComparand, int aoExchange) { return paoDestination.compareAndSet(arrayOffset, aoComparand, aoExchange); } diff --git a/core/src/main/java/org/ode4j/ode/threading/MutexGroupImpl.java b/core/src/main/java/org/ode4j/ode/threading/MutexGroupImpl.java index fe80ec60..0fcd2434 100644 --- a/core/src/main/java/org/ode4j/ode/threading/MutexGroupImpl.java +++ b/core/src/main/java/org/ode4j/ode/threading/MutexGroupImpl.java @@ -24,30 +24,31 @@ *************************************************************************/ package org.ode4j.ode.threading; -import java.util.concurrent.locks.Lock; -import java.util.concurrent.locks.ReentrantLock; +//import java.util.concurrent.locks.Lock; +//import java.util.concurrent.locks.ReentrantLock; public class MutexGroupImpl implements MutexGroup { - final Lock[] m_Mutex_array; + //final Lock[] m_Mutex_array; public MutexGroupImpl() { - m_Mutex_array = new Lock[dxProcessContextMutex.values().length]; - for (int i = 0; i < m_Mutex_array.length; ++i) { - m_Mutex_array[i] = new ReentrantLock(); - } +// m_Mutex_array = new Lock[dxProcessContextMutex.values().length]; +// for (int i = 0; i < m_Mutex_array.length; ++i) { +// m_Mutex_array[i] = new ReentrantLock(); +// } } public void lock(dxProcessContextMutex mutex_index) { - m_Mutex_array[mutex_index.ordinal()].lock(); + //m_Mutex_array[mutex_index.ordinal()].lock(); } public boolean tryLock(dxProcessContextMutex mutex_index) { - return m_Mutex_array[mutex_index.ordinal()].tryLock(); + //return m_Mutex_array[mutex_index.ordinal()].tryLock(); + return true; } public void unlock(dxProcessContextMutex mutex_index) { - m_Mutex_array[mutex_index.ordinal()].unlock(); + //m_Mutex_array[mutex_index.ordinal()].unlock(); } } \ No newline at end of file diff --git a/core/src/main/java/org/ode4j/ode/threading/task/MultiThreadTaskExecutor.java b/core/src/main/java/org/ode4j/ode/threading/task/MultiThreadTaskExecutor.java index fbf2cf73..daba136d 100644 --- a/core/src/main/java/org/ode4j/ode/threading/task/MultiThreadTaskExecutor.java +++ b/core/src/main/java/org/ode4j/ode/threading/task/MultiThreadTaskExecutor.java @@ -23,41 +23,42 @@ *************************************************************************/ package org.ode4j.ode.threading.task; -import java.util.concurrent.LinkedBlockingQueue; -import java.util.concurrent.ThreadFactory; -import java.util.concurrent.ThreadPoolExecutor; -import java.util.concurrent.TimeUnit; +//import java.util.concurrent.LinkedBlockingQueue; +//import java.util.concurrent.ThreadFactory; +//import java.util.concurrent.ThreadPoolExecutor; +//import java.util.concurrent.TimeUnit; -public class MultiThreadTaskExecutor extends AbstractTaskExecutor { +//public class MultiThreadTaskExecutor extends AbstractTaskExecutor { + public class MultiThreadTaskExecutor { - private final ThreadPoolExecutor executor; - - public MultiThreadTaskExecutor(int threads) { - executor = new ThreadPoolExecutor(threads, threads, 0, TimeUnit.SECONDS, new LinkedBlockingQueue(), - new DaemonThreadFactory()); - } - - private class DaemonThreadFactory implements ThreadFactory { - @Override - public Thread newThread(Runnable r) { - Thread t = new Thread(r); - t.setDaemon(true); - return t; - } - } - - @Override - public void submit(Task task) { - executor.execute(task); - } - - @Override - public int getThreadCount() { - return executor.getCorePoolSize(); - } - - @Override - public void flush() { - } +// private final ThreadPoolExecutor executor; +// +// public MultiThreadTaskExecutor(int threads) { +// executor = new ThreadPoolExecutor(threads, threads, 0, TimeUnit.SECONDS, new LinkedBlockingQueue(), +// new DaemonThreadFactory()); +// } +// +// private class DaemonThreadFactory implements ThreadFactory { +// @Override +// public Thread newThread(Runnable r) { +// Thread t = new Thread(r); +// t.setDaemon(true); +// return t; +// } +// } +// +// @Override +// public void submit(Task task) { +// executor.execute(task); +// } +// +// @Override +// public int getThreadCount() { +// return executor.getCorePoolSize(); +// } +// +// @Override +// public void flush() { +// } } diff --git a/core/src/main/java/org/ode4j/ode/threading/task/SameThreadTaskExecutor.java b/core/src/main/java/org/ode4j/ode/threading/task/SameThreadTaskExecutor.java index 946a3bb2..71caf54a 100644 --- a/core/src/main/java/org/ode4j/ode/threading/task/SameThreadTaskExecutor.java +++ b/core/src/main/java/org/ode4j/ode/threading/task/SameThreadTaskExecutor.java @@ -48,7 +48,8 @@ public void flush() { task.parent.subtaskCompleted(); } task.runnable.run(); - task.completed.countDown(); + //task.completed.countDown(); + task.completed = true; } } } diff --git a/core/src/main/java/org/ode4j/ode/threading/task/Task.java b/core/src/main/java/org/ode4j/ode/threading/task/Task.java index f26034d0..a5ef98d1 100644 --- a/core/src/main/java/org/ode4j/ode/threading/task/Task.java +++ b/core/src/main/java/org/ode4j/ode/threading/task/Task.java @@ -32,7 +32,8 @@ public class Task implements Runnable { public final String name; public final TaskGroup parent; public final Runnable runnable; - protected final CountDownLatch completed; + //protected final CountDownLatch completed; + public boolean completed; protected final AtomicInteger subtaskCount; protected Task(TaskExecutor executor, String name, TaskGroup parent, Runnable runnable) { @@ -41,15 +42,16 @@ protected Task(TaskExecutor executor, String name, TaskGroup parent, Runnable ru this.parent = parent; this.runnable = runnable; subtaskCount = new AtomicInteger(0); - completed = new CountDownLatch(1); + //completed = new CountDownLatch(1); + completed = false; } public void awaitCompletion() { - try { + //try { executor.flush(); - completed.await(); - } catch (InterruptedException e) { - } + //completed.await(); + //} catch (InterruptedException e) { + //} } public void submit() { @@ -65,7 +67,8 @@ public void run() { } catch (Exception e) { e.printStackTrace(); } finally { - completed.countDown(); + //completed.countDown(); + completed = true; if (parent != null) { parent.subtaskCompleted(); } diff --git a/core/src/main/resources/gdx_ode4j.gwt.xml b/core/src/main/resources/gdx_ode4j.gwt.xml new file mode 100644 index 00000000..7d968f7a --- /dev/null +++ b/core/src/main/resources/gdx_ode4j.gwt.xml @@ -0,0 +1,17 @@ + + + + + + + + + + diff --git a/core/src/test/java/org/ode4j/benchmarks/DemoSpaceStressTest.java b/core/src/test/java/org/ode4j/benchmarks/DemoSpaceStressTest.java index bbf48971..e0256f49 100644 --- a/core/src/test/java/org/ode4j/benchmarks/DemoSpaceStressTest.java +++ b/core/src/test/java/org/ode4j/benchmarks/DemoSpaceStressTest.java @@ -353,12 +353,12 @@ private void demo() { command('s'); } - long t0 = System.nanoTime(); + long t0 = TimeUtils.nanoTime(); // run simulation for (int i = 0; i < 100; ++i) { simLoop(); } - long t1 = System.nanoTime(); + long t1 = TimeUtils.nanoTime(); System.out.print("time: " + (t1 - t0) / 1000 / 1000 + "ms "); } } diff --git a/core/src/test/java/org/ode4j/benchmarks/SpacePerformanceTest.java b/core/src/test/java/org/ode4j/benchmarks/SpacePerformanceTest.java index 73ecd337..ff85c480 100644 --- a/core/src/test/java/org/ode4j/benchmarks/SpacePerformanceTest.java +++ b/core/src/test/java/org/ode4j/benchmarks/SpacePerformanceTest.java @@ -65,16 +65,16 @@ private void test_performance_with_dynamic_world(DSpace space, int iterations, i long timer1 = 0; long timer2 = 0; for (int j = 0; j < iterations; j++) { - long time1 = System.nanoTime(); + long time1 = TimeUtils.nanoTime(); space.collide(null, (data, o1, o2) -> spaceCollisions++); - long time2 = System.nanoTime(); + long time2 = TimeUtils.nanoTime(); for (int k = 0; k < 50; k++) { int i = r.nextInt(geoms.length); space.collide2(geoms[i], null, (data, o1, o2) -> geomCollisions++); } - long time3 = System.nanoTime(); + long time3 = TimeUtils.nanoTime(); timer1 += time2 - time1; timer2 += time3 - time2; for (int i = 0; i < geomNum; i++) { @@ -147,16 +147,16 @@ private void test_performance_with_static_world(DSpace space, int iterations, in long timer1 = 0; long timer2 = 0; for (int j = 0; j < iterations; j++) { - long time1 = System.nanoTime(); + long time1 = TimeUtils.nanoTime(); space.collide(null, (data, o1, o2) -> spaceCollisions++); - long time2 = System.nanoTime(); + long time2 = TimeUtils.nanoTime(); for (int k = 0; k < 50; k++) { int i = r.nextInt(geoms.length); space.collide2(geoms[i], null, (data, o1, o2) -> geomCollisions++); } - long time3 = System.nanoTime(); + long time3 = TimeUtils.nanoTime(); timer1 += time2 - time1; timer2 += time3 - time2; } diff --git a/core/src/test/java/org/ode4j/ode/CollisionPerformanceTest.java b/core/src/test/java/org/ode4j/ode/CollisionPerformanceTest.java index b13b8126..4f8d97f4 100644 --- a/core/src/test/java/org/ode4j/ode/CollisionPerformanceTest.java +++ b/core/src/test/java/org/ode4j/ode/CollisionPerformanceTest.java @@ -278,14 +278,14 @@ private void collide(DGeom geom1, DGeom geom2, int iterations) { int totalCount = 0; int maxCollisionCount = 0; for (int j = 0; j < iterations; j++) { - long time1 = System.nanoTime(); + long time1 = TimeUtils.nanoTime(); space.collide(0, (data, o1, o2) -> nearCallback(o1, o2)); // world.step(0.05); world.quickStep(0.05); contactgroup.empty (); // remove all contact joints - long time2 = System.nanoTime(); + long time2 = TimeUtils.nanoTime(); timer += (time2 - time1); if (prevCount > 0 && j < 2) { diff --git a/gradle.properties b/gradle.properties new file mode 100644 index 00000000..b89c4c04 --- /dev/null +++ b/gradle.properties @@ -0,0 +1,70 @@ +org.gradle.daemon=true +org.gradle.jvmargs=-Xms128m -Xmx512m -Dfile.encoding=UTF-8 -Dconsole.encoding=UTF-8 +org.gradle.configureondemand=false +# You can downgrade this for compatibility with older libGDX versions. +gdxVersion=1.12.0 +formicVersion=0.1.4 + +# This must match your Maven Central group if you publish there. +GROUP=com.github.antzGames +# The name of the library, as it can be downloaded using Maven or Gradle. +POM_ARTIFACT_ID=gdx-ode4j +# This version should always be updated here; it is used elsewhere. +VERSION_NAME=0.5.1-SNAPSHOT + +# The name of the library; might be different from POM_ARTIFACT_ID . +POM_NAME=gdx-ode4j +POM_DESCRIPTION=A GWT compatible ODE4J Physics implementation for all backends +# This is probably not correct for a new project; 2021 is when the template +# was first made. +POM_INCEPTION_YEAR=2023 + +# Just change all this to use your GitHub or other URL. +POM_URL=https://github.com/antzGames/gdx-ode4j +POM_SCM_URL=https://github.com/antzGames/gdx-ode4j +POM_SCM_CONNECTION=scm:https://antzGames@github.com/antzGames/gdx-ode4j.git +POM_SCM_DEV_CONNECTION=scm:git://github.com/antzGames/gdx-ode4j.git + +# This applies to the template itself; it does not apply to your library unless +# you choose it as the license for your library. Using CC0 means all code in your +# library was written by you, or was already public-domain. +POM_LICENCE_NAME=Creative Commons Zero +POM_LICENCE_URL=https://creativecommons.org/publicdomain/zero/1.0/ +POM_LICENCE_DIST=repo + +# Another common option is the Apache License, which libGDX uses. It is considered +# a "business-friendly" permissive license, and allows commercial use. +## POM_LICENCE_NAME=The Apache Software License, Version 2.0 +## POM_LICENCE_URL=https://www.apache.org/licenses/LICENSE-2.0.txt +## POM_LICENCE_DIST=repo + +# Another option is the MIT License, which is very permissive. It also allows +# commercial use, and only requires any license headers to stay intact. +## POM_LICENCE_NAME=MIT License +## POM_LICENCE_URL=https://opensource.org/licenses/mit-license.php +## POM_LICENCE_DIST=repo + +# Another option is the Eclipse Public License. It is very similar to the Apache +# License; it is also "business-friendly," permissive, and allows commercial use. +## POM_LICENCE_NAME=Eclipse Public License v 1.0 +## POM_LICENCE_URL=http://www.eclipse.org/legal/epl-v10.html +## POM_LICENCE_DIST=repo + +# I can't stop you from licensing your code as GPL, but I won't use it if you do. +# The GPL isn't compatible with most other licenses, and restricts code that uses +# a GPL library to also be GPL. The LGPL was created in an attempt to solve this +# library issue; still, it isn't preferable to Apache, EPL, MIT, or BSD in regard +# to license compatibility with existing Java libraries. + +# Obviously, change this part of the template if you aren't Tommy Ettinger. +POM_DEVELOPER_ID=antzGames +POM_DEVELOPER_NAME=Antz +POM_DEVELOPER_URL=https://github.com/antzGames/ + +# These two lines allow uploading to Maven Central, if you want. +# You can use JitPack to handle releases and never touch Maven Central, or you can +# register with Sonatype to get a Maven Central "group" that you can push to. +# Maven Central can be a lot more work, but is the more "professional" and stable +# of the two options. +SONATYPE_HOST=DEFAULT +RELEASE_SIGNING_ENABLED=true diff --git a/gradle/wrapper/gradle-wrapper.jar b/gradle/wrapper/gradle-wrapper.jar new file mode 100644 index 00000000..249e5832 Binary files /dev/null and b/gradle/wrapper/gradle-wrapper.jar differ diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties new file mode 100644 index 00000000..98debb84 --- /dev/null +++ b/gradle/wrapper/gradle-wrapper.properties @@ -0,0 +1,5 @@ +distributionBase=GRADLE_USER_HOME +distributionPath=wrapper/dists +distributionUrl=https\://services.gradle.org/distributions/gradle-7.6.2-bin.zip +zipStoreBase=GRADLE_USER_HOME +zipStorePath=wrapper/dists diff --git a/gradlew b/gradlew new file mode 100644 index 00000000..a69d9cb6 --- /dev/null +++ b/gradlew @@ -0,0 +1,240 @@ +#!/bin/sh + +# +# Copyright © 2015-2021 the original authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +############################################################################## +# +# Gradle start up script for POSIX generated by Gradle. +# +# Important for running: +# +# (1) You need a POSIX-compliant shell to run this script. If your /bin/sh is +# noncompliant, but you have some other compliant shell such as ksh or +# bash, then to run this script, type that shell name before the whole +# command line, like: +# +# ksh Gradle +# +# Busybox and similar reduced shells will NOT work, because this script +# requires all of these POSIX shell features: +# * functions; +# * expansions «$var», «${var}», «${var:-default}», «${var+SET}», +# «${var#prefix}», «${var%suffix}», and «$( cmd )»; +# * compound commands having a testable exit status, especially «case»; +# * various built-in commands including «command», «set», and «ulimit». +# +# Important for patching: +# +# (2) This script targets any POSIX shell, so it avoids extensions provided +# by Bash, Ksh, etc; in particular arrays are avoided. +# +# The "traditional" practice of packing multiple parameters into a +# space-separated string is a well documented source of bugs and security +# problems, so this is (mostly) avoided, by progressively accumulating +# options in "$@", and eventually passing that to Java. +# +# Where the inherited environment variables (DEFAULT_JVM_OPTS, JAVA_OPTS, +# and GRADLE_OPTS) rely on word-splitting, this is performed explicitly; +# see the in-line comments for details. +# +# There are tweaks for specific operating systems such as AIX, CygWin, +# Darwin, MinGW, and NonStop. +# +# (3) This script is generated from the Groovy template +# https://github.com/gradle/gradle/blob/master/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt +# within the Gradle project. +# +# You can find Gradle at https://github.com/gradle/gradle/. +# +############################################################################## + +# Attempt to set APP_HOME + +# Resolve links: $0 may be a link +app_path=$0 + +# Need this for daisy-chained symlinks. +while + APP_HOME=${app_path%"${app_path##*/}"} # leaves a trailing /; empty if no leading path + [ -h "$app_path" ] +do + ls=$( ls -ld "$app_path" ) + link=${ls#*' -> '} + case $link in #( + /*) app_path=$link ;; #( + *) app_path=$APP_HOME$link ;; + esac +done + +APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit + +APP_NAME="Gradle" +APP_BASE_NAME=${0##*/} + +# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' + +# Use the maximum available, or set MAX_FD != -1 to use that value. +MAX_FD=maximum + +warn () { + echo "$*" +} >&2 + +die () { + echo + echo "$*" + echo + exit 1 +} >&2 + +# OS specific support (must be 'true' or 'false'). +cygwin=false +msys=false +darwin=false +nonstop=false +case "$( uname )" in #( + CYGWIN* ) cygwin=true ;; #( + Darwin* ) darwin=true ;; #( + MSYS* | MINGW* ) msys=true ;; #( + NONSTOP* ) nonstop=true ;; +esac + +CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar + + +# Determine the Java command to use to start the JVM. +if [ -n "$JAVA_HOME" ] ; then + if [ -x "$JAVA_HOME/jre/sh/java" ] ; then + # IBM's JDK on AIX uses strange locations for the executables + JAVACMD=$JAVA_HOME/jre/sh/java + else + JAVACMD=$JAVA_HOME/bin/java + fi + if [ ! -x "$JAVACMD" ] ; then + die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." + fi +else + JAVACMD=java + which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." +fi + +# Increase the maximum file descriptors if we can. +if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then + case $MAX_FD in #( + max*) + MAX_FD=$( ulimit -H -n ) || + warn "Could not query maximum file descriptor limit" + esac + case $MAX_FD in #( + '' | soft) :;; #( + *) + ulimit -n "$MAX_FD" || + warn "Could not set maximum file descriptor limit to $MAX_FD" + esac +fi + +# Collect all arguments for the java command, stacking in reverse order: +# * args from the command line +# * the main class name +# * -classpath +# * -D...appname settings +# * --module-path (only if needed) +# * DEFAULT_JVM_OPTS, JAVA_OPTS, and GRADLE_OPTS environment variables. + +# For Cygwin or MSYS, switch paths to Windows format before running java +if "$cygwin" || "$msys" ; then + APP_HOME=$( cygpath --path --mixed "$APP_HOME" ) + CLASSPATH=$( cygpath --path --mixed "$CLASSPATH" ) + + JAVACMD=$( cygpath --unix "$JAVACMD" ) + + # Now convert the arguments - kludge to limit ourselves to /bin/sh + for arg do + if + case $arg in #( + -*) false ;; # don't mess with options #( + /?*) t=${arg#/} t=/${t%%/*} # looks like a POSIX filepath + [ -e "$t" ] ;; #( + *) false ;; + esac + then + arg=$( cygpath --path --ignore --mixed "$arg" ) + fi + # Roll the args list around exactly as many times as the number of + # args, so each arg winds up back in the position where it started, but + # possibly modified. + # + # NB: a `for` loop captures its iteration list before it begins, so + # changing the positional parameters here affects neither the number of + # iterations, nor the values presented in `arg`. + shift # remove old arg + set -- "$@" "$arg" # push replacement arg + done +fi + +# Collect all arguments for the java command; +# * $DEFAULT_JVM_OPTS, $JAVA_OPTS, and $GRADLE_OPTS can contain fragments of +# shell script including quotes and variable substitutions, so put them in +# double quotes to make sure that they get re-expanded; and +# * put everything else in single quotes, so that it's not re-expanded. + +set -- \ + "-Dorg.gradle.appname=$APP_BASE_NAME" \ + -classpath "$CLASSPATH" \ + org.gradle.wrapper.GradleWrapperMain \ + "$@" + +# Stop when "xargs" is not available. +if ! command -v xargs >/dev/null 2>&1 +then + die "xargs is not available" +fi + +# Use "xargs" to parse quoted args. +# +# With -n1 it outputs one arg per line, with the quotes and backslashes removed. +# +# In Bash we could simply go: +# +# readarray ARGS < <( xargs -n1 <<<"$var" ) && +# set -- "${ARGS[@]}" "$@" +# +# but POSIX shell has neither arrays nor command substitution, so instead we +# post-process each arg (as a line of input to sed) to backslash-escape any +# character that might be a shell metacharacter, then use eval to reverse +# that process (while maintaining the separation between arguments), and wrap +# the whole thing up as a single "set" statement. +# +# This will of course break if any of these variables contains a newline or +# an unmatched quote. +# + +eval "set -- $( + printf '%s\n' "$DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS" | + xargs -n1 | + sed ' s~[^-[:alnum:]+,./:=@_]~\\&~g; ' | + tr '\n' ' ' + )" '"$@"' + +exec "$JAVACMD" "$@" diff --git a/gradlew.bat b/gradlew.bat new file mode 100644 index 00000000..f127cfd4 --- /dev/null +++ b/gradlew.bat @@ -0,0 +1,91 @@ +@rem +@rem Copyright 2015 the original author or authors. +@rem +@rem Licensed under the Apache License, Version 2.0 (the "License"); +@rem you may not use this file except in compliance with the License. +@rem You may obtain a copy of the License at +@rem +@rem https://www.apache.org/licenses/LICENSE-2.0 +@rem +@rem Unless required by applicable law or agreed to in writing, software +@rem distributed under the License is distributed on an "AS IS" BASIS, +@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +@rem See the License for the specific language governing permissions and +@rem limitations under the License. +@rem + +@if "%DEBUG%"=="" @echo off +@rem ########################################################################## +@rem +@rem Gradle startup script for Windows +@rem +@rem ########################################################################## + +@rem Set local scope for the variables with windows NT shell +if "%OS%"=="Windows_NT" setlocal + +set DIRNAME=%~dp0 +if "%DIRNAME%"=="" set DIRNAME=. +set APP_BASE_NAME=%~n0 +set APP_HOME=%DIRNAME% + +@rem Resolve any "." and ".." in APP_HOME to make it shorter. +for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi + +@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" + +@rem Find java.exe +if defined JAVA_HOME goto findJavaFromJavaHome + +set JAVA_EXE=java.exe +%JAVA_EXE% -version >NUL 2>&1 +if %ERRORLEVEL% equ 0 goto execute + +echo. +echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:findJavaFromJavaHome +set JAVA_HOME=%JAVA_HOME:"=% +set JAVA_EXE=%JAVA_HOME%/bin/java.exe + +if exist "%JAVA_EXE%" goto execute + +echo. +echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:execute +@rem Setup the command line + +set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar + + +@rem Execute Gradle +"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %* + +:end +@rem End local scope for the variables with windows NT shell +if %ERRORLEVEL% equ 0 goto mainEnd + +:fail +rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of +rem the _cmd.exe /c_ return code! +set EXIT_CODE=%ERRORLEVEL% +if %EXIT_CODE% equ 0 set EXIT_CODE=1 +if not ""=="%GRADLE_EXIT_CONSOLE%" exit %EXIT_CODE% +exit /b %EXIT_CODE% + +:mainEnd +if "%OS%"=="Windows_NT" endlocal + +:omega diff --git a/jitpack.yml b/jitpack.yml new file mode 100644 index 00000000..a9598f74 --- /dev/null +++ b/jitpack.yml @@ -0,0 +1,4 @@ +install: + - echo "Installing with Gradle" + - chmod 755 gradlew + - ./gradlew clean publishToMavenLocal -x signMavenPublication diff --git a/settings.gradle b/settings.gradle new file mode 100644 index 00000000..668ab09b --- /dev/null +++ b/settings.gradle @@ -0,0 +1,4 @@ +rootProject.name = 'gdx-ode4j' + +include 'core' +