mirror of https://github.com/rusefi/RomRaider.git
Fixed floats appearing as squares
git-svn-id: http://svn.3splooges.com/romraider-arch/trunk@49 d2e2e1cd-ba16-0410-be16-b7c4453c7c2d
This commit is contained in:
parent
299393832f
commit
6384609fce
|
@ -3,6 +3,7 @@
|
||||||
package enginuity.xml;
|
package enginuity.xml;
|
||||||
|
|
||||||
import enginuity.maps.*;
|
import enginuity.maps.*;
|
||||||
|
import enginuity.maps.TableSwitch;
|
||||||
import enginuity.swing.JProgressPane;
|
import enginuity.swing.JProgressPane;
|
||||||
import javax.management.modelmbean.XMLParseException;
|
import javax.management.modelmbean.XMLParseException;
|
||||||
import org.w3c.dom.Node;
|
import org.w3c.dom.Node;
|
||||||
|
@ -162,6 +163,11 @@ public class DOMRomUnmarshaller {
|
||||||
}
|
}
|
||||||
return romID;
|
return romID;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private Table copyTable(Table input) {
|
||||||
|
Table output = input;
|
||||||
|
return output;
|
||||||
|
}
|
||||||
|
|
||||||
private Table unmarshallTable(Node tableNode, Table table, Rom rom) throws XMLParseException, TableIsOmittedException, Exception {
|
private Table unmarshallTable(Node tableNode, Table table, Rom rom) throws XMLParseException, TableIsOmittedException, Exception {
|
||||||
|
|
||||||
|
@ -184,16 +190,24 @@ public class DOMRomUnmarshaller {
|
||||||
} catch (NullPointerException ex) { // if type is null or less than 0, create new instance (otherwise it is inherited)
|
} catch (NullPointerException ex) { // if type is null or less than 0, create new instance (otherwise it is inherited)
|
||||||
if (unmarshallAttribute(tableNode, "type", "unknown").equalsIgnoreCase("3D")) {
|
if (unmarshallAttribute(tableNode, "type", "unknown").equalsIgnoreCase("3D")) {
|
||||||
table = new Table3D();
|
table = new Table3D();
|
||||||
|
|
||||||
} else if (unmarshallAttribute(tableNode, "type", "unknown").equalsIgnoreCase("2D")) {
|
} else if (unmarshallAttribute(tableNode, "type", "unknown").equalsIgnoreCase("2D")) {
|
||||||
table = new Table2D();
|
table = new Table2D();
|
||||||
|
|
||||||
} else if (unmarshallAttribute(tableNode, "type", "unknown").equalsIgnoreCase("1D")) {
|
} else if (unmarshallAttribute(tableNode, "type", "unknown").equalsIgnoreCase("1D")) {
|
||||||
table = new Table1D();
|
table = new Table1D();
|
||||||
|
|
||||||
} else if (unmarshallAttribute(tableNode, "type", "unknown").equalsIgnoreCase("X Axis") ||
|
} else if (unmarshallAttribute(tableNode, "type", "unknown").equalsIgnoreCase("X Axis") ||
|
||||||
unmarshallAttribute(tableNode, "type", "unknown").equalsIgnoreCase("Y Axis")) {
|
unmarshallAttribute(tableNode, "type", "unknown").equalsIgnoreCase("Y Axis")) {
|
||||||
table = new Table1D();
|
table = new Table1D();
|
||||||
|
|
||||||
} else if (unmarshallAttribute(tableNode, "type", "unknown").equalsIgnoreCase("Static Y Axis") ||
|
} else if (unmarshallAttribute(tableNode, "type", "unknown").equalsIgnoreCase("Static Y Axis") ||
|
||||||
unmarshallAttribute(tableNode, "type", "unknown").equalsIgnoreCase("Static X Axis")) {
|
unmarshallAttribute(tableNode, "type", "unknown").equalsIgnoreCase("Static X Axis")) {
|
||||||
table = new Table1D();
|
table = new Table1D();
|
||||||
|
|
||||||
|
} else if (unmarshallAttribute(tableNode, "type", "unknown").equalsIgnoreCase("Switch")) {
|
||||||
|
table = new TableSwitch();
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
throw new XMLParseException();
|
throw new XMLParseException();
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,6 +5,7 @@ package enginuity.xml;
|
||||||
import enginuity.maps.Table;
|
import enginuity.maps.Table;
|
||||||
import enginuity.maps.Scale;
|
import enginuity.maps.Scale;
|
||||||
import java.nio.ByteBuffer;
|
import java.nio.ByteBuffer;
|
||||||
|
import java.nio.ByteOrder;
|
||||||
|
|
||||||
public abstract class RomAttributeParser {
|
public abstract class RomAttributeParser {
|
||||||
|
|
||||||
|
@ -114,37 +115,17 @@ public abstract class RomAttributeParser {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static byte[] floatToByte(float f, int endian) {
|
public static byte[] floatToByte(float input, int endian) {
|
||||||
byte[] output = new byte[4];
|
byte[] output = new byte[4];
|
||||||
int input = Float.floatToIntBits(f);
|
ByteBuffer bb = ByteBuffer.wrap(output, 0, 4);
|
||||||
|
if (endian == Table.ENDIAN_LITTLE) bb.order(ByteOrder.BIG_ENDIAN);
|
||||||
if (endian == Table.ENDIAN_LITTLE) {
|
bb.putFloat(input);
|
||||||
output[0] = (byte)(input >> 24);
|
return bb.array();
|
||||||
output[1] = (byte)(input >> 16);
|
|
||||||
output[2] = (byte)(input >> 8);
|
|
||||||
output[3] = (byte)(input);
|
|
||||||
} else { // big endian
|
|
||||||
output[3] = (byte)(input >> 24);
|
|
||||||
output[2] = (byte)(input >> 16);
|
|
||||||
output[1] = (byte)(input >> 8);
|
|
||||||
output[0] = (byte)(input);
|
|
||||||
}
|
|
||||||
return output;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static float byteToFloat(byte[] input, int endian) {
|
public static float byteToFloat(byte[] input, int endian) {
|
||||||
int i = 0;
|
ByteBuffer bb = ByteBuffer.wrap(input, 0, 4);
|
||||||
if (endian == Table.ENDIAN_LITTLE) {
|
if (endian == Table.ENDIAN_LITTLE) bb.order(ByteOrder.BIG_ENDIAN);
|
||||||
i = input[3];
|
return bb.getFloat();
|
||||||
i = i | ((input[2] << 8) & 0xff00);
|
}
|
||||||
i = i | ((input[1] << 16) & 0xff0000);
|
|
||||||
i = i | ((input[0] << 24) & 0xff000000);
|
|
||||||
} else { // big endian
|
|
||||||
i = input[0];
|
|
||||||
i = i | ((input[1] << 8) & 0xff00);
|
|
||||||
i = i | ((input[2] << 16) & 0xff0000);
|
|
||||||
i = i | ((input[3] << 24) & 0xff000000);
|
|
||||||
}
|
|
||||||
return Float.intBitsToFloat(i);
|
|
||||||
}
|
|
||||||
}
|
}
|
Loading…
Reference in New Issue