mirror of https://github.com/rusefi/RomRaider.git
Refactor to filter out BASE tables not needed to evaluate ROM file. A
50% reduction in load time achieved.
This commit is contained in:
parent
696f9019c5
commit
5bd5439296
|
@ -1,6 +1,6 @@
|
|||
/*
|
||||
* RomRaider Open-Source Tuning, Logging and Reflashing
|
||||
* Copyright (C) 2006-2014 RomRaider.com
|
||||
* Copyright (C) 2006-2016 RomRaider.com
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
|
@ -176,8 +176,8 @@ public class Rom extends DefaultMutableTreeNode implements Serializable {
|
|||
for (int i = 0; i < tableNodes.size(); i++) {
|
||||
|
||||
// update progress
|
||||
int currProgress = (int) (i / (double) tableNodes.size() * 40);
|
||||
progress.update("Populating tables...", 50 + currProgress);
|
||||
int currProgress = (int) (i / (double) tableNodes.size() * 100);
|
||||
progress.update("Populating tables...", currProgress);
|
||||
|
||||
Table table = tableNodes.get(i).getTable();
|
||||
try {
|
||||
|
|
|
@ -26,7 +26,9 @@ import static com.romraider.xml.DOMHelper.unmarshallText;
|
|||
import static org.w3c.dom.Node.ELEMENT_NODE;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.management.modelmbean.XMLParseException;
|
||||
import javax.swing.JOptionPane;
|
||||
|
@ -48,7 +50,6 @@ import com.romraider.maps.Table3D;
|
|||
import com.romraider.maps.TableSwitch;
|
||||
import com.romraider.swing.DebugPanel;
|
||||
import com.romraider.swing.JProgressPane;
|
||||
import com.romraider.util.LogManager;
|
||||
import com.romraider.util.ObjectCloner;
|
||||
import com.romraider.util.SettingsManager;
|
||||
|
||||
|
@ -59,6 +60,7 @@ public final class DOMRomUnmarshaller {
|
|||
private final List<Scale> scales = new ArrayList<Scale>();
|
||||
private String memModelEndian = null;
|
||||
private final Scale rawScale = new Scale();
|
||||
private final Map<String, Integer> tableNames = new HashMap<String, Integer>();
|
||||
|
||||
public DOMRomUnmarshaller() {
|
||||
}
|
||||
|
@ -171,30 +173,13 @@ public final class DOMRomUnmarshaller {
|
|||
}
|
||||
}
|
||||
|
||||
public static void main(String args[]) {
|
||||
LogManager.initDebugLogging();
|
||||
RomID romID = new RomID();
|
||||
romID.setInternalIdString("Asdfd");
|
||||
|
||||
byte[] file = "Asdfd".getBytes();
|
||||
LOGGER.debug(foundMatch(romID, file));
|
||||
|
||||
file[0] = 1;
|
||||
file[1] = 1;
|
||||
file[2] = 1;
|
||||
file[3] = 1;
|
||||
LOGGER.debug(foundMatch(romID, file));
|
||||
|
||||
romID.setInternalIdString("0x010101");
|
||||
LOGGER.debug(foundMatch(romID, file));
|
||||
}
|
||||
|
||||
public Rom unmarshallRom(Node rootNode, Rom rom) throws XMLParseException,
|
||||
RomNotFoundException, StackOverflowError, Exception {
|
||||
Node n;
|
||||
NodeList nodes = rootNode.getChildNodes();
|
||||
filterFoundRomTables(nodes);
|
||||
|
||||
progress.update("Creating tables...", 15);
|
||||
progress.update("Creating " + rom.getRomID().getXmlid() + " tables...", 0);
|
||||
|
||||
if (!unmarshallAttribute(rootNode, "base", "none").equalsIgnoreCase(
|
||||
"none")) {
|
||||
|
@ -207,8 +192,8 @@ public final class DOMRomUnmarshaller {
|
|||
n = nodes.item(i);
|
||||
|
||||
// update progress
|
||||
int currProgress = (int) ((double) i / (double) nodes.getLength() * 40);
|
||||
progress.update("Creating tables...", 10 + currProgress);
|
||||
int currProgress = (int) (i / (double) nodes.getLength() * 100);
|
||||
progress.update("Creating " + rom.getRomID().getXmlid() + " tables...", currProgress);
|
||||
|
||||
if (n.getNodeType() == ELEMENT_NODE) {
|
||||
if (n.getNodeName().equalsIgnoreCase("romid")) {
|
||||
|
@ -232,7 +217,10 @@ public final class DOMRomUnmarshaller {
|
|||
try {
|
||||
table = unmarshallTable(n, table, rom);
|
||||
//rom.addTableByName(table);
|
||||
rom.addTable(table);
|
||||
if (table != null) {
|
||||
//rom.removeTableByName(table);
|
||||
rom.addTable(table);
|
||||
}
|
||||
} catch (TableIsOmittedException ex) {
|
||||
// table is not supported in inherited def (skip)
|
||||
if (table != null) {
|
||||
|
@ -384,49 +372,59 @@ public final class DOMRomUnmarshaller {
|
|||
} 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")) {
|
||||
table = new Table3D();
|
||||
table.getScales().add(rawScale);
|
||||
((Table3D) table).getXAxis().getScales().add(rawScale);
|
||||
((Table3D) table).getYAxis().getScales().add(rawScale);
|
||||
final String tn = unmarshallAttribute(tableNode, "name", "unknown");
|
||||
final String type = unmarshallAttribute(tableNode, "type", "unknown");
|
||||
if (tableNames.containsKey(tn) || type.contains("xis")) {
|
||||
if (unmarshallAttribute(tableNode, "type", "unknown")
|
||||
.equalsIgnoreCase("3D")) {
|
||||
table = new Table3D();
|
||||
table.getScales().add(rawScale);
|
||||
((Table3D) table).getXAxis().getScales().add(rawScale);
|
||||
((Table3D) table).getYAxis().getScales().add(rawScale);
|
||||
|
||||
} else if (unmarshallAttribute(tableNode, "type", "unknown")
|
||||
.equalsIgnoreCase("2D")) {
|
||||
table = new Table2D();
|
||||
table.getScales().add(rawScale);
|
||||
((Table2D) table).getAxis().getScales().add(rawScale);
|
||||
} else if (unmarshallAttribute(tableNode, "type", "unknown")
|
||||
.equalsIgnoreCase("2D")) {
|
||||
table = new Table2D();
|
||||
table.getScales().add(rawScale);
|
||||
((Table2D) table).getAxis().getScales().add(rawScale);
|
||||
|
||||
} else if (unmarshallAttribute(tableNode, "type", "unknown")
|
||||
.equalsIgnoreCase("1D")) {
|
||||
table = new Table1D();
|
||||
} else if (unmarshallAttribute(tableNode, "type", "unknown")
|
||||
.equalsIgnoreCase("1D")) {
|
||||
table = new Table1D();
|
||||
|
||||
} else if (unmarshallAttribute(tableNode, "type", "unknown")
|
||||
.equalsIgnoreCase("X Axis")
|
||||
|| unmarshallAttribute(tableNode, "type", "unknown")
|
||||
.equalsIgnoreCase("Y Axis")) {
|
||||
table = new Table1D();
|
||||
} else if (unmarshallAttribute(tableNode, "type", "unknown")
|
||||
.equalsIgnoreCase("X Axis")
|
||||
|| unmarshallAttribute(tableNode, "type", "unknown")
|
||||
.equalsIgnoreCase("Y Axis")) {
|
||||
table = new Table1D();
|
||||
|
||||
} else if (unmarshallAttribute(tableNode, "type", "unknown")
|
||||
.equalsIgnoreCase("Static Y Axis")
|
||||
|| unmarshallAttribute(tableNode, "type", "unknown")
|
||||
.equalsIgnoreCase("Static X Axis")) {
|
||||
table = new Table1D();
|
||||
} else if (unmarshallAttribute(tableNode, "type", "unknown")
|
||||
.equalsIgnoreCase("Static Y Axis")
|
||||
|| unmarshallAttribute(tableNode, "type", "unknown")
|
||||
.equalsIgnoreCase("Static X Axis")) {
|
||||
table = new Table1D();
|
||||
|
||||
} else if (unmarshallAttribute(tableNode, "type", "unknown")
|
||||
.equalsIgnoreCase("Switch")) {
|
||||
table = new TableSwitch();
|
||||
} else if (unmarshallAttribute(tableNode, "type", "unknown")
|
||||
.equalsIgnoreCase("Switch")) {
|
||||
table = new TableSwitch();
|
||||
|
||||
} else {
|
||||
throw new XMLParseException("Error loading table, "
|
||||
+ tableNode.getAttributes().getNamedItem("name"));
|
||||
} else {
|
||||
throw new XMLParseException("Error loading table, "
|
||||
+ tableNode.getAttributes().getNamedItem("name"));
|
||||
}
|
||||
}
|
||||
else {
|
||||
return table;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// unmarshall table attributes
|
||||
table.setName(unmarshallAttribute(tableNode, "name", table.getName()));
|
||||
table.setType(RomAttributeParser.parseTableType(unmarshallAttribute(
|
||||
tableNode, "type", String.valueOf(table.getType()))));
|
||||
final String tn = unmarshallAttribute(tableNode, "name", table.getName());
|
||||
final int type = RomAttributeParser.parseTableType(unmarshallAttribute(
|
||||
tableNode, "type", String.valueOf(table.getType())));
|
||||
table.setName(tn);
|
||||
table.setType(type);
|
||||
if (unmarshallAttribute(tableNode, "beforeram", "false")
|
||||
.equalsIgnoreCase("true")) {
|
||||
table.setBeforeRam(true);
|
||||
|
@ -452,10 +450,15 @@ public final class DOMRomUnmarshaller {
|
|||
table.setMemModelEndian(endian);
|
||||
table.setEndian(endian);
|
||||
}
|
||||
table.setStorageAddress(RomAttributeParser
|
||||
if (tableNames.containsKey(tn)) {
|
||||
table.setStorageAddress(tableNames.get(tn));
|
||||
}
|
||||
else {
|
||||
table.setStorageAddress(RomAttributeParser
|
||||
.parseHexString(unmarshallAttribute(tableNode,
|
||||
"storageaddress",
|
||||
String.valueOf(table.getStorageAddress()))));
|
||||
}
|
||||
table.setDescription(unmarshallAttribute(tableNode, "description",
|
||||
table.getDescription()));
|
||||
table.setDataSize(unmarshallAttribute(tableNode, "sizey",
|
||||
|
@ -626,11 +629,49 @@ public final class DOMRomUnmarshaller {
|
|||
scale.setFineIncrement(unmarshallAttribute(scaleNode, "fineincrement",
|
||||
scale.getFineIncrement()));
|
||||
for (Scale s : scales) {
|
||||
if (s.equals(scale)) {
|
||||
return s;
|
||||
}
|
||||
if (s.equals(scale)) {
|
||||
return s;
|
||||
}
|
||||
}
|
||||
scales.add(scale);
|
||||
return scale;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a list of table names to be used as a filter on the inherited
|
||||
* tables to reduce unnecessary table object creation.
|
||||
* @param nodes - the NodeList to filter
|
||||
* @throws XMLParseException
|
||||
* @throws TableIsOmittedException
|
||||
* @throws Exception
|
||||
*/
|
||||
private void filterFoundRomTables (NodeList nodes) {
|
||||
Node n;
|
||||
|
||||
for (int i = 0; i < nodes.getLength(); i++) {
|
||||
n = nodes.item(i);
|
||||
if (n.getNodeType() == ELEMENT_NODE
|
||||
&& n.getNodeName().equalsIgnoreCase("table")) {
|
||||
|
||||
final String name = unmarshallAttribute(n, "name", "unknown");
|
||||
final int address = RomAttributeParser
|
||||
.parseHexString(unmarshallAttribute(n,
|
||||
"storageaddress", "-1"));
|
||||
|
||||
if (unmarshallAttribute(n, "omit", "false").equalsIgnoreCase(
|
||||
"true")) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!tableNames.containsKey(name) && address > 0) {
|
||||
tableNames.put(name, address);
|
||||
}
|
||||
else if (tableNames.containsKey(name)) {
|
||||
if (tableNames.get(name) < 1 && address > 0) {
|
||||
tableNames.put(name, address);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue