From a025fb5d0eb258440405f64961c4ea9894087064 Mon Sep 17 00:00:00 2001 From: Yan <115050813@qq.com> Date: Sun, 14 Jan 2018 18:12:29 +0800 Subject: [PATCH 1/2] [taken]Fix issue #783 Fix issue #783 --- .../xml/java/com/jme3/export/xml/DOMInputCapsule.java | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/jme3-plugins/src/xml/java/com/jme3/export/xml/DOMInputCapsule.java b/jme3-plugins/src/xml/java/com/jme3/export/xml/DOMInputCapsule.java index a8ba4f7aab..6b0eb39b75 100644 --- a/jme3-plugins/src/xml/java/com/jme3/export/xml/DOMInputCapsule.java +++ b/jme3-plugins/src/xml/java/com/jme3/export/xml/DOMInputCapsule.java @@ -974,14 +974,13 @@ private Savable readSavableFromCurrentElem(Savable defVal) throws ret = referencedSavables.get(reference); } else { String className = currentElem.getNodeName(); - if (defVal != null) { - className = defVal.getClass().getName(); - } else if (currentElem.hasAttribute("class")) { + if (currentElem.hasAttribute("class")) { className = currentElem.getAttribute("class"); + } else if (defVal != null) { + className = defVal.getClass().getName(); } tmp = SavableClassUtil.fromName(className, null); - String versionsStr = currentElem.getAttribute("savable_versions"); if (versionsStr != null && !versionsStr.equals("")){ String[] versionStr = versionsStr.split(","); @@ -1508,4 +1507,4 @@ protected String[] parseTokens(String inString) { ? zeroStrings : outStrings; } -} \ No newline at end of file +} From 1690cf8495890b27b5cbd7648784fb47cb19662b Mon Sep 17 00:00:00 2001 From: Yan <115050813@qq.com> Date: Sun, 14 Jan 2018 18:08:23 +0800 Subject: [PATCH 2/2] [taken]Fix issue #764 Fix infinity loop in EmitterSphereShape. issue #764 I test on both method: public void getRandomPoint1(Vector3f store) { float l = FastMath.pow(FastMath.nextRandomFloat(), 1f / 3f); float u = FastMath.nextRandomFloat() * 2f - 1f; float o = FastMath.nextRandomFloat() * FastMath.TWO_PI; store.z = l * u; u = 1f / FastMath.fastInvSqrt(1f - u * u); store.x = l * u * FastMath.cos(o); store.y = l * u * FastMath.sin(o); store.multLocal(radius); store.addLocal(center); } public void getRandomPoint2(Vector3f store) { do { store.x = (FastMath.nextRandomFloat() * 2f - 1f); store.y = (FastMath.nextRandomFloat() * 2f - 1f); store.z = (FastMath.nextRandomFloat() * 2f - 1f); } while (store.lengthSquared() > 1); store.multLocal(radius); store.addLocal(center); } // Test public void testGetRandomPoint() { int n = 1000000; long start = System.nanoTime(); for (int i = 0; i < n; i++) { getRandomPoint1(store); } long time1 = System.nanoTime() - start; start = System.nanoTime(); for (int i = 0; i < n; i++) { getRandomPoint2(store); } long time2 = System.nanoTime() - start; System.out.println("t1:" + time1); System.out.println("t2:" + time2); System.out.println("t1/t2:" + (float) time1 / time2); } Result: t1:352272158 t2:94436324 t1/t2:3.7302613 Method2 seems nearly 4 times faster than method1. --- .../com/jme3/effect/shapes/EmitterSphereShape.java | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/jme3-core/src/main/java/com/jme3/effect/shapes/EmitterSphereShape.java b/jme3-core/src/main/java/com/jme3/effect/shapes/EmitterSphereShape.java index 99d76205d4..a74eeaf39e 100644 --- a/jme3-core/src/main/java/com/jme3/effect/shapes/EmitterSphereShape.java +++ b/jme3-core/src/main/java/com/jme3/effect/shapes/EmitterSphereShape.java @@ -96,10 +96,12 @@ public void cloneFields( Cloner cloner, Object original ) { @Override public void getRandomPoint(Vector3f store) { do { - store.x = (FastMath.nextRandomFloat() * 2f - 1f) * radius; - store.y = (FastMath.nextRandomFloat() * 2f - 1f) * radius; - store.z = (FastMath.nextRandomFloat() * 2f - 1f) * radius; - } while (store.distance(center) > radius); + store.x = (FastMath.nextRandomFloat() * 2f - 1f); + store.y = (FastMath.nextRandomFloat() * 2f - 1f); + store.z = (FastMath.nextRandomFloat() * 2f - 1f); + } while (store.lengthSquared() > 1); + store.multLocal(radius); + store.addLocal(center); } @Override