Fix war format speed regression with metadata

Found you could still get the raw data value by converting to an ItemStack, so I am using that now to reduce the lag caused by reading the serialized form of the metadata class.
This commit is contained in:
cmastudios 2013-10-12 21:58:38 -05:00
parent ac12c2af29
commit f44c2528e7
2 changed files with 12 additions and 25 deletions

View File

@ -85,14 +85,9 @@ public class VolumeMapper {
while (query.next()) { while (query.next()) {
int x = query.getInt("x"), y = query.getInt("y"), z = query.getInt("z"); int x = query.getInt("x"), y = query.getInt("y"), z = query.getInt("z");
BlockState modify = corner1.getRelative(x, y, z).getState(); BlockState modify = corner1.getRelative(x, y, z).getState();
modify.setType(Material.valueOf(query.getString("type"))); ItemStack data = new ItemStack(Material.valueOf(query.getString("type")), 0, query.getShort("data"));
YamlConfiguration data = new YamlConfiguration(); modify.setType(data.getType());
try { modify.setData(data.getData());
data.loadFromString(query.getString("data"));
modify.setData(data.getItemStack("data").getData());
} catch (InvalidConfigurationException e) {
War.war.getLogger().log(Level.WARNING, "Exception loading some material data", e);
}
volume.getBlocks().add(modify); volume.getBlocks().add(modify);
} }
query.close(); query.close();
@ -194,7 +189,7 @@ public class VolumeMapper {
.getConnection("jdbc:sqlite:" + databaseFile.getPath()); .getConnection("jdbc:sqlite:" + databaseFile.getPath());
Statement stmt = databaseConnection.createStatement(); Statement stmt = databaseConnection.createStatement();
stmt.executeUpdate("PRAGMA user_version = " + DATABASE_VERSION); stmt.executeUpdate("PRAGMA user_version = " + DATABASE_VERSION);
stmt.executeUpdate("CREATE TABLE IF NOT EXISTS blocks (x BIGINT, y BIGINT, z BIGINT, type TEXT, data BLOB)"); stmt.executeUpdate("CREATE TABLE IF NOT EXISTS blocks (x BIGINT, y BIGINT, z BIGINT, type TEXT, data SMALLINT)");
stmt.executeUpdate("CREATE TABLE IF NOT EXISTS corners (pos INTEGER PRIMARY KEY NOT NULL UNIQUE, x INTEGER NOT NULL, y INTEGER NOT NULL, z INTEGER NOT NULL)"); stmt.executeUpdate("CREATE TABLE IF NOT EXISTS corners (pos INTEGER PRIMARY KEY NOT NULL UNIQUE, x INTEGER NOT NULL, y INTEGER NOT NULL, z INTEGER NOT NULL)");
stmt.executeUpdate("DELETE FROM blocks"); stmt.executeUpdate("DELETE FROM blocks");
stmt.executeUpdate("DELETE FROM corners"); stmt.executeUpdate("DELETE FROM corners");
@ -221,9 +216,7 @@ public class VolumeMapper {
dataStmt.setInt(2, relLoc.getBlockY()); dataStmt.setInt(2, relLoc.getBlockY());
dataStmt.setInt(3, relLoc.getBlockZ()); dataStmt.setInt(3, relLoc.getBlockZ());
dataStmt.setString(4, block.getType().toString()); dataStmt.setString(4, block.getType().toString());
YamlConfiguration data = new YamlConfiguration(); dataStmt.setShort(5, block.getData().toItemStack().getDurability());
data.set("data", block.getData().toItemStack());
dataStmt.setString(5, data.saveToString());
dataStmt.addBatch(); dataStmt.addBatch();
if (++changed % batchSize == 0) { if (++changed % batchSize == 0) {
dataStmt.executeBatch(); dataStmt.executeBatch();
@ -335,7 +328,8 @@ public class VolumeMapper {
} }
public static void delete(Volume volume) { public static void delete(Volume volume) {
File volFile = new File("War/dat/volume-" + volume.getName()); File volFile = new File(War.war.getDataFolder(), String.format(
"/dat/volume-%s.sl3", volume.getName()));
boolean deletedData = volFile.delete(); boolean deletedData = volFile.delete();
if (!deletedData) { if (!deletedData) {
War.war.log("Failed to delete file " + volFile.getName(), Level.WARNING); War.war.log("Failed to delete file " + volFile.getName(), Level.WARNING);

View File

@ -105,14 +105,9 @@ public class ZoneVolumeMapper {
while (query.next()) { while (query.next()) {
int x = query.getInt("x"), y = query.getInt("y"), z = query.getInt("z"); int x = query.getInt("x"), y = query.getInt("y"), z = query.getInt("z");
BlockState modify = corner1.getRelative(x, y, z).getState(); BlockState modify = corner1.getRelative(x, y, z).getState();
modify.setType(Material.valueOf(query.getString("type"))); ItemStack data = new ItemStack(Material.valueOf(query.getString("type")), 0, query.getShort("data"));
YamlConfiguration data = new YamlConfiguration(); modify.setType(data.getType());
try { modify.setData(data.getData());
data.loadFromString(query.getString("data"));
modify.setData(data.getItemStack("data").getData());
} catch (InvalidConfigurationException e) {
War.war.getLogger().log(Level.WARNING, "Exception loading some material data", e);
}
modify.update(true, false); // No-physics update, preventing the need for deferring blocks modify.update(true, false); // No-physics update, preventing the need for deferring blocks
modify = corner1.getRelative(x, y, z).getState(); // Grab a new instance modify = corner1.getRelative(x, y, z).getState(); // Grab a new instance
try { try {
@ -182,7 +177,7 @@ public class ZoneVolumeMapper {
Connection databaseConnection = DriverManager.getConnection("jdbc:sqlite:" + databaseFile.getPath()); Connection databaseConnection = DriverManager.getConnection("jdbc:sqlite:" + databaseFile.getPath());
Statement stmt = databaseConnection.createStatement(); Statement stmt = databaseConnection.createStatement();
stmt.executeUpdate("PRAGMA user_version = " + DATABASE_VERSION); stmt.executeUpdate("PRAGMA user_version = " + DATABASE_VERSION);
stmt.executeUpdate("CREATE TABLE IF NOT EXISTS blocks (x BIGINT, y BIGINT, z BIGINT, type TEXT, data BLOB, sign TEXT, container BLOB, note INT, record TEXT, skull TEXT, command TEXT, mobid TEXT)"); stmt.executeUpdate("CREATE TABLE IF NOT EXISTS blocks (x BIGINT, y BIGINT, z BIGINT, type TEXT, data SMALLINT, sign TEXT, container BLOB, note INT, record TEXT, skull TEXT, command TEXT, mobid TEXT)");
stmt.executeUpdate("CREATE TABLE IF NOT EXISTS corners (pos INTEGER PRIMARY KEY NOT NULL UNIQUE, x INTEGER NOT NULL, y INTEGER NOT NULL, z INTEGER NOT NULL)"); stmt.executeUpdate("CREATE TABLE IF NOT EXISTS corners (pos INTEGER PRIMARY KEY NOT NULL UNIQUE, x INTEGER NOT NULL, y INTEGER NOT NULL, z INTEGER NOT NULL)");
stmt.executeUpdate("DELETE FROM blocks"); stmt.executeUpdate("DELETE FROM blocks");
stmt.executeUpdate("DELETE FROM corners"); stmt.executeUpdate("DELETE FROM corners");
@ -208,9 +203,7 @@ public class ZoneVolumeMapper {
dataStmt.setInt(2, relLoc.getBlockY()); dataStmt.setInt(2, relLoc.getBlockY());
dataStmt.setInt(3, relLoc.getBlockZ()); dataStmt.setInt(3, relLoc.getBlockZ());
dataStmt.setString(4, block.getType().toString()); dataStmt.setString(4, block.getType().toString());
YamlConfiguration data = new YamlConfiguration(); dataStmt.setShort(5, block.getState().getData().toItemStack().getDurability());
data.set("data", block.getState().getData().toItemStack());
dataStmt.setString(5, data.saveToString());
if (block.getState() instanceof Sign) { if (block.getState() instanceof Sign) {
final String signText = StringUtils.join(((Sign) block.getState()).getLines(), "\n"); final String signText = StringUtils.join(((Sign) block.getState()).getLines(), "\n");
dataStmt.setString(6, signText); dataStmt.setString(6, signText);