|
|
@ -29,7 +29,6 @@ |
|
|
|
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
|
|
|
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
|
|
|
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
|
|
|
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
|
|
|
|
|
|
|
|
package com.jme3.util; |
|
|
|
package com.jme3.util; |
|
|
|
|
|
|
|
|
|
|
|
import com.jme3.math.ColorRGBA; |
|
|
|
import com.jme3.math.ColorRGBA; |
|
|
@ -48,7 +47,6 @@ import java.util.Collections; |
|
|
|
import java.util.Map; |
|
|
|
import java.util.Map; |
|
|
|
import java.util.WeakHashMap; |
|
|
|
import java.util.WeakHashMap; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* <code>BufferUtils</code> is a helper class for generating nio buffers from |
|
|
|
* <code>BufferUtils</code> is a helper class for generating nio buffers from |
|
|
|
* jME data classes such as Vectors and ColorRGBA. |
|
|
|
* jME data classes such as Vectors and ColorRGBA. |
|
|
@ -62,14 +60,12 @@ public final class BufferUtils { |
|
|
|
// private static final Vector2f _tempVec2 = new Vector2f();
|
|
|
|
// private static final Vector2f _tempVec2 = new Vector2f();
|
|
|
|
// private static final Vector3f _tempVec3 = new Vector3f();
|
|
|
|
// private static final Vector3f _tempVec3 = new Vector3f();
|
|
|
|
// private static final ColorRGBA _tempColor = new ColorRGBA();
|
|
|
|
// private static final ColorRGBA _tempColor = new ColorRGBA();
|
|
|
|
|
|
|
|
|
|
|
|
//// -- TRACKER HASH -- ////
|
|
|
|
//// -- TRACKER HASH -- ////
|
|
|
|
private static final Map<Buffer, Object> trackingHash = Collections.synchronizedMap(new WeakHashMap<Buffer, Object>()); |
|
|
|
private static final Map<Buffer, Object> trackingHash = Collections.synchronizedMap(new WeakHashMap<Buffer, Object>()); |
|
|
|
private static final Object ref = new Object(); |
|
|
|
private static final Object ref = new Object(); |
|
|
|
private static final boolean trackDirectMemory = false; |
|
|
|
private static final boolean trackDirectMemory = false; |
|
|
|
|
|
|
|
|
|
|
|
//// -- GENERIC CLONE -- ////
|
|
|
|
//// -- GENERIC CLONE -- ////
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* Creates a clone of the given buffer. The clone's capacity is |
|
|
|
* Creates a clone of the given buffer. The clone's capacity is |
|
|
|
* equal to the given buffer's limit. |
|
|
|
* equal to the given buffer's limit. |
|
|
@ -93,9 +89,7 @@ public final class BufferUtils { |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//// -- VECTOR3F METHODS -- ////
|
|
|
|
//// -- VECTOR3F METHODS -- ////
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* Generate a new FloatBuffer using the given array of Vector3f objects. |
|
|
|
* Generate a new FloatBuffer using the given array of Vector3f objects. |
|
|
|
* The FloatBuffer will be 3 * data.length long and contain the vector data |
|
|
|
* The FloatBuffer will be 3 * data.length long and contain the vector data |
|
|
@ -104,14 +98,17 @@ public final class BufferUtils { |
|
|
|
* @param data array of Vector3f objects to place into a new FloatBuffer |
|
|
|
* @param data array of Vector3f objects to place into a new FloatBuffer |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public static FloatBuffer createFloatBuffer(Vector3f... data) { |
|
|
|
public static FloatBuffer createFloatBuffer(Vector3f... data) { |
|
|
|
if (data == null) return null; |
|
|
|
if (data == null) { |
|
|
|
|
|
|
|
return null; |
|
|
|
|
|
|
|
} |
|
|
|
FloatBuffer buff = createFloatBuffer(3 * data.length); |
|
|
|
FloatBuffer buff = createFloatBuffer(3 * data.length); |
|
|
|
for (int x = 0; x < data.length; x++) { |
|
|
|
for (int x = 0; x < data.length; x++) { |
|
|
|
if (data[x] != null) |
|
|
|
if (data[x] != null) { |
|
|
|
buff.put(data[x].x).put(data[x].y).put(data[x].z); |
|
|
|
buff.put(data[x].x).put(data[x].y).put(data[x].z); |
|
|
|
else |
|
|
|
} else { |
|
|
|
buff.put(0).put(0).put(0); |
|
|
|
buff.put(0).put(0).put(0); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
buff.flip(); |
|
|
|
buff.flip(); |
|
|
|
return buff; |
|
|
|
return buff; |
|
|
|
} |
|
|
|
} |
|
|
@ -123,15 +120,17 @@ public final class BufferUtils { |
|
|
|
* @param data array of Quaternion objects to place into a new FloatBuffer |
|
|
|
* @param data array of Quaternion objects to place into a new FloatBuffer |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public static FloatBuffer createFloatBuffer(Quaternion... data) { |
|
|
|
public static FloatBuffer createFloatBuffer(Quaternion... data) { |
|
|
|
if (data == null) return null; |
|
|
|
if (data == null) { |
|
|
|
|
|
|
|
return null; |
|
|
|
|
|
|
|
} |
|
|
|
FloatBuffer buff = createFloatBuffer(4 * data.length); |
|
|
|
FloatBuffer buff = createFloatBuffer(4 * data.length); |
|
|
|
for (int x = 0; x < data.length; x++) { |
|
|
|
for (int x = 0; x < data.length; x++) { |
|
|
|
if (data[x] != null) |
|
|
|
if (data[x] != null) { |
|
|
|
buff.put(data[x].getX()).put(data[x].getY()) |
|
|
|
buff.put(data[x].getX()).put(data[x].getY()).put(data[x].getZ()).put(data[x].getW()); |
|
|
|
.put(data[x].getZ()).put(data[x].getW()); |
|
|
|
} else { |
|
|
|
else |
|
|
|
|
|
|
|
buff.put(0).put(0).put(0); |
|
|
|
buff.put(0).put(0).put(0); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
buff.flip(); |
|
|
|
buff.flip(); |
|
|
|
return buff; |
|
|
|
return buff; |
|
|
|
} |
|
|
|
} |
|
|
@ -141,7 +140,9 @@ public final class BufferUtils { |
|
|
|
* @param data array of float primitives to place into a new FloatBuffer |
|
|
|
* @param data array of float primitives to place into a new FloatBuffer |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public static FloatBuffer createFloatBuffer(float... data) { |
|
|
|
public static FloatBuffer createFloatBuffer(float... data) { |
|
|
|
if (data == null) return null; |
|
|
|
if (data == null) { |
|
|
|
|
|
|
|
return null; |
|
|
|
|
|
|
|
} |
|
|
|
FloatBuffer buff = createFloatBuffer(data.length); |
|
|
|
FloatBuffer buff = createFloatBuffer(data.length); |
|
|
|
buff.clear(); |
|
|
|
buff.clear(); |
|
|
|
buff.put(data); |
|
|
|
buff.put(data); |
|
|
@ -311,12 +312,12 @@ public final class BufferUtils { |
|
|
|
* to normalize |
|
|
|
* to normalize |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public static void normalizeVector3(FloatBuffer buf, int index) { |
|
|
|
public static void normalizeVector3(FloatBuffer buf, int index) { |
|
|
|
assert TempVars.get().lock(); |
|
|
|
TempVars vars = TempVars.get(); |
|
|
|
Vector3f tempVec3 = TempVars.get().vect1; |
|
|
|
Vector3f tempVec3 = vars.vect1; |
|
|
|
populateFromBuffer(tempVec3, buf, index); |
|
|
|
populateFromBuffer(tempVec3, buf, index); |
|
|
|
tempVec3.normalizeLocal(); |
|
|
|
tempVec3.normalizeLocal(); |
|
|
|
setInBuffer(tempVec3, buf, index); |
|
|
|
setInBuffer(tempVec3, buf, index); |
|
|
|
assert TempVars.get().unlock(); |
|
|
|
vars.release(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
@ -331,12 +332,12 @@ public final class BufferUtils { |
|
|
|
* to add to |
|
|
|
* to add to |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public static void addInBuffer(Vector3f toAdd, FloatBuffer buf, int index) { |
|
|
|
public static void addInBuffer(Vector3f toAdd, FloatBuffer buf, int index) { |
|
|
|
assert TempVars.get().lock(); |
|
|
|
TempVars vars = TempVars.get(); |
|
|
|
Vector3f tempVec3 = TempVars.get().vect1; |
|
|
|
Vector3f tempVec3 = vars.vect1; |
|
|
|
populateFromBuffer(tempVec3, buf, index); |
|
|
|
populateFromBuffer(tempVec3, buf, index); |
|
|
|
tempVec3.addLocal(toAdd); |
|
|
|
tempVec3.addLocal(toAdd); |
|
|
|
setInBuffer(tempVec3, buf, index); |
|
|
|
setInBuffer(tempVec3, buf, index); |
|
|
|
assert TempVars.get().unlock(); |
|
|
|
vars.release(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
@ -351,12 +352,12 @@ public final class BufferUtils { |
|
|
|
* to multiply |
|
|
|
* to multiply |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public static void multInBuffer(Vector3f toMult, FloatBuffer buf, int index) { |
|
|
|
public static void multInBuffer(Vector3f toMult, FloatBuffer buf, int index) { |
|
|
|
assert TempVars.get().lock(); |
|
|
|
TempVars vars = TempVars.get(); |
|
|
|
Vector3f tempVec3 = TempVars.get().vect1; |
|
|
|
Vector3f tempVec3 = vars.vect1; |
|
|
|
populateFromBuffer(tempVec3, buf, index); |
|
|
|
populateFromBuffer(tempVec3, buf, index); |
|
|
|
tempVec3.multLocal(toMult); |
|
|
|
tempVec3.multLocal(toMult); |
|
|
|
setInBuffer(tempVec3, buf, index); |
|
|
|
setInBuffer(tempVec3, buf, index); |
|
|
|
assert TempVars.get().unlock(); |
|
|
|
vars.release(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
@ -373,16 +374,15 @@ public final class BufferUtils { |
|
|
|
* @return |
|
|
|
* @return |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public static boolean equals(Vector3f check, FloatBuffer buf, int index) { |
|
|
|
public static boolean equals(Vector3f check, FloatBuffer buf, int index) { |
|
|
|
assert TempVars.get().lock(); |
|
|
|
TempVars vars = TempVars.get(); |
|
|
|
Vector3f tempVec3 = TempVars.get().vect1; |
|
|
|
Vector3f tempVec3 = vars.vect1; |
|
|
|
populateFromBuffer(tempVec3, buf, index); |
|
|
|
populateFromBuffer(tempVec3, buf, index); |
|
|
|
boolean eq = tempVec3.equals(check); |
|
|
|
boolean eq = tempVec3.equals(check); |
|
|
|
assert TempVars.get().unlock(); |
|
|
|
vars.release(); |
|
|
|
return eq; |
|
|
|
return eq; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// // -- VECTOR2F METHODS -- ////
|
|
|
|
// // -- VECTOR2F METHODS -- ////
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* Generate a new FloatBuffer using the given array of Vector2f objects. |
|
|
|
* Generate a new FloatBuffer using the given array of Vector2f objects. |
|
|
|
* The FloatBuffer will be 2 * data.length long and contain the vector data |
|
|
|
* The FloatBuffer will be 2 * data.length long and contain the vector data |
|
|
@ -391,14 +391,17 @@ public final class BufferUtils { |
|
|
|
* @param data array of Vector2f objects to place into a new FloatBuffer |
|
|
|
* @param data array of Vector2f objects to place into a new FloatBuffer |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public static FloatBuffer createFloatBuffer(Vector2f... data) { |
|
|
|
public static FloatBuffer createFloatBuffer(Vector2f... data) { |
|
|
|
if (data == null) return null; |
|
|
|
if (data == null) { |
|
|
|
|
|
|
|
return null; |
|
|
|
|
|
|
|
} |
|
|
|
FloatBuffer buff = createFloatBuffer(2 * data.length); |
|
|
|
FloatBuffer buff = createFloatBuffer(2 * data.length); |
|
|
|
for (int x = 0; x < data.length; x++) { |
|
|
|
for (int x = 0; x < data.length; x++) { |
|
|
|
if (data[x] != null) |
|
|
|
if (data[x] != null) { |
|
|
|
buff.put(data[x].x).put(data[x].y); |
|
|
|
buff.put(data[x].x).put(data[x].y); |
|
|
|
else |
|
|
|
} else { |
|
|
|
buff.put(0).put(0); |
|
|
|
buff.put(0).put(0); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
buff.flip(); |
|
|
|
buff.flip(); |
|
|
|
return buff; |
|
|
|
return buff; |
|
|
|
} |
|
|
|
} |
|
|
@ -514,12 +517,12 @@ public final class BufferUtils { |
|
|
|
* to normalize |
|
|
|
* to normalize |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public static void normalizeVector2(FloatBuffer buf, int index) { |
|
|
|
public static void normalizeVector2(FloatBuffer buf, int index) { |
|
|
|
assert TempVars.get().lock(); |
|
|
|
TempVars vars = TempVars.get(); |
|
|
|
Vector2f tempVec2 = TempVars.get().vect2d; |
|
|
|
Vector2f tempVec2 = vars.vect2d; |
|
|
|
populateFromBuffer(tempVec2, buf, index); |
|
|
|
populateFromBuffer(tempVec2, buf, index); |
|
|
|
tempVec2.normalizeLocal(); |
|
|
|
tempVec2.normalizeLocal(); |
|
|
|
setInBuffer(tempVec2, buf, index); |
|
|
|
setInBuffer(tempVec2, buf, index); |
|
|
|
assert TempVars.get().unlock(); |
|
|
|
vars.release(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
@ -534,12 +537,12 @@ public final class BufferUtils { |
|
|
|
* to add to |
|
|
|
* to add to |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public static void addInBuffer(Vector2f toAdd, FloatBuffer buf, int index) { |
|
|
|
public static void addInBuffer(Vector2f toAdd, FloatBuffer buf, int index) { |
|
|
|
assert TempVars.get().lock(); |
|
|
|
TempVars vars = TempVars.get(); |
|
|
|
Vector2f tempVec2 = TempVars.get().vect2d; |
|
|
|
Vector2f tempVec2 = vars.vect2d; |
|
|
|
populateFromBuffer(tempVec2, buf, index); |
|
|
|
populateFromBuffer(tempVec2, buf, index); |
|
|
|
tempVec2.addLocal(toAdd); |
|
|
|
tempVec2.addLocal(toAdd); |
|
|
|
setInBuffer(tempVec2, buf, index); |
|
|
|
setInBuffer(tempVec2, buf, index); |
|
|
|
assert TempVars.get().unlock(); |
|
|
|
vars.release(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
@ -554,12 +557,12 @@ public final class BufferUtils { |
|
|
|
* to multiply |
|
|
|
* to multiply |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public static void multInBuffer(Vector2f toMult, FloatBuffer buf, int index) { |
|
|
|
public static void multInBuffer(Vector2f toMult, FloatBuffer buf, int index) { |
|
|
|
assert TempVars.get().lock(); |
|
|
|
TempVars vars = TempVars.get(); |
|
|
|
Vector2f tempVec2 = TempVars.get().vect2d; |
|
|
|
Vector2f tempVec2 = vars.vect2d; |
|
|
|
populateFromBuffer(tempVec2, buf, index); |
|
|
|
populateFromBuffer(tempVec2, buf, index); |
|
|
|
tempVec2.multLocal(toMult); |
|
|
|
tempVec2.multLocal(toMult); |
|
|
|
setInBuffer(tempVec2, buf, index); |
|
|
|
setInBuffer(tempVec2, buf, index); |
|
|
|
assert TempVars.get().unlock(); |
|
|
|
vars.release(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
@ -576,17 +579,15 @@ public final class BufferUtils { |
|
|
|
* @return |
|
|
|
* @return |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public static boolean equals(Vector2f check, FloatBuffer buf, int index) { |
|
|
|
public static boolean equals(Vector2f check, FloatBuffer buf, int index) { |
|
|
|
assert TempVars.get().lock(); |
|
|
|
TempVars vars = TempVars.get(); |
|
|
|
Vector2f tempVec2 = TempVars.get().vect2d; |
|
|
|
Vector2f tempVec2 = vars.vect2d; |
|
|
|
populateFromBuffer(tempVec2, buf, index); |
|
|
|
populateFromBuffer(tempVec2, buf, index); |
|
|
|
boolean eq = tempVec2.equals(check); |
|
|
|
boolean eq = tempVec2.equals(check); |
|
|
|
assert TempVars.get().unlock(); |
|
|
|
vars.release(); |
|
|
|
return eq; |
|
|
|
return eq; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//// -- INT METHODS -- ////
|
|
|
|
//// -- INT METHODS -- ////
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* Generate a new IntBuffer using the given array of ints. The IntBuffer |
|
|
|
* Generate a new IntBuffer using the given array of ints. The IntBuffer |
|
|
|
* will be data.length long and contain the int data as data[0], data[1]... |
|
|
|
* will be data.length long and contain the int data as data[0], data[1]... |
|
|
@ -596,7 +597,9 @@ public final class BufferUtils { |
|
|
|
* array of ints to place into a new IntBuffer |
|
|
|
* array of ints to place into a new IntBuffer |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public static IntBuffer createIntBuffer(int... data) { |
|
|
|
public static IntBuffer createIntBuffer(int... data) { |
|
|
|
if (data == null) return null; |
|
|
|
if (data == null) { |
|
|
|
|
|
|
|
return null; |
|
|
|
|
|
|
|
} |
|
|
|
IntBuffer buff = createIntBuffer(data.length); |
|
|
|
IntBuffer buff = createIntBuffer(data.length); |
|
|
|
buff.clear(); |
|
|
|
buff.clear(); |
|
|
|
buff.put(data); |
|
|
|
buff.put(data); |
|
|
@ -613,7 +616,9 @@ public final class BufferUtils { |
|
|
|
* @return a new int array populated from the IntBuffer |
|
|
|
* @return a new int array populated from the IntBuffer |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public static int[] getIntArray(IntBuffer buff) { |
|
|
|
public static int[] getIntArray(IntBuffer buff) { |
|
|
|
if (buff == null) return null; |
|
|
|
if (buff == null) { |
|
|
|
|
|
|
|
return null; |
|
|
|
|
|
|
|
} |
|
|
|
buff.clear(); |
|
|
|
buff.clear(); |
|
|
|
int[] inds = new int[buff.limit()]; |
|
|
|
int[] inds = new int[buff.limit()]; |
|
|
|
for (int x = 0; x < inds.length; x++) { |
|
|
|
for (int x = 0; x < inds.length; x++) { |
|
|
@ -631,7 +636,9 @@ public final class BufferUtils { |
|
|
|
* @return a new float array populated from the FloatBuffer |
|
|
|
* @return a new float array populated from the FloatBuffer |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public static float[] getFloatArray(FloatBuffer buff) { |
|
|
|
public static float[] getFloatArray(FloatBuffer buff) { |
|
|
|
if (buff == null) return null; |
|
|
|
if (buff == null) { |
|
|
|
|
|
|
|
return null; |
|
|
|
|
|
|
|
} |
|
|
|
buff.clear(); |
|
|
|
buff.clear(); |
|
|
|
float[] inds = new float[buff.limit()]; |
|
|
|
float[] inds = new float[buff.limit()]; |
|
|
|
for (int x = 0; x < inds.length; x++) { |
|
|
|
for (int x = 0; x < inds.length; x++) { |
|
|
@ -640,9 +647,7 @@ public final class BufferUtils { |
|
|
|
return inds; |
|
|
|
return inds; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//// -- GENERAL DOUBLE ROUTINES -- ////
|
|
|
|
//// -- GENERAL DOUBLE ROUTINES -- ////
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* Create a new DoubleBuffer of the specified size. |
|
|
|
* Create a new DoubleBuffer of the specified size. |
|
|
|
* |
|
|
|
* |
|
|
@ -691,7 +696,9 @@ public final class BufferUtils { |
|
|
|
* @return the copy |
|
|
|
* @return the copy |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public static DoubleBuffer clone(DoubleBuffer buf) { |
|
|
|
public static DoubleBuffer clone(DoubleBuffer buf) { |
|
|
|
if (buf == null) return null; |
|
|
|
if (buf == null) { |
|
|
|
|
|
|
|
return null; |
|
|
|
|
|
|
|
} |
|
|
|
buf.rewind(); |
|
|
|
buf.rewind(); |
|
|
|
|
|
|
|
|
|
|
|
DoubleBuffer copy; |
|
|
|
DoubleBuffer copy; |
|
|
@ -705,10 +712,7 @@ public final class BufferUtils { |
|
|
|
return copy; |
|
|
|
return copy; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//// -- GENERAL FLOAT ROUTINES -- ////
|
|
|
|
//// -- GENERAL FLOAT ROUTINES -- ////
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* Create a new FloatBuffer of the specified size. |
|
|
|
* Create a new FloatBuffer of the specified size. |
|
|
|
* |
|
|
|
* |
|
|
@ -756,7 +760,9 @@ public final class BufferUtils { |
|
|
|
* @return the copy |
|
|
|
* @return the copy |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public static FloatBuffer clone(FloatBuffer buf) { |
|
|
|
public static FloatBuffer clone(FloatBuffer buf) { |
|
|
|
if (buf == null) return null; |
|
|
|
if (buf == null) { |
|
|
|
|
|
|
|
return null; |
|
|
|
|
|
|
|
} |
|
|
|
buf.rewind(); |
|
|
|
buf.rewind(); |
|
|
|
|
|
|
|
|
|
|
|
FloatBuffer copy; |
|
|
|
FloatBuffer copy; |
|
|
@ -770,9 +776,7 @@ public final class BufferUtils { |
|
|
|
return copy; |
|
|
|
return copy; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//// -- GENERAL INT ROUTINES -- ////
|
|
|
|
//// -- GENERAL INT ROUTINES -- ////
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* Create a new IntBuffer of the specified size. |
|
|
|
* Create a new IntBuffer of the specified size. |
|
|
|
* |
|
|
|
* |
|
|
@ -821,7 +825,9 @@ public final class BufferUtils { |
|
|
|
* @return the copy |
|
|
|
* @return the copy |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public static IntBuffer clone(IntBuffer buf) { |
|
|
|
public static IntBuffer clone(IntBuffer buf) { |
|
|
|
if (buf == null) return null; |
|
|
|
if (buf == null) { |
|
|
|
|
|
|
|
return null; |
|
|
|
|
|
|
|
} |
|
|
|
buf.rewind(); |
|
|
|
buf.rewind(); |
|
|
|
|
|
|
|
|
|
|
|
IntBuffer copy; |
|
|
|
IntBuffer copy; |
|
|
@ -835,9 +841,7 @@ public final class BufferUtils { |
|
|
|
return copy; |
|
|
|
return copy; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//// -- GENERAL BYTE ROUTINES -- ////
|
|
|
|
//// -- GENERAL BYTE ROUTINES -- ////
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* Create a new ByteBuffer of the specified size. |
|
|
|
* Create a new ByteBuffer of the specified size. |
|
|
|
* |
|
|
|
* |
|
|
@ -901,7 +905,9 @@ public final class BufferUtils { |
|
|
|
* @return the copy |
|
|
|
* @return the copy |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public static ByteBuffer clone(ByteBuffer buf) { |
|
|
|
public static ByteBuffer clone(ByteBuffer buf) { |
|
|
|
if (buf == null) return null; |
|
|
|
if (buf == null) { |
|
|
|
|
|
|
|
return null; |
|
|
|
|
|
|
|
} |
|
|
|
buf.rewind(); |
|
|
|
buf.rewind(); |
|
|
|
|
|
|
|
|
|
|
|
ByteBuffer copy; |
|
|
|
ByteBuffer copy; |
|
|
@ -915,9 +921,7 @@ public final class BufferUtils { |
|
|
|
return copy; |
|
|
|
return copy; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//// -- GENERAL SHORT ROUTINES -- ////
|
|
|
|
//// -- GENERAL SHORT ROUTINES -- ////
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* Create a new ShortBuffer of the specified size. |
|
|
|
* Create a new ShortBuffer of the specified size. |
|
|
|
* |
|
|
|
* |
|
|
@ -956,7 +960,9 @@ public final class BufferUtils { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public static ShortBuffer createShortBuffer(short... data) { |
|
|
|
public static ShortBuffer createShortBuffer(short... data) { |
|
|
|
if (data == null) return null; |
|
|
|
if (data == null) { |
|
|
|
|
|
|
|
return null; |
|
|
|
|
|
|
|
} |
|
|
|
ShortBuffer buff = createShortBuffer(data.length); |
|
|
|
ShortBuffer buff = createShortBuffer(data.length); |
|
|
|
buff.clear(); |
|
|
|
buff.clear(); |
|
|
|
buff.put(data); |
|
|
|
buff.put(data); |
|
|
@ -975,7 +981,9 @@ public final class BufferUtils { |
|
|
|
* @return the copy |
|
|
|
* @return the copy |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public static ShortBuffer clone(ShortBuffer buf) { |
|
|
|
public static ShortBuffer clone(ShortBuffer buf) { |
|
|
|
if (buf == null) return null; |
|
|
|
if (buf == null) { |
|
|
|
|
|
|
|
return null; |
|
|
|
|
|
|
|
} |
|
|
|
buf.rewind(); |
|
|
|
buf.rewind(); |
|
|
|
|
|
|
|
|
|
|
|
ShortBuffer copy; |
|
|
|
ShortBuffer copy; |
|
|
@ -1068,25 +1076,20 @@ public final class BufferUtils { |
|
|
|
dBufs++; |
|
|
|
dBufs++; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
long heapMem = Runtime.getRuntime().totalMemory() - |
|
|
|
long heapMem = Runtime.getRuntime().totalMemory() |
|
|
|
Runtime.getRuntime().freeMemory(); |
|
|
|
- Runtime.getRuntime().freeMemory(); |
|
|
|
|
|
|
|
|
|
|
|
boolean printStout = store == null; |
|
|
|
boolean printStout = store == null; |
|
|
|
if (store == null) { |
|
|
|
if (store == null) { |
|
|
|
store = new StringBuilder(); |
|
|
|
store = new StringBuilder(); |
|
|
|
} |
|
|
|
} |
|
|
|
store.append("Existing buffers: ").append(bufs.size()).append("\n"); |
|
|
|
store.append("Existing buffers: ").append(bufs.size()).append("\n"); |
|
|
|
store.append("(b: ").append(bBufs).append(" f: ").append(fBufs) |
|
|
|
store.append("(b: ").append(bBufs).append(" f: ").append(fBufs).append(" i: ").append(iBufs).append(" s: ").append(sBufs).append(" d: ").append(dBufs).append(")").append("\n"); |
|
|
|
.append(" i: ").append(iBufs).append(" s: ").append(sBufs) |
|
|
|
|
|
|
|
.append(" d: ").append(dBufs).append(")").append("\n"); |
|
|
|
|
|
|
|
store.append("Total heap memory held: ").append(heapMem / 1024).append("kb\n"); |
|
|
|
store.append("Total heap memory held: ").append(heapMem / 1024).append("kb\n"); |
|
|
|
store.append("Total direct memory held: ").append(totalHeld / 1024).append("kb\n"); |
|
|
|
store.append("Total direct memory held: ").append(totalHeld / 1024).append("kb\n"); |
|
|
|
store.append("(b: ").append(bBufsM/1024).append("kb f: ").append(fBufsM/1024) |
|
|
|
store.append("(b: ").append(bBufsM / 1024).append("kb f: ").append(fBufsM / 1024).append("kb i: ").append(iBufsM / 1024).append("kb s: ").append(sBufsM / 1024).append("kb d: ").append(dBufsM / 1024).append("kb)").append("\n"); |
|
|
|
.append("kb i: ").append(iBufsM/1024).append("kb s: ").append(sBufsM/1024) |
|
|
|
|
|
|
|
.append("kb d: ").append(dBufsM/1024).append("kb)").append("\n"); |
|
|
|
|
|
|
|
if (printStout) { |
|
|
|
if (printStout) { |
|
|
|
System.out.println(store.toString()); |
|
|
|
System.out.println(store.toString()); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|