3
0
Mirror von https://github.com/ViaVersion/ViaVersion.git synchronisiert 2024-11-20 06:50:08 +01:00

Update TODO list, add pipeline cache

Dieser Commit ist enthalten in:
Myles 2016-03-23 14:00:48 +00:00
Ursprung 95ceabb495
Commit 0376602894
3 geänderte Dateien mit 20 neuen und 13 gelöschten Zeilen

Datei anzeigen

@ -3,16 +3,8 @@
This is an experimental branch, but soon to be live. This is an experimental branch, but soon to be live.
(The only issues would be really really complex protocol pipelines...)
The things which stop this from going live: (But I don't see them happening any time soon)
Need to implement debug mode using deprecated PacketType for english
and then javadocs.
It would be nice to have a Pipeline cache so it doesn't have to figure it out all the time.
(and to ensure it uses the shortest pipeline)
License: License:
-------- --------

Datei anzeigen

@ -6,7 +6,7 @@
<groupId>us.myles</groupId> <groupId>us.myles</groupId>
<artifactId>viaversion</artifactId> <artifactId>viaversion</artifactId>
<version>0.6.8-SNAPSHOT</version> <version>0.7.0-ALPHA</version>
<packaging>jar</packaging> <packaging>jar</packaging>
<name>ViaVersion</name> <name>ViaVersion</name>

Datei anzeigen

@ -10,6 +10,7 @@ public class ProtocolRegistry {
public static int SERVER_PROTOCOL = -1; public static int SERVER_PROTOCOL = -1;
// Input Version -> Output Version & Protocol (Allows fast lookup) // Input Version -> Output Version & Protocol (Allows fast lookup)
private static Map<Integer, Map<Integer, Protocol>> registryMap = new HashMap<>(); private static Map<Integer, Map<Integer, Protocol>> registryMap = new HashMap<>();
private static Map<Pair<Integer, Integer>, List<Pair<Integer, Protocol>>> pathCache = new HashMap<>();
static { static {
// Register built in protocols // Register built in protocols
@ -25,6 +26,10 @@ public class ProtocolRegistry {
* @param output The output server version it converts to. * @param output The output server version it converts to.
*/ */
public static void registerProtocol(Protocol protocol, List<Integer> supported, Integer output) { public static void registerProtocol(Protocol protocol, List<Integer> supported, Integer output) {
// Clear cache as this may make new routes.
if (pathCache.size() > 0)
pathCache.clear();
for (Integer version : supported) { for (Integer version : supported) {
if (!registryMap.containsKey(version)) { if (!registryMap.containsKey(version)) {
registryMap.put(version, new HashMap<Integer, Protocol>()); registryMap.put(version, new HashMap<Integer, Protocol>());
@ -97,7 +102,17 @@ public class ProtocolRegistry {
* @return The path it generated, null if it failed. * @return The path it generated, null if it failed.
*/ */
public static List<Pair<Integer, Protocol>> getProtocolPath(int clientVersion, int serverVersion) { public static List<Pair<Integer, Protocol>> getProtocolPath(int clientVersion, int serverVersion) {
// TODO: Cache Pair<Integer, Integer> protocolKey = new Pair<>(clientVersion, serverVersion);
return getProtocolPath(new ArrayList<Pair<Integer, Protocol>>(), clientVersion, serverVersion); // Check cache
if (pathCache.containsKey(protocolKey)) {
return pathCache.get(protocolKey);
}
// Generate path
List<Pair<Integer, Protocol>> outputPath = getProtocolPath(new ArrayList<Pair<Integer, Protocol>>(), clientVersion, serverVersion);
// If it found a path, cache it.
if (outputPath != null) {
pathCache.put(protocolKey, outputPath);
}
return outputPath;
} }
} }