Skip to content

Commit

Permalink
Undid XMLExporter saving buffer positions.
Browse files Browse the repository at this point in the history
Not saving positions is intentional jMonkeyEngine#2312 (comment)
  • Loading branch information
JosiahGoeman committed Sep 19, 2024
1 parent fdaa7b7 commit 45a0cf6
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 61 deletions.
48 changes: 4 additions & 44 deletions jme3-plugins/src/xml/java/com/jme3/export/xml/DOMInputCapsule.java
Original file line number Diff line number Diff line change
Expand Up @@ -704,17 +704,7 @@ public ByteBuffer readByteBuffer(String name, ByteBuffer defVal) throws IOExcept
return defVal;
}

int position = 0;
String positionString = XMLUtils.getAttribute(importer.getFormatVersion(), element, XMLExporter.ATTRIBUTE_POSITION);
if (!positionString.isEmpty()) {
try {
position = Integer.parseInt(positionString);
} catch (NumberFormatException nfe) {
throw new IOException(nfe);
}
}

return (ByteBuffer) BufferUtils.createByteBuffer(array.length).put(array).position(position);
return (ByteBuffer) BufferUtils.createByteBuffer(array.length).put(array).rewind();
}

@Override
Expand All @@ -727,17 +717,7 @@ public ShortBuffer readShortBuffer(String name, ShortBuffer defVal) throws IOExc
return defVal;
}

int position = 0;
String positionString = XMLUtils.getAttribute(importer.getFormatVersion(), element, XMLExporter.ATTRIBUTE_POSITION);
if (!positionString.isEmpty()) {
try {
position = Integer.parseInt(positionString);
} catch (NumberFormatException nfe) {
throw new IOException(nfe);
}
}

return (ShortBuffer) BufferUtils.createShortBuffer(array.length).put(array).position(position);
return (ShortBuffer) BufferUtils.createShortBuffer(array.length).put(array).rewind();
}

@Override
Expand All @@ -750,17 +730,7 @@ public IntBuffer readIntBuffer(String name, IntBuffer defVal) throws IOException
return defVal;
}

int position = 0;
String positionString = XMLUtils.getAttribute(importer.getFormatVersion(), element, XMLExporter.ATTRIBUTE_POSITION);
if (!positionString.isEmpty()) {
try {
position = Integer.parseInt(positionString);
} catch (NumberFormatException nfe) {
throw new IOException(nfe);
}
}

return (IntBuffer) BufferUtils.createIntBuffer(array.length).put(array).position(position);
return (IntBuffer) BufferUtils.createIntBuffer(array.length).put(array).rewind();
}

@Override
Expand All @@ -773,17 +743,7 @@ public FloatBuffer readFloatBuffer(String name, FloatBuffer defVal) throws IOExc
return defVal;
}

int position = 0;
String positionString = XMLUtils.getAttribute(importer.getFormatVersion(), element, XMLExporter.ATTRIBUTE_POSITION);
if (!positionString.isEmpty()) {
try {
position = Integer.parseInt(positionString);
} catch (NumberFormatException nfe) {
throw new IOException(nfe);
}
}

return (FloatBuffer) BufferUtils.createFloatBuffer(array.length).put(array).position(position);
return (FloatBuffer) BufferUtils.createFloatBuffer(array.length).put(array).rewind();
}

@Override
Expand Down
30 changes: 14 additions & 16 deletions jme3-plugins/src/xml/java/com/jme3/export/xml/DOMOutputCapsule.java
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ private Element appendElement(String name) {

// helper function to reduce duplicate code. uses reflection to write an array of any primitive type.
// also has optional position argument for writing buffers.
private void writePrimitiveArrayHelper(Object value, String name, int position) throws IOException {
private void writePrimitiveArrayHelper(Object value, String name) throws IOException {
StringBuilder sb = new StringBuilder();

for(int i = 0; i < Array.getLength(value); i++) {
Expand All @@ -104,9 +104,7 @@ private void writePrimitiveArrayHelper(Object value, String name, int position)
appendElement(name);
XMLUtils.setAttribute(currentElement, XMLExporter.ATTRIBUTE_SIZE, String.valueOf(Array.getLength(value)));
XMLUtils.setAttribute(currentElement, XMLExporter.ATTRIBUTE_DATA, sb.toString());
if (position >= 0) {
XMLUtils.setAttribute(currentElement, XMLExporter.ATTRIBUTE_POSITION, String.valueOf(position));
}

currentElement = (Element) currentElement.getParentNode();
}

Expand All @@ -124,7 +122,7 @@ private void writePrimitiveArray2DHelper(Object[] value, String name) throws IOE
String childName = childNamePrefix + i;

if (value[i] != null) {
writePrimitiveArrayHelper(value[i], childName, -1);
writePrimitiveArrayHelper(value[i], childName);
} else {
// empty tag
appendElement(childName);
Expand All @@ -145,7 +143,7 @@ public void write(byte value, String name, byte defVal) throws IOException {
@Override
public void write(byte[] value, String name, byte[] defVal) throws IOException {
if (!Arrays.equals(value, defVal)) {
writePrimitiveArrayHelper(value, name, -1);
writePrimitiveArrayHelper(value, name);
}
}

Expand All @@ -166,7 +164,7 @@ public void write(short value, String name, short defVal) throws IOException {
@Override
public void write(short[] value, String name, short[] defVal) throws IOException {
if (!Arrays.equals(value, defVal)) {
writePrimitiveArrayHelper(value, name, -1);
writePrimitiveArrayHelper(value, name);
}
}

Expand All @@ -187,7 +185,7 @@ public void write(int value, String name, int defVal) throws IOException {
@Override
public void write(int[] value, String name, int[] defVal) throws IOException {
if (!Arrays.equals(value, defVal)) {
writePrimitiveArrayHelper(value, name, -1);
writePrimitiveArrayHelper(value, name);
}
}

Expand All @@ -208,7 +206,7 @@ public void write(long value, String name, long defVal) throws IOException {
@Override
public void write(long[] value, String name, long[] defVal) throws IOException {
if (!Arrays.equals(value, defVal)) {
writePrimitiveArrayHelper(value, name, -1);
writePrimitiveArrayHelper(value, name);
}
}

Expand All @@ -229,7 +227,7 @@ public void write(float value, String name, float defVal) throws IOException {
@Override
public void write(float[] value, String name, float[] defVal) throws IOException {
if (!Arrays.equals(value, defVal)) {
writePrimitiveArrayHelper(value, name, -1);
writePrimitiveArrayHelper(value, name);
}
}

Expand All @@ -250,7 +248,7 @@ public void write(double value, String name, double defVal) throws IOException {
@Override
public void write(double[] value, String name, double[] defVal) throws IOException {
if (!Arrays.equals(value, defVal)) {
writePrimitiveArrayHelper(value, name, -1);
writePrimitiveArrayHelper(value, name);
}
}

Expand All @@ -271,7 +269,7 @@ public void write(boolean value, String name, boolean defVal) throws IOException
@Override
public void write(boolean[] value, String name, boolean[] defVal) throws IOException {
if (!Arrays.equals(value, defVal)) {
writePrimitiveArrayHelper(value, name, -1);
writePrimitiveArrayHelper(value, name);
}
}

Expand Down Expand Up @@ -478,7 +476,7 @@ public void write(ByteBuffer value, String name, ByteBuffer defVal) throws IOExc
value.get(array);
value.position(position);

writePrimitiveArrayHelper(array, name, value.position());
writePrimitiveArrayHelper(array, name);
}

@Override
Expand All @@ -493,7 +491,7 @@ public void write(ShortBuffer value, String name, ShortBuffer defVal) throws IOE
value.get(array);
value.position(position);

writePrimitiveArrayHelper(array, name, value.position());
writePrimitiveArrayHelper(array, name);
}

@Override
Expand All @@ -508,7 +506,7 @@ public void write(IntBuffer value, String name, IntBuffer defVal) throws IOExcep
value.get(array);
value.position(position);

writePrimitiveArrayHelper(array, name, value.position());
writePrimitiveArrayHelper(array, name);
}

@Override
Expand All @@ -523,7 +521,7 @@ public void write(FloatBuffer value, String name, FloatBuffer defVal) throws IOE
value.get(array);
value.position(position);

writePrimitiveArrayHelper(array, name, value.position());
writePrimitiveArrayHelper(array, name);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@ public class XMLExporter implements JmeExporter {
public static final String ELEMENT_VALUE = "Value";
public static final String ATTRIBUTE_SIZE = "size";
public static final String ATTRIBUTE_DATA = "data";
public static final String ATTRIBUTE_POSITION = "position"; // for buffers only
public static final String ATTRIBUTE_CLASS = "class";
public static final String ATTRIBUTE_REFERENCE_ID = "reference_ID";
public static final String ATTRIBUTE_REFERENCE = "ref";
Expand Down

0 comments on commit 45a0cf6

Please sign in to comment.