Mirror von
https://github.com/ViaVersion/ViaVersion.git
synchronisiert 2024-11-03 14:50:30 +01:00
Cache identifiers files
Dieser Commit ist enthalten in:
Ursprung
b3825e637e
Commit
3ced95903a
@ -74,6 +74,7 @@ public class Int2IntMapBiMappings implements BiMappings {
|
|||||||
@Override
|
@Override
|
||||||
public Mappings createInverse() {
|
public Mappings createInverse() {
|
||||||
final Int2IntBiMap inverseCopy = new Int2IntBiHashMap(inverse.mappings.size());
|
final Int2IntBiMap inverseCopy = new Int2IntBiHashMap(inverse.mappings.size());
|
||||||
|
inverseCopy.defaultReturnValue(-1);
|
||||||
for (final Int2IntMap.Entry entry : inverse.mappings.int2IntEntrySet()) {
|
for (final Int2IntMap.Entry entry : inverse.mappings.int2IntEntrySet()) {
|
||||||
inverseCopy.put(entry.getIntKey(), entry.getIntValue());
|
inverseCopy.put(entry.getIntKey(), entry.getIntValue());
|
||||||
}
|
}
|
||||||
|
@ -66,6 +66,7 @@ public class Int2IntMapMappings implements Mappings {
|
|||||||
@Override
|
@Override
|
||||||
public Mappings createInverse() {
|
public Mappings createInverse() {
|
||||||
final Int2IntMap inverse = new Int2IntOpenHashMap();
|
final Int2IntMap inverse = new Int2IntOpenHashMap();
|
||||||
|
inverse.defaultReturnValue(-1);
|
||||||
for (final Int2IntMap.Entry entry : mappings.int2IntEntrySet()) {
|
for (final Int2IntMap.Entry entry : mappings.int2IntEntrySet()) {
|
||||||
inverse.put(entry.getIntValue(), entry.getIntKey());
|
inverse.put(entry.getIntValue(), entry.getIntKey());
|
||||||
}
|
}
|
||||||
|
@ -67,7 +67,9 @@ public class IntArrayMappings implements Mappings {
|
|||||||
Arrays.fill(inverse, -1);
|
Arrays.fill(inverse, -1);
|
||||||
for (int id = 0; id < mappings.length; id++) {
|
for (int id = 0; id < mappings.length; id++) {
|
||||||
final int mappedId = mappings[id];
|
final int mappedId = mappings[id];
|
||||||
inverse[mappedId] = id;
|
if (mappedId != -1) {
|
||||||
|
inverse[mappedId] = id;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return of(inverse, mappings.length);
|
return of(inverse, mappings.length);
|
||||||
}
|
}
|
||||||
|
@ -75,9 +75,8 @@ public class MappingDataBase implements MappingData {
|
|||||||
paintingMappings = loadMappings(data, "paintings");
|
paintingMappings = loadMappings(data, "paintings");
|
||||||
itemMappings = loadBiMappings(data, "items");
|
itemMappings = loadBiMappings(data, "items");
|
||||||
|
|
||||||
// TODO Don't load one file multiple times
|
final CompoundTag unmappedIdentifierData = MappingDataLoader.loadNBT("identifiers-" + unmappedVersion + ".nbt", true);
|
||||||
final CompoundTag unmappedIdentifierData = MappingDataLoader.loadNBT("identifiers-" + unmappedVersion + ".nbt");
|
final CompoundTag mappedIdentifierData = MappingDataLoader.loadNBT("identifiers-" + mappedVersion + ".nbt", true);
|
||||||
final CompoundTag mappedIdentifierData = MappingDataLoader.loadNBT("identifiers-" + mappedVersion + ".nbt");
|
|
||||||
if (unmappedIdentifierData != null && mappedIdentifierData != null) {
|
if (unmappedIdentifierData != null && mappedIdentifierData != null) {
|
||||||
entityMappings = loadFullMappings(data, unmappedIdentifierData, mappedIdentifierData, "entities");
|
entityMappings = loadFullMappings(data, unmappedIdentifierData, mappedIdentifierData, "entities");
|
||||||
argumentTypeMappings = loadFullMappings(data, unmappedIdentifierData, mappedIdentifierData, "argumenttypes");
|
argumentTypeMappings = loadFullMappings(data, unmappedIdentifierData, mappedIdentifierData, "argumenttypes");
|
||||||
|
@ -44,6 +44,7 @@ import java.io.IOException;
|
|||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.io.InputStreamReader;
|
import java.io.InputStreamReader;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||||
@ -54,9 +55,17 @@ public final class MappingDataLoader {
|
|||||||
private static final byte SHIFTS_ID = 1;
|
private static final byte SHIFTS_ID = 1;
|
||||||
private static final byte CHANGES_ID = 2;
|
private static final byte CHANGES_ID = 2;
|
||||||
private static final byte IDENTITY_ID = 3;
|
private static final byte IDENTITY_ID = 3;
|
||||||
|
private static final Map<String, CompoundTag> MAPPINGS_CACHE = new HashMap<>();
|
||||||
|
private static boolean cacheValid = true;
|
||||||
|
|
||||||
|
@Deprecated/*(forRemoval = true)*/
|
||||||
public static void enableMappingsCache() {
|
public static void enableMappingsCache() {
|
||||||
//TODO
|
// Always enabled
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void clearCache() {
|
||||||
|
MAPPINGS_CACHE.clear();
|
||||||
|
cacheValid = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -100,7 +109,29 @@ public final class MappingDataLoader {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static @Nullable CompoundTag loadNBT(final String name, final boolean cache) {
|
||||||
|
if (!cacheValid) {
|
||||||
|
return loadNBTFromFile(name);
|
||||||
|
}
|
||||||
|
|
||||||
|
CompoundTag data = MAPPINGS_CACHE.get(name);
|
||||||
|
if (data != null) {
|
||||||
|
return data;
|
||||||
|
}
|
||||||
|
|
||||||
|
data = loadNBTFromFile(name);
|
||||||
|
|
||||||
|
if (cache && data != null) {
|
||||||
|
MAPPINGS_CACHE.put(name, data);
|
||||||
|
}
|
||||||
|
return data;
|
||||||
|
}
|
||||||
|
|
||||||
public static @Nullable CompoundTag loadNBT(final String name) {
|
public static @Nullable CompoundTag loadNBT(final String name) {
|
||||||
|
return loadNBT(name, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static @Nullable CompoundTag loadNBTFromFile(final String name) {
|
||||||
final InputStream resource = getResource(name);
|
final InputStream resource = getResource(name);
|
||||||
if (resource == null) {
|
if (resource == null) {
|
||||||
return null;
|
return null;
|
||||||
|
@ -23,6 +23,7 @@ import com.google.common.collect.Range;
|
|||||||
import com.google.common.util.concurrent.ThreadFactoryBuilder;
|
import com.google.common.util.concurrent.ThreadFactoryBuilder;
|
||||||
import com.viaversion.viaversion.api.Via;
|
import com.viaversion.viaversion.api.Via;
|
||||||
import com.viaversion.viaversion.api.connection.UserConnection;
|
import com.viaversion.viaversion.api.connection.UserConnection;
|
||||||
|
import com.viaversion.viaversion.api.data.MappingDataLoader;
|
||||||
import com.viaversion.viaversion.api.protocol.Protocol;
|
import com.viaversion.viaversion.api.protocol.Protocol;
|
||||||
import com.viaversion.viaversion.api.protocol.ProtocolManager;
|
import com.viaversion.viaversion.api.protocol.ProtocolManager;
|
||||||
import com.viaversion.viaversion.api.protocol.ProtocolPathEntry;
|
import com.viaversion.viaversion.api.protocol.ProtocolPathEntry;
|
||||||
@ -517,6 +518,9 @@ public class ProtocolManagerImpl implements ProtocolManager {
|
|||||||
mappingLoaderExecutor = null;
|
mappingLoaderExecutor = null;
|
||||||
mappingLoaderFutures.clear();
|
mappingLoaderFutures.clear();
|
||||||
mappingLoaderFutures = null;
|
mappingLoaderFutures = null;
|
||||||
|
|
||||||
|
// Clear cached mapping files
|
||||||
|
MappingDataLoader.clearCache();
|
||||||
}
|
}
|
||||||
|
|
||||||
private Function<Throwable, Void> mappingLoaderThrowable(Class<? extends Protocol> protocolClass) {
|
private Function<Throwable, Void> mappingLoaderThrowable(Class<? extends Protocol> protocolClass) {
|
||||||
|
Binäre Datei nicht angezeigt.
Binäre Datei nicht angezeigt.
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren