3
0
Mirror von https://github.com/ViaVersion/ViaBackwards.git synchronisiert 2024-07-26 00:48:03 +02:00

Make mapping loading considerably faster

Dieser Commit ist enthalten in:
KennyTV 2020-09-09 11:00:31 +02:00
Ursprung c6d8a83ac9
Commit b1af6ad721
Es konnte kein GPG-Schlüssel zu dieser Signatur gefunden werden
GPG-Schlüssel-ID: 6BE3B555EBC5982B
3 geänderte Dateien mit 27 neuen und 75 gelöschten Zeilen

Datei anzeigen

@ -6,7 +6,7 @@ import us.myles.ViaVersion.api.data.MappingDataLoader;
import us.myles.ViaVersion.util.GsonUtil;
import us.myles.viaversion.libs.fastutil.ints.Int2ObjectMap;
import us.myles.viaversion.libs.fastutil.ints.Int2ObjectOpenHashMap;
import us.myles.viaversion.libs.gson.JsonArray;
import us.myles.viaversion.libs.fastutil.objects.Object2IntMap;
import us.myles.viaversion.libs.gson.JsonElement;
import us.myles.viaversion.libs.gson.JsonIOException;
import us.myles.viaversion.libs.gson.JsonObject;
@ -56,10 +56,11 @@ public class VBMappingDataLoader {
}
public static void mapIdentifiers(short[] output, JsonObject oldIdentifiers, JsonObject newIdentifiers, JsonObject diffIdentifiers, boolean warnOnMissing) {
Object2IntMap newIdentifierMap = MappingDataLoader.indexedObjectToMap(newIdentifiers);
for (Map.Entry<String, JsonElement> entry : oldIdentifiers.entrySet()) {
String key = entry.getValue().getAsString();
Map.Entry<String, JsonElement> value = MappingDataLoader.findValue(newIdentifiers, key);
if (value == null) {
int mappedId = newIdentifierMap.getInt(key);
if (mappedId == -1) {
if (diffIdentifiers != null) {
// Search in diff mappings
JsonPrimitive diffValueJson = diffIdentifiers.getAsJsonPrimitive(key);
@ -78,11 +79,11 @@ public class VBMappingDataLoader {
}
if (diffValue != null) {
value = MappingDataLoader.findValue(newIdentifiers, diffValue);
mappedId = newIdentifierMap.getInt(diffValue);
}
}
if (value == null) {
if (mappedId == -1) {
// Nothing found :(
if (warnOnMissing && !Via.getConfig().isSuppressConversionWarnings() || Via.getManager().isDebug()) {
ViaBackwards.getPlatform().getLogger().warning("No key for " + entry.getValue() + " :( ");
@ -91,39 +92,7 @@ public class VBMappingDataLoader {
}
}
output[Integer.parseInt(entry.getKey())] = Short.parseShort(value.getKey());
}
}
public static void mapIdentifiers(short[] output, JsonArray oldIdentifiers, JsonArray newIdentifiers, JsonObject diffIdentifiers, boolean warnOnMissing) {
int i = -1;
for (JsonElement oldIdentifier : oldIdentifiers) {
i++;
String key = oldIdentifier.getAsString();
Integer index = MappingDataLoader.findIndex(newIdentifiers, key);
if (index == null) {
// Search in diff mappings
if (diffIdentifiers != null) {
JsonPrimitive diffValue = diffIdentifiers.getAsJsonPrimitive(key);
if (diffValue == null) {
if (warnOnMissing && !Via.getConfig().isSuppressConversionWarnings() || Via.getManager().isDebug()) {
ViaBackwards.getPlatform().getLogger().warning("No diff key for " + key + " :( ");
}
continue;
}
String mappedName = diffValue.getAsString();
if (mappedName.isEmpty()) continue; // "empty" remaps
index = MappingDataLoader.findIndex(newIdentifiers, mappedName);
}
if (index == null) {
if (warnOnMissing && !Via.getConfig().isSuppressConversionWarnings() || Via.getManager().isDebug()) {
ViaBackwards.getPlatform().getLogger().warning("No key for " + key + " :( ");
}
continue;
}
}
output[i] = index.shortValue();
output[Integer.parseInt(entry.getKey())] = (short) mappedId;
}
}
@ -144,32 +113,32 @@ public class VBMappingDataLoader {
}
public static Int2ObjectMap<MappedItem> loadItemMappings(JsonObject oldMapping, JsonObject newMapping, JsonObject diffMapping) {
Map<Integer, MappedItem> itemMapping = new HashMap<>();
Int2ObjectMap<MappedItem> itemMapping = new Int2ObjectOpenHashMap<>(diffMapping.size(), 1F);
Object2IntMap newIdenfierMap = MappingDataLoader.indexedObjectToMap(newMapping);
Object2IntMap oldIdenfierMap = MappingDataLoader.indexedObjectToMap(oldMapping);
for (Map.Entry<String, JsonElement> entry : diffMapping.entrySet()) {
JsonObject object = entry.getValue().getAsJsonObject();
String mappedIdName = object.getAsJsonPrimitive("id").getAsString();
Map.Entry<String, JsonElement> value = MappingDataLoader.findValue(newMapping, mappedIdName);
if (value == null) {
int mappedId = newIdenfierMap.getInt(mappedIdName);
if (mappedId == -1) {
if (!Via.getConfig().isSuppressConversionWarnings() || Via.getManager().isDebug()) {
ViaBackwards.getPlatform().getLogger().warning("No key for " + mappedIdName + " :( ");
}
continue;
}
Map.Entry<String, JsonElement> oldEntry = MappingDataLoader.findValue(oldMapping, entry.getKey());
if (oldEntry == null) {
int oldId = oldIdenfierMap.getInt(entry.getKey());
if (oldId == -1) {
if (!Via.getConfig().isSuppressConversionWarnings() || Via.getManager().isDebug()) {
ViaBackwards.getPlatform().getLogger().warning("No old entry for " + mappedIdName + " :( ");
}
continue;
}
int id = Integer.parseInt(oldEntry.getKey());
int mappedId = Integer.parseInt(value.getKey());
String name = object.getAsJsonPrimitive("name").getAsString();
itemMapping.put(id, new MappedItem(mappedId, name));
itemMapping.put(oldId, new MappedItem(mappedId, name));
}
return new Int2ObjectOpenHashMap<>(itemMapping, 1F);
return itemMapping;
}
}

Datei anzeigen

@ -8,18 +8,6 @@ import java.util.Arrays;
public class VBMappings extends Mappings {
public VBMappings(JsonObject oldMapping, JsonObject newMapping, boolean warnOnMissing) {
this(oldMapping, newMapping, null, warnOnMissing);
}
public VBMappings(int size, JsonObject oldMapping, JsonObject newMapping, JsonObject diffMapping) {
this(size, oldMapping, newMapping, diffMapping, true);
}
public VBMappings(JsonObject oldMapping, JsonObject newMapping, JsonObject diffMapping) {
this(oldMapping, newMapping, diffMapping, true);
}
public VBMappings(int size, JsonObject oldMapping, JsonObject newMapping, JsonObject diffMapping, boolean warnOnMissing) {
super(create(size, oldMapping, newMapping, diffMapping, warnOnMissing));
}
@ -28,12 +16,12 @@ public class VBMappings extends Mappings {
super(create(oldMapping.entrySet().size(), oldMapping, newMapping, diffMapping, warnOnMissing));
}
public VBMappings(JsonArray oldMapping, JsonArray newMapping, JsonObject diffMapping) {
super(create(oldMapping, newMapping, diffMapping, true));
public VBMappings(JsonObject oldMapping, JsonObject newMapping, boolean warnOnMissing) {
this(oldMapping, newMapping, null, warnOnMissing);
}
public VBMappings(JsonArray oldMapping, JsonArray newMapping, JsonObject diffMapping, boolean warnOnMissing) {
super(create(oldMapping, newMapping, diffMapping, warnOnMissing));
super(oldMapping.size(), oldMapping, newMapping, diffMapping, warnOnMissing);
}
private static short[] create(int size, JsonObject oldMapping, JsonObject newMapping, JsonObject diffMapping, boolean warnOnMissing) {
@ -42,11 +30,4 @@ public class VBMappings extends Mappings {
VBMappingDataLoader.mapIdentifiers(oldToNew, oldMapping, newMapping, diffMapping, warnOnMissing);
return oldToNew;
}
private static short[] create(JsonArray oldMapping, JsonArray newMapping, JsonObject diffMapping, boolean warnOnMissing) {
short[] oldToNew = new short[oldMapping.size()];
Arrays.fill(oldToNew, (short) -1);
VBMappingDataLoader.mapIdentifiers(oldToNew, oldMapping, newMapping, diffMapping, warnOnMissing);
return oldToNew;
}
}

Datei anzeigen

@ -20,6 +20,7 @@ import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.Protocol1_13To1_12_2;
import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.data.StatisticMappings;
import us.myles.viaversion.libs.fastutil.ints.Int2ObjectMap;
import us.myles.viaversion.libs.fastutil.ints.Int2ObjectOpenHashMap;
import us.myles.viaversion.libs.fastutil.objects.Object2IntMap;
import us.myles.viaversion.libs.gson.JsonElement;
import us.myles.viaversion.libs.gson.JsonObject;
import us.myles.viaversion.libs.gson.JsonPrimitive;
@ -50,11 +51,12 @@ public class BackwardsMappings extends nl.matsv.viabackwards.api.data.BackwardsM
// Has lots of compat layers, so we can't use the default Via method
private static void mapIdentifiers(short[] output, JsonObject newIdentifiers, JsonObject oldIdentifiers, JsonObject mapping) {
Object2IntMap newIdentifierMap = MappingDataLoader.indexedObjectToMap(oldIdentifiers);
for (Map.Entry<String, JsonElement> entry : newIdentifiers.entrySet()) {
String key = entry.getValue().getAsString();
Map.Entry<String, JsonElement> value = MappingDataLoader.findValue(oldIdentifiers, key);
int value = newIdentifierMap.getInt(key);
short hardId = -1;
if (value == null) {
if (value == -1) {
JsonPrimitive replacement = mapping.getAsJsonPrimitive(key);
int propertyIndex;
if (replacement == null && (propertyIndex = key.indexOf('[')) != -1) {
@ -64,12 +66,12 @@ public class BackwardsMappings extends nl.matsv.viabackwards.api.data.BackwardsM
if (replacement.getAsString().startsWith("id:")) {
String id = replacement.getAsString().replace("id:", "");
hardId = Short.parseShort(id);
value = MappingDataLoader.findValue(oldIdentifiers, oldIdentifiers.getAsJsonPrimitive(id).getAsString());
value = newIdentifierMap.getInt(oldIdentifiers.getAsJsonPrimitive(id).getAsString());
} else {
value = MappingDataLoader.findValue(oldIdentifiers, replacement.getAsString());
value = newIdentifierMap.getInt(replacement.getAsString());
}
}
if (value == null) {
if (value == -1) {
if (!Via.getConfig().isSuppressConversionWarnings() || Via.getManager().isDebug()) {
if (replacement != null) {
ViaBackwards.getPlatform().getLogger().warning("No key for " + entry.getValue() + "/" + replacement.getAsString() + " :( ");
@ -80,7 +82,7 @@ public class BackwardsMappings extends nl.matsv.viabackwards.api.data.BackwardsM
continue;
}
}
output[Integer.parseInt(entry.getKey())] = hardId != -1 ? hardId : Short.parseShort(value.getKey());
output[Integer.parseInt(entry.getKey())] = hardId != -1 ? hardId : (short) value;
}
}